-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
217 additions
and
0 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
orleans.storageprovider.couchbase/CouchbaseStorageProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Orleans; | ||
using Orleans.Storage; | ||
using Orleans.Runtime; | ||
using Newtonsoft.Json; | ||
using Couchbase; | ||
using Couchbase.Extensions; | ||
using Enyim.Caching.Memcached; | ||
|
||
|
||
namespace Orleans.StorageProvider.Couchbase | ||
{ | ||
public class CouchbaseStorageProvider : IStorageProvider | ||
{ | ||
public string Name { get; set;} | ||
public OrleansLogger Log { get; set; } | ||
|
||
public Task Init(string name, Orleans.Providers.IProviderRuntime providerRuntime, Orleans.Providers.IProviderConfiguration config) | ||
{ | ||
this.Name = name; | ||
return TaskDone.Done; | ||
} | ||
|
||
public Task Close() | ||
{ | ||
return TaskDone.Done; | ||
} | ||
|
||
public async Task ReadStateAsync(string grainType, Orleans.Runtime.GrainReference grainReference, IGrainState grainState) | ||
{ | ||
|
||
var GrainKey = GetGrainKey(grainType, grainReference); | ||
try | ||
{ | ||
var Client = new CouchbaseClient(); | ||
if (Client.KeyExists(GrainKey)) | ||
{ | ||
var json = ""; | ||
await Task.Run(() => { json = Client.Get(GrainKey).ToString(); }); | ||
var data = JsonConvert.DeserializeObject<Dictionary<String, Object>>(json); | ||
grainState.SetAll(data); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
|
||
Log.Error(0, "Error in ReadStateAsync", ex); | ||
} | ||
} | ||
|
||
public async Task WriteStateAsync(string grainType, Orleans.Runtime.GrainReference grainReference, IGrainState grainState) | ||
{ | ||
try | ||
{ | ||
var Client = new CouchbaseClient(); | ||
var GrainKey = GetGrainKey(grainType, grainReference); | ||
var json = JsonConvert.SerializeObject(grainState.AsDictionary()); | ||
await Task.Run(() => | ||
{ | ||
Client.Store(StoreMode.Set, GrainKey, json); | ||
}); | ||
|
||
} | ||
catch (Exception ex) | ||
{ | ||
|
||
Log.Error(0, "Error in WriteStateAsync", ex); | ||
} | ||
} | ||
|
||
public async Task ClearStateAsync(string grainType, Orleans.Runtime.GrainReference grainReference, IGrainState grainState) | ||
{ | ||
try | ||
{ | ||
var Client = new CouchbaseClient(); | ||
await Task.Run(() => Client.Remove(GetGrainKey(grainType, grainReference))); | ||
} | ||
catch (Exception ex) | ||
{ | ||
|
||
Log.Error(0, "Error in ClearStateAsync", ex); | ||
} | ||
} | ||
|
||
private string GetGrainKey(string grainType, GrainReference grainReference) | ||
{ | ||
return string.Format("{0}-{1}.json", grainType, grainReference.ToKeyString()); | ||
} | ||
|
||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
orleans.storageprovider.couchbase/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("orleans.storageprovider.couchbase")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("orleans.storageprovider.couchbase")] | ||
[assembly: AssemblyCopyright("Copyright © 2014")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("42cea8a9-17be-4f3e-93fe-28e2a3abefb3")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<runtime> | ||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
<dependentAssembly> | ||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> | ||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> | ||
</dependentAssembly> | ||
</assemblyBinding> | ||
</runtime> | ||
</configuration> |
70 changes: 70 additions & 0 deletions
70
orleans.storageprovider.couchbase/orleans.storageprovider.couchbase.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{E9559B07-65A5-48B7-9565-15BCB89A2910}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>orleans.storageprovider.couchbase</RootNamespace> | ||
<AssemblyName>orleans.storageprovider.couchbase</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Couchbase"> | ||
<HintPath>..\..\..\Users\Mohamed\Documents\Visual Studio 2013\Projects\IoT.FileStorage\packages\CouchbaseNetClient.1.3.9\lib\net40\Couchbase.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Enyim.Caching"> | ||
<HintPath>..\..\..\Users\Mohamed\Documents\Visual Studio 2013\Projects\IoT.FileStorage\packages\CouchbaseNetClient.1.3.9\lib\net40\Enyim.Caching.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>..\..\..\Users\Mohamed\Documents\Visual Studio 2013\Projects\IoT.FileStorage\packages\Newtonsoft.Json.6.0.5\lib\net45\Newtonsoft.Json.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Orleans"> | ||
<HintPath>D:\Microsoft Codename Orleans SDK v0.9\SDK\Binaries\OrleansServer\Orleans.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="CouchbaseStorageProvider.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="app.config" /> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="CouchbaseNetClient" version="1.3.9" targetFramework="net45" /> | ||
<package id="Newtonsoft.Json" version="6.0.5" targetFramework="net45" /> | ||
</packages> |