Пример #1
0
 public void OnDetector(IDetectorPlugin plugin, IDetectorEvent detector, EventArgs e)
 {
     try
     {
         Log.Information("Detector " + plugin.Entity.name + " was triggered, with id " + plugin.Entity._id);
         foreach (var wi in WorkflowInstance.Instances.ToList())
         {
             if (wi.isCompleted)
             {
                 continue;
             }
             if (wi.Bookmarks != null)
             {
                 foreach (var b in wi.Bookmarks)
                 {
                     var _id = (plugin.Entity as Interfaces.entity.Detector)._id;
                     Log.Debug(b.Key + " -> " + "detector_" + _id);
                     if (b.Key == "detector_" + _id)
                     {
                         wi.ResumeBookmark(b.Key, detector);
                     }
                 }
             }
         }
         if (!global.isConnected)
         {
             return;
         }
         Interfaces.mq.RobotCommand command = new Interfaces.mq.RobotCommand();
         // detector.user = global.webSocketClient.user;
         var data   = JObject.FromObject(detector);
         var Entity = (plugin.Entity as Interfaces.entity.Detector);
         command.command    = "detector";
         command.detectorid = Entity._id;
         if (string.IsNullOrEmpty(Entity._id))
         {
             return;
         }
         command.data = data;
         Task.Run(async() =>
         {
             try
             {
                 await global.webSocketClient.QueueMessage(Entity._id, command, null, null, 0);
             }
             catch (Exception ex)
             {
                 Log.Debug(ex.Message);
             }
         });
     }
     catch (Exception ex)
     {
         Log.Error(ex, "");
         MessageBox.Show(ex.Message);
     }
 }
Пример #2
0
 public void IdleOrComplete(IWorkflowInstance instance, EventArgs e)
 {
     GenericTools.RunUI(() =>
     {
         try
         {
             System.Windows.Input.CommandManager.InvalidateRequerySuggested();
         }
         catch (Exception ex)
         {
             Log.Error(ex.ToString());
         }
     });
     try
     {
         bool isRemote = false;
         if (!string.IsNullOrEmpty(instance.queuename) && !string.IsNullOrEmpty(instance.correlationId))
         {
             isRemote = true;
             Interfaces.mq.RobotCommand command = new Interfaces.mq.RobotCommand();
             var data = JObject.FromObject(instance.Parameters);
             command.command    = "invoke" + instance.state;
             command.workflowid = instance.WorkflowId;
             command.data       = data;
             if ((instance.state == "failed" || instance.state == "aborted") && instance.Exception != null)
             {
                 command.data = JObject.FromObject(instance.Exception);
             }
             Task.Run(async() =>
             {
                 try
                 {
                     await global.webSocketClient.QueueMessage(instance.queuename, command, null, instance.correlationId, 0);
                 }
                 catch (Exception ex)
                 {
                     Log.Debug(ex.Message);
                 }
             });
         }
         if (instance.hasError || instance.isCompleted)
         {
             string message = "";
             if (instance.runWatch != null)
             {
                 message += (instance.Workflow.name + " " + instance.state + " in " + string.Format("{0:mm\\:ss\\.fff}", instance.runWatch.Elapsed));
             }
             else
             {
                 message += (instance.Workflow.name + " " + instance.state);
             }
             if (!string.IsNullOrEmpty(instance.errormessage))
             {
                 message += (Environment.NewLine + "# " + instance.errormessage);
             }
             Log.Information(message);
             if ((Config.local.notify_on_workflow_end && !isRemote) || (Config.local.notify_on_workflow_remote_end && isRemote))
             {
                 if (instance.state == "completed")
                 {
                     // App.notifyIcon.ShowBalloonTip(1000, instance.Workflow.name + " " + instance.state, message, System.Windows.Forms.ToolTipIcon.Info);
                     App.notifyIcon.ShowBalloonTip(1000, "", message, System.Windows.Forms.ToolTipIcon.Info);
                 }
                 else
                 {
                     // App.notifyIcon.ShowBalloonTip(1000, instance.Workflow.name + " " + instance.state, message, System.Windows.Forms.ToolTipIcon.Error);
                     App.notifyIcon.ShowBalloonTip(1000, "", message, System.Windows.Forms.ToolTipIcon.Error);
                 }
             }
             System.Threading.Thread.Sleep(200);
             foreach (var wi in WorkflowInstance.Instances.ToList())
             {
                 if (wi.isCompleted)
                 {
                     continue;
                 }
                 if (wi.Bookmarks == null)
                 {
                     continue;
                 }
                 foreach (var b in wi.Bookmarks)
                 {
                     if (b.Key == instance._id)
                     {
                         wi.ResumeBookmark(b.Key, instance);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex.ToString());
     }
 }
Пример #3
0
        public void IdleOrComplete(IWorkflowInstance instance, EventArgs e)
        {
            if (instance == null)
            {
                return;
            }
            Log.FunctionIndent("MainWindow", "IdleOrComplete");
            try
            {
                bool isRemote = false;
                if (!string.IsNullOrEmpty(instance.queuename) && !string.IsNullOrEmpty(instance.correlationId))
                {
                    isRemote = true;
                    Interfaces.mq.RobotCommand command = new Interfaces.mq.RobotCommand();
                    var data = JObject.FromObject(instance.Parameters);
                    command.command    = "invoke" + instance.state;
                    command.workflowid = instance.WorkflowId;
                    command.data       = data;
                    if ((instance.state == "failed" || instance.state == "aborted") && instance.Exception != null)
                    {
                        command.data = JObject.FromObject(instance.Exception);
                    }
                    Task.Run(async() =>
                    {
                        try
                        {
                            await global.webSocketClient.QueueMessage(instance.queuename, command, null, instance.correlationId, 0);
                        }
                        catch (Exception ex)
                        {
                            Log.Debug(ex.Message);
                        }
                    });
                }

                if (instance.state != "idle")
                {
                    GenericTools.RunUI(() =>
                    {
                        CommandManager.InvalidateRequerySuggested();
                    });
                }

                if (instance.hasError || instance.isCompleted)
                {
                    string message = "";
                    if (instance.runWatch != null)
                    {
                        message += instance.Workflow.name + " " + instance.state + " in " + string.Format("{0:mm\\:ss\\.fff}", instance.runWatch.Elapsed);
                    }
                    else
                    {
                        message += instance.Workflow.name + " " + instance.state;
                    }
                    if (!string.IsNullOrEmpty(instance.errormessage))
                    {
                        message += Environment.NewLine + "# " + instance.errormessage;
                    }
                    Log.Information(message);
                    if ((Config.local.notify_on_workflow_end && !isRemote) || (Config.local.notify_on_workflow_remote_end && isRemote))
                    {
                        if (instance.state == "completed")
                        {
                            // App.notifyIcon.ShowBalloonTip(1000, instance.Workflow.name + " " + instance.state, message, System.Windows.Forms.ToolTipIcon.Info);
                            App.notifyIcon.ShowBalloonTip(1000, "", message, System.Windows.Forms.ToolTipIcon.Info);
                        }
                        else
                        {
                            // App.notifyIcon.ShowBalloonTip(1000, instance.Workflow.name + " " + instance.state, message, System.Windows.Forms.ToolTipIcon.Error);
                            App.notifyIcon.ShowBalloonTip(1000, "", message, System.Windows.Forms.ToolTipIcon.Error);
                        }
                    }
                    _ = Task.Run(() =>
                    {
                        if (instance.Workflow != null)
                        {
                            instance.Workflow.NotifyUIState();
                        }
                        var sw = new System.Diagnostics.Stopwatch(); sw.Start();
                        while (sw.Elapsed < TimeSpan.FromSeconds(1))
                        {
                            lock (WorkflowInstance.Instances)
                            {
                                foreach (var wi in WorkflowInstance.Instances.ToList())
                                {
                                    if (wi.isCompleted)
                                    {
                                        continue;
                                    }
                                    if (wi.Bookmarks == null)
                                    {
                                        continue;
                                    }
                                    foreach (var b in wi.Bookmarks)
                                    {
                                        if (b.Key == instance._id)
                                        {
                                            wi.ResumeBookmark(b.Key, instance);
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    });
                }
                RobotInstance.instance.NotifyPropertyChanged("Projects");
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }
            finally
            {
            }
        }