public void ChekMessageTaskStopProcessingMessage() { if (!MessageQueue.Exists(@".\private$\ChekMessageTaskStopProcessingMessage")) { MessageQueue.Create(@".\private$\ChekMessageTaskStopProcessingMessage"); } MessageQueue testQueue = new MessageQueue(@".\private$\ChekMessageTaskStopProcessingMessage"); testQueue.Formatter = new BinaryMessageFormatter(); Task task = new Task("test", 1); List <Thread> listThread = new List <Thread>(); Agent.tasksList.Add(task); Agent.threadDictionary.Add(1, listThread); TaskStopProcessingMessage testMessage = new TaskStopProcessingMessage(0, 0, 1); testQueue.Send(testMessage); Assert.AreEqual((int)EnumTypeMessage.TaskStopProcessingMessage, ProcessingMessage.ChekMessage(testQueue)); Assert.AreEqual(0, Agent.tasksList.Count); MessageQueue.Delete(@".\private$\ChekMessageTaskStopProcessingMessage"); }
public static void DisconnectAgentHandler(Dictionary <Task, List <string[]> > tasks, ref List <Agent> agentsList) { foreach (var itemTask in tasks) { foreach (var itemSegment in itemTask.Value) { var idAgent = GetFreeAgent(agentsList); if (idAgent != -1) { TaskMessage taskMessage = new TaskMessage(idAgent, 0, itemTask.Key, itemSegment[0], itemSegment[1]); for (int index = 0; index < agentsList.Count; ++index) { if (agentsList[index].IdAgent == idAgent) { string[] tempSegment = { itemSegment[0], itemSegment[1] }; if (agentsList[index].Tasks.ContainsKey(itemTask.Key)) { agentsList[index].Tasks[itemTask.Key].Add(tempSegment); } else { List <string[]> newList = new List <string[]> { tempSegment }; agentsList[index].Tasks.Add(itemTask.Key, newList); } agentsList[index].Info.CountCore--; agentsList[index].QueueReceive.Send(taskMessage); break; } } } else { Console.WriteLine("Ошибка распределения HASH:" + itemTask.Key.Hash + " (недостаточно агентов) введите задание заново."); for (int index = 0; index < agentsList.Count; ++index) { if (agentsList[index].Tasks.ContainsKey(itemTask.Key)) { TaskStopProcessingMessage taskStopProcessing = new TaskStopProcessingMessage(agentsList[index].IdAgent, 0, itemTask.Key.IdTask); agentsList[index].QueueReceive.Send(taskStopProcessing); agentsList[index].Info.CountCore++; } } break; } } } }
public static void ProcessingTaskStopProcessingMessage(TaskStopProcessingMessage message) { if (Agent.threadDictionary.ContainsKey(message.IdTask)) { foreach (var item in Agent.threadDictionary[message.IdTask]) { item.Abort(); } for (int index = 0; index < Agent.tasksList.Count; ++index) { Agent.tasksList.Remove(Agent.tasksList[index]); } } }
/// <summary> /// обработчик ExitMessage сообщения /// </summary> /// <param name="quere">очередь откуда пришло сообщение</param> /// <param name="message">приянтое сообщение</param> public static bool ProcessingTaskMessage(MessageQueue quere, TaskMessage message) { try { Console.Write("TaskMessage idAgent: " + message.IdSender); for (int index = 0; index < tasksList.Count; ++index) { if (tasksList[index].IdTask == message.Task.IdTask && message.Task.Complete) { tasksList[index] = message.Task; } } if (message.Task.Complete) { TaskStopProcessingMessage taskCompleteMessage = new TaskStopProcessingMessage(message.IdSender, 0, message.Task.IdTask); for (int index = 0; index < agentsList.Count; ++index) { foreach (var itemTask in agentsList[index].Tasks) { if (itemTask.Key.IdTask == message.Task.IdTask) { agentsList[index].Info.CountCore++; agentsList[index].QueueReceive.Send(taskCompleteMessage); } } } Console.WriteLine("пароль к хешу " + message.Task.Hash + " подобран: " + message.Task.ReadyPassword); } } catch (Exception e) { Console.WriteLine(e.Message); return(false); } return(true); }