diff --git a/.gitignore b/.gitignore index e30ee6c..3ae1c36 100644 --- a/.gitignore +++ b/.gitignore @@ -1,28 +1,23 @@ -# Akka - -# Fake directories -src/.build/** - - - -#GitExtensions -us.stackdump - -#KDiff3 and other git merge tools -*.orig - -#------------------------------------------------------------------------------- -#Based on https://github.com/github/gitignore/blob/master/VisualStudio.gitignore +# Custom +tools/ +build/ +.nuget/ +.dotnet/ +.idea/ +.[Dd][Ss]_[Ss]tore ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore # User-specific files *.suo *.user +*.userosscache *.sln.docstates -#MonoDevelop +# User-specific files (MonoDevelop/Xamarin Studio) *.userprefs # Build results @@ -32,19 +27,28 @@ us.stackdump [Rr]eleases/ x64/ x86/ -build/ bld/ [Bb]in/ [Oo]bj/ +[Ll]og/ + +#FAKE +.fake +tools/ -# Roslyn cache directories -*.ide/ +#DocFx output +_site/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ # MSTest test Results [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* -#NUNIT +# NUNIT *.VisualState.xml TestResult.xml @@ -53,6 +57,12 @@ TestResult.xml [Rr]eleasePS/ dlldata.c +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ +**/Properties/launchSettings.json + *_i.c *_p.c *_i.h @@ -85,14 +95,18 @@ _Chutzpah* ipch/ *.aps *.ncb +*.opendb *.opensdf *.sdf *.cachefile +*.VC.db +*.VC.VC.opendb # Visual Studio profiler *.psess *.vsp *.vspx +*.sap # TFS 2012 Local Workspace $tf/ @@ -105,7 +119,7 @@ _ReSharper*/ *.[Rr]e[Ss]harper *.DotSettings.user -# JustCode is a .NET coding addin-in +# JustCode is a .NET coding add-in .JustCode # TeamCity is a build add-in @@ -114,9 +128,14 @@ _TeamCity* # DotCover is a Code Coverage Tool *.dotCover +# Visual Studio code coverage results +*.coverage +*.coveragexml + # NCrunch _NCrunch_* .*crunch*.local.xml +nCrunchTemp_* # MightyMoose *.mm.* @@ -144,8 +163,15 @@ publish/ # Publish Web Output *.[Pp]ublish.xml *.azurePubxml -# TODO: Comment out the next line if you want to keep your passwords hidden +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted *.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ # NuGet Packages *.nupkg @@ -153,28 +179,46 @@ publish/ **/packages/* # except build/, which is used as an MSBuild target. !**/packages/build/ -# If using the old MSBuild-Integrated Package Restore, uncomment this: -!**/packages/repositories.config +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets -# Windows Azure Build Output +# Microsoft Azure Build Output csx/ *.build.csdef -# Windows Store app package directory +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ # Others -sql/ -*.Cache ClientBin/ -[Ss]tyle[Cc]op.* ~$* *~ *.dbmdl *.dbproj.schemaview +*.jfm *.pfx *.publishsettings -node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ # RIA/Silverlight projects Generated_Code/ @@ -190,10 +234,7 @@ UpgradeLog*.htm # SQL Server files *.mdf *.ldf - -# make exception for Akka.Persistence.SqlServer database file -!AkkaPersistenceSqlServerSpecDb.mdf -!AkkaPersistenceSqlServerSpecDb_log.ldf +*.ndf # Business Intelligence projects *.rdl.data @@ -202,15 +243,61 @@ UpgradeLog*.htm # Microsoft Fakes FakesAssemblies/ -/src/.Akka.boltdata/NCover/Executions/0.jf -/src/.Akka.boltdata/NCover/Executions/ProjectId/0.jf -/src/.Akka.boltdata/NCover/Executions/ProjectOrderIndex/0.jf -/src/.Akka.boltdata/NCover/Projects/0.jf -/src/.Akka.boltdata/NCover/Projects/Name/0.jf -/src/.Akka.boltdata/Settings.json -/src/.Akka.boltdata/TestResults.json -resetdev.bat -/src/packages/repositories.config - -# FAKE build folder + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Typescript v1 declaration files +typings/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make .fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs diff --git a/Akka.Persistence.MongoDb.sln b/Akka.Persistence.MongoDb.sln new file mode 100644 index 0000000..9498ffa --- /dev/null +++ b/Akka.Persistence.MongoDb.sln @@ -0,0 +1,45 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27130.2027 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Akka.Persistence.MongoDb", "src\Akka.Persistence.MongoDb\Akka.Persistence.MongoDb.csproj", "{E945AABA-2779-41E8-9B43-8898FFD64F22}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Akka.Persistence.MongoDb.Tests", "src\Akka.Persistence.MongoDb.Tests\Akka.Persistence.MongoDb.Tests.csproj", "{0F9B9BC6-9F86-40E8-BA9B-D27BF3AC7970}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Akka.Persistence.MongoDb.Tests.Performance", "src\Akka.Persistence.MongoDb.Tests.Performance\Akka.Persistence.MongoDb.Tests.Performance.csproj", "{CAE7CA7C-0D0C-4FDA-BDE9-BE16A27343EF}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{BE1178E1-2069-4762-82E5-43805913DCB8}" + ProjectSection(SolutionItems) = preProject + build.cmd = build.cmd + build.fsx = build.fsx + build.ps1 = build.ps1 + build.sh = build.sh + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E945AABA-2779-41E8-9B43-8898FFD64F22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E945AABA-2779-41E8-9B43-8898FFD64F22}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E945AABA-2779-41E8-9B43-8898FFD64F22}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E945AABA-2779-41E8-9B43-8898FFD64F22}.Release|Any CPU.Build.0 = Release|Any CPU + {0F9B9BC6-9F86-40E8-BA9B-D27BF3AC7970}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0F9B9BC6-9F86-40E8-BA9B-D27BF3AC7970}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0F9B9BC6-9F86-40E8-BA9B-D27BF3AC7970}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0F9B9BC6-9F86-40E8-BA9B-D27BF3AC7970}.Release|Any CPU.Build.0 = Release|Any CPU + {CAE7CA7C-0D0C-4FDA-BDE9-BE16A27343EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CAE7CA7C-0D0C-4FDA-BDE9-BE16A27343EF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CAE7CA7C-0D0C-4FDA-BDE9-BE16A27343EF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CAE7CA7C-0D0C-4FDA-BDE9-BE16A27343EF}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D4F3F966-EB9C-443A-8158-419703A68B92} + EndGlobalSection +EndGlobal diff --git a/README.md b/README.md index a46add4..d41d45c 100644 --- a/README.md +++ b/README.md @@ -74,9 +74,10 @@ akka.persistence { ``` ### Serialization -The events and snapshots are stored as BsonDocument, so you need to register you types with the BsonClassMap before you can use your persistence actor. -Otherwise the recovery will fail and you receive a RecoveryFailure with the message: +The events and snapshots are stored as BsonDocument. On the previous version of this driver you needed to register your types with BsonClassMap before you could use your persistence actor, otherwise the recovery would fail and you'd receive a RecoveryFailure with the message: >An error occurred while deserializing the Payload property of class \: Unknown discriminator value '\' +#### **Since now, all types are registered automatically for you so you don't need to use BsonClassMap to serialize/deserialize your types!** + ### Notice - The MongoDB operator to limit the number of documents in a query only accepts an integer while akka provides a long as maximum for the loading of events during the replay. Internally the long value is cast to an integer and if the value is higher then Int32.MaxValue, Int32.MaxValue is used. So if you have stored more then 2,147,483,647 events for a single PersistenceId, you may have a problem :wink: diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 000cd2d..198733b 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,7 +1,50 @@ + +#### 1.3.5 March 23 2018 #### +Support for Akka.Persistence 1.3.5. +Support for .NET Standard 1.6 +Supports latest version of .NET MongoDB Driver. +You don't neeed to register/map your classes for serialization/deserialization anymore! + #### 1.1.0 July 30 2016 #### Updated to Akka.Persistence 1.1.1 +**Migration from 1.0.5 Up** +As of 1.1.0, the highest SequenceNr for each PersistenceId in the EventJournal collection is kept in a separate collection, Metadata. +This script creates the Metadata collection, then finds the highest SequenceNr for each persistence id from the EventJournal and adds it to the Metadata collection. + +To run, save this to a JavaScript file, update {your_database_address} e.g. 127.0.0.1:27017/events. Run: mongo {file_name}.js +```javascript +try { + var db = connect('{your_database_address}'); + + var persistenceIds = db.EventJournal.distinct('PersistenceId'); + + persistenceIds.forEach(persistenceId => { + print('Finding highest SequenceNr for PersistenceId: ' + persistenceId); + var highestSequenceNr = db.EventJournal + .find({ PersistenceId: persistenceId }, { SequenceNr: true }) + .sort({ SequenceNr: -1 }) + .limit(1) + .next() + .SequenceNr; + + print('Highest SequenceNr found ' + highestSequenceNr + ', inserting into Metadata table...'); + db.Metadata.insertOne( + { + _id: persistenceId, + PersistenceId: persistenceId, + SequenceNr: highestSequenceNr + } + ); + + print('Inserted successfully'); + }); +} catch(e) { + print(e); +} +``` + #### 1.0.5 August 08 2015 #### #### 1.0.4 August 07 2015 #### -Initial release of Akka.Persistence.MongoDb \ No newline at end of file +Initial release of Akka.Persistence.MongoDb diff --git a/build.cmd b/build.cmd index 5457002..3cb534e 100644 --- a/build.cmd +++ b/build.cmd @@ -1,19 +1 @@ -@echo off - -pushd %~dp0 - -src\.nuget\NuGet.exe update -self - -src\.nuget\NuGet.exe install FAKE -ConfigFile src\.nuget\Nuget.Config -OutputDirectory src\packages -ExcludeVersion -Version 4.35.0 - -src\.nuget\NuGet.exe install xunit.runner.console -ConfigFile src\.nuget\Nuget.Config -OutputDirectory src\packages\FAKE -ExcludeVersion -Version 2.1.0 - -if not exist src\packages\SourceLink.Fake\tools\SourceLink.fsx ( - src\.nuget\nuget.exe install SourceLink.Fake -ConfigFile src\.nuget\Nuget.Config -OutputDirectory src\packages -ExcludeVersion -Version 1.1.0 -) -rem cls - -set encoding=utf-8 -src\packages\FAKE\tools\FAKE.exe build.fsx %* - -popd +PowerShell.exe -file "build.ps1" %* \ No newline at end of file diff --git a/build.fsx b/build.fsx index f6f600a..892e3b8 100644 --- a/build.fsx +++ b/build.fsx @@ -1,291 +1,232 @@ -#I @"src/packages/FAKE/tools" +#I @"tools/FAKE/tools" #r "FakeLib.dll" -#r "System.Xml.Linq" open System open System.IO open System.Text -open Fake -open Fake.FileUtils -open Fake.TaskRunnerHelper -open Fake.ProcessHelper -cd __SOURCE_DIRECTORY__ +open Fake +open Fake.DotNetCli +open Fake.DocFxHelper -//-------------------------------------------------------------------------------- // Information about the project for Nuget and Assembly info files -//-------------------------------------------------------------------------------- - - -let product = "Akka.NET" -let authors = [ "Akka.NET Team" ] -let copyright = "Copyright © 2013-2016 Akka.NET Team" -let company = "Akka.NET Team" -let description = "Akka.NET is a port of the popular Java/Scala framework Akka to .NET" -let tags = ["akka";"actors";"actor";"model";"Akka";"concurrency"] +let product = "Akka.Persistence.MongoDb" +let authors = [ "Your name here" ] +let copyright = "Copyright © 2017" +let company = "Your name here" +let description = "Your description here" +let tags = ["";] let configuration = "Release" // Read release notes and version - -let parsedRelease = - File.ReadLines "RELEASE_NOTES.md" +let solutionFile = FindFirstMatchingFile "*.sln" __SOURCE_DIRECTORY__ // dynamically look up the solution +let buildNumber = environVarOrDefault "BUILD_NUMBER" "0" +let hasTeamCity = (not (buildNumber = "0")) // check if we have the TeamCity environment variable for build # set +let preReleaseVersionSuffix = (if (not (buildNumber = "0")) then (buildNumber) else "") + "-beta" +let versionSuffix = + match (getBuildParam "nugetprerelease") with + | "dev" -> preReleaseVersionSuffix + | _ -> "" + +let releaseNotes = + File.ReadLines "./RELEASE_NOTES.md" |> ReleaseNotesHelper.parseReleaseNotes -let envBuildNumber = System.Environment.GetEnvironmentVariable("BUILD_NUMBER") -let buildNumber = if String.IsNullOrWhiteSpace(envBuildNumber) then "0" else envBuildNumber - -let version = parsedRelease.AssemblyVersion + "." + buildNumber -let preReleaseVersion = version + "-beta" - -let isUnstableDocs = hasBuildParam "unstable" -let isPreRelease = hasBuildParam "nugetprerelease" -let release = if isPreRelease then ReleaseNotesHelper.ReleaseNotes.New(version, version + "-beta", parsedRelease.Notes) else parsedRelease - -printfn "Assembly version: %s\nNuget version; %s\n" release.AssemblyVersion release.NugetVersion -//-------------------------------------------------------------------------------- // Directories - -let binDir = "bin" -let testOutput = "TestResults" - -let nugetDir = binDir @@ "nuget" -let workingDir = binDir @@ "build" -let libDir = workingDir @@ @"lib\net45\" -let nugetExe = FullName @"src\.nuget\NuGet.exe" -let slnFile = "./src/Akka.Persistence.MongoDB.sln" - -open Fake.RestorePackageHelper -Target "RestorePackages" (fun _ -> - slnFile - |> RestoreMSSolutionPackages (fun p -> - { p with - OutputPath = "./src/packages" - Retries = 4 }) - ) - -//-------------------------------------------------------------------------------- -// Clean build results - -Target "Clean" <| fun _ -> - DeleteDir binDir - -//-------------------------------------------------------------------------------- -// Generate AssemblyInfo files with the version for release notes - -open AssemblyInfoFile - -Target "AssemblyInfo" <| fun _ -> - CreateCSharpAssemblyInfoWithConfig "src/SharedAssemblyInfo.cs" [ - Attribute.Company company - Attribute.Copyright copyright - Attribute.Trademark "" - Attribute.Version version - Attribute.FileVersion version ] <| AssemblyInfoFileConfig(false) - - -//-------------------------------------------------------------------------------- -// Build the solution - -Target "Build" <| fun _ -> - - !! slnFile - |> MSBuildRelease "" "Rebuild" - |> ignore - +let toolsDir = __SOURCE_DIRECTORY__ @@ "tools" +let output = __SOURCE_DIRECTORY__ @@ "bin" +let outputTests = __SOURCE_DIRECTORY__ @@ "TestResults" +let outputPerfTests = __SOURCE_DIRECTORY__ @@ "PerfResults" +let outputNuGet = output @@ "nuget" + +// Copied from original NugetCreate target +let nugetDir = output @@ "nuget" +let workingDir = output @@ "build" +let nugetExe = FullName @"./tools/nuget.exe" + +Target "Clean" (fun _ -> + CleanDir output + CleanDir outputTests + CleanDir outputPerfTests + CleanDir outputNuGet + CleanDir "docs/_site" + CleanDirs !! "./**/bin" + CleanDirs !! "./**/obj" +) + +Target "AssemblyInfo" (fun _ -> + XmlPokeInnerText "./src/common.props" "//Project/PropertyGroup/VersionPrefix" releaseNotes.AssemblyVersion + XmlPokeInnerText "./src/common.props" "//Project/PropertyGroup/PackageReleaseNotes" (releaseNotes.Notes |> String.concat "\n") +) + +Target "RestorePackages" (fun _ -> + DotNetCli.Restore + (fun p -> + { p with + Project = solutionFile + NoCache = false }) +) + +Target "Build" (fun _ -> + let runSingleProject project = + DotNetCli.Build + (fun p -> + { p with + Project = project + Configuration = configuration + AdditionalArgs = ["--no-incremental"]}) // "Rebuild" + + let assemblies = !! "./src/**/*.csproj" + + assemblies |> Seq.iter (runSingleProject) +) //-------------------------------------------------------------------------------- -// Copy the build output to bin directory +// Tests targets //-------------------------------------------------------------------------------- - -Target "CopyOutput" <| fun _ -> +module internal ResultHandling = + let (|OK|Failure|) = function + | 0 -> OK + | x -> Failure x + + let buildErrorMessage = function + | OK -> None + | Failure errorCode -> + Some (sprintf "xUnit2 reported an error (Error Code %d)" errorCode) + + let failBuildWithMessage = function + | DontFailBuild -> traceError + | _ -> (fun m -> raise(FailedTestsException m)) + + let failBuildIfXUnitReportedError errorLevel = + buildErrorMessage + >> Option.iter (failBuildWithMessage errorLevel) + +Target "RunTests" (fun _ -> + let projects = + match (isWindows) with + | true -> !! "./src/**/*.Tests.csproj" + | _ -> !! "./src/**/*.Tests.csproj" // if you need to filter specs for Linux vs. Windows, do it here + + let runSingleProject project = + let arguments = + match (hasTeamCity) with + | true -> (sprintf "xunit -c Release -nobuild -parallel none -teamcity -xml %s_xunit.xml" (outputTests @@ fileNameWithoutExt project)) + | false -> (sprintf "xunit -c Release -nobuild -parallel none -xml %s_xunit.xml" (outputTests @@ fileNameWithoutExt project)) + + let result = ExecProcess(fun info -> + info.FileName <- "dotnet" + info.WorkingDirectory <- (Directory.GetParent project).FullName + info.Arguments <- arguments) (TimeSpan.FromMinutes 30.0) + + ResultHandling.failBuildIfXUnitReportedError TestRunnerErrorLevel.DontFailBuild result + + projects |> Seq.iter (log) + projects |> Seq.iter (runSingleProject) +) + +Target "NBench" <| fun _ -> + let nbenchTestPath = findToolInSubPath "NBench.Runner.exe" (toolsDir @@ "NBench.Runner*") + printfn "Using NBench.Runner: %s" nbenchTestPath + + let nbenchTestAssemblies = !! "./src/**/*Tests.Performance.dll" // doesn't support .NET Core at the moment + + let runNBench assembly = + let includes = getBuildParam "include" + let excludes = getBuildParam "exclude" + let teamcityStr = (getBuildParam "teamcity") + let enableTeamCity = + match teamcityStr with + | null -> false + | "" -> false + | _ -> bool.Parse teamcityStr + + let args = StringBuilder() + |> append assembly + |> append (sprintf "output-directory=\"%s\"" outputPerfTests) + |> append (sprintf "concurrent=\"%b\"" true) + |> append (sprintf "trace=\"%b\"" true) + |> append (sprintf "teamcity=\"%b\"" enableTeamCity) + |> appendIfNotNullOrEmpty includes "include=" + |> appendIfNotNullOrEmpty excludes "include=" + |> toText + + let result = ExecProcess(fun info -> + info.FileName <- nbenchTestPath + info.WorkingDirectory <- (Path.GetDirectoryName (FullName nbenchTestPath)) + info.Arguments <- args) (System.TimeSpan.FromMinutes 45.0) (* Reasonably long-running task. *) + if result <> 0 then failwithf "NBench.Runner failed. %s %s" nbenchTestPath args - let copyOutput project = - let src = "src" @@ project @@ @"bin/Release/" - let dst = binDir @@ project - CopyDir dst src allFiles - [ "Akka.Persistence.MongoDB" - ] - |> List.iter copyOutput - -Target "BuildRelease" DoNothing - + nbenchTestAssemblies |> Seq.iter runNBench -//-------------------------------------------------------------------------------- -// Tests targets -//-------------------------------------------------------------------------------- - -//-------------------------------------------------------------------------------- -// Clean test output - -Target "CleanTests" <| fun _ -> - DeleteDir testOutput -//-------------------------------------------------------------------------------- -// Run tests - -open Fake.Testing -Target "RunTests" <| fun _ -> - let xunitTestAssemblies = !! "src/**/bin/Release/*.Tests.dll" - - mkdir testOutput - - let xunitToolPath = findToolInSubPath "xunit.console.exe" "src/packages/FAKE/xunit.runner.console*/tools" - - printfn "Using XUnit runner: %s" xunitToolPath - let runSingleAssembly assembly = - let assemblyName = Path.GetFileNameWithoutExtension(assembly) - xUnit2 - (fun p -> { p with XmlOutputPath = Some (testOutput + @"\" + assemblyName + "_xunit.xml"); HtmlOutputPath = Some (testOutput + @"\" + assemblyName + "_xunit.HTML"); ToolPath = xunitToolPath; TimeOut = System.TimeSpan.FromMinutes 30.0; Parallel = ParallelMode.NoParallelization }) - (Seq.singleton assembly) - - xunitTestAssemblies |> Seq.iter (runSingleAssembly) - //-------------------------------------------------------------------------------- // Nuget targets //-------------------------------------------------------------------------------- -module Nuget = - // add Akka dependency for other projects - let getAkkaDependency project = - match project with - | _ -> [] - - // used to add -pre suffix to pre-release packages - let getProjectVersion project = - match project with - | "Akka.Cluster" -> preReleaseVersion - | persistence when persistence.StartsWith("Akka.Persistence") -> preReleaseVersion - | _ -> release.NugetVersion - -open Nuget -open NuGet.Update +let overrideVersionSuffix (project:string) = + match project with + | _ -> versionSuffix // add additional matches to publish different versions for different projects in solution +Target "CreateNuget" (fun _ -> + let projects = !! "src/**/*.csproj" + -- "src/**/*Tests.csproj" // Don't publish unit tests + -- "src/**/*Tests*.csproj" + + let runSingleProject project = + DotNetCli.Pack + (fun p -> + { p with + Project = project + Configuration = configuration + AdditionalArgs = ["--include-symbols"] + VersionSuffix = overrideVersionSuffix project + OutputPath = outputNuGet }) + + projects |> Seq.iter (runSingleProject) +) + +Target "PublishNuget" (fun _ -> + let projects = !! "./bin/nuget/*.nupkg" -- "./bin/nuget/*.symbols.nupkg" + let apiKey = getBuildParamOrDefault "nugetkey" "" + let source = getBuildParamOrDefault "nugetpublishurl" "" + let symbolSource = getBuildParamOrDefault "symbolspublishurl" "" + let shouldPublishSymbolsPackages = not (symbolSource = "") + + if (not (source = "") && not (apiKey = "") && shouldPublishSymbolsPackages) then + let runSingleProject project = + DotNetCli.RunCommand + (fun p -> + { p with + TimeOut = TimeSpan.FromMinutes 10. }) + (sprintf "nuget push %s --api-key %s --source %s --symbol-source %s" project apiKey source symbolSource) + + projects |> Seq.iter (runSingleProject) + else if (not (source = "") && not (apiKey = "") && not shouldPublishSymbolsPackages) then + let runSingleProject project = + DotNetCli.RunCommand + (fun p -> + { p with + TimeOut = TimeSpan.FromMinutes 10. }) + (sprintf "nuget push %s --api-key %s --source %s" project apiKey source) + + projects |> Seq.iter (runSingleProject) +) //-------------------------------------------------------------------------------- -// Clean nuget directory - -Target "CleanNuget" <| fun _ -> - CleanDir nugetDir - -//-------------------------------------------------------------------------------- -// Pack nuget for all projects -// Publish to nuget.org if nugetkey is specified - -let createNugetPackages _ = - let removeDir dir = - let del _ = - DeleteDir dir - not (directoryExists dir) - runWithRetries del 3 |> ignore - - ensureDirectory nugetDir - for nuspec in !! "src/**/*.nuspec" do - printfn "Creating nuget packages for %s" nuspec - - CleanDir workingDir - - let project = Path.GetFileNameWithoutExtension nuspec - let projectDir = Path.GetDirectoryName nuspec - let projectFile = (!! (projectDir @@ project + ".*sproj")) |> Seq.head - let releaseDir = projectDir @@ @"bin\Release" - let packages = projectDir @@ "packages.config" - let packageDependencies = if (fileExists packages) then (getDependencies packages) else [] - let dependencies = packageDependencies @ getAkkaDependency project - let releaseVersion = getProjectVersion project - - let pack outputDir symbolPackage = - NuGetHelper.NuGet - (fun p -> - { p with - Description = description - Authors = authors - Copyright = copyright - Project = project - Properties = ["Configuration", "Release"] - ReleaseNotes = release.Notes |> String.concat "\n" - Version = releaseVersion - Tags = tags |> String.concat " " - OutputPath = outputDir - WorkingDir = workingDir - SymbolPackage = symbolPackage - Dependencies = dependencies }) - nuspec - - // Copy dll, pdb and xml to libdir = workingDir/lib/net45/ - ensureDirectory libDir - !! (releaseDir @@ project + ".dll") - ++ (releaseDir @@ project + ".pdb") - ++ (releaseDir @@ project + ".xml") - ++ (releaseDir @@ project + ".ExternalAnnotations.xml") - |> CopyFiles libDir - - // Copy all src-files (.cs and .fs files) to workingDir/src - let nugetSrcDir = workingDir @@ @"src/" - // CreateDir nugetSrcDir - - let isCs = hasExt ".cs" - let isFs = hasExt ".fs" - let isAssemblyInfo f = (filename f).Contains("AssemblyInfo") - let isSrc f = (isCs f || isFs f) && not (isAssemblyInfo f) - CopyDir nugetSrcDir projectDir isSrc - - //Remove workingDir/src/obj and workingDir/src/bin - removeDir (nugetSrcDir @@ "obj") - removeDir (nugetSrcDir @@ "bin") - - // Create both normal nuget package and symbols nuget package. - // Uses the files we copied to workingDir and outputs to nugetdir - pack nugetDir NugetSymbolPackage.Nuspec - - -let publishNugetPackages _ = - let rec publishPackage url accessKey trialsLeft packageFile = - let tracing = enableProcessTracing - enableProcessTracing <- false - let args p = - match p with - | (pack, key, "") -> sprintf "push \"%s\" %s" pack key - | (pack, key, url) -> sprintf "push \"%s\" %s -source %s" pack key url - - tracefn "Pushing %s Attempts left: %d" (FullName packageFile) trialsLeft - try - let result = ExecProcess (fun info -> - info.FileName <- nugetExe - info.WorkingDirectory <- (Path.GetDirectoryName (FullName packageFile)) - info.Arguments <- args (packageFile, accessKey,url)) (System.TimeSpan.FromMinutes 1.0) - enableProcessTracing <- tracing - if result <> 0 then failwithf "Error during NuGet symbol push. %s %s" nugetExe (args (packageFile, accessKey,url)) - with exn -> - if (trialsLeft > 0) then (publishPackage url accessKey (trialsLeft-1) packageFile) - else raise exn - let shouldPushNugetPackages = hasBuildParam "nugetkey" - let shouldPushSymbolsPackages = (hasBuildParam "symbolspublishurl") && (hasBuildParam "symbolskey") - - if (shouldPushNugetPackages || shouldPushSymbolsPackages) then - printfn "Pushing nuget packages" - if shouldPushNugetPackages then - let normalPackages= - !! (nugetDir @@ "*.nupkg") - -- (nugetDir @@ "*.symbols.nupkg") |> Seq.sortBy(fun x -> x.ToLower()) - for package in normalPackages do - publishPackage (getBuildParamOrDefault "nugetpublishurl" "") (getBuildParam "nugetkey") 3 package - - if shouldPushSymbolsPackages then - let symbolPackages= !! (nugetDir @@ "*.symbols.nupkg") |> Seq.sortBy(fun x -> x.ToLower()) - for package in symbolPackages do - publishPackage (getBuildParam "symbolspublishurl") (getBuildParam "symbolskey") 3 package - - -Target "Nuget" <| fun _ -> - createNugetPackages() - publishNugetPackages() - -Target "CreateNuget" <| fun _ -> - createNugetPackages() - -Target "PublishNuget" <| fun _ -> - publishNugetPackages() +// Documentation +//-------------------------------------------------------------------------------- +Target "DocFx" (fun _ -> + DotNetCli.Restore (fun p -> { p with Project = solutionFile }) + DotNetCli.Build (fun p -> { p with Project = solutionFile; Configuration = configuration }) + let docsPath = "./docs" + DocFx (fun p -> + { p with + Timeout = TimeSpan.FromMinutes 30.0; + WorkingDirectory = docsPath; + DocFxJson = docsPath @@ "docfx.json" }) +) //-------------------------------------------------------------------------------- // Help @@ -294,113 +235,43 @@ Target "PublishNuget" <| fun _ -> Target "Help" <| fun _ -> List.iter printfn [ "usage:" - "build [target]" + "./build.ps1 [target]" "" " Targets for building:" " * Build Builds" " * Nuget Create and optionally publish nugets packages" " * RunTests Runs tests" " * All Builds, run tests, creates and optionally publish nuget packages" + " * DocFx Creates a DocFx-based website for this solution" "" " Other Targets" " * Help Display this help" - " * HelpNuget Display help about creating and pushing nuget packages" - " * HelpDocs Display help about creating and pushing API docs" - ""] - -Target "HelpNuget" <| fun _ -> - List.iter printfn [ - "usage: " - "build Nuget [nugetkey= [nugetpublishurl=]] " - " [symbolskey= symbolspublishurl=] " - " [nugetprerelease=]" - "" - "Arguments for Nuget target:" - " nugetprerelease= Creates a pre-release package." - " The version will be version-prefix" - " Example: nugetprerelease=dev =>" - " 0.6.3-dev1408191917" - "" - "In order to publish a nuget package, keys must be specified." - "If a key is not specified the nuget packages will only be created on disk" - "After a build you can find them in bin/nuget" - "" - "For pushing nuget packages to nuget.org and symbols to symbolsource.org" - "you need to specify nugetkey=" - " build Nuget nugetKey=" - "" - "For pushing the ordinary nuget packages to another place than nuget.org specify the url" - " nugetkey= nugetpublishurl= " - "" - "For pushing symbols packages specify:" - " symbolskey= symbolspublishurl= " - "" - "Examples:" - " build Nuget Build nuget packages to the bin/nuget folder" - "" - " build Nuget nugetprerelease=dev Build pre-release nuget packages" - "" - " build Nuget nugetkey=123 Build and publish to nuget.org and symbolsource.org" - "" - " build Nuget nugetprerelease=dev nugetkey=123 nugetpublishurl=http://abc" - " symbolskey=456 symbolspublishurl=http://xyz" - " Build and publish pre-release nuget packages to http://abc" - " and symbols packages to http://xyz" - ""] - -Target "HelpDocs" <| fun _ -> - List.iter printfn [ - "usage: " - "build Docs" - "Just builds the API docs for Akka.NET locally. Does not attempt to publish." - "" - "build PublishDocs azureKey= " - " azureUrl= " - " [unstable=true]" - "" - "Arguments for PublishDocs target:" - " azureKey= Azure blob storage key." - " Used to authenticate to the storage account." - "" - " azureUrl= Base URL for Azure storage container." - " FAKE will automatically set container" - " names based on build parameters." - "" - " [unstable=true] Indicates that we'll publish to an Azure" - " container named 'unstable'. If this param" - " is not present we'll publish to containers" - " 'stable' and the 'release.version'" - "" - "In order to publish documentation all of these values must be provided." - "Examples:" - " build PublishDocs azureKey=1s9HSAHA+..." - " azureUrl=http://fooaccount.blob.core.windows.net/docs" - " Build and publish docs to http://fooaccount.blob.core.windows.net/docs/stable" - " and http://fooaccount.blob.core.windows.net/docs/{release.version}" - "" - " build PublishDocs azureKey=1s9HSAHA+..." - " azureUrl=http://fooaccount.blob.core.windows.net/docs" - " unstable=true" - " Build and publish docs to http://fooaccount.blob.core.windows.net/docs/unstable" ""] //-------------------------------------------------------------------------------- // Target dependencies //-------------------------------------------------------------------------------- +Target "BuildRelease" DoNothing +Target "All" DoNothing +Target "Nuget" DoNothing + // build dependencies -"Clean" ==> "AssemblyInfo" ==> "RestorePackages" ==> "Build" ==> "CopyOutput" ==> "BuildRelease" +"Clean" ==> "RestorePackages" ==> "AssemblyInfo" ==> "Build" ==> "BuildRelease" // tests dependencies -"CleanTests" ==> "RunTests" // nuget dependencies -"CleanNuget" ==> "CreateNuget" -"CleanNuget" ==> "BuildRelease" ==> "Nuget" +"Clean" ==> "RestorePackages" ==> "Build" ==> "CreateNuget" +"CreateNuget" ==> "PublishNuget" ==> "Nuget" -Target "All" DoNothing +// docs +"BuildRelease" ==> "Docfx" + +// all "BuildRelease" ==> "All" "RunTests" ==> "All" +//"NBench" ==> "All" "Nuget" ==> "All" -RunTargetOrDefault "Help" +RunTargetOrDefault "Help" \ No newline at end of file diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..f2180fc --- /dev/null +++ b/build.ps1 @@ -0,0 +1,162 @@ +<# +.SYNOPSIS +This is a Powershell script to bootstrap a Fake build. +.DESCRIPTION +This Powershell script will download NuGet if missing, restore NuGet tools (including Fake) +and execute your Fake build script with the parameters you provide. +.PARAMETER Target +The build script target to run. +.PARAMETER Configuration +The build configuration to use. +.PARAMETER Verbosity +Specifies the amount of information to be displayed. +.PARAMETER WhatIf +Performs a dry run of the build script. +No tasks will be executed. +.PARAMETER ScriptArgs +Remaining arguments are added here. +#> + +[CmdletBinding()] +Param( + [string]$Target = "Default", + [ValidateSet("Release", "Debug")] + [string]$Configuration = "Release", + [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")] + [string]$Verbosity = "Verbose", + [switch]$WhatIf, + [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] + [string[]]$ScriptArgs +) + +$FakeVersion = "4.61.2" +$NBenchVersion = "1.0.1" +$DotNetChannel = "LTS"; +$DotNetVersion = "2.0.0"; +$DotNetInstallerUri = "https://raw.githubusercontent.com/dotnet/cli/v$DotNetVersion/scripts/obtain/dotnet-install.ps1"; +$NugetVersion = "4.1.0"; +$NugetUrl = "https://dist.nuget.org/win-x86-commandline/v$NugetVersion/nuget.exe" +$ProtobufVersion = "3.2.0" +$DocfxVersion = "2.21.1" + +# Make sure tools folder exists +$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent +$ToolPath = Join-Path $PSScriptRoot "tools" +if (!(Test-Path $ToolPath)) { + Write-Verbose "Creating tools directory..." + New-Item -Path $ToolPath -Type directory | out-null +} + +########################################################################### +# INSTALL .NET CORE CLI +########################################################################### + +Function Remove-PathVariable([string]$VariableToRemove) +{ + $path = [Environment]::GetEnvironmentVariable("PATH", "User") + if ($path -ne $null) + { + $newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove } + [Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User") + } + + $path = [Environment]::GetEnvironmentVariable("PATH", "Process") + if ($path -ne $null) + { + $newItems = $path.Split(';', [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove } + [Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process") + } +} + +# Get .NET Core CLI path if installed. +$FoundDotNetCliVersion = $null; +if (Get-Command dotnet -ErrorAction SilentlyContinue) { + $FoundDotNetCliVersion = dotnet --version; + $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 + $env:DOTNET_CLI_TELEMETRY_OPTOUT=1 +} + +if($FoundDotNetCliVersion -ne $DotNetVersion) { + $InstallPath = Join-Path $PSScriptRoot ".dotnet" + if (!(Test-Path $InstallPath)) { + mkdir -Force $InstallPath | Out-Null; + } + (New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, "$InstallPath\dotnet-install.ps1"); + & $InstallPath\dotnet-install.ps1 -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath -Architecture x64; + + Remove-PathVariable "$InstallPath" + $env:PATH = "$InstallPath;$env:PATH" + $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 + $env:DOTNET_CLI_TELEMETRY_OPTOUT=1 +} + +########################################################################### +# INSTALL NUGET +########################################################################### + +# Make sure nuget.exe exists. +$NugetPath = Join-Path $ToolPath "nuget.exe" +if (!(Test-Path $NugetPath)) { + Write-Host "Downloading NuGet.exe..." + (New-Object System.Net.WebClient).DownloadFile($NugetUrl, $NugetPath); +} + +########################################################################### +# INSTALL FAKE +########################################################################### +# Make sure Fake has been installed. + +$FakeExePath = Join-Path $ToolPath "FAKE/tools/FAKE.exe" +if (!(Test-Path $FakeExePath)) { + Write-Host "Installing Fake..." + Invoke-Expression "&`"$NugetPath`" install Fake -ExcludeVersion -Version $FakeVersion -OutputDirectory `"$ToolPath`"" | Out-Null; + if ($LASTEXITCODE -ne 0) { + Throw "An error occured while restoring Fake from NuGet." + } +} + +########################################################################### +# INSTALL NBench Runner +########################################################################### + +# Make sure NBench Runner has been installed. +$NBenchDllPath = Join-Path $ToolPath "NBench.Runner/lib/net45/NBench.Runner.exe" +if (!(Test-Path $NBenchDllPath)) { + Write-Host "Installing NBench..." + Invoke-Expression "&`"$NugetPath`" install NBench.Runner -ExcludeVersion -Version $NBenchVersion -OutputDirectory `"$ToolPath`"" | Out-Null; + if ($LASTEXITCODE -ne 0) { + Throw "An error occured while restoring NBench.Runner from NuGet." + } +} + +########################################################################### +# Docfx +########################################################################### + +# Make sure Docfx has been installed. +$DocfxExePath = Join-Path $ToolPath "docfx.console/tools/docfx.exe" +if (!(Test-Path $DocfxExePath)) { + Write-Host "Installing Docfx..." + Invoke-Expression "&`"$NugetPath`" install docfx.console -ExcludeVersion -Version $DocfxVersion -OutputDirectory `"$ToolPath`"" | Out-Null; + if ($LASTEXITCODE -ne 0) { + Throw "An error occured while restoring docfx.console from NuGet." + } +} + +########################################################################### +# RUN BUILD SCRIPT +########################################################################### + +# Build the argument list. +$Arguments = @{ + target=$Target; + configuration=$Configuration; + verbosity=$Verbosity; + dryrun=$WhatIf; +}.GetEnumerator() | %{"--{0}=`"{1}`"" -f $_.key, $_.value }; + +# Start Fake +Write-Host "Running build script..." +Invoke-Expression "$FakeExePath `"build.fsx`" $ScriptArgs $Arguments" + +exit $LASTEXITCODE \ No newline at end of file diff --git a/build.sh b/build.sh index 84e65b6..8e70878 100644 --- a/build.sh +++ b/build.sh @@ -1,25 +1,98 @@ -#!/bin/bash +#!/usr/bin/env bash +########################################################################## +# This is the Fake bootstrapper script for Linux and OS X. +########################################################################## -SCRIPT_PATH="${BASH_SOURCE[0]}"; -if ([ -h "${SCRIPT_PATH}" ]) then - while([ -h "${SCRIPT_PATH}" ]) do SCRIPT_PATH=`readlink "${SCRIPT_PATH}"`; done +# Define directories. +SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +TOOLS_DIR=$SCRIPT_DIR/tools +NUGET_EXE=$TOOLS_DIR/nuget.exe +NUGET_URL=https://dist.nuget.org/win-x86-commandline/v4.0.0/nuget.exe +FAKE_VERSION=4.61.2 +FAKE_EXE=$TOOLS_DIR/FAKE/tools/FAKE.exe +DOTNET_VERSION=2.0.0 +DOTNET_INSTALLER_URL=https://raw.githubusercontent.com/dotnet/cli/2.0.0/scripts/obtain/dotnet-install.sh +# Define default arguments. +TARGET="Default" +CONFIGURATION="Release" +VERBOSITY="verbose" +DRYRUN= +SCRIPT_ARGUMENTS=() + +# Parse arguments. +for i in "$@"; do + case $1 in + -t|--target) TARGET="$2"; shift ;; + -c|--configuration) CONFIGURATION="$2"; shift ;; + -v|--verbosity) VERBOSITY="$2"; shift ;; + -d|--dryrun) DRYRUN="-dryrun" ;; + --) shift; SCRIPT_ARGUMENTS+=("$@"); break ;; + *) SCRIPT_ARGUMENTS+=("$1") ;; + esac + shift +done + +# Make sure the tools folder exist. +if [ ! -d "$TOOLS_DIR" ]; then + mkdir "$TOOLS_DIR" +fi + +########################################################################### +# INSTALL .NET CORE CLI +########################################################################### + +echo "Installing .NET CLI..." +if [ ! -d "$SCRIPT_DIR/.dotnet" ]; then + mkdir "$SCRIPT_DIR/.dotnet" fi -pushd . > /dev/null -cd `dirname ${SCRIPT_PATH}` > /dev/null -SCRIPT_PATH=`pwd`; -popd > /dev/null +curl -Lsfo "$SCRIPT_DIR/.dotnet/dotnet-install.sh" $DOTNET_INSTALLER_URL +bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --version $DOTNET_VERSION --install-dir .dotnet --no-path +export PATH="$SCRIPT_DIR/.dotnet":$PATH +export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +export DOTNET_CLI_TELEMETRY_OPTOUT=1 +chmod -R 0755 ".dotnet" +"$SCRIPT_DIR/.dotnet/dotnet" --info -mono $SCRIPT_PATH/src/.nuget/NuGet.exe update -self +########################################################################### +# INSTALL NUGET +########################################################################### -mono $SCRIPT_PATH/src/.nuget/NuGet.exe install FAKE -OutputDirectory $SCRIPT_PATH/src/packages -ExcludeVersion -Version 4.35.0 +# Download NuGet if it does not exist. +if [ ! -f "$NUGET_EXE" ]; then + echo "Downloading NuGet..." + curl -Lsfo "$NUGET_EXE" $NUGET_URL + if [ $? -ne 0 ]; then + echo "An error occured while downloading nuget.exe." + exit 1 + fi +fi -mono $SCRIPT_PATH/src/.nuget/NuGet.exe install xunit.runners -OutputDirectory $SCRIPT_PATH/src/packages/FAKE -ExcludeVersion -Version 2.1.0 +########################################################################### +# INSTALL FAKE +########################################################################### -if ! [ -e $SCRIPT_PATH/src/packages/SourceLink.Fake/tools/SourceLink.fsx ] ; then - mono $SCRIPT_PATH/src/.nuget/NuGet.exe install SourceLink.Fake -OutputDirectory $SCRIPT_PATH/src/packages -ExcludeVersion -Version 1.1.0 +if [ ! -f "$FAKE_EXE" ]; then + mono "$NUGET_EXE" install Fake -ExcludeVersion -Version $FAKE_VERSION -OutputDirectory "$TOOLS_DIR" + if [ $? -ne 0 ]; then + echo "An error occured while installing Cake." + exit 1 + fi +fi +# Make sure that Fake has been installed. +if [ ! -f "$FAKE_EXE" ]; then + echo "Could not find Fake.exe at '$FAKE_EXE'." + exit 1 fi -export encoding=utf-8 +########################################################################### +# WORKAROUND FOR MONO +########################################################################### +export FrameworkPathOverride=/usr/lib/mono/4.5/ + +########################################################################### +# RUN BUILD SCRIPT +########################################################################### -mono $SCRIPT_PATH/src/packages/FAKE/tools/FAKE.exe build.fsx "$@" +# Start Fake +exec mono "$FAKE_EXE" build.fsx "${SCRIPT_ARGUMENTS[@]}" --verbosity=$VERBOSITY --configuration=$CONFIGURATION --target=$TARGET $DRYRUN diff --git a/docs/api/index.md b/docs/api/index.md new file mode 100644 index 0000000..9e0155b --- /dev/null +++ b/docs/api/index.md @@ -0,0 +1 @@ +# API Docs \ No newline at end of file diff --git a/docs/articles/index.md b/docs/articles/index.md new file mode 100644 index 0000000..9d45024 --- /dev/null +++ b/docs/articles/index.md @@ -0,0 +1,3 @@ +# Introduction + +Article text goes here. \ No newline at end of file diff --git a/docs/articles/toc.yml b/docs/articles/toc.yml new file mode 100644 index 0000000..4262931 --- /dev/null +++ b/docs/articles/toc.yml @@ -0,0 +1,2 @@ +- name: Introduction + href: index.md \ No newline at end of file diff --git a/docs/docfx.json b/docs/docfx.json new file mode 100644 index 0000000..7d75f8d --- /dev/null +++ b/docs/docfx.json @@ -0,0 +1,67 @@ +{ + "metadata": [ + { + "src": [ + { + "files": [ "**/*.csproj" ], + "exclude": [ + "**/obj/**", + "**/bin/**", + "_site/**", + "**/*Tests*.csproj", + "**/*Tests.*.csproj" + ], + "src": "../src" + } + ], + "dest": "api" + } + ], + "build": { + "content": [ + { + "files": [ + "api/**.yml", + "api/index.md" + ] + }, + { + "files": [ + "articles/**.md", + "articles/**/toc.yml", + "toc.yml", + "*.md" + ], + "exclude": [ + "obj/**", + "_site/**" + ] + }, + ], + "resource": [ + { + "files": [ + "images/**" + ], + "exclude": [ + "obj/**", + "_site/**" + ] + } + ], + "dest": "_site", + "globalMetadata": { + "_appTitle": "Akka.Persistence.MongoDb", + "_disableContribution": "true", + "_appLogoPath": "/images/icon.png", + }, + "globalMetadataFiles": [], + "fileMetadataFiles": [], + "template": [ + "default", + "template" + ], + "postProcessors": [], + "noLangKeyword": false + } +} \ No newline at end of file diff --git a/docs/images/icon.png b/docs/images/icon.png new file mode 100644 index 0000000..86698cd Binary files /dev/null and b/docs/images/icon.png differ diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..2270f83 --- /dev/null +++ b/docs/index.md @@ -0,0 +1 @@ +# Introduction to My Project \ No newline at end of file diff --git a/docs/toc.yml b/docs/toc.yml new file mode 100644 index 0000000..0fcaa0f --- /dev/null +++ b/docs/toc.yml @@ -0,0 +1,6 @@ +- name: Home + href: index.md +- name: Documentation + href: articles/ +- name: API Reference + href: api/ \ No newline at end of file diff --git a/serve-docs.cmd b/serve-docs.cmd new file mode 100644 index 0000000..fa42861 --- /dev/null +++ b/serve-docs.cmd @@ -0,0 +1 @@ +PowerShell.exe -file "serve-docs.ps1" %* .\docs\docfx.json --serve -p 8090 \ No newline at end of file diff --git a/serve-docs.ps1 b/serve-docs.ps1 new file mode 100644 index 0000000..91dbe9f --- /dev/null +++ b/serve-docs.ps1 @@ -0,0 +1,21 @@ +# docfx.ps1 +$VisualStudioVersion = "15.0"; +$DotnetSDKVersion = "2.0.0"; + +# Get dotnet paths +$MSBuildExtensionsPath = "C:\Program Files\dotnet\sdk\" + $DotnetSDKVersion; +$MSBuildSDKsPath = $MSBuildExtensionsPath + "\SDKs"; + +# Get Visual Studio install path +$VSINSTALLDIR = $(Get-ItemProperty "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\SxS\VS7").$VisualStudioVersion; + +# Add Visual Studio environment variables +$env:VisualStudioVersion = $VisualStudioVersion; +$env:VSINSTALLDIR = $VSINSTALLDIR; + +# Add dotnet environment variables +$env:MSBuildExtensionsPath = $MSBuildExtensionsPath; +$env:MSBuildSDKsPath = $MSBuildSDKsPath; + +# Build our docs +& .\tools\docfx.console\tools\docfx @args \ No newline at end of file diff --git a/src/Akka.Persistence.MongoDb.Tests.Performance/Akka.Persistence.MongoDb.Tests.Performance.csproj b/src/Akka.Persistence.MongoDb.Tests.Performance/Akka.Persistence.MongoDb.Tests.Performance.csproj new file mode 100644 index 0000000..dfd6786 --- /dev/null +++ b/src/Akka.Persistence.MongoDb.Tests.Performance/Akka.Persistence.MongoDb.Tests.Performance.csproj @@ -0,0 +1,18 @@ + + + + + + net461 + + + + + + + + + + + + diff --git a/src/Akka.Persistence.MongoDb.Tests.Performance/UnitTest1.cs b/src/Akka.Persistence.MongoDb.Tests.Performance/UnitTest1.cs new file mode 100644 index 0000000..dba4a5b --- /dev/null +++ b/src/Akka.Persistence.MongoDb.Tests.Performance/UnitTest1.cs @@ -0,0 +1,26 @@ +using System; +using NBench; + +namespace Akka.Persistence.MongoDb.Tests.Performance +{ + public class UnitTest1 + { + public const string CounterName = "Operations"; + private Counter _opsCounter; + + [PerfSetup] + public void Setup(BenchmarkContext context) + { + _opsCounter = context.GetCounter(CounterName); + } + + [PerfBenchmark(NumberOfIterations = 5, RunMode = RunMode.Throughput, RunTimeMilliseconds = 1000)] + [CounterMeasurement(CounterName)] + [GcMeasurement(GcMetric.TotalCollections, GcGeneration.AllGc)] + [MemoryMeasurement(MemoryMetric.TotalBytesAllocated)] + public void TestMethod1() + { + _opsCounter.Increment(); + } + } +} diff --git a/src/Akka.Persistence.MongoDb.Tests/Akka.Persistence.MongoDb.Tests.csproj b/src/Akka.Persistence.MongoDb.Tests/Akka.Persistence.MongoDb.Tests.csproj index 7ced513..90bddeb 100644 --- a/src/Akka.Persistence.MongoDb.Tests/Akka.Persistence.MongoDb.Tests.csproj +++ b/src/Akka.Persistence.MongoDb.Tests/Akka.Persistence.MongoDb.Tests.csproj @@ -1,166 +1,28 @@ - - - - - - Debug - AnyCPU - {32A2ACBE-8A3C-4093-8C13-D65B113B3327} - Library - Properties - Akka.Persistence.MongoDb.Tests - Akka.Persistence.MongoDb.Tests - v4.5 - 512 - - - ..\ - true - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 + + + + + netcoreapp2.0 + + - - ..\packages\Akka.1.1.1\lib\net45\Akka.dll - True - - - ..\packages\Akka.Persistence.1.1.1.28-beta\lib\net45\Akka.Persistence.dll - True - - - ..\packages\Akka.Persistence.TestKit.1.1.1.28-beta\lib\net45\Akka.Persistence.TestKit.dll - True - - - ..\packages\Akka.TestKit.1.1.1\lib\net45\Akka.TestKit.dll - True - - - ..\packages\Akka.TestKit.Xunit2.1.1.1\lib\net45\Akka.TestKit.Xunit2.dll - True - - - ..\packages\FluentAssertions.4.12.0\lib\net45\FluentAssertions.dll - True - - - ..\packages\FluentAssertions.4.12.0\lib\net45\FluentAssertions.Core.dll - True - - - ..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.dll - True - - - ..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.Serialization.dll - True - - - ..\packages\Mongo2Go.0.2.0\lib\net35\Mongo2Go.dll - True - - - ..\packages\MongoDB.Bson.2.2.4\lib\net45\MongoDB.Bson.dll - True - - - ..\packages\MongoDB.Driver.2.2.4\lib\net45\MongoDB.Driver.dll - True - - - ..\packages\MongoDB.Driver.Core.2.2.4\lib\net45\MongoDB.Driver.Core.dll - True - - - ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - True - - - - ..\packages\System.Collections.Immutable.1.1.36\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll - True - - - - - - - - - - - ..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll - True - - - ..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll - True - - - ..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll - True - - - ..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll - True - + + + + + + + + + - - Properties\SharedAssemblyInfo.cs - - - - - + - - - {12e044ef-08a2-428b-aaf5-c3d328860c4e} - Akka.Persistence.MongoDb - - - - - Designer - - - Designer - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - + + + $(DefineConstants);RELEASE + + \ No newline at end of file diff --git a/src/Akka.Persistence.MongoDb.Tests/App.config b/src/Akka.Persistence.MongoDb.Tests/App.config deleted file mode 100644 index 408e986..0000000 --- a/src/Akka.Persistence.MongoDb.Tests/App.config +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/src/Akka.Persistence.MongoDb.Tests/DatabaseFixture.cs b/src/Akka.Persistence.MongoDb.Tests/DatabaseFixture.cs new file mode 100644 index 0000000..ed08b7d --- /dev/null +++ b/src/Akka.Persistence.MongoDb.Tests/DatabaseFixture.cs @@ -0,0 +1,30 @@ +//----------------------------------------------------------------------- +// +// Copyright (C) 2009-2016 Lightbend Inc. +// Copyright (C) 2013-2016 Akka.NET project +// +//----------------------------------------------------------------------- + +using Mongo2Go; +using System; + +namespace Akka.Persistence.MongoDb.Tests +{ + public class DatabaseFixture : IDisposable + { + private MongoDbRunner _runner; + + public string ConnectionString { get; private set; } + + public DatabaseFixture() + { + _runner = MongoDbRunner.Start(); + ConnectionString = _runner.ConnectionString + "akkanet"; + } + + public void Dispose() + { + _runner.Dispose(); + } + } +} diff --git a/src/Akka.Persistence.MongoDb.Tests/MongoDbJournalSpec.cs b/src/Akka.Persistence.MongoDb.Tests/MongoDbJournalSpec.cs index 3575e20..38f059a 100644 --- a/src/Akka.Persistence.MongoDb.Tests/MongoDbJournalSpec.cs +++ b/src/Akka.Persistence.MongoDb.Tests/MongoDbJournalSpec.cs @@ -5,63 +5,40 @@ // //----------------------------------------------------------------------- -using System; -using System.Configuration; -using Akka.Persistence.TestKit.Journal; -using Mongo2Go; -using MongoDB.Driver; +using Akka.Persistence.TCK.Journal; using Xunit; +using Akka.Configuration; namespace Akka.Persistence.MongoDb.Tests { [Collection("MongoDbSpec")] - public class MongoDbJournalSpec : JournalSpec + public class MongoDbJournalSpec : JournalSpec, IClassFixture { - private static readonly MongoDbRunner Runner = MongoDbRunner.Start(ConfigurationManager.AppSettings[0]); + protected override bool SupportsRejectingNonSerializableObjects { get; } = false; - protected override bool SupportsRejectingNonSerializableObjects { get; } = false; - - private static readonly string SpecConfig = @" - akka.test.single-expect-default = 3s - akka.persistence { - publish-plugin-commands = on - journal { - plugin = ""akka.persistence.journal.mongodb"" - mongodb { - class = ""Akka.Persistence.MongoDb.Journal.MongoDbJournal, Akka.Persistence.MongoDb"" - connection-string = """" - auto-initialize = on - collection = ""EventJournal"" - } - } - }"; - - public MongoDbJournalSpec() : base(CreateSpecConfig(), "MongoDbJournalSpec") + public MongoDbJournalSpec(DatabaseFixture databaseFixture) : base(CreateSpecConfig(databaseFixture), "MongoDbJournalSpec") { - AppDomain.CurrentDomain.DomainUnload += (_, __) => - { - try - { - Runner.Dispose(); - } - catch { } - }; - Initialize(); } - private static string CreateSpecConfig() + private static Config CreateSpecConfig(DatabaseFixture databaseFixture) { - return SpecConfig.Replace("", Runner.ConnectionString + "akkanet"); - } + var specString = @" + akka.test.single-expect-default = 3s + akka.persistence { + publish-plugin-commands = on + journal { + plugin = ""akka.persistence.journal.mongodb"" + mongodb { + class = ""Akka.Persistence.MongoDb.Journal.MongoDbJournal, Akka.Persistence.MongoDb"" + connection-string = """ + databaseFixture.ConnectionString + @""" + auto-initialize = on + collection = ""EventJournal"" + } + } + }"; - protected override void Dispose(bool disposing) - { - new MongoClient(Runner.ConnectionString) - .GetDatabase("akkanet") - .DropCollectionAsync("EventJournal").Wait(); - - base.Dispose(disposing); + return ConfigurationFactory.ParseString(specString); } } } diff --git a/src/Akka.Persistence.MongoDb.Tests/MongoDbSnapshotStoreSpec.cs b/src/Akka.Persistence.MongoDb.Tests/MongoDbSnapshotStoreSpec.cs index a945894..87d9a4e 100644 --- a/src/Akka.Persistence.MongoDb.Tests/MongoDbSnapshotStoreSpec.cs +++ b/src/Akka.Persistence.MongoDb.Tests/MongoDbSnapshotStoreSpec.cs @@ -5,62 +5,38 @@ // //----------------------------------------------------------------------- -using System; -using System.Configuration; -using Akka.Persistence.TestKit.Snapshot; -using Mongo2Go; -using MongoDB.Driver; using Xunit; +using Akka.Persistence.TCK.Snapshot; +using Akka.Configuration; namespace Akka.Persistence.MongoDb.Tests { [Collection("MongoDbSpec")] - public class MongoDbSnapshotStoreSpec : SnapshotStoreSpec + public class MongoDbSnapshotStoreSpec : SnapshotStoreSpec, IClassFixture { - private static readonly MongoDbRunner Runner = MongoDbRunner.Start(ConfigurationManager.AppSettings[0]); - - private static readonly string SpecConfig = @" - akka.test.single-expect-default = 3s - akka.persistence { - publish-plugin-commands = on - snapshot-store { - plugin = ""akka.persistence.snapshot-store.mongodb"" - mongodb { - class = ""Akka.Persistence.MongoDb.Snapshot.MongoDbSnapshotStore, Akka.Persistence.MongoDb"" - connection-string = """" - auto-initialize = on - collection = ""SnapshotStore"" - } - } - }"; - - public MongoDbSnapshotStoreSpec() : base(CreateSpecConfig(), "MongoDbSnapshotStoreSpec") + public MongoDbSnapshotStoreSpec(DatabaseFixture databaseFixture) : base(CreateSpecConfig(databaseFixture), "MongoDbSnapshotStoreSpec") { - AppDomain.CurrentDomain.DomainUnload += (_, __) => - { - try - { - Runner.Dispose(); - } - catch { } - }; - - Initialize(); } - private static string CreateSpecConfig() + private static Config CreateSpecConfig(DatabaseFixture databaseFixture) { - return SpecConfig.Replace("", Runner.ConnectionString + "akkanet"); - } - - protected override void Dispose(bool disposing) - { - new MongoClient(Runner.ConnectionString) - .GetDatabase("akkanet") - .DropCollectionAsync("SnapshotStore").Wait(); + var specString = @" + akka.test.single-expect-default = 3s + akka.persistence { + publish-plugin-commands = on + snapshot-store { + plugin = ""akka.persistence.snapshot-store.mongodb"" + mongodb { + class = ""Akka.Persistence.MongoDb.Snapshot.MongoDbSnapshotStore, Akka.Persistence.MongoDb"" + connection-string = """ + databaseFixture.ConnectionString + @""" + auto-initialize = on + collection = ""SnapshotStore"" + } + } + }"; - base.Dispose(disposing); + return ConfigurationFactory.ParseString(specString); } } } diff --git a/src/Akka.Persistence.MongoDb.Tests/Properties/AssemblyInfo.cs b/src/Akka.Persistence.MongoDb.Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index 5b563a9..0000000 --- a/src/Akka.Persistence.MongoDb.Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// Allgemeine Informationen über eine Assembly werden über die folgenden -// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, -// die mit einer Assembly verknüpft sind. -[assembly: AssemblyTitle("Akka.Persistence.MongoDb.Tests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyProduct("Akka.Persistence.MongoDb.Tests")] -[assembly: AssemblyCulture("")] - -// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar -// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von -// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. -[assembly: ComVisible(false)] - -// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird -[assembly: Guid("32a2acbe-8a3c-4093-8c13-d65b113b3327")] diff --git a/src/Akka.Persistence.MongoDb.Tests/packages.config b/src/Akka.Persistence.MongoDb.Tests/packages.config deleted file mode 100644 index c1c634d..0000000 --- a/src/Akka.Persistence.MongoDb.Tests/packages.config +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Akka.Persistence.MongoDb.sln b/src/Akka.Persistence.MongoDb.sln deleted file mode 100644 index 6fdb083..0000000 --- a/src/Akka.Persistence.MongoDb.sln +++ /dev/null @@ -1,45 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Persistence.MongoDb", "Akka.Persistence.MongoDb\Akka.Persistence.MongoDb.csproj", "{12E044EF-08A2-428B-AAF5-C3D328860C4E}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Persistence.MongoDb.Tests", "Akka.Persistence.MongoDb.Tests\Akka.Persistence.MongoDb.Tests.csproj", "{32A2ACBE-8A3C-4093-8C13-D65B113B3327}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{86AAC379-3743-4D46-8B92-AE6A5ED80A44}" - ProjectSection(SolutionItems) = preProject - ..\appveyor.yml = ..\appveyor.yml - ..\build.cmd = ..\build.cmd - ..\build.fsx = ..\build.fsx - ..\build.sh = ..\build.sh - ..\README.md = ..\README.md - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{65DAEEC3-80C7-42C5-B0AC-DFC928846EF6}" - ProjectSection(SolutionItems) = preProject - .nuget\NuGet.Config = .nuget\NuGet.Config - .nuget\NuGet.Dev.Config = .nuget\NuGet.Dev.Config - .nuget\NuGet.exe = .nuget\NuGet.exe - .nuget\NuGet.targets = .nuget\NuGet.targets - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {12E044EF-08A2-428B-AAF5-C3D328860C4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {12E044EF-08A2-428B-AAF5-C3D328860C4E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {12E044EF-08A2-428B-AAF5-C3D328860C4E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {12E044EF-08A2-428B-AAF5-C3D328860C4E}.Release|Any CPU.Build.0 = Release|Any CPU - {32A2ACBE-8A3C-4093-8C13-D65B113B3327}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {32A2ACBE-8A3C-4093-8C13-D65B113B3327}.Debug|Any CPU.Build.0 = Debug|Any CPU - {32A2ACBE-8A3C-4093-8C13-D65B113B3327}.Release|Any CPU.ActiveCfg = Release|Any CPU - {32A2ACBE-8A3C-4093-8C13-D65B113B3327}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/src/Akka.Persistence.MongoDb/Akka.Persistence.MongoDb.csproj b/src/Akka.Persistence.MongoDb/Akka.Persistence.MongoDb.csproj index eb364be..d62c621 100644 --- a/src/Akka.Persistence.MongoDb/Akka.Persistence.MongoDb.csproj +++ b/src/Akka.Persistence.MongoDb/Akka.Persistence.MongoDb.csproj @@ -1,117 +1,18 @@ - - - + + + - Debug - AnyCPU - {12E044EF-08A2-428B-AAF5-C3D328860C4E} - Library - Properties - Akka.Persistence.MongoDb - Akka.Persistence.MongoDb - v4.5 - 512 - ..\ - true + net45;netstandard1.6 - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\Akka.1.1.1\lib\net45\Akka.dll - True - - - ..\packages\Akka.Persistence.1.1.1.28-beta\lib\net45\Akka.Persistence.dll - True - - - ..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.dll - True - - - ..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.Serialization.dll - True - - - ..\packages\MongoDB.Bson.2.2.4\lib\net45\MongoDB.Bson.dll - True - - - ..\packages\MongoDB.Driver.2.2.4\lib\net45\MongoDB.Driver.dll - True - - - ..\packages\MongoDB.Driver.Core.2.2.4\lib\net45\MongoDB.Driver.Core.dll - True - - - ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - True - - - - ..\packages\System.Collections.Immutable.1.1.36\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll - True - - - - - - - - - + - - Properties\SharedAssemblyInfo.cs - - - - - - - - - - + - - - - - Designer - + + - - - - - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - + + $(DefineConstants);RELEASE + \ No newline at end of file diff --git a/src/Akka.Persistence.MongoDb/Akka.Persistence.MongoDb.nuspec b/src/Akka.Persistence.MongoDb/Akka.Persistence.MongoDb.nuspec deleted file mode 100644 index 4cd912f..0000000 --- a/src/Akka.Persistence.MongoDb/Akka.Persistence.MongoDb.nuspec +++ /dev/null @@ -1,20 +0,0 @@ - - - - @project@ - @project@@title@ - @build.number@ - @authors@ - @authors@ - Akka.NET Persistence journal and snapshot store backed by MongoDB. - https://github.com/akkadotnet/akka.net/blob/master/LICENSE - https://github.com/akkadotnet/Akka.Persistence.MongoDB - http://getakka.net/images/AkkaNetLogo.Normal.png - false - @releaseNotes@ - @copyright@ - @tags@ persistence eventsource mongodb mongo - @dependencies@ - @references@ - - diff --git a/src/Akka.Persistence.MongoDb/FullTypeNameDiscriminatorConvention.cs b/src/Akka.Persistence.MongoDb/FullTypeNameDiscriminatorConvention.cs new file mode 100644 index 0000000..e923b48 --- /dev/null +++ b/src/Akka.Persistence.MongoDb/FullTypeNameDiscriminatorConvention.cs @@ -0,0 +1,37 @@ +//----------------------------------------------------------------------- +// +// Copyright (C) 2009-2016 Lightbend Inc. +// Copyright (C) 2013-2016 Akka.NET project +// +//----------------------------------------------------------------------- +using System; +using System.Reflection; +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Conventions; + +namespace Akka.Persistence.MongoDb +{ + /// + /// Our discriminator is the type's full name with the assembly name. + /// Additional assembly information is excluded for forward compatibility. + /// + class FullTypeNameDiscriminatorConvention : StandardDiscriminatorConvention + { + public static readonly FullTypeNameDiscriminatorConvention Instance = new FullTypeNameDiscriminatorConvention("_t"); + + public FullTypeNameDiscriminatorConvention(string element) : base(element) { } + + /// + /// Our discriminator is the full type name with the assembly name. + /// Additional assembly information is excluded for forward compatibility. + /// + /// + /// + /// full type name with the simple assembly name + public override BsonValue GetDiscriminator(Type nominalType, Type actualType) + { + var assemblyName = actualType.GetTypeInfo().Assembly.FullName.Split(',')[0]; + return $"{actualType.FullName}, {assemblyName}"; + } + } +} diff --git a/src/Akka.Persistence.MongoDb/FullTypeNameObjectSerializer.cs b/src/Akka.Persistence.MongoDb/FullTypeNameObjectSerializer.cs new file mode 100644 index 0000000..dc98dba --- /dev/null +++ b/src/Akka.Persistence.MongoDb/FullTypeNameObjectSerializer.cs @@ -0,0 +1,81 @@ +//----------------------------------------------------------------------- +// +// Copyright (C) 2009-2016 Lightbend Inc. +// Copyright (C) 2013-2016 Akka.NET project +// +//----------------------------------------------------------------------- + +using System; +using System.Reflection; +using MongoDB.Bson; +using MongoDB.Bson.Serialization; +using MongoDB.Bson.Serialization.Conventions; +using MongoDB.Bson.Serialization.Serializers; + +namespace Akka.Persistence.MongoDb +{ + /// + /// Represents a serializer for objects. + /// + class FullTypeNameObjectSerializer : ObjectSerializer + { + protected readonly IDiscriminatorConvention DiscriminatorConvention = FullTypeNameDiscriminatorConvention.Instance; + + /// + /// Initializes a new instance of the class. + /// + public FullTypeNameObjectSerializer() : base(FullTypeNameDiscriminatorConvention.Instance) { } + + /// + /// Deserializes a value. + /// + public override object Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) + { + var bsonReader = context.Reader; + + if (BsonType.Document == bsonReader.GetCurrentBsonType()) + { + RegisterNewTypesToDiscriminator(DiscriminatorConvention.GetActualType(bsonReader, typeof(object))); + } + + return base.Deserialize(context, args); + } + + /// + /// Serializes a value. + /// + public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, object value) + { + if (value != null) + { + // auto-register new types with MongoDB on serialization, using their full assembly name + RegisterNewTypesToDiscriminator(value.GetType()); + } + + base.Serialize(context, args, value); + } + + /// + /// If the type is not registered, attach it to our discriminator + /// + /// the type to examine + protected void RegisterNewTypesToDiscriminator(Type actualType) + { + // we've detected a new concrete type that isn't registered in MongoDB's serializer + if (actualType != typeof(object) && !actualType.GetTypeInfo().IsInterface && !BsonSerializer.IsTypeDiscriminated(actualType)) + { + try + { + BsonSerializer.RegisterDiscriminatorConvention(actualType, DiscriminatorConvention); + BsonSerializer.RegisterDiscriminator(actualType, DiscriminatorConvention.GetDiscriminator(typeof(object), actualType)); + } + catch (BsonSerializationException) + { + // the MongoDB driver library has no nice mechanism for checking if a discriminator convention is registerd. + // The "Lookup" logic tends to define a default if it doesn't exist. + // So we're forced to eat the "duplicate registration" exception. + } + } + } + } +} diff --git a/src/Akka.Persistence.MongoDb/MongoDbPersistence.cs b/src/Akka.Persistence.MongoDb/MongoDbPersistence.cs index c33e13d..1106a28 100644 --- a/src/Akka.Persistence.MongoDb/MongoDbPersistence.cs +++ b/src/Akka.Persistence.MongoDb/MongoDbPersistence.cs @@ -8,6 +8,7 @@ using System; using Akka.Actor; using Akka.Configuration; +using MongoDB.Bson.Serialization; namespace Akka.Persistence.MongoDb { @@ -16,6 +17,13 @@ namespace Akka.Persistence.MongoDb /// public class MongoDbPersistence : IExtension { + static MongoDbPersistence() + { + // Some MongoDB things are statically configured. + + // Register our own serializer for objects that uses the type's FullName + Assembly for the discriminator + BsonSerializer.RegisterSerializer(typeof(object), new FullTypeNameObjectSerializer()); + } /// /// Returns a default configuration for akka persistence MongoDb journal and snapshot store. /// diff --git a/src/Akka.Persistence.MongoDb/Properties/AssemblyInfo.cs b/src/Akka.Persistence.MongoDb/Properties/AssemblyInfo.cs deleted file mode 100644 index 8b4cdd1..0000000 --- a/src/Akka.Persistence.MongoDb/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// Allgemeine Informationen über eine Assembly werden über die folgenden -// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, -// die mit einer Assembly verknüpft sind. -[assembly: AssemblyTitle("Akka.Persistence.MongoDb")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyProduct("Akka.Persistence.MongoDb")] -[assembly: AssemblyCulture("")] - -// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar -// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von -// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. -[assembly: ComVisible(false)] - -// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird -[assembly: Guid("12e044ef-08a2-428b-aaf5-c3d328860c4e")] diff --git a/src/Akka.Persistence.MongoDb/app.config b/src/Akka.Persistence.MongoDb/app.config deleted file mode 100644 index 8460dd4..0000000 --- a/src/Akka.Persistence.MongoDb/app.config +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/src/Akka.Persistence.MongoDb/packages.config b/src/Akka.Persistence.MongoDb/packages.config deleted file mode 100644 index 30d01c6..0000000 --- a/src/Akka.Persistence.MongoDb/packages.config +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/src/SharedAssemblyInfo.cs b/src/SharedAssemblyInfo.cs deleted file mode 100644 index 73a687b..0000000 --- a/src/SharedAssemblyInfo.cs +++ /dev/null @@ -1,8 +0,0 @@ -// -using System.Reflection; - -[assembly: AssemblyCompanyAttribute("Akka.NET Team")] -[assembly: AssemblyCopyrightAttribute("Copyright © 2013-2016 Akka.NET Team")] -[assembly: AssemblyTrademarkAttribute("")] -[assembly: AssemblyVersionAttribute("1.1.0.0")] -[assembly: AssemblyFileVersionAttribute("1.1.0.0")] diff --git a/src/common.props b/src/common.props new file mode 100644 index 0000000..041fe55 --- /dev/null +++ b/src/common.props @@ -0,0 +1,18 @@ + + + Copyright © 2013-2018 Akka.NET Project + Akka.NET Contrib + 1.3.5 + http://getakka.net/images/akkalogo.png + https://github.com/AkkaNetContrib/Akka.Persistence.MongoDB + https://github.com/AkkaNetContrib/Akka.Persistence.MongoDB/blob/master/LICENSE.md + Support for Akka.NET 1.3.5 and upgraded MongoDb drivers et al. + true + Akka Persistence journal and snapshot store backed by MongoDB database. + $(NoWarn);CS1591 + + + 2.3.0 + 15.3.0 + + \ No newline at end of file