Example #1
0
 private void NodeEventHandler(NodeEvent e)
 {
     switch (e.Type)
     {
         case NodeEventType.DeviceUpdate:
             if (e.Device != null && e.Device.Guid != Guid.Empty)
                 DeviceUpdatedHandler(e.Device);
             break;
         case NodeEventType.DeviceDeregister:
             if (e.Guid != Guid.Empty)
                 DeviceDeregisteredHandler(e.Guid);
             break;
         case NodeEventType.Data:
             if (e.Data != null)
                 DataReceivedHandler(e.Data);
             break;
     }
 }
Example #2
0
 private static void Notify(Guid device, NodeEvent e)
 {
     NodeSession session = Get(DeviceLookup(device));
     if (session != null)
         session.NodeEventEnqueue(e);
 }
Example #3
0
 /// <summary>
 /// Dequeue events
 /// </summary>
 /// <returns></returns>
 public NodeEvent[] NodeEventDequeue(int timeout)
 {
     if (queue.Count <= 0 && timeout > 0)
         if (!queue_wait.WaitOne(timeout, true))
             return new NodeEvent[0];
     queue_mutex.WaitOne();
     if (queue.Count <= 0)
     {
         queue_mutex.ReleaseMutex();
         return new NodeEvent[0];
     }
     NodeEvent[] e = new NodeEvent[queue.Count];
     for (int i = 0; i < e.Length; i++)
         e[i] = queue.Dequeue();
     queue_mutex.ReleaseMutex();
     return e;
 }
Example #4
0
 /// <summary>
 /// Push an event into the queue
 /// </summary>
 /// <param name="e"></param>
 public void NodeEventEnqueue(NodeEvent e)
 {
     if (e == null) throw new ArgumentNullException();
     queue_mutex.WaitOne();
     int max = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Reactivity.Server.Nodes.NodeSession.NodeEventQueueLength"]);
     while (queue.Count >= max)
         queue.Dequeue();
     queue.Enqueue(e);
     queue_mutex.ReleaseMutex();
     queue_wait.Set();
 }
Example #5
0
 public static void Notify(NodeEvent e)
 {
     switch (e.Type)
     {
         case NodeEventType.Data:
             if (e.Data != null && e.Data.Device != Guid.Empty)
                 Notify(e.Data.Device, e);
             break;
         case NodeEventType.DeviceUpdate:
             if (e.Device != null && e.Device.Guid != Guid.Empty)
                 Notify(e.Device.Guid, e);
             break;
         case NodeEventType.DeviceDeregister:
             //must be coming from DeviceManager when device get deleted
             if (e.Guid != Guid.Empty)
             {
                 devices_mutex.WaitOne();
                 if (!devices_sessions.ContainsKey(e.Guid))
                 {
                     devices_mutex.ReleaseMutex();
                     break;
                 }
                 NodeSession session = Get(devices_sessions[e.Guid]);
                 devices_sessions.Remove(e.Guid);
                 devices_mutex.ReleaseMutex();
                 if (session != null)
                     session.NodeEventEnqueue(e);
             }
             break;
     }
 }