public override bool Equals(object obj) { SolveRequestMessage message = obj as SolveRequestMessage; return(Id == message.Id && ProblemType == message.ProblemType && SolvingTimeout == message.SolvingTimeout && Enumerable.SequenceEqual(Data, message.Data)); }
public static SolveRequestMessage CreateSolveRequestMessage() { string problemType = "TSP"; ulong id = 12; byte[] data = { 1, 23, 25, 2, 5, 5, 5, 5, 2, 26, 87 }; ulong solvingTimeout = 1000; SolveRequestMessage expectedMessage = new SolveRequestMessage(problemType, data, solvingTimeout, id); return expectedMessage; }
public static SolveRequestMessage loadDataFromDisc(String filePath) { SolveRequestMessage solveRequestMessage; StreamReader streamReader = new StreamReader(filePath); string text = streamReader.ReadToEnd(); VRPParser benchmark = new VRPParser(text); string problemType=""; byte[] data; streamReader.Close(); String extension = Path.GetExtension(filePath); if (extension == ".vrp") { problemType = "DVRP"; } else { Console.WriteLine(">> Unsupported problem type. Please load a problem with one of the following problem types: \n *DVRP"); return null; } data = DataSerialization.ObjectToByteArray(benchmark); // data = GetBytes(filePath); solveRequestMessage = new SolveRequestMessage(problemType, data); Console.WriteLine(" >> Success"); return solveRequestMessage; }
static void Main(string[] args) { RegisterType type = RegisterType.ComputationalClient; byte parallelThreads = 5; string[] problems = { "DVRP" }; SolveRequestMessage solveRequestMessage = new SolveRequestMessage(); string inputLine = ""; foreach (string arg in args) inputLine += arg + " "; InputParser inputParser = new InputParser(inputLine); inputParser.ParseInput(); IPAddress address = inputParser.Address; int port = inputParser.Port; NetworkNode node = new NetworkNode(type, parallelThreads, problems) { Timeout = CLIENT_REQUEST_FREQUENCY }; SmartConsole.PrintLine("ComputationalClient starting work", SmartConsole.DebugLevel.Advanced); NetworkClient client = new NetworkClient(address, port); for (; ; ) { /*************** Register *****************/ doWork = true; SmartConsole.PrintLine("Type in a file path", SmartConsole.DebugLevel.Advanced); String filePath = Console.ReadLine(); solveRequestMessage = loadDataFromDisc(filePath); /****** setup logic modules *****************/ SystemTracker systemTracker = new SystemTracker(node); MessageHandler messageHandler = new MessageHandler(systemTracker, client); MessageProcessor messageProcessor = new MessageProcessor(messageHandler, client, node); KeepAliveTimer keepAliveTimer = new KeepAliveTimer(messageProcessor, systemTracker); messageHandler.keepAliveTimer = keepAliveTimer; node.MessageProcessor = messageProcessor; /************ send solve request *****************/ client.Connect(); messageProcessor.Communicate(solveRequestMessage); COMP_TIME = DateTime.Now; while (doWork) { Thread.Sleep(1000); } /*Object mutex = new Object(); lock (mutex) { Monitor.Wait(mutex); }*/ } }
public void Parse_XMLString_SolveRequestMessage() { /*********** Actual message ***********/ string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"xml_samples\SolveRequest.xml"); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(path); string xmlStr = xmlDoc.OuterXml; string name = Message.GetMessageName(xmlStr); SolveRequestMessage actualMessage = null; if (name == SolveRequestMessage.ELEMENT_NAME) actualMessage = SolveRequestMessage.Construct(xmlStr); /*********** Expected message ***********/ string problemType = "TSP"; ulong id = 12; byte[] data = { 1, 23, 25, 2, 5, 5, 5, 5, 2, 26, 87 }; ulong solvingTimeout = 1000; SolveRequestMessage expectedMessage = new SolveRequestMessage(problemType, data, solvingTimeout, id); Assert.AreEqual(expectedMessage, actualMessage); }
public void Parse_SolveRequestMessage_XMLString() { string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"xml_samples\SolveRequest.xml"); string problemType = "TSP"; ulong id = 12; byte[] data = { 1, 23, 25, 2, 5, 5, 5, 5, 2, 26, 87 }; ulong solvingTimeout = 1000; SolveRequestMessage message = new SolveRequestMessage(problemType, data, solvingTimeout, id); message.ToXmlFile(path); string actualXmlStr = message.ToXmlString(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(path); string expectedXmlStr = xmlDoc.OuterXml; Assert.AreEqual(expectedXmlStr, actualXmlStr); }