Демка с чатом работает
This commit is contained in:
@@ -27,7 +27,7 @@ namespace Example.Backend
|
|||||||
// throw new Exception("The method or operation is not implemented.");
|
// throw new Exception("The method or operation is not implemented.");
|
||||||
var page = new Page { Text = text };
|
var page = new Page { Text = text };
|
||||||
Console.WriteLine($"Request id : :{context.RequestId}");
|
Console.WriteLine($"Request id : :{context.RequestId}");
|
||||||
OnPrint?.Invoke(page, new RequestContext(context.RequestId, -1000));
|
OnPrint?.Invoke(page, context);
|
||||||
Resource /= 1.5;
|
Resource /= 1.5;
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using Example.Events.Shared;
|
||||||
|
using mROA.Implementation;
|
||||||
|
|
||||||
|
namespace Example.Events.Backend;
|
||||||
|
|
||||||
|
public class Chat : IChat
|
||||||
|
{
|
||||||
|
public void PostSymbol(string symbol, RequestContext context)
|
||||||
|
{
|
||||||
|
OnCharPosted?.Invoke(symbol, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public event Action<string, RequestContext>? OnCharPosted;
|
||||||
|
|
||||||
|
public void OnCharPostedExternal(string p0, RequestContext p1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using Example.Events.Shared;
|
||||||
|
using mROA.Implementation.Attributes;
|
||||||
|
|
||||||
|
namespace Example.Events.Backend;
|
||||||
|
|
||||||
|
[SharedObjectSingleton]
|
||||||
|
public class ChatFactory : IChatFactory
|
||||||
|
{
|
||||||
|
private static readonly Dictionary<Guid, IChat> Chats = new();
|
||||||
|
|
||||||
|
public IChat GetChat(Guid id)
|
||||||
|
{
|
||||||
|
if (Chats.TryGetValue(id, out var chat))
|
||||||
|
{
|
||||||
|
return chat;
|
||||||
|
}
|
||||||
|
|
||||||
|
var created = new Chat();
|
||||||
|
Chats.Add(id, created);
|
||||||
|
return created;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using mROA.Implementation;
|
||||||
|
using mROA.Implementation.Attributes;
|
||||||
|
|
||||||
|
namespace Example.Events.Shared
|
||||||
|
{
|
||||||
|
[SharedObjectInterface]
|
||||||
|
public partial interface IChat : IShared
|
||||||
|
{
|
||||||
|
void PostSymbol(string symbol, RequestContext context = default);
|
||||||
|
event Action<string, RequestContext> OnCharPosted;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using mROA.Implementation;
|
||||||
|
using mROA.Implementation.Attributes;
|
||||||
|
|
||||||
|
namespace Example.Events.Shared
|
||||||
|
{
|
||||||
|
[SharedObjectInterface]
|
||||||
|
public interface IChatFactory : IShared
|
||||||
|
{
|
||||||
|
IChat GetChat(Guid id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,14 +2,12 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
<LangVersion>9</LangVersion>
|
<LangVersion>9</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\mROA.Cbor\mROA.Cbor.csproj" />
|
<ProjectReference Include="..\mROA.Cbor\mROA.Cbor.csproj"/>
|
||||||
<ProjectReference Include="..\mROA\mROA.csproj"/>
|
<ProjectReference Include="..\mROA\mROA.csproj"/>
|
||||||
<ProjectReference Include="..\mROA.Codegen\mROA.Codegen.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
|
<ProjectReference Include="..\mROA.Codegen\mROA.Codegen.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
|
||||||
|
|
||||||
|
|||||||
@@ -16,4 +16,3 @@ namespace Example.Shared
|
|||||||
Task AsyncTest(CancellationToken token = default);
|
Task AsyncTest(CancellationToken token = default);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,13 @@ namespace mROA.Cbor
|
|||||||
|
|
||||||
if (nonCasted is PreParsedValue preParsed)
|
if (nonCasted is PreParsedValue preParsed)
|
||||||
return preParsed.ToObject(type, context);
|
return preParsed.ToObject(type, context);
|
||||||
|
|
||||||
|
|
||||||
|
if (type == typeof(Guid))
|
||||||
|
{
|
||||||
|
return new Guid((byte[])nonCasted);
|
||||||
|
}
|
||||||
|
|
||||||
return Convert.ChangeType(nonCasted, type);
|
return Convert.ChangeType(nonCasted, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -283,8 +283,8 @@ namespace {classSymbol.ContainingNamespace.ToDisplayString()}
|
|||||||
{{
|
{{
|
||||||
BindAction = (instance, context, representationProducer, index) =>
|
BindAction = (instance, context, representationProducer, index) =>
|
||||||
{{
|
{{
|
||||||
var module = representationProducer.Produce(context.OwnerId);
|
var ownerId = context.OwnerId;
|
||||||
|
var module = representationProducer.Produce(ownerId);
|
||||||
{string.Join("\r\n", singleEventBinder)}
|
{string.Join("\r\n", singleEventBinder)}
|
||||||
}}
|
}}
|
||||||
}}";
|
}}";
|
||||||
@@ -471,14 +471,15 @@ namespace {classSymbol.ContainingNamespace.ToDisplayString()}
|
|||||||
var requestIndex = parameters.FindIndex(i => i.Name == "RequestContext");
|
var requestIndex = parameters.FindIndex(i => i.Name == "RequestContext");
|
||||||
if (requestIndex != -1)
|
if (requestIndex != -1)
|
||||||
{
|
{
|
||||||
callFilter = $"\n\r\t\t\tif(context.OwnerId == p{requestIndex}.OwnerId) return;";
|
callFilter = $"\n\r\t\t\tif(ownerId == p{requestIndex}.OwnerId) return;";
|
||||||
}
|
}
|
||||||
|
|
||||||
var eventBinderCode =
|
var eventBinderCode =
|
||||||
$@" (instance as {baseType.ToDisplayString()}).{eventSymbol.Name} += ({parametersDeclaration}) =>
|
$@" (instance as {baseType.ToDisplayString()}).{eventSymbol.Name} += ({parametersDeclaration}) =>
|
||||||
{{
|
{{
|
||||||
|
Console.WriteLine($""Try to send to {{ownerId}} with hash code {{context.GetHashCode()}}"");
|
||||||
|
{callFilter}
|
||||||
Console.WriteLine(""Sending event..."");
|
Console.WriteLine(""Sending event..."");
|
||||||
{callFilter}
|
|
||||||
var request = new DefaultCallRequest
|
var request = new DefaultCallRequest
|
||||||
{{
|
{{
|
||||||
CommandId = {index}, ObjectId = new ComplexObjectIdentifier(index, context.HostId), Parameters = new object[] {{ {transferParameters} }}
|
CommandId = {index}, ObjectId = new ComplexObjectIdentifier(index, context.HostId), Parameters = new object[] {{ {transferParameters} }}
|
||||||
|
|||||||
@@ -21,6 +21,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mROA.Benchmark", "mROA.Benc
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mROA.Cbor", "mROA.Cbor\mROA.Cbor.csproj", "{6211E4EA-13FD-4EB1-8E6A-C0173DD0784A}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mROA.Cbor", "mROA.Cbor\mROA.Cbor.csproj", "{6211E4EA-13FD-4EB1-8E6A-C0173DD0784A}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TotalDemo", "TotalDemo", "{FC4FA752-10A7-4D78-A7C2-9BCD8A81FB5E}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Events", "Events", "{032E1288-4D26-4FA5-ABB6-E7D738F319DE}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.Events.Shared", "Example.Events.Shared\Example.Events.Shared.csproj", "{6342C7FC-12B4-4BC6-BA25-159B1400D952}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.Events.Backend", "Example.Events.Backend\Example.Events.Backend.csproj", "{B63F58B2-8D86-42F3-96A5-470CB449BFD3}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.Events.Client", "Example.Events.Client\Example.Events.Client.csproj", "{98451C0E-E179-4F5F-9F1A-8B353EDE2EBC}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -59,13 +69,30 @@ Global
|
|||||||
{6211E4EA-13FD-4EB1-8E6A-C0173DD0784A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{6211E4EA-13FD-4EB1-8E6A-C0173DD0784A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{6211E4EA-13FD-4EB1-8E6A-C0173DD0784A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{6211E4EA-13FD-4EB1-8E6A-C0173DD0784A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{6211E4EA-13FD-4EB1-8E6A-C0173DD0784A}.Release|Any CPU.Build.0 = Release|Any CPU
|
{6211E4EA-13FD-4EB1-8E6A-C0173DD0784A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{6342C7FC-12B4-4BC6-BA25-159B1400D952}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{6342C7FC-12B4-4BC6-BA25-159B1400D952}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{6342C7FC-12B4-4BC6-BA25-159B1400D952}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{6342C7FC-12B4-4BC6-BA25-159B1400D952}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{B63F58B2-8D86-42F3-96A5-470CB449BFD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B63F58B2-8D86-42F3-96A5-470CB449BFD3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B63F58B2-8D86-42F3-96A5-470CB449BFD3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B63F58B2-8D86-42F3-96A5-470CB449BFD3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{98451C0E-E179-4F5F-9F1A-8B353EDE2EBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{98451C0E-E179-4F5F-9F1A-8B353EDE2EBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{98451C0E-E179-4F5F-9F1A-8B353EDE2EBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{98451C0E-E179-4F5F-9F1A-8B353EDE2EBC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(NestedProjects) = preSolution
|
GlobalSection(NestedProjects) = preSolution
|
||||||
{A9BB364E-0BA6-40B9-A293-757BC48EFC06} = {EAE92F5A-664C-41AB-8811-5885524B5347}
|
{FC4FA752-10A7-4D78-A7C2-9BCD8A81FB5E} = {EAE92F5A-664C-41AB-8811-5885524B5347}
|
||||||
{E7703F5B-F2A6-4A88-AA57-EBB1E38D533E} = {EAE92F5A-664C-41AB-8811-5885524B5347}
|
{A9BB364E-0BA6-40B9-A293-757BC48EFC06} = {FC4FA752-10A7-4D78-A7C2-9BCD8A81FB5E}
|
||||||
{9BD25A13-3165-47C0-9EAA-5C59EC490E32} = {EAE92F5A-664C-41AB-8811-5885524B5347}
|
{9BD25A13-3165-47C0-9EAA-5C59EC490E32} = {FC4FA752-10A7-4D78-A7C2-9BCD8A81FB5E}
|
||||||
|
{E7703F5B-F2A6-4A88-AA57-EBB1E38D533E} = {FC4FA752-10A7-4D78-A7C2-9BCD8A81FB5E}
|
||||||
|
{032E1288-4D26-4FA5-ABB6-E7D738F319DE} = {EAE92F5A-664C-41AB-8811-5885524B5347}
|
||||||
|
{6342C7FC-12B4-4BC6-BA25-159B1400D952} = {032E1288-4D26-4FA5-ABB6-E7D738F319DE}
|
||||||
|
{B63F58B2-8D86-42F3-96A5-470CB449BFD3} = {032E1288-4D26-4FA5-ABB6-E7D738F319DE}
|
||||||
|
{98451C0E-E179-4F5F-9F1A-8B353EDE2EBC} = {032E1288-4D26-4FA5-ABB6-E7D738F319DE}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
Reference in New Issue
Block a user