Example #1
0
 /// <summary>Unregisters the client, caused via an event.</summary>
 /// <param name="clientCallback">The client callback.</param>
 /// <param name="faulted">Set to <c>true</c> if the client faulted.</param>
 /// <returns>The result.</returns>
 public bool UnregisterClientViaEvent(ISubscriptionServiceCallback clientCallback, bool faulted)
 {
     lock (_clients)
     {
         return UnregisterClient(clientCallback, faulted);
     }
 }
Example #2
0
 /// <summary>Removes the client registration.</summary>
 /// <param name="clientCallback">The client callback.</param>
 public void RemoveClient(ISubscriptionServiceCallback clientCallback)
 {
     lock (_clients)
     {
         UnregisterClient(clientCallback, false);
     }
 }
Example #3
0
 /// <summary>Adds the client registration.</summary>
 /// <param name="serviceProtocol">The service protocol.</param>
 /// <param name="clientCallback">The client callback.</param>
 /// <param name="clientName">The client name.</param>
 public void AddClient(string serviceProtocol, ISubscriptionServiceCallback clientCallback, string clientName)
 {
     lock (_clients)
     {
         RegisterClient(serviceProtocol, clientCallback, clientName);
     }
 }
Example #4
0
        private bool UnregisterClient(ISubscriptionServiceCallback clientCallback, bool faulted)
        {
            // only if actually registered...
            var existing = GetRegisteredClient(clientCallback);
            if (existing == null)
                return false;

            _clients.Remove(existing);

            // and notify...
            if (faulted)
                this.WriteLine(ConsoleColor.Yellow, "Client faulted: " + existing.ServiceProtocol + "/" + existing.ClientName);
            else
                this.WriteLine(ConsoleColor.White, "Client removed: " + existing.ServiceProtocol + "/" + existing.ClientName);
            NotifyClients(Notification.ClientRemoved, existing.ClientName);
            return true;
        }
Example #5
0
        private bool RegisterClient(string serviceProtocol, ISubscriptionServiceCallback clientCallback, string clientName)
        {
            // only if not yet registered...
            var existing = GetRegisteredClient(clientCallback);
            if (existing != null)
                return false;

            _clients.Add(new ClientRegistration(serviceProtocol, clientCallback, clientName));

            // register event handlers to handle lost connections
            // Note: These events come for netTcpBinding, but NOT for wsDualHttpBinding!
            var clientChannel = (IContextChannel)clientCallback;
            clientChannel.Closing += (s, e) => UnregisterClientViaEvent(clientCallback, faulted: false);
            clientChannel.Faulted += (s, e) => UnregisterClientViaEvent(clientCallback, faulted: true);

            // timeout on the callback channel (no way to do this via configuration)
            clientChannel.OperationTimeout = TimeSpan.FromSeconds(10);

            // and notify...
            this.WriteLine(ConsoleColor.White, "Client added: " + serviceProtocol + "/" + clientName);
            NotifyClients(Notification.ClientAdded, clientName);
            return true;
        }
 /// <summary>Initializes a new instance of the <see cref="ClientRegistration" /> class.</summary>
 /// <param name="clientName">Name of the client.</param>
 /// <param name="clientCallback">The client callback.</param>
 public ClientRegistration(string serviceProtocol, ISubscriptionServiceCallback clientCallback, string clientName)
 {
     this.ClientName      = clientName;
     this.ClientCallback  = clientCallback;
     this.ServiceProtocol = serviceProtocol;
 }
Example #7
0
 private ClientRegistration GetRegisteredClient(ISubscriptionServiceCallback clientCallback)
 {
     return _clients.Where(c => c.ClientCallback == clientCallback).FirstOrDefault();
 }