-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decouple Orleans server dependency from base CloudActors
We already had a separate assembly for the Orleans server extensions. By moving the grain generator to its own assembly, we can fully decouple the server/hosting interface and types from the bare business logic implemented via cloud actors. The only dependency would be the serializer generation which needs to be based on annotating the actual types, so it's unavoidable. But this is just the abstractions package.
- Loading branch information
Showing
24 changed files
with
164 additions
and
102 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
File renamed without changes.
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
File renamed without changes.
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
|
||
namespace Devlooped.CloudActors; | ||
|
||
public static class AnalysisExtensions | ||
{ | ||
public static SymbolDisplayFormat FullName { get; } = new( | ||
typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, | ||
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, | ||
miscellaneousOptions: SymbolDisplayMiscellaneousOptions.ExpandNullable); | ||
|
||
public static IEnumerable<ITypeSymbol> GetAllTypes(this IAssemblySymbol assembly) | ||
=> GetAllTypes(assembly.GlobalNamespace); | ||
|
||
static IEnumerable<ITypeSymbol> GetAllTypes(INamespaceSymbol namespaceSymbol) | ||
{ | ||
foreach (var typeSymbol in namespaceSymbol.GetTypeMembers()) | ||
{ | ||
yield return typeSymbol; | ||
} | ||
|
||
foreach (var childNamespace in namespaceSymbol.GetNamespaceMembers()) | ||
{ | ||
foreach (var typeSymbol in GetAllTypes(childNamespace)) | ||
{ | ||
yield return typeSymbol; | ||
} | ||
} | ||
} | ||
|
||
public static string GetTypeName(this ITypeSymbol type, string containingNamespace) | ||
{ | ||
var typeName = type.ToDisplayString(FullName); | ||
if (typeName.StartsWith(containingNamespace + ".")) | ||
return typeName.Substring(containingNamespace.Length + 1); | ||
|
||
return typeName; | ||
} | ||
|
||
public static string ToFileName(this ITypeSymbol type) => type.ToDisplayString(FullName).Replace('+', '.'); | ||
|
||
public static bool IsActorMessage(this ITypeSymbol type) => type.AllInterfaces.Any(x => | ||
x.ToDisplayString(FullName).Equals("Devlooped.CloudActors.IActorMessage")); | ||
|
||
public static bool IsActorCommand(this ITypeSymbol type) => type.AllInterfaces.Any(x => | ||
x.ToDisplayString(FullName).StartsWith("Devlooped.CloudActors.IActorCommand") && x.IsGenericType); | ||
|
||
public static bool IsActorVoidCommand(this ITypeSymbol type) => type.AllInterfaces.Any(x => | ||
x.ToDisplayString(FullName).StartsWith("Devlooped.CloudActors.IActorCommand") && !x.IsGenericType); | ||
|
||
public static bool IsActorQuery(this ITypeSymbol type) => type.AllInterfaces.Any(x => | ||
x.ToDisplayString(FullName).StartsWith("Devlooped.CloudActors.IActorQuery") && x.IsGenericType); | ||
|
||
public static bool IsActor(this ITypeSymbol type) => type.GetAttributes().Any(a => a.IsActor()); | ||
|
||
public static bool IsActor(this AttributeData attr) => | ||
attr.AttributeClass?.ToDisplayString(FullName) == "Devlooped.CloudActors.ActorAttribute"; | ||
|
||
public static bool IsPartial(this ITypeSymbol node) => node.DeclaringSyntaxReferences.Any( | ||
r => r.GetSyntax() is TypeDeclarationSyntax { Modifiers: { } modifiers } && | ||
modifiers.Any(m => m.IsKind(SyntaxKind.PartialKeyword))); | ||
} |
File renamed without changes.
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
File renamed without changes.
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Collections.Generic; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
|
||
namespace Devlooped.CloudActors; | ||
|
||
static class Extensions | ||
{ | ||
} |
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
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
45 changes: 45 additions & 0 deletions
45
src/CloudActors.Orleans.CodeAnalysis/CloudActors.Orleans.CodeAnalysis.csproj
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,45 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<AssemblyName>Devlooped.CloudActors.Orleans.CodeAnalysis</AssemblyName> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
|
||
<IsRoslynComponent>true</IsRoslynComponent> | ||
<!-- CS8785: ignoring Orleans source generator being run due to https://github.com/NuGet/Home/issues/6279 --> | ||
<NoWarn>RS1036;CS8785</NoWarn> | ||
|
||
<PackFolder>analyzers/dotnet/roslyn4.5/cs</PackFolder> | ||
<!-- See https://github.com/scriban/scriban#source-embedding --> | ||
<PackageScribanIncludeSource>true</PackageScribanIncludeSource> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="..\CloudActors.CodeAnalysis\AnalysisExtensions.cs" Link="AnalysisExtensions.cs" /> | ||
<Compile Include="..\CloudActors.CodeAnalysis\OrleansGenerator.cs" Link="OrleansGenerator.cs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<!-- See: https://github.com/NuGet/Home/issues/6279. For now, ExcludeAssets doesn't work for analyzers/generators, so we ARE running | ||
the Orleans source generator in this analyzer project itself, even if we don't want/need to. --> | ||
<PackageReference Include="Microsoft.Orleans.CodeGenerator" Version="8.2.0" ExcludeAssets="all" PrivateAssets="all" GeneratePathProperty="true" /> | ||
<PackageReference Include="NuGetizer" Version="1.2.2" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Pack="false" Version="4.5.0" /> | ||
<PackageReference Include="PolySharp" PrivateAssets="All" Version="1.14.1" /> | ||
|
||
<PackageReference Include="Scriban" Version="5.10.0" Pack="false" IncludeAssets="build" /> | ||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" PrivateAssets="all" /> | ||
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" PrivateAssets="all" /> | ||
<PackageReference Include="ThisAssembly.AssemblyInfo" Version="1.4.3" PrivateAssets="all" /> | ||
<PackageReference Include="ThisAssembly.Resources" Version="1.4.3" PrivateAssets="all" Pack="false" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="$(PkgMicrosoft_Orleans_CodeGenerator)\analyzers\dotnet\cs\Orleans.CodeGenerator.dll" /> | ||
<PackageFile Include="$(PkgMicrosoft_Orleans_CodeGenerator)\analyzers\dotnet\cs\Orleans.CodeGenerator.dll" PackagePath="$(PackFolder)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<EmbeddedResource Include="@(None -> WithMetadataValue('Extension', '.sbntxt'))" Kind="text" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.