예제 #1
0
        public bool AddTask(string target)
        {
            if (!Tasks.ContainsKey(target))
            {
                try
                {
                    var      host     = ScanHosts.OrderBy(h => h.WaitTaskCount).First();
                    TaskUnit taskUnit = new TaskUnit(host.Host, host.Port);
                    if (taskUnit.NewTask(target))
                    {
                        Tasks.Add(target, taskUnit);
                        host.WaitTaskCount += 1;
                        OnMessageNotify($"成功添加目标[{target}]到执行主机[{host.Host}:{host.Port}]", MessageNotifyTypes.AddTask, taskUnit);
                    }
                    else
                    {
                        OnMessageNotify($"添加目标[{target}]到执行主机[{host.Host}:{host.Port}]失败!", MessageNotifyTypes.AddTaskFailed, taskUnit);
                    }
                }
                catch (Exception e)
                {
                    OnMessageNotify($"添加目标[{target}]失败:{e.Message}", MessageNotifyTypes.AddTaskFailed);
                    return(false);
                }
            }
            else
            {
                OnMessageNotify($"目标[{target}]任务已添加,无需重复添加.", MessageNotifyTypes.Info);
            }

            return(true);
        }
예제 #2
0
 public MessageNotifyEventArgs(string message, MessageNotifyTypes type, TaskUnit task = null)
 {
     Time     = DateTime.Now;
     Message  = message;
     Type     = type;
     TaskUnit = task;
 }
예제 #3
0
        void OnMessageNotify(string message, MessageNotifyTypes type, TaskUnit task = null)
        {
            var handler = MessageNotify;

            if (handler != null)
            {
                handler(this, new MessageNotifyEventArgs(message, type, task));
            }
        }