예제 #1
0
        public TRemoteService Service <TRemoteService>()
        {
            if (proxies.TryGetValue(typeof(TRemoteService), out object ipcProxy))
            {
                return((TRemoteService)ipcProxy);
            }

            if (ipcClientChannel == null)
            {
                ipcClientChannel = new IpcClientChannel();

                ChannelServices.RegisterChannel(ipcClientChannel, true);
            }

            string ipcServiceName = ApiIpcCommon.GetServiceName <TRemoteService>(serverId);
            string ipcUrl         = $"ipc://{serverId}/{ipcServiceName}";

            Log.Debug($"Calling: {ipcUrl}");

            // Get proxy instance of rpc service instance published by server in PublishService()
            ipcProxy = RemotingServices.Connect(typeof(TRemoteService), ipcUrl);
            proxies[typeof(TRemoteService)] = ipcProxy;

            if (ipcProxy == null)
            {
                throw new Exception($"Failed to create IPC proxy for {typeof(TRemoteService).FullName}");
            }

            return((TRemoteService)ipcProxy);
        }
예제 #2
0
        public async Task PublishServiceAsync <TRemoteService>(IApiIpcService ipcService)
        {
            if (channelMutex == null)
            {
                await CreateServerAsync();
            }

            // Publish the ipc service receiving the data
            string ipcServiceName = ApiIpcCommon.GetServiceName <TRemoteService>(serverId);

            RemotingServices.Marshal(ipcService as ApiIpcService, ipcServiceName);

            Log.Debug($"Published: {ipcServiceName}");
        }
예제 #3
0
        public bool TryPublishService(Type interfaceType, IApiIpcService ipcService)
        {
            if (channelMutex == null)
            {
                if (!TryCreateServer())
                {
                    return(false);
                }
            }

            // Publish the ipc service receiving the data
            string ipcServiceName = ApiIpcCommon.GetServiceName(interfaceType, serverId);

            RemotingServices.Marshal(ipcService as ApiIpcService, ipcServiceName);

            Log.Debug($"Published: {ipcServiceName}");
            return(true);
        }
예제 #4
0
 public static bool IsServerRegistered(string serverName) => ApiIpcCommon.IsServerRegistered(serverName);
예제 #5
0
 public ApiIpcServer(string serverName)
 {
     serverId = ApiIpcCommon.GetServerId(serverName);
     Log.Debug($"Create server: {serverName} as {serverId}");
 }