Example #1
0
        // Send a request to the tasking server
        public void SendRequest(MsgMeas.TaskOperationType operation)
        {
            MsgMeas.TaskRequest request = null;

            switch (operation)
            {
            case MsgMeas.TaskOperationType.Submit:     // Create a new task for "myproc"
                request = MsgMeas.TaskRequest.CreateSubmitRequest(MySupportedProcedure);
                break;

            case MsgMeas.TaskOperationType.Update:     // Update an existing task
                request = MsgMeas.TaskRequest.CreateUpdateRequest(MySupportedProcedure, m_currentTaskId);
                break;

            case MsgMeas.TaskOperationType.GetStatus:     // Get the status of an existing task
                request = MsgMeas.TaskRequest.CreateGetStatusRequest(m_currentTaskId);
                break;

            case MsgMeas.TaskOperationType.Cancel:     // Cancel a task
                request = MsgMeas.TaskRequest.CreateCancelRequest(m_currentTaskId);
                break;

            default:
                throw new ArgumentException("Unexpected operation " + operation.ToString());
            }

            // Sending the request
            SendRequest(request.ToXmlBytes());

            // Waiting for a response
            var responseXml = WaitForResponse();

            MsgMeas.TaskResponse response;
            try
            {
                response = new MsgMeas.TaskResponse(responseXml);
            }
            catch (MsgMeas.Neutral.InvalidMessageException e)
            {
                throw new InvalidOperationException("Failed to read response: " + e.Message);
            }

            if (response.RequestResult != MsgMeas.RequestResultType.Ok)
            {
                // Request failed!
                throw new InvalidOperationException("Unexpected request result " + response.RequestResult.ToString());
            }

            // Processing the request
            m_currentTaskId = response.StatusReports[0].TaskId; // Task ID is assigned by the server

            // Do whatever you want with the response...
        }
Example #2
0
        private MsgMeas.TaskResponse CreateOkResponse(MsgMeas.TaskOperationType operation)
        {
            // Creating a response object
            switch (operation)
            {
            case MsgMeas.TaskOperationType.Submit:
                // Processing a create request...
                // ...
                CurrentTaskStatus = MsgMeas.TaskStatusCodeType.InExecution;
                CurrentTaskId     = Guid.NewGuid().ToString();
                return(MsgMeas.TaskResponse.CreateSubmitResponse(GetStatusReport()));

            case MsgMeas.TaskOperationType.Update:
                // Processing an update request...
                // ...
                return(MsgMeas.TaskResponse.CreateUpdateResponse(GetStatusReport()));

            case MsgMeas.TaskOperationType.GetStatus:
                // Processing a get status request...
                // ...
                return(MsgMeas.TaskResponse.CreateGetStatusResponse(
                           new SysColl.List <MsgMeas.TaskStatusReport>()
                {
                    GetStatusReport()
                }
                           ));

            case MsgMeas.TaskOperationType.Cancel:
                // Processing a cancel request...
                // ...
                CurrentTaskStatus = MsgMeas.TaskStatusCodeType.Cancelled;
                return(MsgMeas.TaskResponse.CreateCancelResponse(GetStatusReport()));

            default:
                throw new InvalidOperationException("Unexpected operation " + operation.ToString());
            }
        }
Example #3
0
        private MsgMeas.TaskResponse CreateFailureResponse(MsgMeas.TaskOperationType operation)
        {
            var statusReport = new MsgMeas.TaskStatusReport("?", "?");

            MsgMeas.TaskResponse retval = null;

            // Creating a response object
            switch (operation)
            {
            case MsgMeas.TaskOperationType.Submit:
                retval = MsgMeas.TaskResponse.CreateSubmitResponse(statusReport);
                break;

            case MsgMeas.TaskOperationType.Update:
                retval = MsgMeas.TaskResponse.CreateUpdateResponse(statusReport);
                break;

            case MsgMeas.TaskOperationType.GetStatus:
                retval = MsgMeas.TaskResponse.CreateGetStatusResponse(
                    new SysColl.List <MsgMeas.TaskStatusReport> {
                    statusReport
                }
                    );
                break;

            case MsgMeas.TaskOperationType.Cancel:
                retval = MsgMeas.TaskResponse.CreateCancelResponse(statusReport);
                break;

            default:
                throw new InvalidOperationException("Unexpected operation " + operation.ToString());
            }

            // This indicates the server did not understand the request
            retval.RequestResult = MsgMeas.RequestResultType.BadRequest;
            return(retval);
        }