Пример #1
0
        public bool Connect(string clientname)
        {
            IMDSClient      _CallBackChannel    = OperationContext.Current.GetCallbackChannel <IMDSClient>();
            IContextChannel _UserContextChannel = OperationContext.Current.Channel;
            int             key = _UserContextChannel.GetHashCode();

            if (!Clients.Keys.Contains(key))
            {
                MDSClient _Client = new MDSClient(clientname, key, _CallBackChannel);
                Clients.Add(key, _Client);

                _Client.Fault += new EventHandler(client_Fault);
                _UserContextChannel.Faulted += new EventHandler(_UserContextChannel_Faulted);
                _UserContextChannel.Closing += new EventHandler(_UserContextChannel_Faulted);
                _UserContextChannel.Closed  += new EventHandler(_UserContextChannel_Faulted);


                createNewMessage("Подключился клиент " + clientname + " (" + key.ToString() + ")");

                foreach (MDSClient c in Clients.Values.ToArray())
                {
                    c.SendUpdateClients();
                }
                return(true);
            }

            return(false);
        }
Пример #2
0
        public bool Connect(string clientname)
        {
            IMDSClient _CallBackChannel = OperationContext.Current.GetCallbackChannel<IMDSClient>();
            IContextChannel _UserContextChannel = OperationContext.Current.Channel;
            int key = _UserContextChannel.GetHashCode();

            if (!Clients.Keys.Contains(key))
            {
                MDSClient _Client = new MDSClient(clientname, key, _CallBackChannel);
                Clients.Add(key, _Client);

                _Client.Fault += new EventHandler(client_Fault);
                _UserContextChannel.Faulted += new EventHandler(_UserContextChannel_Faulted);
                _UserContextChannel.Closing += new EventHandler(_UserContextChannel_Faulted);
                _UserContextChannel.Closed += new EventHandler(_UserContextChannel_Faulted);


                createNewMessage("Подключился клиент " + clientname + " (" + key.ToString() + ")");

                foreach (MDSClient c in Clients.Values.ToArray())
                {
                    c.SendUpdateClients();
                }
                return true;
            }

            return false;
        }
Пример #3
0
        void client_Fault(object sender, EventArgs e)
        {
            MDSClient clientOffline = (MDSClient)sender;
            int       key           = clientOffline.Key;

            if (Clients.Keys.Contains(key))
            {
                Clients.Remove(key);

                createNewMessage("Client callback channel " + clientOffline.ClientName + "(" + clientOffline.Key.ToString() + ") Fault ");

                foreach (MDSClient c in Clients.Values.ToArray())
                {
                    c.SendUpdateClients();
                }
            }
        }