/// <summary>
        /// Update event listener
        /// </summary>
        /// <param name="sender">Sender value</param>
        /// <param name="broadCastEventArgs">BroadCastEventArgs value</param>
        private void UpdateEventListener(object sender, BroadCastEventArgs broadCastEventArgs)
        {
            lock (_locker)
            {
                ConfigurationLookupVM configurationLookUp;
                if (SerializationHelper.TryDeserialize <ConfigurationLookupVM>(broadCastEventArgs.MessageRequest.Message, out configurationLookUp))
                {
                    ConfigurationLookupVM configurationLookUpToBeUpdate = _configurationLookUps.Where(cl => cl.ID == configurationLookUp.ID).FirstOrDefault();

                    if (configurationLookUpToBeUpdate != null)
                    {
                        // Modify the collection.
                        // 1. Set the configuration lookup object status to Update and update the value
                        App.Current.Dispatcher.Invoke(() =>
                        {
                            configurationLookUpToBeUpdate.Status = Status.Updated.ToString();
                            configurationLookUpToBeUpdate.Name   = configurationLookUp.Name;
                            configurationLookUpToBeUpdate.Value  = configurationLookUp.Value;
                        });

                        // 2. Wait few second and set the configuration lookup object status to Default
                        Thread.Sleep(2500);
                        App.Current.Dispatcher.Invoke(() =>
                        {
                            configurationLookUpToBeUpdate.Status = Status.Default.ToString();
                        });
                    }
                }
            }
        }
        /// <summary>
        /// Delete event listener
        /// </summary>
        /// <param name="sender">Sender value</param>
        /// <param name="broadCastEventArgs">BroadCastEventArgs value</param>
        private void DeleteEventListener(object sender, BroadCastEventArgs broadCastEventArgs)
        {
            lock (_locker)
            {
                ConfigurationLookupVM configurationLookUp;
                if (SerializationHelper.TryDeserialize <ConfigurationLookupVM>(broadCastEventArgs.MessageRequest.Message, out configurationLookUp))
                {
                    ConfigurationLookupVM configurationLookUpToBeDelete = _configurationLookUps.Where(cl => cl.ID == configurationLookUp.ID).FirstOrDefault();
                    if (configurationLookUpToBeDelete != null)
                    {
                        // Modify the collection.
                        // 1. Set the configuration lookup object status to Deleted.This is to show the Grid animation related to Delete
                        App.Current.Dispatcher.Invoke(() =>
                        {
                            configurationLookUpToBeDelete.Status = Status.Deleted.ToString();
                        });

                        // 2. Wait few second and remove the deleted from the collecion.
                        Thread.Sleep(2500);
                        App.Current.Dispatcher.Invoke(() =>
                        {
                            ConfigurationLookUpCaches.Remove(configurationLookUpToBeDelete);
                            ConfigurationLookUpCaches.OrderByDescending(cl => cl.ID);
                        });
                    }
                }
            }
        }
Exemplo n.º 3
0
 //tell plugins to pack their states into a dictionary to pass to other plugins
 public void RaiseBroadcastRequest(object sender, IDictionary <string, object> dictPackedPlugin)
 {
     if (BroadcastState != null) //has some method been told to handle this event?
     {
         BroadCastEventArgs e = new BroadCastEventArgs(sender, dictPackedPlugin);
         BroadcastState(sender, e);
     }
 }
        /// <summary>
        /// Message listened and notified
        /// </summary>
        /// <param name="broadCastArgs">BroadCastArgs value</param>
        private void OnMessageListened(BroadCastEventArgs broadCastArgs)
        {
            EventHandler <BroadCastEventArgs> handler = BroadCastListenerEventHandler;

            if (handler != null)
            {
                handler(this, broadCastArgs);
            }
        }
 /// <summary>
 /// Insert event listener
 /// </summary>
 /// <param name="sender">Sender value</param>
 /// <param name="e">BroadCastEventArgs value</param>
 private void InsertEventListener(object sender, BroadCastEventArgs e)
 {
     lock (_locker)
     {
         ConfigurationLookup configurationLookUp;
         if (SerializationHelper.TryDeserialize <ConfigurationLookup>(e.MessageRequest.Message, out configurationLookUp))
         {
             _configurationLookUpCaches.Add(configurationLookUp);
             _configurationLookUpCaches.OrderByDescending(cl => cl.ID);
         }
     }
 }
 /// <summary>
 /// Insert event listener
 /// </summary>
 /// <param name="sender">Sender value</param>
 /// <param name="broadCastEventArgs">BroadCastEventArgs value</param>
 private static void InsertEventListener(object sender, BroadCastEventArgs broadCastEventArgs)
 {
     lock (_locker)
     {
         ConfigurationLookup configurationLookUp;
         if (SerializationHelper.TryDeserialize <ConfigurationLookup>(broadCastEventArgs.MessageRequest.Message, out configurationLookUp))
         {
             _configurationLookUpCaches.Add(configurationLookUp);
             _configurationLookUpCaches.OrderByDescending(cl => cl.ID);
             cache.Set(CONFIGURATION_LOOKUP_CACHE_KEY, _configurationLookUpCaches, policy);
         }
     }
 }
 /// <summary>
 /// Delete event listener
 /// </summary>
 /// <param name="sender">Sender value</param>
 /// <param name="e">BroadCastEventArgs value</param>
 private void DeleteEventListener(object sender, BroadCastEventArgs e)
 {
     lock (_locker)
     {
         ConfigurationLookup configurationLookUp;
         if (SerializationHelper.TryDeserialize <ConfigurationLookup>(e.MessageRequest.Message, out configurationLookUp))
         {
             ConfigurationLookup configurationLookUpToBeDelete = _configurationLookUpCaches.Where(cl => cl.ID == configurationLookUp.ID).FirstOrDefault();
             if (configurationLookUpToBeDelete != null)
             {
                 _configurationLookUpCaches.Remove(configurationLookUpToBeDelete);
                 _configurationLookUpCaches.OrderByDescending(cl => cl.ID);
             }
         }
     }
 }
 /// <summary>
 /// Update event listener
 /// </summary>
 /// <param name="sender">Sender value</param>
 /// <param name="e">BroadCastEventArgs value</param>
 private void UpdateEventListener(object sender, BroadCastEventArgs e)
 {
     lock (_locker)
     {
         ConfigurationLookup configurationLookUp;
         if (SerializationHelper.TryDeserialize <ConfigurationLookup>(e.MessageRequest.Message, out configurationLookUp))
         {
             ConfigurationLookup configurationLookUpToBeUpdate = _configurationLookUpCaches.Where(cl => cl.ID == configurationLookUp.ID).FirstOrDefault();
             if (configurationLookUpToBeUpdate != null)
             {
                 configurationLookUpToBeUpdate.Name  = configurationLookUp.Name;
                 configurationLookUpToBeUpdate.Value = configurationLookUp.Value;
             }
         }
     }
 }
 /// <summary>
 /// Delete event listener
 /// </summary>
 /// <param name="sender">Sender value</param>
 /// <param name="broadCastEventArgs">BroadCastEventArgs value</param>
 private static void DeleteEventListener(object sender, BroadCastEventArgs broadCastEventArgs)
 {
     lock (_locker)
     {
         ConfigurationLookup configurationLookUp;
         if (SerializationHelper.TryDeserialize <ConfigurationLookup>(broadCastEventArgs.MessageRequest.Message, out configurationLookUp))
         {
             ConfigurationLookup configurationLookUpToBeDelete = _configurationLookUpCaches.Where(cl => cl.ID == configurationLookUp.ID).FirstOrDefault();
             if (configurationLookUpToBeDelete != null)
             {
                 _configurationLookUpCaches.Remove(configurationLookUpToBeDelete);
                 _configurationLookUpCaches.OrderByDescending(cl => cl.ID);
                 cache.Set(CONFIGURATION_LOOKUP_CACHE_KEY, _configurationLookUpCaches, policy);
             }
         }
     }
 }
 /// <summary>
 /// Insert event listener
 /// </summary>
 /// <param name="sender">Sender value</param>
 /// <param name="broadCastEventArgs">BroadCastEventArgs value</param>
 private void InsertEventListener(object sender, BroadCastEventArgs broadCastEventArgs)
 {
     lock (_locker)
     {
         ConfigurationLookupVM configurationLookUp;
         if (SerializationHelper.TryDeserialize <ConfigurationLookupVM>(broadCastEventArgs.MessageRequest.Message, out configurationLookUp))
         {
             // Modify the collection. Set the configuration lookup object status to Inserted
             App.Current.Dispatcher.Invoke(() =>
             {
                 configurationLookUp.Status = Status.Inserted.ToString();
                 _configurationLookUps.Add(configurationLookUp);
                 _configurationLookUps.OrderByDescending(cl => cl.ID);
             });
         }
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Register broadcasted message to SignalR events
        /// </summary>
        /// <param name="broadCastArgs">BroadCastEventArgs value</param>
        private void RegisterMessageEvents(BroadCastEventArgs broadCastArgs)
        {
            if (broadCastArgs != null)
            {
                MessageRequest messageRequest = broadCastArgs.MessageRequest;

                IClientProxy clientProxy = Clients.Caller;
                if (messageRequest.EventName != EventNameEnum.UNKNOWN)
                {
                    clientProxy.Invoke(messageRequest.EventName.EnumDescription(), messageRequest.Message);
                }
                else
                {
                    string errorMessage = "Unknown or empty event name is requested!";
                    clientProxy.Invoke(EventNameEnum.ON_EXCEPTION.EnumDescription(), errorMessage); // Goes to the listener
                    throw new Exception(errorMessage);                                              // Goes to the broadcaster
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// 注册广播事件
        /// </summary>
        /// <param name="broadCastArgs"></param>
        private void RegisterMessageEvents(BroadCastEventArgs broadCastArgs)
        {
            if (broadCastArgs != null)
            {
                MessageRequest messageRequest = broadCastArgs.MessageRequest;

                IClientProxy clientProxy = Clients.All;      //Clients.Caller;

                //PropellingMovementDto propellingMovementDto = this.PropellingMovementService.GetPropellingMovementDto(SetupConfig.ServiceNumber
                //    , messageRequest.Group, SetupConfig.Enviroment);
                PropellingMovementDto propellingMovementDto = new PropellingMovementDto();
                //TODO:数据库获取
                if (propellingMovementDto != null)
                {
                    clientProxy.Invoke(messageRequest.Group, messageRequest.Message);
                }
                else
                {
                    throw new Exception("对应的服务广播组不存在");
                }
            }
        }
Exemplo n.º 13
0
 private void BroadcastStateListener(object sender, BroadCastEventArgs e)
 {
     //listen to others broadcast..receiving something
     //e.PackedPluginState
 }
        /// <summary>
        /// Listen hub event and attach the message to the client event
        /// </summary>
        /// <param name="hubEvent">Client hub event</param>
        /// <returns>string value that shows status</returns>
        public string ListenHubEvent(Action <object, BroadCastEventArgs> hubEvent)
        {
            if (!_hubConfiguration.IsHubListeningEnabled)
            {
                return(string.Concat("Hub listening is disabled for an event named ", _hubConfiguration.HubEventName.EnumDescription()));
            }

            string statusMessage = string.Concat("All is well. Message is being listened for an event named ", _hubConfiguration.HubEventName.EnumDescription());

            try
            {
                if (hubEvent == null)
                {
                    throw new ArgumentNullException("HubEvent is null !");
                }

                if (hubConnection == null || isDisposed)
                {
                    hubConnection = new HubConnection(_hubConfiguration.HubURL);
                }

                IHubProxy proxyHub = hubConnection.CreateHubProxy(_hubConfiguration.HubName);

                try
                {
                    hubConnection.Start().
                    ContinueWith(task
                                 =>
                    {
                        if (task.IsFaulted)
                        {
                            throw task.Exception;
                        }
                        else
                        {
                            // Register/attach broadcast listener event
                            if (_hubConfiguration.HubEventName != EventNameEnum.UNKNOWN)
                            {
                                lock (eventLocker)
                                {
                                    BroadCastListenerEventHandler += (sender, broadCastArgs) =>
                                                                     hubEvent.Invoke(sender, broadCastArgs);
                                }
                            }
                        }
                    }, TaskContinuationOptions.OnlyOnRanToCompletion).Wait();
                }
                catch (AggregateException aggregateException)
                {
                    throw aggregateException;
                }


                if (hubConnection.State == ConnectionState.Connected)
                {
                    IsConnected = true;
                }

                proxyHub.On <string>(_hubConfiguration.HubEventName.EnumDescription(),
                                     message =>
                {
                    _broadCastListenerEventArgs = new BroadCastEventArgs(
                        new MessageRequest()
                    {
                        Message   = message,
                        EventName = _hubConfiguration.HubEventName
                    });
                    OnMessageListened(_broadCastListenerEventArgs);
                });


                lock (eventLocker)
                {
                    // Unregister/detach broadcast listener event
                    BroadCastListenerEventHandler -= (sender, broadCastArgs) =>
                                                     hubEvent.Invoke(sender, broadCastArgs);
                }
            }
            catch (Exception exception)
            {
                // Client should handle the exception
                if (hubConnection != null && !string.IsNullOrWhiteSpace(hubConnection.ConnectionId))
                {
                    return(string.Format("Opps something wrong happened ! Hub ConnectionID : {0}, Exception - Message : {1}, StackTrace : {2} ",
                                         hubConnection.ConnectionId, exception.Message, exception.StackTrace));
                }
                return(string.Format("Opps something wrong happened ! Exception - Message : {0}, StackTrace : {1} ", exception.Message, exception.StackTrace));
            }
            return(hubConnection != null && !string.IsNullOrWhiteSpace(hubConnection.ConnectionId) ?
                   string.Concat(statusMessage, " at Hub ConnectionID : ", hubConnection.ConnectionId) : statusMessage);
        }