/// <summary> /// Initializes this deferred initializable object /// </summary> public void Initialize() { if (!Initialized) { baseChannel = new MemoryServiceChannel(hubAddresses, false, MscMode.Server, 0, new IdentityFromWindowsProvider()); baseChannel.ObjectReceived += ConnectionRequest; Initialized = true; } }
public ServiceClient(IMemoryChannel channel, IMemoryChannel baseChannel, IHubFactory hubFactory, AsyncBackStream backStream) { this.channel = channel; this.baseChannel = baseChannel; this.hubFactory = hubFactory; this.backStream = backStream; channel.ObjectReceived += IncomingChannelData; channel.ConnectionStatusChanged += LosingConnection; }
private void TryClose(IMemoryChannel channel) { try { channel.Write(new ConnectionDispose()); } catch (Exception ex) { LogEnvironment.LogDebugEvent(ex.Message, LogSeverity.Warning); } finally { channel.ObjectReceived -= ClientComm; channel.ConnectionStatusChanged -= ClientConnectionChanged; channel.Dispose(); } }
private void TryRemoveChannel(IMemoryChannel channel) { var ok = openChannels.TryRemove(channel.Name, out var mrConn); if (ok) { TryClose(mrConn); } var name = Broker.GetServiceByTag("ChannelName", channel.Name); if (!string.IsNullOrEmpty(name)) { try { Broker.UnsafeServerDrop(name); } catch (Exception ex) { LogEnvironment.LogEvent($"Service drop failed:{ex.Message}", LogSeverity.Error); } } }
public override async Task ServiceReady(ServiceSessionOperationMessage request, IMemoryChannel channel, DataTransferContext context) { try { if (string.IsNullOrEmpty(request.ResponderFor)) { CheckAuth(context, "ActAsService"); } else { CheckAuth(context, "ConnectAnyService", request.ResponderFor); } await base.ServiceReady(request, channel, context); } catch (Exception ex) { LogEnvironment.LogEvent(ex.OutlineException(), LogSeverity.Error); throw; } finally { TemporaryGrants.UnRegisterService(request.ServiceName); if (!string.IsNullOrEmpty(request.ResponderFor)) { TemporaryGrants.RevokeTemporaryPermission(request.ResponderFor, request.ServiceName); } } }
public void ReConnectChannel(IMemoryChannel comm, IMemoryChannel initialChannel) { initialChannel.Write(new ConnectionRequest { ProposedGuid = comm.Name, Ttl = comm.Ttl, User = JsonHelper.ToJsonStrongTyped(provider.CurrentIdentity) }); }
public virtual async Task ServiceReady(ServiceSessionOperationMessage request, IMemoryChannel channel, DataTransferContext context) { CancellationToken cancellationToken = channel.CancellationToken; try { serviceBackend.Broker.AddServiceTag(request, "ChannelName", channel.Name); do { string req = null; try { var nextMessage = await serviceBackend.Broker.NextRequest(request); req = nextMessage.OperationId; if (nextMessage != null) { await channel.WriteAsync(new ServerOperationMessage { HubUser = nextMessage.HubUser, OperationId = nextMessage.OperationId, OperationPayload = nextMessage.OperationPayload, TargetService = nextMessage.TargetService, TickBack = nextMessage.TickBack }).ConfigureAwait(false); } else { await Task.Delay(500, cancellationToken).ConfigureAwait(false); } } catch (ServiceBrokenException sbe) { serviceBackend.Broker.FailOperation(request, req, sbe); LogEnvironment.LogEvent($"Error occurred: {sbe.Message}", LogSeverity.Error); break; } catch (ServiceTimeoutException ste) { serviceBackend.Broker.FailOperation(request, req, ste); LogEnvironment.LogEvent($"Error occurred: {ste.Message}", LogSeverity.Error); break; } catch (ServiceUnknownException sue) { serviceBackend.Broker.FailOperation(request, req, sue); LogEnvironment.LogEvent($"Error occurred: {sue.Message}", LogSeverity.Error); break; } catch (Exception ex) { serviceBackend.Broker.FailOperation(request, req, ex); LogEnvironment.LogEvent($"Error occurred: {ex.OutlineException()}", LogSeverity.Error); } } while (cancellationToken.IsCancellationRequested == false); } finally { serviceBackend.Broker.TryUnRegisterService(request); } }