Exemple #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);
        }
Exemple #2
0
        void _UserContextChannel_Faulted(object sender, EventArgs e)
        {
            IContextChannel ch  = sender as IContextChannel;
            int             key = ch.GetHashCode();

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

                createNewMessage("Client channel " + key.ToString() + " Fault or Closed");
                foreach (MDSClient c in Clients.Values.ToArray())
                {
                    c.SendUpdateClients();
                }
            }
        }