Skip to content

Commit 958c961

Browse files
tsushitsushi
authored andcommitted
Adding SimpleStore Application
1 parent d0443ba commit 958c961

30 files changed

+1487
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{C10B1320-ABBB-4E53-A04C-053198F71E72}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Common</RootNamespace>
11+
<AssemblyName>Common</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
<PlatformTarget>x64</PlatformTarget>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="Microsoft.ServiceFabric.Data, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=AMD64">
35+
<HintPath>..\packages\Microsoft.ServiceFabric.Data.2.1.163\lib\net45\Microsoft.ServiceFabric.Data.dll</HintPath>
36+
<Private>True</Private>
37+
</Reference>
38+
<Reference Include="Microsoft.ServiceFabric.Data.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=AMD64">
39+
<HintPath>..\packages\Microsoft.ServiceFabric.Data.2.1.163\lib\net45\Microsoft.ServiceFabric.Data.Interfaces.dll</HintPath>
40+
<Private>True</Private>
41+
</Reference>
42+
<Reference Include="Microsoft.ServiceFabric.Internal, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=AMD64">
43+
<HintPath>..\packages\Microsoft.ServiceFabric.5.1.163\lib\net45\Microsoft.ServiceFabric.Internal.dll</HintPath>
44+
<Private>True</Private>
45+
</Reference>
46+
<Reference Include="Microsoft.ServiceFabric.Internal.Strings, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=AMD64">
47+
<HintPath>..\packages\Microsoft.ServiceFabric.5.1.163\lib\net45\Microsoft.ServiceFabric.Internal.Strings.dll</HintPath>
48+
<Private>True</Private>
49+
</Reference>
50+
<Reference Include="System" />
51+
<Reference Include="System.Core" />
52+
<Reference Include="System.Fabric, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=AMD64">
53+
<HintPath>..\packages\Microsoft.ServiceFabric.5.1.163\lib\net45\System.Fabric.dll</HintPath>
54+
<Private>True</Private>
55+
</Reference>
56+
<Reference Include="System.Runtime.Serialization" />
57+
<Reference Include="System.ServiceModel" />
58+
<Reference Include="System.Xml.Linq" />
59+
<Reference Include="System.Data.DataSetExtensions" />
60+
<Reference Include="Microsoft.CSharp" />
61+
<Reference Include="System.Data" />
62+
<Reference Include="System.Net.Http" />
63+
<Reference Include="System.Xml" />
64+
</ItemGroup>
65+
<ItemGroup>
66+
<Compile Include="IAsyncEnumerableExtensions.cs" />
67+
<Compile Include="IShoppingCartService.cs" />
68+
<Compile Include="ShoppingCartItem.cs" />
69+
<Compile Include="Properties\AssemblyInfo.cs" />
70+
</ItemGroup>
71+
<ItemGroup>
72+
<None Include="packages.config" />
73+
</ItemGroup>
74+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
75+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
76+
Other similar extension points exist, see Microsoft.Common.targets.
77+
<Target Name="BeforeBuild">
78+
</Target>
79+
<Target Name="AfterBuild">
80+
</Target>
81+
-->
82+
</Project>
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Threading;
7+
using Microsoft.ServiceFabric.Data;
8+
using System.Collections;
9+
10+
namespace Common
11+
{
12+
/// <summary>
13+
/// I copied this class by https://github.com/Azure-Samples/service-fabric-dotnet-management-party-cluster/blob/sdkupdate/PartyCluster/Common/IAsyncEnumerableExtensions.cs
14+
/// for learning purpose. The author is the author of the github account.
15+
/// I added this class for converting IReliableDictionary into Enumerable object.
16+
/// The book's sample didn't work. select can't use for IReliableDictinoary
17+
/// Refer this. http://stackoverflow.com/questions/36877614/what-would-be-the-best-way-to-search-an-ireliabledictionary
18+
/// </summary>
19+
public static class IAsyncEnumerableExtensions
20+
{
21+
public static IEnumerable<TSource> ToEnumerable<TSource>(this IAsyncEnumerable<TSource> source)
22+
{
23+
if (source == null)
24+
{
25+
throw new ArgumentException("source");
26+
}
27+
28+
return new AsyncEnumerableWrapper<TSource>(source);
29+
}
30+
31+
public static async Task ForeachAsync<T>(this IAsyncEnumerable<T> instance, CancellationToken cancellationToken, Action<T> doSomething)
32+
{
33+
using (IAsyncEnumerator<T> e = instance.GetAsyncEnumerator())
34+
{
35+
while (await e.MoveNextAsync(cancellationToken).ConfigureAwait(false))
36+
{
37+
doSomething(e.Current);
38+
}
39+
}
40+
}
41+
42+
public static async Task<int> CountAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate)
43+
{
44+
int count = 0;
45+
using (var asyncEnumerator = source.GetAsyncEnumerator())
46+
{
47+
while (await asyncEnumerator.MoveNextAsync(CancellationToken.None).ConfigureAwait(false))
48+
{
49+
if (predicate(asyncEnumerator.Current))
50+
{
51+
count++;
52+
}
53+
}
54+
}
55+
return count;
56+
}
57+
58+
internal struct AsyncEnumerableWrapper<TSource> : IEnumerable<TSource>
59+
{
60+
61+
private IAsyncEnumerable<TSource> source;
62+
63+
64+
65+
public AsyncEnumerableWrapper(IAsyncEnumerable<TSource> source)
66+
{
67+
this.source = source;
68+
}
69+
70+
public IEnumerator<TSource> GetEnumerator()
71+
{
72+
return new AsyncEnumeratorWrapper<TSource>(this.source.GetAsyncEnumerator());
73+
}
74+
75+
IEnumerator IEnumerable.GetEnumerator()
76+
{
77+
return this.GetEnumerator();
78+
}
79+
}
80+
81+
internal struct AsyncEnumeratorWrapper<TSource> : IEnumerator<TSource>
82+
{
83+
private IAsyncEnumerator<TSource> source;
84+
private TSource current;
85+
86+
public AsyncEnumeratorWrapper(IAsyncEnumerator<TSource> source)
87+
{
88+
this.source = source;
89+
this.current = default(TSource);
90+
}
91+
public TSource Current
92+
{
93+
get { return this.current; }
94+
}
95+
96+
object IEnumerator.Current
97+
{
98+
get { throw new NotImplementedException(); }
99+
}
100+
101+
public void Dispose()
102+
{
103+
104+
}
105+
106+
public bool MoveNext()
107+
{
108+
if (!this.source.MoveNextAsync(CancellationToken.None).GetAwaiter().GetResult())
109+
{
110+
return false;
111+
}
112+
this.current = this.source.Current;
113+
return true;
114+
}
115+
116+
public void Reset()
117+
{
118+
throw new NotImplementedException();
119+
}
120+
}
121+
}
122+
123+
124+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.ServiceModel;
7+
8+
namespace Common
9+
{
10+
[ServiceContract]
11+
public interface IShoppingCartService
12+
{
13+
[OperationContract]
14+
Task AddItem(ShoppingCartItem item);
15+
[OperationContract]
16+
Task DeleteItem(string productName);
17+
[OperationContract]
18+
Task<List<ShoppingCartItem>> GetItems();
19+
}
20+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Common")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Common")]
13+
[assembly: AssemblyCopyright("Copyright © 2016")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("c10b1320-abbb-4e53-a04c-053198f71e72")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Common
8+
{
9+
public struct ShoppingCartItem
10+
{
11+
public string ProductName { get; set; }
12+
public double UnitPrice { get; set; }
13+
public int Amount { get; set; }
14+
public double LineTotal
15+
{
16+
get
17+
{
18+
return Amount * UnitPrice;
19+
}
20+
}
21+
}
22+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Microsoft.ServiceFabric" version="5.1.163" targetFramework="net452" />
4+
<package id="Microsoft.ServiceFabric.Data" version="2.1.163" targetFramework="net452" />
5+
</packages>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
5+
</startup>
6+
</configuration>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<Settings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2011/01/fabric">
3+
<!-- This is used by the StateManager's replicator. -->
4+
<Section Name="ReplicatorConfig">
5+
<Parameter Name="ReplicatorEndpoint" Value="ReplicatorEndpoint" />
6+
</Section>
7+
<!-- This is used for securing StateManager's replication traffic. -->
8+
<Section Name="ReplicatorSecurityConfig" />
9+
10+
<!-- Add your custom configuration sections and parameters here. -->
11+
<!--
12+
<Section Name="MyConfigSection">
13+
<Parameter Name="MyParameter" Value="Value1" />
14+
</Section>
15+
-->
16+
</Settings>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ServiceManifest Name="ShoppingCartServicePkg"
3+
Version="1.0.0"
4+
xmlns="http://schemas.microsoft.com/2011/01/fabric"
5+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
6+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
7+
<ServiceTypes>
8+
<!-- This is the name of your ServiceType.
9+
This name must match the string used in RegisterServiceType call in Program.cs. -->
10+
<StatefulServiceType ServiceTypeName="ShoppingCartServiceType" HasPersistedState="true" />
11+
</ServiceTypes>
12+
13+
<!-- Code package is your service executable. -->
14+
<CodePackage Name="Code" Version="1.0.0">
15+
<EntryPoint>
16+
<ExeHost>
17+
<Program>ShoppingCartService.exe</Program>
18+
</ExeHost>
19+
</EntryPoint>
20+
</CodePackage>
21+
22+
<!-- Config package is the contents of the Config directoy under PackageRoot that contains an
23+
independently-updateable and versioned set of custom configuration settings for your service. -->
24+
<ConfigPackage Name="Config" Version="1.0.0" />
25+
26+
<Resources>
27+
<Endpoints>
28+
<!-- This endpoint is used by the communication listener to obtain the port on which to
29+
listen. Please note that if your service is partitioned, this port is shared with
30+
replicas of different partitions that are placed in your code. -->
31+
<Endpoint Name="ServiceEndpoint" />
32+
33+
<!-- This endpoint is used by the replicator for replicating the state of your service.
34+
This endpoint is configured through a ReplicatorSettings config section in the Settings.xml
35+
file under the ConfigPackage. -->
36+
<Endpoint Name="ReplicatorEndpoint" />
37+
</Endpoints>
38+
</Resources>
39+
</ServiceManifest>

0 commit comments

Comments
 (0)