public void UnSubscribe(int clientId)
        {
            IPublishing     registeredUser = null;
            IContextChannel channel        = null;
            DateTime        value;

            bool result = false;

            if (!_callbackList.Contains(new KeyValuePair <int, IPublishing>(clientId, registeredUser)))
            {
                result = _callbackList.TryRemove(clientId, out registeredUser);
                if (result == true)
                {
                    result = _callbackListChannelByClientId.TryRemove(clientId, out channel);
                    if (result == true)
                    {
                        result = _callbackListClientIdByChannel.TryRemove(channel, out clientId);
                        result = _clientKeepAliveMessageByClientId.TryRemove(clientId, out value);
                        LogServer.LogStatus(STT.General.INFO_GENERAL, "client id:" + clientId + " was removed.");
                    }
                }
            }
            else
            {
                LogServer.LogStatus(STT.General.INFO_GENERAL, "unable to remove client id:" + clientId);
            }
        }
        public void Subscribe(int clientId)
        {
            m_registeredUser = OperationContext.Current.GetCallbackChannel <IPublishing>();

            IContextChannel      channel = OperationContext.Current.Channel;
            ICommunicationObject obj     = (ICommunicationObject)m_registeredUser;

            obj.Faulted += new EventHandler(Channel_Faulted);
            obj.Closed  += new EventHandler(Channel_Faulted);

            var result = false;

            if (!_callbackList.Contains(new KeyValuePair <int, IPublishing>(clientId, m_registeredUser)))
            {
                result = _callbackList.TryAdd(clientId, m_registeredUser);
                if (result)
                {
                    LogServer.LogStatus(STT.General.INFO_GENERAL, $"ClientNotifier client ID= {clientId} had been subscribe ");
                }
                else
                {
                    LogServer.LogStatus(STT.General.ERROR_GENERAL, $"ClientNotifier client ID= {clientId} subscribtion Failure ");
                }

                result = _callbackListClientIdByChannel.TryAdd(channel, clientId);
                result = _callbackListChannelByClientId.TryAdd(clientId, channel);

                DateTime today = DateTime.Now;
                result = _clientKeepAliveMessageByClientId.TryAdd(clientId, today);
            }

            m_timer          = new Timer(1000);
            m_timer.Elapsed += Channel_Opened;
            m_timer.Start();
        }
Exemple #3
0
        virtual public void NotifyHost()
        {
            string jsonStr = SerializeToJson();

            ClientManager.Instance.Notify(m_obj.m_clientId, jsonStr);
            LogServer.LogStatus(STT.General.INFO_GENERAL, $"ClientManager notify server with serializing data from client ID= {m_obj.m_clientId}");
        }
        private void Channel_Opened(object sender, EventArgs e)
        {
            LogServer.LogStatus(STT.General.INFO_GENERAL, $"ClientNotifier channel open successfuly ");
            m_registeredUser.ServerNotify("connect");
            m_timer.Stop();

            Console.WriteLine("connected.");
        }
Exemple #5
0
        virtual public string SerializeToJson()
        {
            LogServer.LogStatus(STT.General.INFO_GENERAL, $"Serializing data from client ID= {m_obj.m_clientId}");
            m_serviceData.obj = m_obj;

            string actualJsonData = JsonConvert.SerializeObject(m_serviceData);

            return(actualJsonData);
        }
Exemple #6
0
 private void Subscribe(object sender, EventArgs e)
 {
     try
     {
         _proxySub.Subscribe(m_clientId);
         LogServer.LogStatus(STT.General.INFO_GENERAL, $"New Client request to subscribe client ID= {m_clientId}");
     }
     catch
     {
     }
 }
Exemple #7
0
 public void Notify(int clientId, string data)
 {
     try
     {
         LogServer.LogStatus(STT.General.INFO_GENERAL, $"Data from client ID= {m_clientId} to server side had been sent.");
         _proxySub.SendData(clientId, data);
     }
     catch (Exception ex)
     {
         //Add something to log
     }
 }
Exemple #8
0
 public void ServerNotify(string state)
 {
     try
     {
         MessageRecievedEvent?.Invoke(this, state);
         LogServer.LogStatus(STT.General.INFO_GENERAL, $"Notification from client sent to client side");
     }
     catch (Exception e)
     {
         string s = e.Message;
     }
 }
        public void Load(string port, string address)
        {
            try
            {
                string configStreamingServicePort = ConfigurationManager.AppSettings.Get("ConfigStreamingServicePort");
                string configRipServicePort       = ConfigurationManager.AppSettings.Get("ConfigRipServicePort");

                HostSubscribeService(port, address);
                HostSubscribeServiceStreaming(configStreamingServicePort, address);
                HostSubscribeServiceRip(configRipServicePort, address);

                LogServer.LogStatus(STT.General.INFO_GENERAL, $"ServiceProvider Address= {address}, Port = {port} loaded successfuly.");
            }
            catch (Exception ex)
            {
                string s = ex.Message;
            }
        }
        public void SendDataToClient(int clientId, string message)
        {
            try
            {
                IPublishing registeredUser = null;

                _callbackList.TryGetValue(clientId, out registeredUser);
                if (registeredUser != null)
                {
                    LogServer.LogStatus(STT.General.INFO_GENERAL, $"ClientNotifier message to client ID= {clientId} had been sent successfuly ");
                    registeredUser.ServerNotify(message);
                }
                else
                {
                    LogServer.LogStatus(STT.General.ERROR_GENERAL, $"ClientNotifier message to client ID= {clientId} message sent Failure ");
                }
            }
            catch (Exception e)
            {
                LogServer.LogStatus(STT.General.ERROR_GENERAL, $"ClientNotifier message to client ID= {clientId} message sent Failure ");
                Console.WriteLine(e.Message);
            }
        }
        private void Channel_Faulted(object sender, EventArgs e)
        {
            int clientId = 0;

            foreach (var retriveChannelPair in _callbackListClientIdByChannel)
            {
                KeyValuePair <IContextChannel, int> myValue = retriveChannelPair;
                try
                {
                    IContextChannel testChannel = myValue.Key;
                    if (testChannel.State != CommunicationState.Opened)
                    {
                        clientId = myValue.Value;
                        UnSubscribe(clientId);
                        LogServer.LogStatus(STT.General.INFO_GENERAL, $"ClientNotifier unregister client ID= {clientId} successfuly ");
                    }
                }
                catch (Exception ex)
                {
                    clientId = myValue.Value;
                    LogServer.LogStatus(STT.General.ERROR_GENERAL, $"ClientNotifier Unable to unregister client ID= {clientId}  ");
                }
            }
        }
Exemple #12
0
 public void Load(int clientId, string port, string address)
 {
     Init(clientId, port, address);
     m_serviceManager = new ServiceManager(m_clientId);
     LogServer.LogStatus(STT.General.INFO_GENERAL, $"ServiceManager had been loaded.");
 }
 public override void SendData(int clientId, string data)
 {
     LogServer.LogStatus(STT.General.INFO_GENERAL, $"CommClientNotifier client ID= {clientId}send data to server side. ");
     CommClientNotifier.Instance.StringDataToServerEvent?.Invoke(clientId, data);
 }