Ejemplo n.º 1
0
        private static void _ValidateResponse(GetVrpJobResultResponse resp)
        {
            Debug.Assert(resp != null);

            if (resp.Outputs == null ||
                resp.Outputs.Routes == null ||
                resp.Outputs.Stops == null)
            {
                throw new RouteException(Properties.Messages.Error_InvalidResultJobResponse);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads result data from response from the VRP REST service.
        /// </summary>
        /// <param name="client">The reference to the REST service client object
        /// to send requests with.</param>
        /// <param name="resp">The response from the VRP service.</param>
        /// <param name="tracker">The reference to the cancellation tracker
        /// object.</param>
        /// <returns>Result of the response GP route.</returns>
        private GPRouteResult _LoadResultData(
            IVrpRestService client,
            GetVrpJobResultResponse resp,
            ICancelTracker tracker)
        {
            Debug.Assert(client != null);
            Debug.Assert(resp != null);

            // get output routes
            _CheckCancelState(tracker);
            var routesParam = _GetGPObject <GPFeatureRecordSetLayerParam>(
                client,
                resp.JobId,
                resp.Outputs.Routes.ParamUrl);

            // get output stops
            _CheckCancelState(tracker);
            var stopsParam = _GetGPObject <GPRecordSetParam>(
                client,
                resp.JobId,
                resp.Outputs.Stops.ParamUrl);

            // get unassigned orders
            _CheckCancelState(tracker);
            var violatedStopsParam = _GetGPObject <GPRecordSetParam>(
                client,
                resp.JobId,
                resp.Outputs.ViolatedStops.ParamUrl);

            // Get directions.
            _CheckCancelState(tracker);
            var directionsParam = _GetGPObject <GPFeatureRecordSetLayerParam>(
                client,
                resp.JobId,
                resp.Outputs.Directions.ParamUrl);

            GPRouteResult result = new GPRouteResult();

            result.Routes        = routesParam.Value;
            result.Stops         = stopsParam.Value;
            result.ViolatedStops = violatedStopsParam.Value;
            result.Directions    = directionsParam.Value;

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Converts job submitting response into the result of synchronous
        /// job execution.
        /// </summary>
        /// <param name="response">The reference to the response object to
        /// be converted.</param>
        /// <param name="client">The reference to the REST service client object
        /// to retrieve job results with.</param>
        /// <param name="cancelTracker">The reference to the cancellation tracker
        /// object.</param>
        /// <returns><see cref="T:ESRI.ArcLogistics.Routing.Json.VrpResultsResponse"/>
        /// object corresponding to the specified job submitting response.</returns>
        private VrpResultsResponse _ConvertToSyncReponse(
            GetVrpJobResultResponse response,
            IVrpRestService client,
            ICancelTracker cancelTracker)
        {
            var syncResponse = new VrpResultsResponse()
            {
                SolveSucceeded = false,
                JobID          = response.JobId,
            };

            syncResponse.SolveSucceeded = false;
            syncResponse.Messages       = response.Messages;
            syncResponse.SolveHR        = HResult.E_FAIL;

            if (response.JobStatus != NAJobStatus.esriJobSucceeded)
            {
                return(syncResponse);
            }

            var solveSucceeded = _GetGPObject <GPBoolParam>(
                client,
                response.JobId,
                response.Outputs.SolveSucceeded.ParamUrl);

            syncResponse.SolveSucceeded = solveSucceeded.Value;
            syncResponse.SolveHR        = _GetSolveHR(syncResponse);

            if (CanProcessResult(syncResponse.SolveHR))
            {
                _ValidateResponse(response);

                // get route results
                syncResponse.RouteResult = _LoadResultData(
                    client,
                    response,
                    cancelTracker);
            }

            return(syncResponse);
        }
Ejemplo n.º 4
0
        private GetVrpJobResultResponse _GetJobResult(
            IVrpRestService client,
            string jobId)
        {
            Debug.Assert(client != null);
            Debug.Assert(jobId != null);

            GetVrpJobResultResponse response = null;

            try
            {
                response = client.GetJobResult(jobId);
            }
            catch (RestException e)
            {
                _LogServiceError(e);
                throw SolveHelper.ConvertServiceException(
                          String.Format(Properties.Messages.Erorr_GetJobResult, jobId), e);
            }

            return(response);
        }
Ejemplo n.º 5
0
        private GetVrpJobResultResponse _SubmitJob(
            IVrpRestService client,
            SubmitVrpJobRequest request)
        {
            Debug.Assert(client != null);
            Debug.Assert(request != null);

            GetVrpJobResultResponse response = null;

            try
            {
                response = client.SubmitJob(request);
            }
            catch (RestException e)
            {
                _LogServiceError(e);
                throw SolveHelper.ConvertServiceException(
                          Properties.Messages.Error_SubmitJobFailed, e);
            }

            return(response);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Sends async. request to the VRP REST service using either asynchronous service
        /// depending on the request.
        /// </summary>
        /// <param name="context">The reference to the VRP REST service context.</param>
        /// <param name="request">The request to be sent to the VRP service.</param>
        /// <param name="tracker">The reference to the cancellation tracker object.</param>
        /// <returns>Result of the request processing by the VRP REST service.</returns>
        private GetVrpJobResultResponse _SendAsyncRequest(
            IVrpRestService context,
            SubmitVrpJobRequest request,
            ICancelTracker tracker)
        {
            Debug.Assert(context != null);
            Debug.Assert(request != null);

            // check cancellation state
            _CheckCancelState(tracker);

            GetVrpJobResultResponse resp = null;

            try
            {
                // submit job
                resp = _SubmitJob(context, request);

                // poll job status
                bool jobCompleted = false;
                do
                {
                    // check cancellation state
                    _CheckCancelState(tracker);

                    // check job status
                    if (resp.JobStatus == NAJobStatus.esriJobFailed ||
                        resp.JobStatus == NAJobStatus.esriJobSucceeded ||
                        resp.JobStatus == NAJobStatus.esriJobCancelled)
                    {
                        // job completed
                        jobCompleted = true;
                        _LogResponse(resp);
                    }
                    else
                    {
                        // TODO: limit number of retries or total request time

                        // job is still executing, make timeout
                        Thread.Sleep(RETRY_DELAY);

                        // check cancellation state
                        _CheckCancelState(tracker);

                        string jobId = resp.JobId;
                        try
                        {
                            // try to get job result
                            resp = _GetJobResult(context, jobId);
                        }
                        catch (Exception e)
                        {
                            _LogJobError(jobId, e);
                            if (!ServiceHelper.IsCommunicationError(e))
                            {
                                throw;
                            }
                        }
                    }
                }while (!jobCompleted);
            }
            catch (UserBreakException)
            {
                if (resp != null)
                {
                    _CancelJob(context, resp.JobId); // cancel job on server
                }
                throw;
            }

            return(resp);
        }