public void SolutionsEmptyListTest() { //Arrange Solutions s = new Solutions("name", 123, new byte[]{}, new Solution[] {}); //Act byte[] data = s.GetXmlData(); //Debug.WriteLine(System.Text.Encoding.UTF8.GetString(data)); Console.WriteLine(System.Text.Encoding.UTF8.GetString(data)); //Assert Assert.IsNotNull(data); }
public void SolutionsTest() { //Arrange Solutions s = new Solutions("name", 123, new byte[] { 1, 3, 5 }, new Solution[] { new Solution(null, false, SolutionType.Ongoing, 100, new byte[]{ 1, 2}), new Solution(123, true, SolutionType.Partial, 400, new byte[]{ 3, 5, 7, 8}) }); //Act byte[] data = s.GetXmlData(); //Debug.WriteLine(System.Text.Encoding.UTF8.GetString(data)); Console.WriteLine(System.Text.Encoding.UTF8.GetString(data)); //Assert Assert.IsNotNull(data); }
public void SolutionsParseTest() { //Arrange Solutions s = new Solutions("name", 123, new byte[] { 1, 3, 5 }, new Solution[] { new Solution(null, false, SolutionType.Ongoing, 100, new byte[]{ 1, 2}), new Solution(123, true, SolutionType.Partial, 400, new byte[]{ 3, 5, 7, 8}) }); byte[] data = s.GetXmlData(); //Act XMLParser parser = new XMLParser(data); //Assert Assert.IsNotNull(parser); Assert.AreEqual(MessageTypes.Solutions, parser.MessageType); Solutions rs = (Solutions)parser.Message; Assert.AreEqual(s.CommonData.Length, rs.CommonData.Length); Assert.AreEqual(s.Id, rs.Id); Assert.AreEqual(s.ProblemType, rs.ProblemType); Assert.AreEqual(s.SolutionsList.Count, rs.SolutionsList.Count); Solution sol = s.SolutionsList[0]; Solution rsol = rs.SolutionsList[0]; Assert.AreEqual(sol.ComputationsTime, rsol.ComputationsTime); Assert.AreEqual(sol.Data.Length, rsol.Data.Length); Assert.AreEqual(sol.TaskId, rsol.TaskId); Assert.AreEqual(sol.TimeoutOccured, rsol.TimeoutOccured); Assert.AreEqual(sol.Type, rsol.Type); }
public void MergeThreadFunc(Solutions msg, ComputationalThread thread) { var asm = Assembly.Load(AssemblyName.GetAssemblyName(Path.GetFullPath(msg.ProblemType + ".dll")));//Assembly.LoadFile(Path.GetFullPath("DVRP.dll")); //Type t = asm.GetType("DVRP.DVRP"); Type t = asm.GetTypes().Where(x => x.IsSubclassOf(typeof(UCCTaskSolver.TaskSolver))).FirstOrDefault(); if (t == null) throw new ArgumentException("Brak odpowiedniej klasy w module."); var methodInfo = t.GetMethod("MergeSolution"); object[] constructor_param = new object[1]; constructor_param[0] = msg.CommonData; var o = Activator.CreateInstance(t, constructor_param); Solutions solutions_msg; object[] param = new object[1]; param[0] = PartialSolutions[msg.Id].ToArray(); try { methodInfo.Invoke(o, param); } catch (Exception e) { MessageBox.Show("Moduł '" + msg.ProblemType + ".dll' zakończył działanie z błędem:\n\n" + e.InnerException.Message, "Błąd modułu", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } var meth = t.GetMethod("get_Solution"); byte[] ans = (byte[])meth.Invoke(o, null); // TimeSpan ts = DateTime.Now - start_time; Solution final_solution = new Solution(msg.Id, false, SolutionType.Final, thread.HowLong, ans); List<Solution> solution_to_send = new List<Solution>(); solution_to_send.Add(final_solution); solutions_msg = new Solutions(msg.ProblemType, msg.Id, msg.CommonData, solution_to_send); client.Work(solutions_msg.GetXmlData()); SetComputationalThreadIdle((ulong)thread.ProblemInstanceId, (ulong)thread.TaskId); }
public void NodeThreadFunc(/*object o, MethodInfo methodInfo,*/ SolvePartialProblems msg, PartialProblem pp, ComputationalThread ct) { DateTime start_time = DateTime.Now; var asm = Assembly.Load(AssemblyName.GetAssemblyName(Path.GetFullPath(msg.ProblemType + ".dll"))); //Type t = asm.GetType("DVRP.DVRP"); Type t = asm.GetTypes().Where(x => x.IsSubclassOf(typeof(UCCTaskSolver.TaskSolver))).FirstOrDefault(); var methodInfo = t.GetMethod("Solve"); object[] constructor_params = new object[1]; constructor_params[0] = msg.CommonData; var o = Activator.CreateInstance(t, constructor_params); /*********event handler*/ var eventInfo = t.GetEvent("SolutionsMergingFinished"); Type tDelegate = eventInfo.EventHandlerType; MethodInfo addHandler = eventInfo.GetAddMethod(); Type returnType = GetDelegateReturnType(tDelegate); Console.WriteLine(returnType.ToString()); DynamicMethod handler = new DynamicMethod("", null, GetDelegateParameterTypes(tDelegate), t); ILGenerator ilgen = handler.GetILGenerator(); Type[] showParameters = { typeof(String) }; MethodInfo simpleShow = typeof(CNNode).GetMethod("SetComputationalThreadIdle"); Console.WriteLine(simpleShow.ToString()); ilgen.Emit(OpCodes.Ldstr, "string");//ct.ProblemInstanceId.Value);//Ldstr,"This event handler was constructed at run time."); ilgen.Emit(OpCodes.Call, simpleShow); // ilgen.Emit(OpCodes.Pop); ilgen.Emit(OpCodes.Ret); // Complete the dynamic method by calling its CreateDelegate // method. Use the "add" accessor to add the delegate to // the invocation list for the event. // Delegate dEmitted = handler.CreateDelegate(tDelegate); addHandler.Invoke(o, new Object[] { dEmitted }); if (methodInfo != null) { object[] param = new object[2]; param[0] = pp.Data; if (msg.SolvingTimeout == null) param[1] = null; else param[1] = new TimeSpan((long)msg.SolvingTimeout * 10000000); byte[] result = null; try { result = (byte[])methodInfo.Invoke(o, param); } catch (Exception e) { MessageBox.Show("Moduł '" + msg.ProblemType + ".dll' zakończył działanie z błędem:\n\n" + e.InnerException.Message, "Błąd modułu", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } TimeSpan ts = DateTime.Now - start_time; Solution s = new Solution(pp.TaskId, false, SolutionType.Partial, (ulong)ts.TotalSeconds, result); solution.Add(s); Console.WriteLine("sending partial solutions"); Solutions solutions = new Solutions(msg.ProblemType, msg.Id, msg.CommonData, solution); client.Work(solutions.GetXmlData()); SetComputationalThreadIdle(msg.Id, pp.TaskId); } else Console.WriteLine("Method equal to null"); }