Esempio n. 1
0
 /// <summary>
 /// Callback that is called when a Simias event is occurs.
 /// </summary>
 /// <param name="args">A SimiasEventArgs structure that contains event information.</param>
 private void OnNotifyEvent(SimiasEventArgs args)
 {
     try
     {
         if (enabled)
         {
             NotifyEventArgs nArgs = args as NotifyEventArgs;
             if ((nArgs != null) && (NotifyEvent != null))
             {
                 Delegate[] cbList = NotifyEvent.GetInvocationList();
                 foreach (NotifyEventHandler cb in cbList)
                 {
                     try
                     {
                         cb(nArgs);
                     }
                     catch (Exception ex)
                     {
                         logger.Debug(ex, "Delegate {0}.{1} failed", cb.Target, cb.Method);
                         NotifyEvent -= cb;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         new SimiasException(args.ToString(), ex);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Callback for the event Need credentials
 /// </summary>
 /// <param name="args">Simias event</param>
 private void OnNeedCredentials(SimiasEventArgs args)
 {
     try
     {
         if (enabled)
         {
             NeedCredentialsEventArgs cArgs = args as NeedCredentialsEventArgs;
             if (cArgs != null)
             {
                 if (NeedCredentials != null)
                 {
                     Delegate[] cbList = NeedCredentials.GetInvocationList();
                     foreach (NeedCredentialsEventHandler cb in cbList)
                     {
                         try
                         {
                             cb(cArgs);
                         }
                         catch
                         {
                             NeedCredentials -= cb;
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         new SimiasException(args.ToString(), ex);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Call back method which is called when sync event occurs
 /// </summary>
 /// <param name="args">Simias event details</param>
 private void OnSyncEvent(SimiasEventArgs args)
 {
     try
     {
         if (enabled)
         {
             CollectionSyncEventArgs cArgs = args as CollectionSyncEventArgs;
             if (cArgs != null)
             {
                 if (CollectionSync != null)
                 {
                     Delegate[] cbList = CollectionSync.GetInvocationList();
                     foreach (CollectionSyncEventHandler cb in cbList)
                     {
                         try
                         {
                             cb(cArgs);
                         }
                         catch (Exception ex)
                         {
                             logger.Debug(ex, "Delegate {0}.{1} failed", cb.Target, cb.Method);
                             CollectionSync -= cb;
                         }
                     }
                 }
             }
             else
             {
                 FileSyncEventArgs fArgs = args as FileSyncEventArgs;
                 if (fArgs != null)
                 {
                     if (FileSync != null)
                     {
                         Delegate[] cbList = FileSync.GetInvocationList();
                         foreach (FileSyncEventHandler cb in cbList)
                         {
                             try
                             {
                                 cb(fArgs);
                             }
                             catch (Exception ex)
                             {
                                 logger.Debug(ex, "Delegate {0}.{1} failed", cb.Target, cb.Method);
                                 FileSync -= cb;
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         new SimiasException(args.ToString(), ex);
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Called to publish a collection event.
 /// </summary>
 /// <param name="args">The arguments describing the event.</param>
 public void RaiseEvent(SimiasEventArgs args)
 {
     try
     {
         broker.RaiseEvent(args);
     }
     catch
     {
         logger.Debug("Failed to Raise Event {0}", args.ToString());
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Callback for handling simias event received
 /// </summary>
 /// <param name="args">Simias even details</param>
 private void OnSimiasEvent(SimiasEventArgs args)
 {
     try
     {
         string typeString = args.GetType().ToString();
         switch (typeString)
         {
         case "Simias.Service.ShutdownEventArgs":
             if (Shutdown != null)
             {
                 Shutdown((ShutdownEventArgs)args);
             }
             break;
         }
     }
     catch (Exception ex)
     {
         new SimiasException(args.ToString(), ex);
     }
 }
Esempio n. 6
0
        /// <summary>
        /// When Collection even is generated, this method is called
        /// </summary>
        /// <param name="args">Simias event details</param>
        private void OnCollectionEvent(SimiasEventArgs args)
        {
            try
            {
                NodeEventArgs nodeArgs = args as NodeEventArgs;
                if (nodeArgs != null)
                {
                    if (applyNodeFilter(nodeArgs))
                    {
                        EventType changeType = (EventType)Enum.Parse(typeof(EventType), (string)nodeArgs.EventData, false);
                        switch (changeType)
                        {
                        case EventType.NodeChanged:
                            if (NodeChanged != null)
                            {
                                Delegate[] cbList = NodeChanged.GetInvocationList();
                                foreach (NodeEventHandler cb in cbList)
                                {
                                    try
                                    {
                                        cb(nodeArgs);
                                    }
                                    catch (Exception ex)
                                    {
                                        logger.Debug(ex, "Delegate {0}.{1} failed", cb.Target, cb.Method);
                                        NodeChanged -= cb;
                                    }
                                }
                            }
                            break;

                        case EventType.NodeCreated:
                            if (NodeCreated != null)
                            {
                                Delegate[] cbList = NodeCreated.GetInvocationList();
                                foreach (NodeEventHandler cb in cbList)
                                {
                                    try
                                    {
                                        cb(nodeArgs);
                                    }
                                    catch (Exception ex)
                                    {
                                        logger.Debug(ex, "Delegate {0}.{1} failed", cb.Target, cb.Method);
                                        NodeCreated -= cb;
                                    }
                                }
                            }
                            break;

                        case EventType.NodeDeleted:
                            if (NodeDeleted != null)
                            {
                                Delegate[] cbList = NodeDeleted.GetInvocationList();
                                foreach (NodeEventHandler cb in cbList)
                                {
                                    try
                                    {
                                        cb(nodeArgs);
                                    }
                                    catch (Exception ex)
                                    {
                                        logger.Debug(ex, "Delegate {0}.{1} failed", cb.Target, cb.Method);
                                        NodeDeleted -= cb;
                                    }
                                }
                            }
                            break;

                        case EventType.NoAccess:
                            if (NoAccess != null)
                            {
                                Delegate[] cbList = NoAccess.GetInvocationList();
                                foreach (NodeEventHandler cb in cbList)
                                {
                                    try
                                    {
                                        cb(nodeArgs);
                                    }
                                    catch (Exception ex)
                                    {
                                        logger.Debug(ex, "Delegate {0}.{1} failed", cb.Target, cb.Method);
                                        NodeDeleted -= cb;
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                new SimiasException(args.ToString(), ex);
            }
        }