Skip to content

Commit c2a6e76

Browse files
committed
Northwind Example Fixes/Updates
* Switched dependency to nuget from lib folder to simplify future updates. * Updated obsolete usages to use newer syntax. * Optimized images (lossless) * Removed contents of pacakages folder * Various minor tweaks --Chris McKee
1 parent b761383 commit c2a6e76

File tree

114 files changed

+2667
-14889
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+2667
-14889
lines changed
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+
<solution>
4+
<add key="disableSourceControlIntegration" value="true" />
5+
</solution>
6+
</configuration>
788 KB
Binary file not shown.
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
5+
6+
<!-- Enable the restore command to run before builds -->
7+
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>
8+
9+
<!-- Property that enables building a package from a project -->
10+
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>
11+
12+
<!-- Determines if package restore consent is required to restore packages -->
13+
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>
14+
15+
<!-- Download NuGet.exe if it does not already exist -->
16+
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
17+
</PropertyGroup>
18+
19+
<ItemGroup Condition=" '$(PackageSources)' == '' ">
20+
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
21+
<!-- The official NuGet package source (https://www.nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
22+
<!--
23+
<PackageSource Include="https://www.nuget.org/api/v2/" />
24+
<PackageSource Include="https://my-nuget-source/nuget/" />
25+
-->
26+
</ItemGroup>
27+
28+
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
29+
<!-- Windows specific commands -->
30+
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
31+
<PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
32+
</PropertyGroup>
33+
34+
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
35+
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
36+
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
37+
<PackagesConfig>packages.config</PackagesConfig>
38+
</PropertyGroup>
39+
40+
<PropertyGroup>
41+
<!-- NuGet command -->
42+
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\NuGet.exe</NuGetExePath>
43+
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>
44+
45+
<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
46+
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>
47+
48+
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
49+
50+
<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
51+
<NonInteractiveSwitch Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' ">-NonInteractive</NonInteractiveSwitch>
52+
53+
<PaddedSolutionDir Condition=" '$(OS)' == 'Windows_NT'">"$(SolutionDir) "</PaddedSolutionDir>
54+
<PaddedSolutionDir Condition=" '$(OS)' != 'Windows_NT' ">"$(SolutionDir)"</PaddedSolutionDir>
55+
56+
<!-- Commands -->
57+
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)</RestoreCommand>
58+
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand>
59+
60+
<!-- We need to ensure packages are restored prior to assembly resolve -->
61+
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
62+
RestorePackages;
63+
$(BuildDependsOn);
64+
</BuildDependsOn>
65+
66+
<!-- Make the build depend on restore packages -->
67+
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
68+
$(BuildDependsOn);
69+
BuildPackage;
70+
</BuildDependsOn>
71+
</PropertyGroup>
72+
73+
<Target Name="CheckPrerequisites">
74+
<!-- Raise an error if we're unable to locate nuget.exe -->
75+
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
76+
<!--
77+
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
78+
This effectively acts as a lock that makes sure that the download operation will only happen once and all
79+
parallel builds will have to wait for it to complete.
80+
-->
81+
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadNuGetExe=$(DownloadNuGetExe)" />
82+
</Target>
83+
84+
<Target Name="_DownloadNuGet">
85+
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
86+
</Target>
87+
88+
<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
89+
<Exec Command="$(RestoreCommand)"
90+
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
91+
92+
<Exec Command="$(RestoreCommand)"
93+
LogStandardErrorAsError="true"
94+
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
95+
</Target>
96+
97+
<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
98+
<Exec Command="$(BuildCommand)"
99+
Condition=" '$(OS)' != 'Windows_NT' " />
100+
101+
<Exec Command="$(BuildCommand)"
102+
LogStandardErrorAsError="true"
103+
Condition=" '$(OS)' == 'Windows_NT' " />
104+
</Target>
105+
106+
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
107+
<ParameterGroup>
108+
<OutputFilename ParameterType="System.String" Required="true" />
109+
</ParameterGroup>
110+
<Task>
111+
<Reference Include="System.Core" />
112+
<Using Namespace="System" />
113+
<Using Namespace="System.IO" />
114+
<Using Namespace="System.Net" />
115+
<Using Namespace="Microsoft.Build.Framework" />
116+
<Using Namespace="Microsoft.Build.Utilities" />
117+
<Code Type="Fragment" Language="cs">
118+
<![CDATA[
119+
try {
120+
OutputFilename = Path.GetFullPath(OutputFilename);
121+
122+
Log.LogMessage("Downloading latest version of NuGet.exe...");
123+
WebClient webClient = new WebClient();
124+
webClient.DownloadFile("https://www.nuget.org/nuget.exe", OutputFilename);
125+
126+
return true;
127+
}
128+
catch (Exception ex) {
129+
Log.LogErrorFromException(ex);
130+
return false;
131+
}
132+
]]>
133+
</Code>
134+
</Task>
135+
</UsingTask>
136+
</Project>
Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,51 @@
1-
using ServiceStack.Common;
2-
using Northwind.ServiceModel.Operations;
3-
using ServiceStack.ServiceHost;
4-
using ServiceStack.ServiceInterface;
1+

52

6-
namespace Northwind.ServiceInterface
7-
{
8-
/// <summary>
9-
/// Create your ServiceStack RESTful web service implementation.
10-
/// </summary>
11-
public class CachedCustomersService : Service
12-
{
13-
public object Get(CachedCustomers request)
14-
{
15-
//Manually create the Unified Resource Name "urn:customers".
16-
return base.RequestContext.ToOptimizedResultUsingCache(base.Cache, "urn:customers", () =>
17-
{
18-
//Resolve the service in order to get the customers.
19-
using (var service = this.ResolveService<CustomersService>())
20-
return service.Get(new Customers());
21-
});
22-
}
3+
namespace ServiceStack.Northwind.ServiceInterface
4+
{
5+
using ServiceStack.CacheAccess;
6+
using ServiceStack.Common;
7+
using ServiceStack.Northwind.ServiceModel.Operations;
8+
using ServiceStack.ServiceHost;
9+
using ServiceStack.ServiceInterface;
10+
11+
public class CachedCustomersService : ServiceStack.ServiceInterface.Service
12+
{
13+
public ICacheClient CacheClient { get; set; }
2314

24-
public object Get(CachedCustomerDetails request)
25-
{
26-
//Create the Unified Resource Name "urn:customerdetails:{id}".
27-
var cacheKey = UrnId.Create<CustomerDetails>(request.Id);
28-
return base.RequestContext.ToOptimizedResultUsingCache(base.Cache, cacheKey, () =>
29-
{
30-
using (var service = this.ResolveService<CustomerDetailsService>())
31-
{
32-
return service.Get(new CustomerDetails { Id = request.Id });
33-
}
34-
});
35-
}
15+
public object Get(CachedCustomers request)
16+
{
17+
return base.RequestContext.ToOptimizedResultUsingCache(
18+
this.CacheClient, "urn:customers", () => {
19+
var service = this.ResolveService<CustomersService>();
20+
return (CustomersResponse) service.Get(new Customers());
21+
});
22+
}
23+
}
24+
25+
public class CachedCustomerDetailsService : Service
26+
{
27+
public ICacheClient CacheClient { get; set; }
3628

37-
public object Get(CachedOrders request)
38-
{
39-
var cacheKey = UrnId.Create<Orders>(request.CustomerId ?? "all", request.Page.GetValueOrDefault(0).ToString());
40-
return base.RequestContext.ToOptimizedResultUsingCache(this.Cache, cacheKey, () =>
41-
{
42-
using(var service = this.ResolveService<OrdersService>())
43-
{
44-
return service.Get(new Orders { CustomerId = request.CustomerId, Page = request.Page });
45-
}
46-
});
47-
}
48-
}
29+
public object Get(CachedCustomerDetails request)
30+
{
31+
var cacheKey = UrnId.Create<CustomerDetails>(request.Id);
32+
return base.RequestContext.ToOptimizedResultUsingCache(
33+
this.CacheClient, cacheKey, () => (CustomerDetailsResponse)this.ResolveService<CustomerDetailsService>()
34+
.Get(new CustomerDetails { Id = request.Id }));
35+
}
36+
}
37+
38+
public class CachedOrdersService : Service
39+
{
40+
public ICacheClient CacheClient { get; set; }
41+
42+
public object Get(CachedOrders request)
43+
{
44+
var cacheKey = UrnId.Create<Orders>(request.CustomerId ?? "all", request.Page.GetValueOrDefault(0).ToString());
45+
return base.RequestContext.ToOptimizedResultUsingCache(CacheClient, cacheKey,
46+
() => (OrdersResponse) ResolveService<OrdersService>()
47+
.Get(new Orders { CustomerId = request.CustomerId, Page = request.Page }));
48+
}
49+
}
4950

5051
}
Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
1-
using System;
2-
using System.Net;
3-
using ServiceStack.Common.Web;
4-
using Northwind.ServiceModel.Operations;
5-
using Northwind.ServiceModel.Types;
6-
using ServiceStack.OrmLite;
7-
using ServiceStack.ServiceInterface;
8-
9-
namespace Northwind.ServiceInterface
10-
{
11-
/// <summary>
12-
/// Create your ServiceStack RESTful web service implementation.
13-
/// </summary>
14-
public class CustomerDetailsService : Service
15-
{
16-
public CustomerDetailsResponse Get(CustomerDetails request)
17-
{
18-
var customer = Db.IdOrDefault<Customer>(request.Id);
19-
if (customer == null)
20-
throw new HttpError(HttpStatusCode.NotFound, new ArgumentException("Customer does not exist: " + request.Id));
21-
22-
using (var ordersService = base.ResolveService<OrdersService>())
23-
{
24-
var ordersResponse = ordersService.Get(new Orders { CustomerId = customer.Id });
25-
26-
return new CustomerDetailsResponse {
27-
Customer = customer,
28-
CustomerOrders = ordersResponse.Results,
29-
};
30-
}
31-
}
32-
}
33-
}
1+
namespace ServiceStack.Northwind.ServiceInterface
2+
{
3+
using System;
4+
using System.Net;
5+
using ServiceStack.Common.Web;
6+
using ServiceStack.Northwind.ServiceModel.Operations;
7+
using ServiceStack.Northwind.ServiceModel.Types;
8+
using ServiceStack.OrmLite;
9+
using ServiceStack.ServiceInterface;
10+
11+
public class CustomerDetailsService : Service
12+
{
13+
public IDbConnectionFactory DbFactory { get; set; }
14+
15+
public CustomerDetailsResponse Get(CustomerDetails request)
16+
{
17+
var customer = DbFactory.Run(dbCmd => dbCmd.GetByIdOrDefault<Customer>(request.Id));
18+
if (customer == null)
19+
throw new HttpError(HttpStatusCode.NotFound,
20+
new ArgumentException("Customer does not exist: " + request.Id));
21+
22+
var ordersService = base.ResolveService<OrdersService>();
23+
var ordersResponse = (OrdersResponse) ordersService.Get(new Orders {CustomerId = customer.Id});
24+
25+
return new CustomerDetailsResponse
26+
{
27+
Customer = customer,
28+
CustomerOrders = ordersResponse.Results,
29+
};
30+
}
31+
}
32+
}
Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
using Northwind.ServiceModel.Operations;
2-
using Northwind.ServiceModel.Types;
3-
using ServiceStack.OrmLite;
4-
using ServiceStack.ServiceInterface;
5-
6-
namespace Northwind.ServiceInterface
7-
{
8-
/// <summary>
9-
/// Create your ServiceStack RESTful web service implementation.
10-
/// </summary>
11-
public class CustomersService : Service
12-
{
13-
public CustomersResponse Get(Customers request)
14-
{
15-
return new CustomersResponse { Customers = base.Db.Select<Customer>() };
16-
}
17-
}
18-
}
1+
namespace ServiceStack.Northwind.ServiceInterface
2+
{
3+
using ServiceStack.Northwind.ServiceModel.Operations;
4+
using ServiceStack.Northwind.ServiceModel.Types;
5+
using ServiceStack.OrmLite;
6+
using ServiceStack.ServiceInterface;
7+
8+
public class CustomersService : Service
9+
{
10+
public IDbConnectionFactory DbFactory { get; set; }
11+
12+
public CustomersResponse Get(Customers request)
13+
{
14+
return new CustomersResponse {Customers = DbFactory.Run(dbCmd => dbCmd.Select<Customer>())};
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)