This repository has been archived by the owner on Dec 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.NET Core support; adding ASP.NET Core support and sample; fix-ups; r…
…efactoring.
- Loading branch information
Showing
52 changed files
with
834 additions
and
730 deletions.
There are no files selected for viewing
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 was deleted.
Oops, something went wrong.
This file was deleted.
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
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> |
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,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; | ||
} | ||
} | ||
} |
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,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(); | ||
} | ||
} | ||
} |
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,16 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true | ||
}, | ||
"profiles": { | ||
"AspRpc": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "http://localhost:8000/" | ||
} | ||
} | ||
} |
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,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> |
Oops, something went wrong.