Click here to Skip to main content
14,024,123 members
Click here to Skip to main content
Articles » Database » NoSQL » General » Downloads

Stats

210.9K views
2.6K downloads
111 bookmarked
Posted 20 Apr 2010
Licenced CPOL

RavenDB - An Introduction

, , 28 Apr 2010
An introduction to RavenDB - a new open source .NET document database using .NET 4.0 and VS 2010
RavenDB
.gitignore
ayende-open-source.snk
build
Raven.Client.Tests
Document
Properties
Shard
Transactions
Raven.Client
Client
Document
Properties
Shard
ShardStrategy
ShardAccess
ShardResolution
ShardSelection
Util
Raven.Database
Data
Defaults
Exceptions
Extensions
Indexing
Json
Linq
PrivateExtensions
Properties
Storage
Tasks
Raven.FileStorage
Properties
Raven.Importer
Properties
Raven.Sample.ShardClient
Properties
Raven.Sample.SimpleClient
Properties
Raven.Scenarios
Properties
Scenarios
AddDocument_AddIndex_QueryIndexForDoc.saz
AfterTooManyErrorsDocumentIndexingForTheIndexWillBeDisabled.saz
AfterTooManyErrorsIndexWillBeDisabled.saz
BatchAndGetDocuments.saz
BatchQueryById.saz
BrowseIndex.saz
CanGenerateIdentityValues.saz
CanGetMetadataWhenLookingAtAllDocs.saz
CanGetMetadataWhenLookingAtAnIndex.saz
CannotDeleteStaticWithoutAccruateETag.saz
CanPutAndDeleteDocumentWithETag.saz
CanUseCollectionNamesInIndexes.saz
DeleteStatic.saz
DeletingDocumentThatDoesNotExistsAlwaysWorks.saz
DeletingWithBadETagWillFail.saz
IndexingErrorsWillShowUpInTheStats.saz
IndexingFunctionWithMultipleResultsPerSourceDocument.saz
PatchDocument.saz
PutAndGetAttachment.saz
PutAndGetDocument.saz
PutAndGetDocumentWithMetadataViaHeaders.saz
PutAndGetIndex.saz
PuttingDocumentUsingTransaction.saz
QueryMapReduceIndex.saz
QueryUsingIndex.saz
RecordHeadersForStatics.saz
SelectFieldsFromIndex.saz
TryingToUpdateAttachmentWithBadETagWillFail.saz
TryingToUpdateDocumentWithBadETagWillFail.saz
TryingToUpdateDocumentWithNonGuidETagWillFail.saz
UpdateAttachemtnUsingETag.saz
UpdatingDocsWillUpdateMapReduceResult.saz
WhenDeletingDocsWillUpdateMapReduceIndex.saz
WillDeleteDocumentFromIndex.saz
WillSupport304.saz
WillSupport304ForAttachments.saz
Raven.Server
Defaults
PowerShellProvider
Properties
Responders
WebUI
css
smoothness
images
ui-bg_flat_0_aaaaaa_40x100.png
ui-bg_flat_75_ffffff_40x100.png
ui-bg_glass_55_fbf9ee_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_glass_75_dadada_1x400.png
ui-bg_glass_75_e6e6e6_1x400.png
ui-bg_glass_95_fef1ec_1x400.png
ui-bg_highlight-soft_75_cccccc_1x100.png
ui-icons_222222_256x240.png
ui-icons_2e83ff_256x240.png
ui-icons_454545_256x240.png
ui-icons_888888_256x240.png
ui-icons_cd0a0a_256x240.png
favicon.ico
images
ajax-loader.gif
bgR.png
c1_i1.png
c2_i2.png
c2_i3.png
c2_i4.png
c2_i5.png
c2_i6.png
c3_i7.png
footer_bg.png
footerContainerBgR.png
header_bg.png
jsonEditor
doc.gif
docNode.gif
docNodeLast.gif
docNodeLastFirst.gif
folder.gif
folderNode.gif
folderNodeFirst.gif
folderNodeLast.gif
folderNodeLastFirst.gif
folderNodeOpen.gif
folderNodeOpenFirst.gif
folderNodeOpenLast.gif
folderNodeOpenLastFirst.gif
folderOpen.gif
vertLine.gif
logo.png
midBox1.png
midBox2Arrow.png
sideBarArrow.png
sideBarListBoxBottom.png
sideBarListBoxTop.png
submit.png
topNavSep.png
js
jstree
themes
default
dot_for_ie.gif
icons.png
throbber.gif
icons
txt.png
rdb.jsonEditor
JSONTemplates
Raven.Tests
Indexes
Linq
Patching
Properties
Storage
Transactions
Views
Raven.Tryouts
Properties
RavenDB.suo
Release
SharedLibs
Esent.Interop.dll
Esent.Interop.pdb
Esent.Interop.XML
ICSharpCode.NRefactory.dll
ICSharpCode.SharpZipLib.dll
log4net.dll
Lucene.Net.dll
Lucene.Net.pdb
Newtonsoft.Json.dll
Newtonsoft.Json.XML
Rhino.Mocks.dll
SgmlReaderDll.dll
SgmlReaderDll.pdb
System.Management.Automation.dll
xunit.dll
xunit.extensions.dll
Tools
ILMerge.exe
xUnit
xunit.console.exe
xunit.dll
xunit.extensions.dll
xunit.gui.exe
xunit.installer.exe
XUnit.NAntTasks.dll
xunit.runner.msbuild.dll
xunit.runner.resharper.dll
xunit.runner.tdnet.dll
xunit.runner.utility.dll
zip.exe
Utilities
Binaries
ILMerge.exe
Newtonsoft.Json.dll
Raven.DefaultDatabase.Creator.exe
Raven.DefaultDatabase.Creator.pdb
Raven.Merger.exe
Raven.Merger.pdb
SgmlReaderDll.dll
SgmlReaderDll.pdb
Raven.DefaultDatabase.Creator
Properties
Raven.Merger
Properties
# psake v0.22
# Copyright � 2009 James Kovacs
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

param(
  [string]$buildFile = 'default.ps1',
  [string[]]$taskList = @(),
  [string]$framework = '3.5',
  [switch]$debug = $false,
  [switch]$help  = $false,
  [switch]$timing = $false,
  [switch]$docs = $false
)

if($help) {
@"
psake [buildFile] [tasks] [-framework ver] [-debug] [-timing] [-docs]
  where buildFile is the name of the build file, (default: default.ps1)
        tasks is a list of tasks to execute from the build file,
        ver is the .NET Framework version to target - 1.0, 1.1, 2.0, 3.0, or 3.5 (default)
        debug dumps information on the properties, includes, and tasks, as well as more detailed error information.
        timing prints a report showing how long each task took to execute
        docs prints a list of available tasks

psake -help
  Displays this message.
"@
  return
}

$global:tasks = @{}
$global:properties = @()
$global:includes = New-Object System.Collections.Queue
$global:psake_version = "0.22"
$global:psake_buildScript = $buildFile
$global:psake_frameworkVersion = $framework

$script:executedTasks = New-Object System.Collections.Stack
$script:callStack = New-Object System.Collections.Stack
$script:originalEnvPath = $env:path
$script:originalDirectory = Get-Location
$originalErrorActionPreference = $Global:ErrorActionPreference

function task([string]$name=$null, [scriptblock]$action = $null, [scriptblock]$precondition = $null, [scriptblock]$postcondition = $null, [switch]$continueOnError = $false, [string[]]$depends = @(), [string]$description = $null) {
  if (($name -eq $null) -or ($name.Trim() -eq "")) {
	  throw "Error: Task must have a name"	
  }
  if($name.ToLower() -eq 'default' -and $action -ne $null) {
    throw "Error: Default task cannot specify an action"
  }
  $newTask = @{
    Name = $name
    DependsOn = $depends
    Action = $action
    Precondition = $precondition
    Postcondition = $postcondition
    ContinueOnError = $continueOnError
    Description = $description
  }
  if($global:tasks.$name -ne $null) { throw "Error: Task, $name, has already been defined." }
  $global:tasks.$name = $newTask
}

function properties([scriptblock]$propertyBlock) {
  $global:properties += $propertyBlock
}

function include([string]$include){
  if (!(test-path $include)) { throw "Error: $include not found."} 	
  $global:includes.Enqueue((Resolve-Path $include));
}

function AssertNotCircular([string]$name) {
  if($script:callStack.Contains($name)) {
    throw "Error: Circular reference found for task, $name"
  }
}

function ExecuteTask([string]$name) {
  if($script:executedTasks.Contains($name)) { return }
  AssertNotCircular $name
  $script:callStack.Push($name)
  
  $task = $global:tasks.$name
  foreach($childTask in $task.DependsOn) {
    ExecuteTask $childTask
  }
  if($name -ne 'default') {
    $stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
    $precondition = $true
    if($task.Precondition -ne $null) {
      $precondition = (& $task.Precondition)
    }
    "Executing task, $name..."
    if($task.Action -ne $null) {
      if($precondition) {
        trap {
          if ($task.ContinueOnError) {
			"-"*70
            "Error in Task [$name] $_"
			"-"*70
            continue
          } else {
            throw $_
          }
        }                
        & $task.Action
        $postcondition = $true
        if($task.Postcondition -ne $null) {
          $postcondition = (& $task.Postcondition)
        }
        if (!$postcondition) {
          throw "Error: Postcondition failed for $name"
        }
      } else {
        "Precondition was false not executing $name"
      }
    }    
    $stopwatch.stop()
    $task.Duration = $stopwatch.Elapsed
  }

  $poppedTask = $script:callStack.Pop()
  if($poppedTask -ne $name) {
    throw "Error: CallStack was corrupt. Expected $name, but got $poppedTask."
  }
  $script:executedTasks.Push($name)
}

function Dump-Tasks {
  'Dumping tasks:'
  foreach($key in $global:tasks.Keys) {
    $task = $global:tasks.$key;
    $task.Name + " depends on " + $task.DependsOn.Length + " other tasks: " + $task.DependsOn;
  }
  "`n"
}

function Dump-Properties {
  'Dumping properties:'
  $global:properties
}

function Dump-Includes {
  'Dumping includes:'
  $global:includes
}

function Configure-BuildEnvironment {
  $version = $null
  switch ($framework) {
    '1.0' { $version = 'v1.0.3705'  }
    '1.1' { $version = 'v1.1.4322'  }
    '2.0' { $version = 'v2.0.50727' }
    '3.0' { $version = 'v2.0.50727' } # .NET 3.0 uses the .NET 2.0 compilers
    '3.5' { $version = 'v3.5'       }
    default { throw "Error: Unknown .NET Framework version, $framework" }
  }
  $frameworkDir = "$env:windir\Microsoft.NET\Framework\$version\"
  if(!(test-path $frameworkDir)) {
    throw "Error: No .NET Framework installation directory found at $frameworkDir"
  }
  $env:path = "$frameworkDir;$env:path"
  $global:ErrorActionPreference = "Stop"
}

function Cleanup-Environment {
  $env:path = $script:originalEnvPath	
  Set-Location $script:originalDirectory
  $global:ErrorActionPreference = $originalErrorActionPreference
  remove-variable tasks -scope "global" 
  remove-variable properties -scope "global"
  remove-variable includes -scope "global"
  remove-variable psake_* -scope "global"  
}

#borrowed from Jeffrey Snover http://blogs.msdn.com/powershell/archive/2006/12/07/resolve-error.aspx
function Resolve-Error($ErrorRecord=$Error[0]) {	
  $ErrorRecord | Format-List * -Force
  $ErrorRecord.InvocationInfo | Format-List *
  $Exception = $ErrorRecord.Exception
  for ($i = 0; $Exception; $i++, ($Exception = $Exception.InnerException)) {
    "$i" * 70
    $Exception | Format-List * -Force
  }
}

function Write-Documentation {
  $list = New-Object System.Collections.ArrayList
  foreach($key in $global:tasks.Keys) {
    if($key -eq "default") {
      continue;
    }
    $task = $global:tasks.$key;
    $content = "" | Select-Object Name, Description
    $content.Name = $task.Name        
    $content.Description = $task.Description
    $index = $list.Add($content);
  }
  
  $list | Sort 'Name' | Format-Table -Auto
}

function exec([string]$command, [string]$parameters) {    
    & $command $parameters
    if ($lastExitCode -ne 0) {
        throw "Error: Failed to execute ""$command"" with parameters ""$parameters"""
    }
}

function Run-Psake {
  trap {
    Cleanup-Environment
    Write-Host -foregroundcolor Red $_
    if($debug) {
      "-" * 80
      "An Error Occurred. See Error Details Below:"
      "-" * 80
      Resolve-Error
      "-" * 80
    }
    exit(1)
  }

  $stopwatch = [System.Diagnostics.Stopwatch]::StartNew()

  # Execute the build file to set up the tasks and defaults
  if(test-path $buildFile) {
    $buildFile = resolve-path $buildFile
    set-location (split-path $buildFile)
    & $buildFile
  } else {
    throw "Error: Could not find the build file, $buildFile."
  }

  if($debug) {
    Dump-Includes
    Dump-Properties
    Dump-Tasks
  }

  Configure-BuildEnvironment

  # N.B. The initial dot (.) indicates that variables initialized/modified
  #      in the propertyBlock are available in the parent scope.
  while ($global:includes.Count -gt 0) {
  	$includeBlock = $global:includes.Dequeue();
  	. $includeBlock;
  }
  foreach($propertyBlock in $global:properties) {
    . $propertyBlock
  }

  if($docs) {
    Write-Documentation
    Cleanup-Environment
    exit(0)
  }
  
  # Execute the list of tasks or the default task
  if($taskList.Length -ne 0) {
    foreach($task in $taskList) {
      ExecuteTask $task
    }
  } elseif ($global:tasks.default -ne $null) {
    ExecuteTask default
  } else {
    throw 'Error: default task required'
  }

  $stopwatch.Stop()

  if ($timing) {	
	"-"*70
    "Build Time Report"
	"-"*70	
	$list = @()
	while ($script:executedTasks.Count -gt 0) {
		$name = $script:executedTasks.Pop()
		$task = $global:tasks.$name
		if($name -eq "default") {
		  continue;
		}    
		$list += "" | Select-Object @{Name="Name";Expression={$name}}, @{Name="Duration";Expression={$task.Duration}}
	}
	[Array]::Reverse($list)
	$list += "" | Select-Object @{Name="Name";Expression={"Total:"}}, @{Name="Duration";Expression={$stopwatch.Elapsed}}
	$list | Format-Table -Auto | Out-String -Stream | ? {$_}  # using "Out-String -Stream" to filter out the blank line that Format-Table prepends 
  }

  # Clear out any global variables
  Cleanup-Environment
}

Run-Psake

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Authors

Paul B.
United States United States
I've been a software developer since 1996 and have enjoyed C# since 2003. I have a Bachelor's degree in Computer Science and for some reason, a Master's degree in Business Administration. I currently do software development contracting/consulting.

No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.190419.4 | Last Updated 28 Apr 2010
Article Copyright 2010 by Paul B., Ayende @ Rahien
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid