/// <summary>
        /// Runs the specified solve task asynchronously.
        /// </summary>
        /// <param name="task">Task for the solve operation to be run asynchronously.</param>
        /// <returns>The operation identifier.</returns>
        public Guid RunAsync(IAsyncSolveTask task)
        {
            Debug.Assert(task != null);

            var id = Guid.NewGuid();

            _RunAsync(task, id);

            return(id);
        }
        private bool _TryRunAsync(IAsyncSolveTask operation, Guid operationId,
                                  out Exception error)
        {
            error = null;

            bool res = false;

            try
            {
                _RunAsync(operation, operationId);
                res = true;
            }
            catch (Exception e)
            {
                error = e;
            }

            return(res);
        }
Beispiel #3
0
        /// <summary>
        /// Performs solve result processing for the specified solve operation response.
        /// </summary>
        /// <param name="resultProvider">Function returning result of the solve operation.</param>
        /// <returns>A new <see cref="T:ESRI.ArcLogistics.Routing.SolveTaskResult"/> object storing
        /// solve result and the next task to run if any.</returns>
        private SolveTaskResult _ProcessSolveResult(
            Func <SolveOperationResult <TSolveRequest> > resultProvider)
        {
            var result            = resultProvider();
            var nextStepOperation = result.NextStepOperation;

            IAsyncSolveTask nextTask = null;

            if (nextStepOperation != null)
            {
                nextTask = AsyncSolveTask.FromSolveOperation(nextStepOperation);
            }

            return(new SolveTaskResult
            {
                SolveResult = result.SolveResult,
                NextTask = nextTask,
            });
        }
        private void _RunAsync(IAsyncSolveTask task, Guid operationID)
        {
            Debug.Assert(task != null);

            var context = new AsyncSolveContext
            {
                Task        = task,
                OperationID = operationID,
            };

            var worker = new BackgroundWorker();

            worker.WorkerSupportsCancellation = true;
            worker.DoWork             += _BackgroundWorkerDoWork;
            worker.RunWorkerCompleted += _BackgroundWorkerRunWorkerCompleted;

            _workers.Add(worker, context);

            worker.RunWorkerAsync(task);
        }
        private bool _TryRunAsync(IAsyncSolveTask operation, Guid operationId,
            out Exception error)
        {
            error = null;

            bool res = false;
            try
            {
                _RunAsync(operation, operationId);
                res = true;
            }
            catch (Exception e)
            {
                error = e;
            }

            return res;
        }
        private void _RunAsync(IAsyncSolveTask task, Guid operationID)
        {
            Debug.Assert(task != null);

            var context = new AsyncSolveContext
            {
                Task = task,
                OperationID = operationID,
            };

            var worker = new BackgroundWorker();
            worker.WorkerSupportsCancellation = true;
            worker.DoWork += _BackgroundWorkerDoWork;
            worker.RunWorkerCompleted += _BackgroundWorkerRunWorkerCompleted;

            _workers.Add(worker, context);

            worker.RunWorkerAsync(task);
        }
        /// <summary>
        /// Runs the specified solve task asynchronously.
        /// </summary>
        /// <param name="task">Task for the solve operation to be run asynchronously.</param>
        /// <returns>The operation identifier.</returns>
        public Guid RunAsync(IAsyncSolveTask task)
        {
            Debug.Assert(task != null);

            var id = Guid.NewGuid();
            _RunAsync(task, id);

            return id;
        }