Beispiel #1
0
        /// <summary>
        /// UnSubscribe message from the client.
        /// </summary>
        /// <param name="request">Object representing the requested information</param>
        public virtual void UnSubscribe(RequestMessage request)
        {
            request.Header.MessageType = (int)MessageType.UNSUBSCRIBE;
            IIPCDuplexCallback notUsed = null;

            if (_subscriptions.ContainsKey(request.Header.ProcessID.ToString()))
            {
                _subscriptions.TryRemove(request.Header.ProcessID.ToString(), out notUsed);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Subscribe message from the client.
        /// </summary>
        /// <param name="request">Object representing the requested information</param>
        /// <remarks>
        /// The client subscribes to the events from the server.
        /// This may include client specific events or general broadcasts.
        /// </remarks>
        public virtual void Subscribe(RequestMessage request)
        {
            IIPCDuplexCallback callback = OperationContext.Current.GetCallbackChannel <IIPCDuplexCallback>();

            request.Header.MessageType = (int)MessageType.SUBSCRIBE;
            if (!_subscriptions.ContainsKey(request.Header.ProcessID.ToString()))
            {
                _subscriptions.TryAdd(request.Header.ProcessID.ToString(), callback);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Send message from the client.
        /// </summary>
        /// <param name="request">Object representing the requested information</param>
        /// <remarks>
        /// This should be used either when you need a one way notification or an out of band reply.
        /// </remarks>
        public void Send(RequestMessage request)
        {
            IIPCDuplexCallback callback = OperationContext.Current.GetCallbackChannel <IIPCDuplexCallback>();
            var response = Call(request);

            if (callback != null)
            {
                callback.Reply(response);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Broadcast a message to all clients.
        /// </summary>
        /// <param name="response">Response message</param>
        /// <remarks>Only works with duplex clients</remarks>
        public void Broadcast(ResponseMessage response)
        {
            IIPCDuplexCallback notUsed = null;

            foreach (var replyChannel in _subscriptions)
            {
                try
                {
                    replyChannel.Value.Reply(response);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine($"Reply to {response.Header.RequestHeader.ProcessID} failed with error: {ex.Message}");
                    _subscriptions.TryRemove(replyChannel.Key, out notUsed);
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Reply from the server to the client.
        /// </summary>
        /// <param name="clientID">Unique ID for the clients response channel.</param>
        /// <param name="response">Response</param>
        public void SendReply(string clientID, ResponseMessage response)
        {
            if (_subscriptions.ContainsKey(clientID))
            {
                var replyChannel = _subscriptions[clientID];

                try
                {
                    replyChannel.Reply(response);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine($"Reply to {response.Header.RequestHeader.ProcessID} failed with error: {ex.Message}");
                    IIPCDuplexCallback notUsed = null;
                    _subscriptions.TryRemove(clientID, out notUsed);
                }
            }
        }