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); }
public MessageNotifyEventArgs(string message, MessageNotifyTypes type, TaskUnit task = null) { Time = DateTime.Now; Message = message; Type = type; TaskUnit = task; }
void OnMessageNotify(string message, MessageNotifyTypes type, TaskUnit task = null) { var handler = MessageNotify; if (handler != null) { handler(this, new MessageNotifyEventArgs(message, type, task)); } }