コード例 #1
0
        /// <summary>
        ///     Constructs message by given xml string
        /// </summary>
        /// <param name="xmlString">
        ///     xml in string
        /// </param>
        /// <returns>
        ///     Message constructed by the xml
        /// </returns>
        public static Message Construct(string xmlString)
        {
            xmlString = concCompabilityIssuesStringWojtekIsGay(xmlString);

            if (GetMessageName(xmlString) == RegisterMessage.ELEMENT_NAME)
            {
                return(RegisterMessage.Construct(xmlString));
            }
            if (GetMessageName(xmlString) == DivideProblemMessage.ELEMENT_NAME)
            {
                return(DivideProblemMessage.Construct(xmlString));
            }
            if (GetMessageName(xmlString) == NoOperationMessage.ELEMENT_NAME)
            {
                return(NoOperationMessage.Construct(xmlString));
            }
            if (GetMessageName(xmlString) == RegisterResponseMessage.ELEMENT_NAME)
            {
                return(RegisterResponseMessage.Construct(xmlString));
            }
            if (GetMessageName(xmlString) == SolutionRequestMessage.ELEMENT_NAME)
            {
                return(SolutionRequestMessage.Construct(xmlString));
            }
            if (GetMessageName(xmlString) == SolutionsMessage.ELEMENT_NAME)
            {
                return(SolutionsMessage.Construct(xmlString));
            }
            if (GetMessageName(xmlString) == SolvePartialProblemsMessage.ELEMENT_NAME)
            {
                try
                {
                    //return SolvePartialProblemsMessage.Construct(xmlString);
                }
                catch (InvalidOperationException e) { return(null); }
                Console.WriteLine("******** SOLVE PARTIAL PROBLEM MESSAGE **************");
                return(SolvePartialProblemsMessage.Construct(xmlString));
            }
            if (GetMessageName(xmlString) == SolveRequestMessage.ELEMENT_NAME)
            {
                return(SolveRequestMessage.Construct(xmlString));
            }
            if (GetMessageName(xmlString) == SolveRequestResponseMessage.ELEMENT_NAME)
            {
                return(SolveRequestResponseMessage.Construct(xmlString));
            }
            if (GetMessageName(xmlString) == StatusMessage.ELEMENT_NAME)
            {
                return(StatusMessage.Construct(xmlString));
            }
            return(null);
        }
コード例 #2
0
        public void Parse_XMLString_SolvePartialProblemsMessage()
        {
            /*********** Actual message ***********/
            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"xml_samples\SolvePartialProblems.xml");

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(path);
            string xmlStr = xmlDoc.OuterXml;

            string name = Message.GetMessageName(xmlStr);
            SolvePartialProblemsMessage actualMessage = null;

            if (name == SolvePartialProblemsMessage.ELEMENT_NAME)
            {
                actualMessage = SolvePartialProblemsMessage.Construct(xmlStr);
            }

            /*********** Expected message ***********/
            string problemType = "TSP";
            ulong  id          = 12;

            byte[] commonData     = { 1, 23, 25, 2, 5, 5, 5, 5, 2, 26, 87 };
            ulong  solvingTimeout = 1000;

            // fields for PartialProblem1
            ulong taskId1 = 123;

            byte[]         data1           = { 24, 252, 6, 43, 57, 88 };
            ulong          nodeId1         = 1;
            PartialProblem partialProblem1 = new PartialProblem(taskId1, data1, nodeId1);

            // fields for PartialProblem2
            ulong taskId2 = 321;

            byte[]         data2           = { 24, 252, 6, 43, 57, 88 };
            ulong          nodeId2         = 2;
            PartialProblem partialProblem2 = new PartialProblem(taskId2, data2, nodeId2);

            PartialProblem[] partialProblems = { partialProblem1, partialProblem2 };

            SolvePartialProblemsMessage expectedMessage = new SolvePartialProblemsMessage(problemType, id, commonData,
                                                                                          solvingTimeout, partialProblems);

            Assert.AreEqual(expectedMessage, actualMessage);
        }