Example #1
0
        public void SolveRequestMessageXmlIsProperlySerializedAndDeserialized()
        {
            var message = new SolveRequestMessage
            {
                ProblemData = new byte[] {1, 2, 3},
                ProblemInstanceId = 5,
                ProblemType = "Dvrp",
                SolvingTimeout = 50
            };

            var serializedMessage = _serializer.Serialize(message);
            var deserializedMessage = _serializer.Deserialize(serializedMessage);

            Assert.IsInstanceOfType(deserializedMessage, typeof (SolveRequestMessage));
        }
Example #2
0
        public void SolveRequestMessageIsAcceptedAndSolveRequestResponseMessageIsPassedBack()
        {
            var waitHandle = new AutoResetEvent(false);

            var msg = new SolveRequestMessage
            {
                ProblemData = new byte[0],
                ProblemType = "dvrp"
            };
            var rawMsg = _marshaller.Marshall(new Message[] {msg});

            Message outputMessage = null;
            ProcessedDataCallback c = response =>
            {
                outputMessage = _marshaller.Unmarshall(response)[0];
                waitHandle.Set();
            };

            _processor.StartProcessing();
            _processor.EnqueueDataToProcess(rawMsg, null, c);

            waitHandle.WaitOne(5000);
            _processor.StopProcessing();

            Assert.IsInstanceOfType(outputMessage, typeof (SolveRequestResponseMessage));
        }
Example #3
0
        /// <summary>
        ///     Sends request for solving the problem.
        /// </summary>
        /// <param name="problemType">The name of the type as given by TaskSolver.</param>
        /// <param name="data">The serialized problem data.</param>
        /// <param name="solvingTimeout">The optional time restriction for solving the problem (in ms).</param>
        /// <returns>The ID of the problem instance assigned by the server or null if server is not responding.</returns>
        public ulong? SendSolveRequest(string problemType, byte[] data, ulong? solvingTimeout)
        {
            var solveRequestMessage = new SolveRequestMessage
            {
                ProblemType = problemType,
                ProblemData = data,
                SolvingTimeout = solvingTimeout
            };
            var receivedMessages = SendMessage(solveRequestMessage);
            if (receivedMessages == null)
                return null;

            ulong? problemId = null;
            foreach (var receivedMessage in receivedMessages)
            {
                SolveRequestResponseMessage solveRequestResponseMessage;
                if ((solveRequestResponseMessage = receivedMessage as SolveRequestResponseMessage) != null)
                {
                    problemId = solveRequestResponseMessage.AssignedId;
                }
                else
                {
                    RaiseEvent(MessageHandlingException, receivedMessage,
                        new InvalidOperationException("SolveRequestResponseMessage expected."));
                }
            }
            return problemId;
        }