//Subscribe a client to a specific urrency pair value
        static public bool Subscribe(string currencyPair, IPublishing subscriberCallbackReference)
        {
            try
            {
                lock (typeof(PublisherSubscriberHub))
                {
                    //Check if currency pair exists
                    if (Subscribers.ContainsKey(currencyPair))
                    {
                        //Check if the client is already registerd to the currency pair or not
                        if (!Subscribers[currencyPair].Contains(subscriberCallbackReference))
                        {
                            Subscribers[currencyPair].Add(subscriberCallbackReference);
                        }
                    }
                    else
                    {
                        List <IPublishing> newSubscribersList = new List <IPublishing>();
                        newSubscribersList.Add(subscriberCallbackReference);
                        Subscribers.Add(currencyPair, newSubscribersList);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                //Log Exception
                return(false);
            }
        }
Beispiel #2
0
        public void AddClient(String request, IPublishing ClientCallbackReference)
        {
            lock (typeof(Filter))
            {
                if (ClientsList.ContainsKey(request))
                {
                    if (!ClientsList[request].Contains(ClientCallbackReference))
                    {
                        ClientsList[request].Add(ClientCallbackReference);
                    }
                }
                else
                {
                    List <IPublishing> newClientsList = new List <IPublishing>();
                    newClientsList.Add(ClientCallbackReference);
                    ClientsList.Add(request, newClientsList);

                    FilterEventArgs args = new FilterEventArgs();
                    Random          r    = new Random(100);
                    args.Threshold   = r.Next();
                    args.TimeReached = DateTime.Now;
                    OnFiltered(args);
                }
                FilterEventArgs a = new FilterEventArgs()
                {
                    ClientId = "222"
                };
                if (ClientConnected != null)
                {
                    ClientConnected(this, a);
                }
            }
        }
        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();
        }
 public static void RemoveSubsriber(IPublishing subscriber)
 {
     lock (locker)
     {
         Subscribers.Remove(subscriber);
     }
 }
Beispiel #6
0
        private void CreateProxy()
        {
            string          endpointAddressInString = ConfigurationManager.AppSettings["EndpointAddress"];
            EndpointAddress endpointAddress         = new EndpointAddress(endpointAddressInString);
            NetTcpBinding   netTcpBinding           = new NetTcpBinding();

            _proxy = ChannelFactory <IPublishing> .CreateChannel(netTcpBinding, endpointAddress);
        }
Beispiel #7
0
        public frmPublisher()
        {
            InitializeComponent();

            _PubProxy = CreateProxy();

            txtPairName.Text = "EURO_USD";
            txtPairData.Text = "1 Euro equals 1.12 US Dollar";
        }
Beispiel #8
0
 private void CreateProxy()
 {
     string endpointAddressInString = ConfigurationManager.AppSettings["EndpointAddress"];
     EndpointAddress endpointAddress = new EndpointAddress(endpointAddressInString);
     //WSDualHttpBinding wsDualHttpBinding = new WSDualHttpBinding();
     //_proxy = ChannelFactory<IPublishing>.CreateChannel(wsDualHttpBinding, endpointAddress);
     NetTcpBinding netTcpBinding = new NetTcpBinding(SecurityMode.None);
     _proxy = ChannelFactory<IPublishing>.CreateChannel(netTcpBinding, endpointAddress);
 }
Beispiel #9
0
 // for publishing digital, and analog delta
 public PublishThreadData(IPublishing subscriber, List <UIUpdateModel> deltaUpdate, bool isDigital)
 {
     this.subscriber = subscriber;
     if (isDigital)
     {
         this.digitalDeltaUpdate = deltaUpdate;
     }
     else
     {
         this.analogDeltaUpdate = deltaUpdate;
     }
 }
 static public void RemoveSubscriber(String topicName, IPublishing subscriberCallbackReference)
 {
     lock (typeof(Filter))
     {
         if (SubscribersList.ContainsKey(topicName))
         {
             if (SubscribersList[topicName].Contains(subscriberCallbackReference))
             {
                 SubscribersList[topicName].Remove(subscriberCallbackReference);
             }
         }
     }
 }
Beispiel #11
0
 public void RemoveClient(String request, IPublishing ClientCallbackReference)
 {
     lock (typeof(Filter))
     {
         if (ClientsList.ContainsKey(request))
         {
             if (ClientsList[request].Contains(ClientCallbackReference))
             {
                 ClientsList[request].Remove(ClientCallbackReference);
             }
         }
     }
 }
        // for publishing digital, and analog delta
        public PublishThreadData(IPublishing subscriber, string mrid, States state, float value, bool isDigital)
        {
            this.subscriber = subscriber;
            this.mrid       = mrid;

            if (isDigital)
            {
                this.state = state;
            }
            else
            {
                this.value = value;
            }
        }
 public static void AddSubscriber(IPublishing subscriber)
 {
     lock (locker)
     {
         try
         {
             Subscribers.Add(subscriber);
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }
Beispiel #14
0
        private void CreateProxy()
        {
            string address = "";

            try
            {
                address = "net.tcp://localhost:3001/Pub";
                EndpointAddress endpointAddress = new EndpointAddress(address);
                proxy = ChannelFactory <IPublishing> .CreateChannel(NetTcpBindingCreator.Create(), endpointAddress);
            }
            catch (Exception e)
            {
                throw e;
                //TODO log error;
            }
        }
Beispiel #15
0
        public object GetPropertyData(ServiceType type, string data)
        {
            if (OperationContext.Current != null)
            {
                IPublishing registeredUser = OperationContext.Current.GetCallbackChannel <IPublishing>();

                var result = false;
                if (!_callbackList.Contains(new KeyValuePair <ServiceType, IPublishing>(type, registeredUser)))
                {
                    result = _callbackList.TryAdd(type, registeredUser);
                }
            }
            IManager manager;
            object   childManager = null;

            DataBoundary serializedObject = JsonConvert.DeserializeObject <DataBoundary>(data);

            if (Services.TryGetValue(type, out manager) && serializedObject != null)
            {
                MethodInfo method;
                if (serializedObject.TypeName != string.Empty && serializedObject.TypeName != null)
                {
                    method       = manager.GetType().GetMethod(serializedObject.TypeName);
                    childManager = method.Invoke(manager, new object[0]);
                }

                object       temp;
                PropertyInfo info;
                if (childManager != null)
                {
                    info = childManager.GetType().GetProperty(serializedObject.CommandName);
                    temp = childManager.GetType().GetProperty(serializedObject.CommandName).GetValue(childManager, new object[0]);
                }
                else
                {
                    info = manager.GetType().GetProperty(serializedObject.CommandName);
                    temp = manager.GetType().GetProperty(serializedObject.CommandName).GetValue(manager, new object[0]);
                }

                serializedObject.Attributes.Clear();
                serializedObject.Attributes.Add(info.GetMethod.ReturnType, temp);

                return(JsonConvert.SerializeObject(serializedObject));
            }

            return(null);
        }
 static public void AddSubscriber(String topicName, IPublishing subscriberCallbackReference)
 {
     lock (typeof(Filter))
     {
         if (SubscribersList.ContainsKey(topicName))
         {
             if (!SubscribersList[topicName].Contains(subscriberCallbackReference))
             {
                 SubscribersList[topicName].Add(subscriberCallbackReference);
             }
         }
         else
         {
             List <IPublishing> newSubscribersList = new List <IPublishing>();
             newSubscribersList.Add(subscriberCallbackReference);
             SubscribersList.Add(topicName, newSubscribersList);
         }
     }
 }
Beispiel #17
0
        private void CreateProxy()
        {
            string address = "";

            try
            {
                address = "net.tcp://localhost:7001/Pub";
                EndpointAddress endpointAddress = new EndpointAddress(address);
                NetTcpBinding   binding         = new NetTcpBinding();
                binding.CloseTimeout           = TimeSpan.FromMinutes(10);
                binding.OpenTimeout            = TimeSpan.FromMinutes(10);
                binding.ReceiveTimeout         = TimeSpan.FromMinutes(10);
                binding.SendTimeout            = TimeSpan.FromMinutes(10);
                binding.MaxReceivedMessageSize = Int32.MaxValue;
                proxy = ChannelFactory <IPublishing> .CreateChannel(binding, endpointAddress);
            }
            catch (Exception e)
            {
                throw e;
                //TODO log error;
            }
        }
Beispiel #18
0
        public void RegisterClient(ServiceType type, IManager manager)
        {
            if (OperationContext.Current != null)
            {
                IPublishing registeredUser = OperationContext.Current.GetCallbackChannel <IPublishing>();

                var result = false;
                if (!_callbackList.Contains(new KeyValuePair <ServiceType, IPublishing>(type, registeredUser)))
                {
                    result = _callbackList.TryAdd(type, registeredUser);
                }
            }

            try
            {
                Services.TryAdd(ServiceType.FOIL, manager);
                manager.NotifyUi += NotifyUi;
            }
            catch (Exception ex)
            {
                Console.WriteLine(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);
            }
        }
        //UnSubscribe a client from a specific urrency pair value
        static public bool Unsubscribe(string currencyPair, IPublishing subscriberCallbackReference)
        {
            try
            {
                //Lock to handel conurency
                lock (typeof(PublisherSubscriberHub))
                {
                    if (Subscribers.ContainsKey(currencyPair))
                    {
                        if (Subscribers[currencyPair].Contains(subscriberCallbackReference))
                        {
                            Subscribers[currencyPair].Remove(subscriberCallbackReference);
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                //Log Exception
                return(false);
            }
        }
Beispiel #21
0
 // for publishing call incident
 public PublishThreadData(IPublishing subscriber, UIUpdateModel call, bool isCall)
 {
     this.subscriber = subscriber;
     this.call       = call;
 }
Beispiel #22
0
 // for publishing incident
 public PublishThreadData(IPublishing subscriber, IncidentReport report)
 {
     this.subscriber = subscriber;
     this.report     = report;
 }
Beispiel #23
0
 // for publishing crew update
 public PublishThreadData(IPublishing subscriber, UIUpdateModel update)
 {
     this.subscriber = subscriber;
     this.crewUpdate = update;
 }
        public bool Subscribe(string currencyPair)
        {
            IPublishing subscriber = OperationContext.Current.GetCallbackChannel <IPublishing>();

            return(PublisherSubscriberHub.Subscribe(currencyPair, subscriber));;
        }
 public PublishThreadData(IPublishing subscriber, List <SCADAUpdateModel> deltaUpdate)
 {
     this.subscriber  = subscriber;
     this.deltaUpdate = deltaUpdate;
 }
 public void SendPrintData(com.Sconit.Entity.EntityBase masterData)
 {
     try
     {
         PrintOrderMaster printOrderMstr = Mapper.Map<OrderMaster, PrintOrderMaster>((OrderMaster)masterData);
         proxy = pubSubMgr.CreateProxy();
         proxy.Publish(printOrderMstr);
     }
     catch (Exception ex)
     {
         pubSubLog.Error("Send data to print sevrer error:", ex);
     }
 }
Beispiel #27
0
 public void SendPrintData(Hu hu)
 {
     try
     {
         PrintHu printHu = Mapper.Map<Hu, PrintHu>(hu);
         proxy = pubSubMgr.CreateProxy();
         proxy.Publish(printHu);
     }
     catch (Exception ex)
     {
         pubSubLog.Error("Send data to print sevrer error:", ex);
     }
 }
        public void UnSubscribe()
        {
            IPublishing subscriber = OperationContext.Current.GetCallbackChannel <IPublishing>();

            PubSubscribeDB.RemoveSubsriber(subscriber);
        }
Beispiel #29
0
        private object ServiceGenericLogic(ServiceType type, string data)
        {
            try
            {
                if (OperationContext.Current != null)
                {
                    IPublishing registeredUser = OperationContext.Current.GetCallbackChannel <IPublishing>();

                    var result = false;
                    if (!_callbackList.Contains(new KeyValuePair <ServiceType, IPublishing>(type, registeredUser)))
                    {
                        result = _callbackList.TryAdd(type, registeredUser);
                    }
                }
                IManager manager;
                object   childManager = null;

                DataBoundary serializedObject = JsonConvert.DeserializeObject <DataBoundary>(data);

                if (Services.TryGetValue(type, out manager) && serializedObject != null)
                {
                    MethodInfo method;
                    if (serializedObject.TypeName != string.Empty && serializedObject.TypeName != null)
                    {
                        method       = manager.GetType().GetMethod(serializedObject.TypeName);
                        childManager = method.Invoke(manager, new object[0]);
                        method       = childManager.GetType().GetMethod(serializedObject.CommandName);
                    }
                    else
                    {
                        method = manager.GetType().GetMethod(serializedObject.CommandName);
                    }

                    if (method != null)
                    {
                        List <object> parameters = new List <object>();
                        foreach (var val in serializedObject.Attributes)
                        {
                            var typo = Type.GetType(val.Key.ToString());
                            if (typo.IsEnum)
                            {
                                parameters.Add(Enum.Parse(typo, val.Value.ToString()));
                            }
                            else
                            {
                                parameters.Add(val.Value.ToString());
                            }
                        }

                        object result;
                        if (childManager != null)
                        {
                            result = method.Invoke(childManager, parameters.ToArray());
                        }
                        else
                        {
                            result = method.Invoke(manager, parameters.ToArray());
                        }

                        serializedObject.Attributes.Clear();
                        serializedObject.Attributes.Add(method.ReturnType, result);

                        return(JsonConvert.SerializeObject(serializedObject));
                    }
                }
                return(null);
            }
            catch (Exception e)
            {
                LogServer.LogException(e, General.EXCEPTION_GENERAL);
                return(null);
            }
        }
Beispiel #30
0
        static public void AddSubscriber(string GUID, string subType, string flow, string region, string userNm, IPublishing subscriberCallbackReference)
        {
            SubscriptionDetail subscriptionDetail = new SubscriptionDetail();
            subscriptionDetail.SubType = subType;
            subscriptionDetail.Flow = flow;
            subscriptionDetail.Region = region;
            subscriptionDetail.UserNm = userNm;
            subscriptionDetail.CallBackInstance = subscriberCallbackReference;

            if (subType != "")
            {
                lock (typeof(Filter))
                {
                    if (!SubscribersList.ContainsKey(GUID))
                    {
                        lock (SubscribersList)
                        {
                            SubscribersList.Add(GUID, subscriptionDetail);
                        }
                    }
                }
            }
            else
            {
                if (!_heartBeatList.ContainsKey(GUID))
                {
                    _heartBeatList.Add(GUID, subscriptionDetail);
                }
            }
        }
 public PublishThreadData(IPublishing subscriber, List <UIUpdateModel> update)
 {
     this.subscriber = subscriber;
     this.updateList = update;
 }
Beispiel #32
0
 // for publishing ui breakers
 public PublishThreadData(IPublishing subscriber, bool IsIncident, long incidentBreaker)
 {
     this.subscriber      = subscriber;
     this.Isincident      = IsIncident;
     this.incidentBreaker = incidentBreaker;
 }
        public void UnSubscribe(string request)
        {
            IPublishing Client = OperationContext.Current.GetCallbackChannel <IPublishing>();

            Filter.Instance.RemoveClient(request, Client);
        }
    public void UnSubscribe(string topicName)
    {
        IPublishing subscriber = OperationContext.Current.GetCallbackChannel <IPublishing>();

        Filter.RemoveSubscriber(topicName, subscriber);
    }
Beispiel #35
0
 public void SendPrintData(IpMaster ipMaster)
 {
     try
     {
         PrintIpMaster printIpMaster = Mapper.Map<IpMaster, PrintIpMaster>(ipMaster);
         proxy = pubSubMgr.CreateProxy();
         proxy.Publish(printIpMaster);
     }
     catch (Exception ex)
     {
         pubSubLog.Error("Send data to print sevrer error:", ex);
     }
 }