-
Notifications
You must be signed in to change notification settings - Fork 2
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
kokovin
committed
Jul 3, 2014
1 parent
603557f
commit 0e643ac
Showing
34 changed files
with
6,864 additions
and
94 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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,37 @@ | ||
using System; | ||
using System.Net; | ||
using Client; | ||
using Client.Parameters; | ||
|
||
namespace HighLevelClient | ||
{ | ||
public class EnterpriseClient | ||
{ | ||
private static readonly Random random = new Random(); | ||
private readonly IPEndPoint[] endpoints; | ||
private readonly ServiceClient internalClient; | ||
|
||
public EnterpriseClient(IPEndPoint[] endpoints) | ||
{ | ||
this.endpoints = endpoints; | ||
internalClient = new ServiceClient(); | ||
} | ||
|
||
private IPEndPoint NextReplica | ||
{ | ||
get { return endpoints[random.Next(endpoints.Length)]; } | ||
} | ||
|
||
public void Write(string key, string value) | ||
{ | ||
Data data = internalClient.Read(key, NextReplica) ?? new Data(); | ||
internalClient.Write(key, new Data { Value = value, Version = data.Version + 1 }, NextReplica); | ||
} | ||
|
||
public string Read(string key) | ||
{ | ||
Data read = internalClient.Read(key, NextReplica); | ||
return read == null ? null : read.Value; | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
09-NoSQL/CrashCourse/HighLevelClient/HighLevelClient.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,59 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.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>{057BA9C0-E56D-4A74-BED2-7A0AF447E4E3}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>HighLevelClient</RootNamespace> | ||
<AssemblyName>HighLevelClient</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="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="EnterpriseClient.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Client\Client.csproj"> | ||
<Project>{7b9907d3-d0f4-4566-96e8-3e3859abf08e}</Project> | ||
<Name>Client</Name> | ||
</ProjectReference> | ||
</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> |
36 changes: 36 additions & 0 deletions
36
09-NoSQL/CrashCourse/HighLevelClient/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("HighLevelClient")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("HighLevelClient")] | ||
[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("72dd8122-885e-4306-938f-de6ad4e1f8e7")] | ||
|
||
// 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
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
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
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,53 @@ | ||
using System; | ||
using System.Net; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Client; | ||
using Client.Parameters; | ||
using SKBKontur.WebPersonal.Core.ApplicationCommon; | ||
using log4net; | ||
|
||
namespace Service.Infrastructure | ||
{ | ||
public class Replicator | ||
{ | ||
private readonly IServiceClient serviceClient; | ||
private readonly IPEndPoint[] endpoints; | ||
private static ILog log = LogManager.GetLogger(typeof (Replicator)); | ||
|
||
public Replicator(IServiceClient serviceClient, IApplicationSettings applicationSettings) | ||
{ | ||
endpoints = applicationSettings.GetIPEndpointsArray("endpoints"); | ||
this.serviceClient = serviceClient; | ||
} | ||
|
||
public void Replicate(string key, Data value) | ||
{ | ||
Task.Run(() => ReplicateInternal(key, value)); | ||
} | ||
|
||
private void ReplicateInternal(string key, Data value) | ||
{ | ||
foreach (var endPoint in endpoints) | ||
WriteToSingleReplica(key, value, endPoint); | ||
} | ||
|
||
private void WriteToSingleReplica(string key, Data value, IPEndPoint endPoint) | ||
{ | ||
log.InfoFormat("Write '{1}':'{2}',{3} to {0}", endPoint, key, value.Value, value.Version); | ||
Task.Delay(5000).ContinueWith(t => | ||
{ | ||
try | ||
{ | ||
serviceClient.Write(key, value, endPoint); | ||
log.InfoFormat("Write success '{1}':'{2}',{3} to {0}", endPoint, key, value.Value, value.Version); | ||
} | ||
catch (Exception) | ||
{ | ||
log.WarnFormat("Write error '{1}':'{2}',{3} to {0}", endPoint, key, value.Value, value.Version); | ||
WriteToSingleReplica(key, value, endPoint); | ||
} | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.