Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions demo/dotnetCampus.Ipc.WpfDemo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DotNetCampus.Cli;
using dotnetCampus.Ipc.Context;
using dotnetCampus.Ipc.Pipes;
using dotnetCampus.Ipc.WpfDemo.View;

using DotNetCampus.Cli;
using Walterlv.ThreadSwitchingTasks;

namespace dotnetCampus.Ipc.WpfDemo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
(syntaxNode, ct) => syntaxNode is InterfaceDeclarationSyntax { AttributeLists.Count: > 0 },
// 语义解析:确定是否真的是感兴趣的 IPC 接口。
(generatorSyntaxContext, ct) => IpcPublicCompilation.TryCreateIpcPublicCompilation(
(InterfaceDeclarationSyntax)generatorSyntaxContext.Node,
(InterfaceDeclarationSyntax) generatorSyntaxContext.Node,
generatorSyntaxContext.SemanticModel,
out var ipcPublicCompilation)
? ipcPublicCompilation
Expand All @@ -30,7 +30,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
(syntaxNode, ct) => syntaxNode is ClassDeclarationSyntax { AttributeLists.Count: > 0 },
// 语义解析:确定是否真的是感兴趣的 IPC 接口。
(generatorSyntaxContext, ct) => IpcShapeCompilation.TryCreateIpcShapeCompilation(
(ClassDeclarationSyntax)generatorSyntaxContext.Node,
(ClassDeclarationSyntax) generatorSyntaxContext.Node,
generatorSyntaxContext.SemanticModel,
out var ipcPublicCompilation)
? ipcPublicCompilation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using dotnetCampus.Ipc.Generators.Compiling;
using dotnetCampus.Ipc.Generators.Builders;
using dotnetCampus.Ipc.Generators.Builders;
using dotnetCampus.Ipc.Generators.Compiling;

namespace dotnetCampus.Ipc.Generators.Utils;

Expand Down Expand Up @@ -53,10 +53,10 @@ internal static string GenerateProxySource(IpcShapeCompilation ipc)
internal static string GenerateShapeSource(IpcPublicCompilation ipc, string? typeName, string? @namespace)
{
using var builder = new SourceTextBuilder(@namespace ?? ipc.IpcType.ContainingNamespace.ToString())
{
SimplifyTypeNamesByUsingNamespace = true,
ShouldPrependGlobal = false,
}
{
SimplifyTypeNamesByUsingNamespace = true,
ShouldPrependGlobal = false,
}
.Using("dotnetCampus.Ipc.CompilerServices.Attributes")
.Using("dotnetCampus.Ipc.CompilerServices.GeneratedProxies")
.AddTypeDeclaration($"internal sealed class {typeName ?? $"{ipc.IpcType.Name}IpcShape"}", t => t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal static async Task<GeneratedIpcJointResponse> FromAsyncReturnModel(
var returnModel = await asyncReturnModel.ConfigureAwait(false);
var message = returnModel is null
? new IpcMessage()
: serializer.SerializeToIpcMessage((ulong)KnownMessageHeaders.RemoteObjectMessageHeader, returnModel, "Return");
: serializer.SerializeToIpcMessage((ulong) KnownMessageHeaders.RemoteObjectMessageHeader, returnModel, "Return");
return new GeneratedIpcJointResponse(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ public static TPublic CreateIpcProxy<TPublic>(this IIpcProvider ipcProvider, IPe
nameof(TPublic));
}

var proxy = (GeneratedIpcProxy<TPublic>)proxyFactory();
var proxy = (GeneratedIpcProxy<TPublic>) proxyFactory();
proxy.Context = ipcProvider.GetGeneratedContext();
proxy.PeerProxy = peer;
proxy.ObjectId = ipcObjectId;
return (TPublic)(object)proxy;
return (TPublic) (object) proxy;
}

/// <summary>
Expand All @@ -101,12 +101,12 @@ public static TPublic CreateIpcProxy<TPublic>(this IIpcProvider ipcProvider, IPe
nameof(TPublic));
}

var proxy = (GeneratedIpcProxy<TPublic>)proxyFactory();
var proxy = (GeneratedIpcProxy<TPublic>) proxyFactory();
proxy.Context = ipcProvider.GetGeneratedContext();
proxy.PeerProxy = peer;
proxy.ObjectId = ipcObjectId;
proxy.RuntimeConfigs = ipcProxyConfigs;
return (TPublic)(object)proxy;
return (TPublic) (object) proxy;
}

/// <summary>
Expand All @@ -128,11 +128,11 @@ public static TPublic CreateIpcProxy<TPublic, TShape>(this IIpcProvider ipcProvi
nameof(TShape));
}

var proxy = (GeneratedIpcProxy<TPublic>)proxyFactory();
var proxy = (GeneratedIpcProxy<TPublic>) proxyFactory();
proxy.Context = ipcProvider.GetGeneratedContext();
proxy.PeerProxy = peer;
proxy.ObjectId = ipcObjectId;
return (TPublic)(object)proxy;
return (TPublic) (object) proxy;
}

/// <summary>
Expand All @@ -154,7 +154,7 @@ public static TPublic CreateIpcJoint<TPublic>(this IIpcProvider ipcProvider, TPu
}

var context = ipcProvider.GetGeneratedContext();
var joint = (GeneratedIpcJoint<TPublic>)jointFactory();
var joint = (GeneratedIpcJoint<TPublic>) jointFactory();
joint.Context = context;
joint.SetInstance(realInstance);
context.JointManager.AddPublicIpcObject(joint, ipcObjectId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public abstract partial class GeneratedIpcJoint<TContract> : GeneratedIpcJoint w
/// 设置此对接对象的真实实例。
/// </summary>
/// <param name="realInstance">真实实例。</param>
internal sealed override void SetInstance(object realInstance) => SetInstance((TContract)realInstance);
internal sealed override void SetInstance(object realInstance) => SetInstance((TContract) realInstance);

/// <summary>
/// 设置此对接对象的真实实例。
Expand Down Expand Up @@ -107,7 +107,7 @@ protected void MatchMethod(ulong memberId, Action methodInvoker)
methodInvoker();
return DefaultGarm;
}
));
));
}

/// <summary>
Expand All @@ -132,7 +132,7 @@ protected void MatchMethod(ulong memberId, Func<Task> methodInvoker)
await methodInvoker().ConfigureAwait(false);
return DefaultGarm;
}
));
));
}

/// <summary>
Expand All @@ -157,7 +157,7 @@ protected void MatchMethod<T>(ulong memberId, Action<T> methodInvoker)
methodInvoker(CastArg<T>(args[0])!);
return DefaultGarm;
}
));
));
}

/// <summary>
Expand All @@ -172,7 +172,7 @@ protected void MatchMethod<T>(ulong memberId, Func<T, Task> methodInvoker)
await methodInvoker(CastArg<T>(args[0])!).ConfigureAwait(false);
return DefaultGarm;
}
));
));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected async Task<T> GetValueAsync<T>(ulong memberId, IpcMemberInfo info, [Ca
if (_readonlyPropertyValues.TryGetValue(propertyName, out var cachedValue))
{
// 当只读字典中存在此属性的缓存时,直接取缓存。
return (T)cachedValue!;
return (T) cachedValue!;
}
// 否则,通过 IPC 访问获取此属性的值后设入缓存。(这里可能存在并发情况,会导致浪费的 IPC 访问,但能确保数据一致性)。
var value = await IpcInvokeAsync<T>(MemberInvokingType.GetProperty, memberId, propertyName, null, info).ConfigureAwait(false);
Expand Down Expand Up @@ -206,15 +206,15 @@ private async Task<T> IpcInvokeAsync<T>(MemberInvokingType callType, ulong membe
catch (IpcRemoteException) when (ignoresIpcException)
{
// 如果目标要求忽略异常,则返回指定值或默认值。
return info.DefaultReturn is { } defaultReturn ? (T)defaultReturn : default!;
return info.DefaultReturn is { } defaultReturn ? (T) defaultReturn : default!;
}
catch (AggregateException ex) when (ex.InnerExceptions.Count >= 1)
{
var innerException = ex.Flatten().InnerExceptions[0];
if (innerException is IpcRemoteException)
{
// 如果目标要求忽略异常,则返回指定值或默认值。
return info.DefaultReturn is { } defaultReturn ? (T)defaultReturn : default!;
return info.DefaultReturn is { } defaultReturn ? (T) defaultReturn : default!;
}
else
{
Expand All @@ -240,7 +240,7 @@ private async Task<T> InvokeWithTimeoutAsync<T>(MemberInvokingType callType, ulo
{
// 任务超时(不抛异常)。
IgnoreTaskExceptionsAsync(ipcTask);
return defaultReturn is null ? default! : (T)defaultReturn;
return defaultReturn is null ? default! : (T) defaultReturn;
}
// 任务超时(抛异常)。
IgnoreTaskExceptionsAsync(ipcTask);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void AddPublicIpcObject(Type contractType, GeneratedIpcJoint joint, strin
public bool TryJoint(IIpcRequestContext request, out Task<IIpcResponseMessage> responseTask)
{
if (Context.ObjectSerializer.TryDeserializeFromIpcMessage<GeneratedProxyMemberInvokeModel>(
request.IpcBufferMessage, (ulong)KnownMessageHeaders.RemoteObjectMessageHeader, out var requestModel)
request.IpcBufferMessage, (ulong) KnownMessageHeaders.RemoteObjectMessageHeader, out var requestModel)
&& TryFindJoint(requestModel, out var joint)
&& requestModel.MemberName is not null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ internal string TypeName
return null;
}

var header = (ulong)KnownMessageHeaders.RemoteObjectMessageHeader;
var header = (ulong) KnownMessageHeaders.RemoteObjectMessageHeader;
var requestMessage = Context.ObjectSerializer.SerializeToIpcMessage(header, model, model.ToString());
//requestMessage = new IpcMessage(requestMessage.Tag, requestMessage.Body, CoreMessageType.JsonObject);
var responseMessage = await PeerProxy.GetResponseAsync(requestMessage).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if NET6_0_OR_GREATER

using System.Diagnostics.CodeAnalysis;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
Expand Down Expand Up @@ -35,6 +36,15 @@ public SystemTextJsonIpcObjectSerializer(JsonSerializerContext jsonSerializerCon
public JsonSerializerContext? JsonSerializerContext { get; }

/// <inheritdoc />

<<<<<<< TODO: Unmerged change from project 'dotnetCampus.Ipc(net6.0)', Before:
public byte[] Serialize(object? value)
=======
[RequiresUnreferencedCode()]
public byte[] Serialize(object? value)
>>>>>>> After
[RequiresDynamicCode()]
[RequiresUnreferencedCode()]
public byte[] Serialize(object? value)
{
if (value is null)
Expand All @@ -56,6 +66,15 @@ public byte[] Serialize(object? value)
}

/// <inheritdoc />

<<<<<<< TODO: Unmerged change from project 'dotnetCampus.Ipc(net6.0)', Before:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

错误地将冲突解决代码上传

public void Serialize(Stream stream, object? value)
=======
[RequiresUnreferencedCode()]
public void Serialize(Stream stream, object? value)
>>>>>>> After
[RequiresDynamicCode()]
[RequiresUnreferencedCode()]
public void Serialize(Stream stream, object? value)
{
if (value is null)
Expand All @@ -75,6 +94,7 @@ public void Serialize(Stream stream, object? value)
}

/// <inheritdoc />
[RequiresUnreferencedCode()]
public IpcJsonElement SerializeToElement(object? value)
{
if (value is null)
Expand All @@ -96,6 +116,7 @@ public IpcJsonElement SerializeToElement(object? value)
}

/// <inheritdoc />
[RequiresUnreferencedCode()]
public T? Deserialize<T>(byte[] data, int start, int length)
{
var span = data.AsSpan(start, length);
Expand All @@ -111,6 +132,7 @@ public IpcJsonElement SerializeToElement(object? value)
}

/// <inheritdoc />
[RequiresUnreferencedCode()]
public T? Deserialize<T>(Stream stream)
{
if (JsonSerializerContext is null)
Expand All @@ -124,6 +146,7 @@ public IpcJsonElement SerializeToElement(object? value)
}

/// <inheritdoc />
[RequiresUnreferencedCode()]
public T? Deserialize<T>(IpcJsonElement jsonElement)
{
if (jsonElement.RawValueOnSystemTextJson is not { } element)
Expand Down
10 changes: 5 additions & 5 deletions src/dotnetCampus.Ipc/Utils/NullableBooleans.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public bool? this[int index]
set => _booleans = value switch
{
// 设置为 null:将索引处的两位都清零
null => _booleans & (uint)~(3 << (index * 2)),
null => _booleans & (uint) ~(3 << (index * 2)),
// 设置为 true:将高位置 1,低位置 1
true => _booleans | (uint)(3 << (index * 2)),
true => _booleans | (uint) (3 << (index * 2)),
// 设置为 false:将高位置 1,低位置清零
false => (_booleans & (uint)~(1 << (index * 2 + 1))) | (uint)(1 << (index * 2)),
false => (_booleans & (uint) ~(1 << (index * 2 + 1))) | (uint) (1 << (index * 2)),
};
}

Expand All @@ -47,7 +47,7 @@ public void SetBooleanAt(int indexFromEnd, bool value)
{
var index = 31 - indexFromEnd;
_booleans = value
? _booleans | (uint)(1 << index)
: _booleans & (uint)~(1 << index);
? _booleans | (uint) (1 << index)
: _booleans & (uint) ~(1 << index);
}
}
6 changes: 3 additions & 3 deletions tests/dotnetCampus.Ipc.FakeTests/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using DotNetCampus.Cli;
using DotNetCampus.Cli.Compiler;
using dotnetCampus.Ipc.CompilerServices.GeneratedProxies;
using dotnetCampus.Ipc.CompilerServices.GeneratedProxies;
using dotnetCampus.Ipc.FakeTests.FakeApis;
using dotnetCampus.Ipc.Pipes;
using DotNetCampus.Cli;
using DotNetCampus.Cli.Compiler;

namespace dotnetCampus.Ipc.FakeTests;

Expand Down