Skip to content

Commit

Permalink
Building for .netcore 3.0 ,making required code changes, updating nug…
Browse files Browse the repository at this point in the history
…et generation (#60)

* Updating to netcore3.0

* Building for .netcore 3.0 and making required code changes, updating nuget generation.

* Fixing indent in pipeline yaml

* making test interfaces and test classes public to allow codegen

* simplifying default expression (C# 7.1 syntax)

* Using simple using statement (C# 8.0 feature)

* USing unused params and using pattern matching

* Update test/Microsoft.Actions.Actors.Test/ActorMethodInvocationExceptionTests.cs

Co-Authored-By: Ryan Nowak <[email protected]>

* using context.Request.RouteValues instead of context.GetRouteData()
  • Loading branch information
amanbha authored Oct 1, 2019
1 parent 5903142 commit a1ef0dd
Show file tree
Hide file tree
Showing 33 changed files with 330 additions and 355 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ This repo builds the following packages:

### Prerequesites

Each project is a normal C# Visual Studio 2019 project. At minimum, you need [.NET Core SDK 2.2](https://www.microsoft.com/net/download/windows) to build and generate NuGet packages.
Each project is a normal C# Visual Studio 2019 project. At minimum, you need [.NET Core SDK 3.0](https://dotnet.microsoft.com/download/dotnet-core/3.0) to build and generate NuGet packages.

We recommend installing [Visual Studio 2019](https://www.visualstudio.com/vs/) which will set you up with all the .NET build tools and allow you to open the solution files. Community Edition is free and can be used to build everything here.
We recommend installing [Visual Studio 2019 v16.3 or later ](https://www.visualstudio.com/vs/) which will set you up with all the .NET build tools and allow you to open the solution files. Community Edition is free and can be used to build everything here.
Make sure you [update Visual Studio to the most recent release](https://docs.microsoft.com/visualstudio/install/update-visual-studio). To find a version of .NET Core that can be used with earlier versions of Visual Studio, see [].NET SDKs for Visual Studio](https://dotnet.microsoft.com/download/visual-studio-sdks).

### Build

Expand Down Expand Up @@ -44,10 +45,10 @@ Assume that you download nuget packages to you local disk, /pkg/nugets/.

```bash
# Add Microsoft.Actions.Actors nuget package
dotnet add package Microsoft.Actions.Actors -v 1.0.0-preview001 -s /pkg/nugets/
dotnet add package Microsoft.Actions.Actors -v 0.4.0-preview01 -s /pkg/nugets/

# Add Microsoft.Actions.Actors.AspNetCore nuget package
dotnet add package Microsoft.Actions.Actors.AspNetCore -v 1.0.0-preview001 -s /pkg/nugets/
dotnet add package Microsoft.Actions.Actors.AspNetCore -v 0.4.0-preview01 -s /pkg/nugets/
```

## Documentation
Expand Down
6 changes: 6 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ stages:
release:
configuration: release
steps:
- task: UseDotNet@2
displayName: 'Install dotnet SDK 3.0'
inputs:
packageType: sdk
version: 3.0.100
installationPath: $(Agent.ToolsDirectory)/dotnet
- task: DotNetCoreCLI@2
displayName: 'Build solution - $(Configuration)'
inputs:
Expand Down
4 changes: 2 additions & 2 deletions code.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.645
# Visual Studio Version 16
VisualStudioVersion = 16.0.29318.209
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Actions.Actors", "src\Microsoft.Actions.Actors\Microsoft.Actions.Actors.csproj", "{C2DB4B64-B7C3-4FED-8753-C040F677C69A}"
EndProject
Expand Down
2 changes: 1 addition & 1 deletion properties/actions_managed_stylecop.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<StylecopSuppressionsFile>$(MSBuildThisFileDirectory)stylecop\StylecopSuppressions.cs</StylecopSuppressionsFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta006" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
</ItemGroup>
<ItemGroup>
<None Remove="$(StylecopSettingsFile)" />
Expand Down
Binary file added properties/nuget_icon_ms.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
<Import Project="..\..\properties\actions_managed_netstandard.props" />
<Import Project="..\..\properties\actions_managed_stylecop.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Microsoft.Actions.Actors.AspNetCore</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace>
<TargetFramework>netcoreapp3.0</TargetFramework>
<DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>

<!-- Nuget package properties when packed using dotnet pack. -->
<NuspecFile>nuspec\Microsoft.Actions.Actors.AspNetCore.nuspec</NuspecFile>
<NuspecProperties>version=$(NupkgVersion);Configuration=$(Configuration)</NuspecProperties>
<!-- Disabling NU5128 Warning, https://docs.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu5128 -->
<NoWarn>$(NoWarn);NU5128</NoWarn>

</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.Actions.Actors\Microsoft.Actions.Actors.csproj" />
Expand Down
118 changes: 66 additions & 52 deletions src/Microsoft.Actions.Actors.AspNetCore/RouterBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,93 +6,88 @@
namespace Microsoft.Actions.Actors.AspNetCore
{
using System;
using System.Linq;
using System.Buffers;
using System.IO;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.Actions.Actors.Runtime;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Newtonsoft.Json.Linq;

internal static class RouterBuilderExtensions
{
public static void AddActionsConfigRoute(this IRouteBuilder routeBuilder)
{
routeBuilder.MapGet("actions/config", (request, response, routeData) =>
routeBuilder.MapGet("actions/config", async context =>
{
var result = new JObject(
new JProperty("entities", new JArray(ActorRuntime.RegisteredActorTypes.Select(actorType => new JValue(actorType)))));

return response.WriteAsync(result.ToString());
await WriteSupportedActorTypesAsJsonAsync(context.Response.BodyWriter);
});
}

public static void AddGetSupportedActorTypesRoute(this IRouteBuilder routeBuilder)
{
routeBuilder.MapGet("actors", (request, response, routeData) =>
routeBuilder.MapGet("actors", async context =>
{
var result = new JObject(
new JProperty("entities", new JArray(ActorRuntime.RegisteredActorTypes.Select(actorType => new JValue(actorType)))));

return response.WriteAsync(result.ToString());
await WriteSupportedActorTypesAsJsonAsync(context.Response.BodyWriter);
});
}

public static void AddActorActivationRoute(this IRouteBuilder routeBuilder)
{
routeBuilder.MapPost("actors/{actorTypeName}/{actorId}", (request, response, routeData) =>
routeBuilder.MapPost("actors/{actorTypeName}/{actorId}", async context =>
{
var actorTypeName = (string)routeData.Values["actorTypeName"];
var actorId = (string)routeData.Values["actorId"];
return ActorRuntime.ActivateAsync(actorTypeName, actorId);
var routeValues = context.Request.RouteValues;
var actorTypeName = (string)routeValues["actorTypeName"];
var actorId = (string)routeValues["actorId"];
await ActorRuntime.ActivateAsync(actorTypeName, actorId);
});
}

public static void AddActorDeactivationRoute(this IRouteBuilder routeBuilder)
{
routeBuilder.MapDelete("actors/{actorTypeName}/{actorId}", (request, response, routeData) =>
routeBuilder.MapDelete("actors/{actorTypeName}/{actorId}", async context =>
{
var actorTypeName = (string)routeData.Values["actorTypeName"];
var actorId = (string)routeData.Values["actorId"];
return ActorRuntime.DeactivateAsync(actorTypeName, actorId);
var routeValues = context.Request.RouteValues;
var actorTypeName = (string)routeValues["actorTypeName"];
var actorId = (string)routeValues["actorId"];
await ActorRuntime.DeactivateAsync(actorTypeName, actorId);
});
}

public static void AddActorMethodRoute(this IRouteBuilder routeBuilder)
{
routeBuilder.MapPut("actors/{actorTypeName}/{actorId}/method/{methodName}", (request, response, routeData) =>
routeBuilder.MapPut("actors/{actorTypeName}/{actorId}/method/{methodName}", async context =>
{
var actorTypeName = (string)routeData.Values["actorTypeName"];
var actorId = (string)routeData.Values["actorId"];
var methodName = (string)routeData.Values["methodName"];
var routeValues = context.Request.RouteValues;
var actorTypeName = (string)routeValues["actorTypeName"];
var actorId = (string)routeValues["actorId"];
var methodName = (string)routeValues["methodName"];

// If Header is present, call is made using Remoting, use Remoting dispatcher.
if (request.Headers.ContainsKey(Constants.RequestHeaderName))
if (context.Request.Headers.ContainsKey(Constants.RequestHeaderName))
{
var actionsActorheader = request.Headers[Constants.RequestHeaderName];
return ActorRuntime.DispatchWithRemotingAsync(actorTypeName, actorId, methodName, actionsActorheader, request.Body)
.ContinueWith(async t =>
{
var result = t.GetAwaiter().GetResult();

// Item 1 is header , Item 2 is body
if (result.Item1 != string.Empty)
{
// exception case
response.Headers.Add(Constants.ErrorResponseHeaderName, result.Item1); // add error header
}

await response.Body.WriteAsync(result.Item2, 0, result.Item2.Length); // add response message body
});
var actionsActorheader = context.Request.Headers[Constants.RequestHeaderName];
var (header, body) = await ActorRuntime.DispatchWithRemotingAsync(actorTypeName, actorId, methodName, actionsActorheader, context.Request.Body);

// Item 1 is header , Item 2 is body
if (header != string.Empty)
{
// exception case
context.Response.Headers.Add(Constants.ErrorResponseHeaderName, header); // add error header
}

await context.Response.Body.WriteAsync(body, 0, body.Length); // add response message body
}
else
{
// write exception info in response.
try
{
return ActorRuntime.DispatchWithoutRemotingAsync(actorTypeName, actorId, methodName, request.Body, response.Body);
await ActorRuntime.DispatchWithoutRemotingAsync(actorTypeName, actorId, methodName, context.Request.Body, context.Response.Body);
}
catch (Exception e)
{
return response.WriteAsync(e.ToString());
await context.Response.WriteAsync(e.ToString());
throw;
}
}
Expand All @@ -101,28 +96,47 @@ public static void AddActorMethodRoute(this IRouteBuilder routeBuilder)

public static void AddReminderRoute(this IRouteBuilder routeBuilder)
{
routeBuilder.MapPut("actors/{actorTypeName}/{actorId}/method/remind/{reminderName}", (request, response, routeData) =>
routeBuilder.MapPut("actors/{actorTypeName}/{actorId}/method/remind/{reminderName}", async context =>
{
var actorTypeName = (string)routeData.Values["actorTypeName"];
var actorId = (string)routeData.Values["actorId"];
var reminderName = (string)routeData.Values["reminderName"];
var routeValues = context.Request.RouteValues;
var actorTypeName = (string)routeValues["actorTypeName"];
var actorId = (string)routeValues["actorId"];
var reminderName = (string)routeValues["reminderName"];

// read dueTime, period and data from Request Body.
return ActorRuntime.FireReminderAsync(actorTypeName, actorId, reminderName, request.Body);
await ActorRuntime.FireReminderAsync(actorTypeName, actorId, reminderName, context.Request.Body);
});
}

public static void AddTimerRoute(this IRouteBuilder routeBuilder)
{
routeBuilder.MapPut("actors/{actorTypeName}/{actorId}/method/timer/{timerName}", (request, response, routeData) =>
routeBuilder.MapPut("actors/{actorTypeName}/{actorId}/method/timer/{timerName}", async context =>
{
var actorTypeName = (string)routeData.Values["actorTypeName"];
var actorId = (string)routeData.Values["actorId"];
var timerName = (string)routeData.Values["timerName"];
var routeValues = context.Request.RouteValues;
var actorTypeName = (string)routeValues["actorTypeName"];
var actorId = (string)routeValues["actorId"];
var timerName = (string)routeValues["timerName"];

// read dueTime, period and data from Request Body.
return ActorRuntime.FireTimerAsync(actorTypeName, actorId, timerName);
await ActorRuntime.FireTimerAsync(actorTypeName, actorId, timerName);
});
}

private static async Task WriteSupportedActorTypesAsJsonAsync(IBufferWriter<byte> output)
{
using Utf8JsonWriter writer = new Utf8JsonWriter(output);
writer.WriteStartObject();
writer.WritePropertyName("entities");
writer.WriteStartArray();

foreach (var actorType in ActorRuntime.RegisteredActorTypes)
{
writer.WriteStringValue(actorType);
}

writer.WriteEndArray();
writer.WriteEndObject();
await writer.FlushAsync();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@
<owners>Microsoft,Actions,Actors</owners>
<license type="expression">MIT</license>
<projectUrl>http://aka.ms/actions</projectUrl>
<iconUrl>http://go.microsoft.com/fwlink/?LinkID=288890</iconUrl>
<icon>images\nuget_icon_ms.png</icon>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>This package contains the reference assemblies for developing Actor services using actions and AspNetCore.</description>
<summary>This package contains the reference assemblies for developing Actor services using actions.</summary>
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
<tags>Microsoft Azure Actions Actors</tags>
<dependencies>
<dependency id="Microsoft.Actions.Actors" version="[$version$]" />
<dependency id="Microsoft.AspNetCore.Hosting.Abstractions" version="2.2.0" />
<dependency id="Microsoft.AspNetCore.Routing" version="2.2.0" />
</dependencies>
</metadata>
<files>
<file src="..\..\..\bin\$Configuration$\Microsoft.Actions.Actors.AspNetCore.dll" target="lib\netstandard2.0" exclude="" />
<file src="..\..\..\bin\$Configuration$\Microsoft.Actions.Actors.AspNetCore.xml" target="lib\netstandard2.0" exclude="" />
<file src="..\..\..\properties\nuget_icon_ms.png" target="images\" />
<file src="..\..\..\bin\$Configuration$\Microsoft.Actions.Actors.AspNetCore.dll" target="lib\netcoreapp3.0" exclude="" />
<file src="..\..\..\bin\$Configuration$\Microsoft.Actions.Actors.AspNetCore.xml" target="lib\netcoreapp3.0" exclude="" />
</files>
</package>
2 changes: 1 addition & 1 deletion src/Microsoft.Actions.Actors/ActionsError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ActionsError
/// <param name="message">Error Message.</param>
public ActionsError(
ActionsErrorCodes? errorCode,
string message = default(string))
string message = default)
{
errorCode.ThrowIfNull(nameof(errorCode));
this.ErrorCode = errorCode;
Expand Down
Loading

0 comments on commit a1ef0dd

Please sign in to comment.