Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added new demo project NodeStackProxy which demonstrated how to combi…
…ne node.js with ServiceStack services
- Loading branch information
Showing
26 changed files
with
11,359 additions
and
0 deletions.
There are no files selected for viewing
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,6 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<configuration> | |||
<solution> | |||
<add key="disableSourceControlIntegration" value="true" /> | |||
</solution> | |||
</configuration> |
Binary file not shown.
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,151 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<PropertyGroup> | |||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir> | |||
|
|||
<!-- Enable the restore command to run before builds --> | |||
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages> | |||
|
|||
<!-- Property that enables building a package from a project --> | |||
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage> | |||
|
|||
<!-- Determines if package restore consent is required to restore packages --> | |||
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent> | |||
|
|||
<!-- Download NuGet.exe if it does not already exist --> | |||
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe> | |||
</PropertyGroup> | |||
|
|||
<ItemGroup Condition=" '$(PackageSources)' == '' "> | |||
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used --> | |||
<!-- The official NuGet package source (https://nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list --> | |||
<!-- | |||
<PackageSource Include="https://nuget.org/api/v2/" /> | |||
<PackageSource Include="https://my-nuget-source/nuget/" /> | |||
--> | |||
</ItemGroup> | |||
|
|||
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'"> | |||
<!-- Windows specific commands --> | |||
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath> | |||
<PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig> | |||
</PropertyGroup> | |||
|
|||
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'"> | |||
<!-- We need to launch nuget.exe with the mono command if we're not on windows --> | |||
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath> | |||
<PackagesConfig>packages.config</PackagesConfig> | |||
</PropertyGroup> | |||
|
|||
<PropertyGroup> | |||
<!-- NuGet command --> | |||
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\nuget.exe</NuGetExePath> | |||
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources> | |||
|
|||
<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand> | |||
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand> | |||
|
|||
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir> | |||
|
|||
<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch> | |||
<!-- Commands --> | |||
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(RequireConsentSwitch) -solutionDir "$(SolutionDir) "</RestoreCommand> | |||
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols</BuildCommand> | |||
|
|||
<!-- We need to ensure packages are restored prior to assembly resolve --> | |||
<BuildDependsOn Condition="$(RestorePackages) == 'true'"> | |||
RestorePackages; | |||
$(BuildDependsOn); | |||
</BuildDependsOn> | |||
|
|||
<!-- Make the build depend on restore packages --> | |||
<BuildDependsOn Condition="$(BuildPackage) == 'true'"> | |||
$(BuildDependsOn); | |||
BuildPackage; | |||
</BuildDependsOn> | |||
</PropertyGroup> | |||
|
|||
<Target Name="CheckPrerequisites"> | |||
<!-- Raise an error if we're unable to locate nuget.exe --> | |||
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" /> | |||
<SetEnvironmentVariable EnvKey="VisualStudioVersion" EnvValue="$(VisualStudioVersion)" Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' " /> | |||
<!-- | |||
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once. | |||
This effectively acts as a lock that makes sure that the download operation will only happen once and all | |||
parallel builds will have to wait for it to complete. | |||
--> | |||
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT" /> | |||
</Target> | |||
|
|||
<Target Name="_DownloadNuGet"> | |||
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" /> | |||
</Target> | |||
|
|||
<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites"> | |||
<Exec Command="$(RestoreCommand)" | |||
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" /> | |||
|
|||
<Exec Command="$(RestoreCommand)" | |||
LogStandardErrorAsError="true" | |||
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" /> | |||
</Target> | |||
|
|||
<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites"> | |||
<Exec Command="$(BuildCommand)" | |||
Condition=" '$(OS)' != 'Windows_NT' " /> | |||
|
|||
<Exec Command="$(BuildCommand)" | |||
LogStandardErrorAsError="true" | |||
Condition=" '$(OS)' == 'Windows_NT' " /> | |||
</Target> | |||
|
|||
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> | |||
<ParameterGroup> | |||
<OutputFilename ParameterType="System.String" Required="true" /> | |||
</ParameterGroup> | |||
<Task> | |||
<Reference Include="System.Core" /> | |||
<Using Namespace="System" /> | |||
<Using Namespace="System.IO" /> | |||
<Using Namespace="System.Net" /> | |||
<Using Namespace="Microsoft.Build.Framework" /> | |||
<Using Namespace="Microsoft.Build.Utilities" /> | |||
<Code Type="Fragment" Language="cs"> | |||
<![CDATA[ | |||
try { | |||
OutputFilename = Path.GetFullPath(OutputFilename); | |||
Log.LogMessage("Downloading latest version of NuGet.exe..."); | |||
WebClient webClient = new WebClient(); | |||
webClient.DownloadFile("https://nuget.org/nuget.exe", OutputFilename); | |||
return true; | |||
} | |||
catch (Exception ex) { | |||
Log.LogErrorFromException(ex); | |||
return false; | |||
} | |||
]]> | |||
</Code> | |||
</Task> | |||
</UsingTask> | |||
|
|||
<UsingTask TaskName="SetEnvironmentVariable" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> | |||
<ParameterGroup> | |||
<EnvKey ParameterType="System.String" Required="true" /> | |||
<EnvValue ParameterType="System.String" Required="true" /> | |||
</ParameterGroup> | |||
<Task> | |||
<Using Namespace="System" /> | |||
<Code Type="Fragment" Language="cs"> | |||
<![CDATA[ | |||
try { | |||
Environment.SetEnvironmentVariable(EnvKey, EnvValue, System.EnvironmentVariableTarget.Process); | |||
} | |||
catch { | |||
} | |||
]]> | |||
</Code> | |||
</Task> | |||
</UsingTask> | |||
</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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,109 @@ | |||
using System; | |||
using Funq; | |||
using ServiceStack.Configuration; | |||
using ServiceStack.Redis; | |||
using ServiceStack.ServiceInterface; | |||
using ServiceStack.Common.Web; | |||
using ServiceStack.Text; | |||
using ServiceStack.WebHost.Endpoints; | |||
|
|||
namespace Backbone.Todos | |||
{ | |||
/// <summary> | |||
/// Define your ServiceStack web service request (i.e. Request DTO). | |||
/// </summary> | |||
public class Todo | |||
{ | |||
public long Id { get; set; } | |||
public string Content { get; set; } | |||
public int Order { get; set; } | |||
public bool Done { get; set; } | |||
} | |||
|
|||
/// <summary> | |||
/// Create your ServiceStack rest-ful web service implementation. | |||
/// </summary> | |||
public class TodoService : ServiceStack.ServiceInterface.Service | |||
{ | |||
/// <summary> | |||
/// Gets or sets the Redis Manager. The built-in IoC used with ServiceStack autowires this property. | |||
/// </summary> | |||
public IRedisClientsManager RedisManager { get; set; } | |||
|
|||
public object Get(Todo todo) | |||
{ | |||
//Return a single Todo if the id is provided. | |||
if (todo.Id != default(long)) | |||
{ | |||
return RedisManager.ExecAs<Todo>(r => r.GetById(todo.Id)); | |||
} | |||
|
|||
//Return all Todos items. | |||
return RedisManager.ExecAs<Todo>(r => r.GetAll()); | |||
} | |||
|
|||
/// <summary> | |||
/// Handles creating and updating the Todo items. | |||
/// </summary> | |||
/// <param name="todo">The todo.</param> | |||
/// <returns></returns> | |||
public Todo Post(Todo todo) | |||
{ | |||
RedisManager.ExecAs<Todo>(r => | |||
{ | |||
//Get next id for new todo | |||
if (todo.Id == default(long)) todo.Id = r.GetNextSequence(); | |||
r.Store(todo); | |||
}); | |||
return todo; | |||
} | |||
|
|||
/// <summary> | |||
/// Handles creating and updating the Todo items. | |||
/// </summary> | |||
/// <param name="todo">The todo.</param> | |||
/// <returns></returns> | |||
public Todo Put(Todo todo) | |||
{ | |||
return Post(todo); | |||
} | |||
|
|||
public object Delete(Todo todo) | |||
{ | |||
RedisManager.ExecAs<Todo>(r => r.DeleteById(todo.Id)); | |||
return null; | |||
} | |||
} | |||
|
|||
/// <summary> | |||
/// Create your ServiceStack web service application with a singleton AppHost. | |||
/// </summary> | |||
public class ToDoAppHost : AppHostHttpListenerBase | |||
{ | |||
/// <summary> | |||
/// Initializes a new instance of your ServiceStack application, with the specified name and assembly containing the services. | |||
/// </summary> | |||
public ToDoAppHost() : base("Backbone.js TODO", typeof(TodoService).Assembly) { } | |||
|
|||
/// <summary> | |||
/// Configure the container with the necessary routes for your ServiceStack application. | |||
/// </summary> | |||
/// <param name="container">The built-in IoC used with ServiceStack.</param> | |||
public override void Configure(Container container) | |||
{ | |||
//Configure ServiceStack Json web services to return idiomatic Json camelCase properties. | |||
JsConfig.EmitCamelCaseNames = true; | |||
|
|||
JsConfig.TreatEnumAsInteger = true; | |||
|
|||
//Register Redis factory in Funq IoC. | |||
var settings = new AppSettings(); | |||
container.Register<IRedisClientsManager>(new BasicRedisClientManager(settings.GetString("Redis.HostPort"))); | |||
|
|||
//Register user-defined REST Paths | |||
Routes | |||
.Add<Todo>("/todos") | |||
.Add<Todo>("/todos/{Id}"); | |||
} | |||
} | |||
} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
using System.ServiceProcess; | |||
|
|||
namespace Service | |||
{ | |||
public partial class Program : ServiceBase | |||
{ | |||
|
|||
} | |||
} |
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 | Original file line | 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("Service")] | |||
[assembly: AssemblyDescription("")] | |||
[assembly: AssemblyConfiguration("")] | |||
[assembly: AssemblyCompany("")] | |||
[assembly: AssemblyProduct("Service")] | |||
[assembly: AssemblyCopyright("Copyright © 2013")] | |||
[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("d7618582-31e8-4d3d-bf07-7aaee30d1910")] | |||
|
|||
// 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")] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.