Skip to content
This repository has been archived by the owner on Dec 20, 2019. It is now read-only.

Commit

Permalink
.NET Core support; adding ASP.NET Core support and sample; fix-ups; r…
Browse files Browse the repository at this point in the history
…efactoring.
  • Loading branch information
dajuric committed Oct 21, 2017
1 parent a2bc474 commit d430179
Show file tree
Hide file tree
Showing 52 changed files with 834 additions and 730 deletions.
31 changes: 0 additions & 31 deletions Deploy/Nuget/Build.cmd

This file was deleted.

5 changes: 5 additions & 0 deletions Deploy/Nuget/Push.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ timeout /T 5
:: settings
set nugetPath=%cd%\..\..\.nuget

::update NuGet
attrib -R "%nugetPath%\nuget.exe"
echo Updating NuGet...
"%nugetPath%\nuget.exe" update -Self

echo.
echo Pushing packages:
for /r %%f in (*.nupkg) do (
Expand Down
13 changes: 0 additions & 13 deletions Deploy/Nuget/UpdateNuGet.cmd

This file was deleted.

27 changes: 0 additions & 27 deletions Deploy/Nuget/nuSpecs/WebsocketRPC.JS.nuspec

This file was deleted.

29 changes: 0 additions & 29 deletions Deploy/Nuget/nuSpecs/WebsocketRPC.nuspec

This file was deleted.

32 changes: 32 additions & 0 deletions Samples/AspRpc/AspRpc.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;net47</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
<OutputPath>bin\</OutputPath>
<DocumentationFile>bin\netcoreapp2.0\AspRpc.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<None Remove="Site\ReportingService.js" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="2.0.0" />
</ItemGroup>

<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Source\WebSocketRPC.AspCore\WebSocketRPC.AspCore.csproj" />
<ProjectReference Include="..\..\Source\WebSocketRPC.JS\WebSocketRPC.JS.csproj" />
</ItemGroup>

</Project>
32 changes: 32 additions & 0 deletions Samples/AspRpc/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Mvc;

namespace AspRpc.Controllers
{
/// <summary>
/// Home controller.
/// </summary>
[Route("/")]
public class HomeController
{
/// <summary>
/// Gets the home page.
/// </summary>
/// <returns>Home page HTML code.</returns>
[HttpGet]
public RedirectResult Get()
{
return new RedirectResult("/Site/Index.html");
}

/// <summary>
/// Gets the fav-icon.
/// </summary>
/// <returns>Fav-icon.</returns>
[HttpGet]
[Route("/favicon.ico")]
public object GetFavIcon()
{
return null;
}
}
}
64 changes: 64 additions & 0 deletions Samples/AspRpc/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using System;
using System.IO;
using System.Net.WebSockets;
using WebSocketRPC;

namespace AspRpc
{
class Startup
{
ReportingService reportingService = null;

public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

public void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}


app.UseMvc();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "Site")),
RequestPath = "/Site"
});

reportingService = new ReportingService();
app.UseWebSockets();
app.MapWebSocketRPC("/reportingService", (hc, c) => c.Bind<ReportingService, IClientUpdate>(reportingService));
}
}

public class Program
{
public static void Main(string[] args)
{
//generate js code
File.WriteAllText($"./Site/{nameof(ReportingService)}.js", RPCJs.GenerateCallerWithDoc<ReportingService>());

WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build()
.Run();
}
}
}
16 changes: 16 additions & 0 deletions Samples/AspRpc/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true
},
"profiles": {
"AspRpc": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:8000/"
}
}
}
66 changes: 66 additions & 0 deletions Samples/AspRpc/Site/Index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<html>
<head>
<script src="ReportingService.js"></script>
</head>

<body>
<button id="start">Start</button> <button id="stop">Stop</button>
<p id="msg"></p>


<script>
function writeMsg(msg, color)
{
color = color || 'black';

var p = document.getElementById("msg");
p.innerHTML = JSON.stringify(msg, null, "\t");
p.style.color = color;
}

var btnStart = document.getElementById("start");
var btnStop = document.getElementById("stop");

//init API
var baseUri = "ws://localhost:8000/"
var service = new ReportingService(baseUri + "reportingService/");

function implementClientUpdate(api)
{
api.write = writeMsg;
api.onStart = () =>
{
btnStart.disabled = true;
btnStop.disabled = false;
};
api.onStop = () =>
{
btnStart.disabled = false;
btnStop.disabled = true;
};
}

async function exec(api)
{
var isRunning = await api.isRunning();
btnStart.disabled = isRunning;
btnStop.disabled = !isRunning;

btnStart.onclick = async () =>
{
try { await api.start(); }
catch (err) { writeMsg(err, 'red'); }
}
btnStop.onclick = async () =>
{
try { await api.stop(); }
catch (err) { writeMsg(err, 'red'); }
}
}

implementClientUpdate(service);
service.connect(() => exec(service), err => writeMsg(err, 'red'), msg => writeMsg(msg));
</script>

</body>
</html>
Loading

0 comments on commit d430179

Please sign in to comment.