Exemple #1
0
        /// <summary>
        /// Starts operation process.
        /// </summary>
        /// <param name="args">Operation args.</param>
        /// <exception cref="Exception">Throws if any unhandles exception occurs in method.</exception>
        protected override void _Execute(params object[] args)
        {
            try
            {
                // Get current schedule.
                if (_schedulePage == null)
                {
                    _schedulePage = (OptimizeAndEditPage)App.Current.MainWindow.GetPage(PagePaths.SchedulePagePath);
                }

                Schedule schedule = _schedulePage.CurrentSchedule;

                ICollection <Order> selectedOrders = _GetOrdersWhichCanBeUnassignedFromSelection(_schedulePage.SelectedItems);
                ICollection <Order> orders         = RoutingCmdHelpers.GetOrdersIncludingPairs(schedule, selectedOrders);
                ICollection <Route> routes         = ViolationsHelper.GetRouteForUnassignOrders(schedule, orders);

                if (_CheckRoutingParams(schedule, routes, orders))
                {
                    SolveOptions options = new SolveOptions();
                    options.GenerateDirections            = App.Current.MapDisplay.TrueRoute;
                    options.FailOnInvalidOrderGeoLocation = false;

                    _SetOperationStartedStatus((string)App.Current.FindResource(UNASSIGN_ORDERS), (DateTime)schedule.PlannedDate);

                    OperationsIds.Add(App.Current.Solver.UnassignOrdersAsync(schedule, orders, options));

                    // set solve started message
                    string infoMessage = RoutingMessagesHelper.GetUnassignOperationStartedMessage(orders);

                    if (!string.IsNullOrEmpty(infoMessage))
                    {
                        App.Current.Messenger.AddInfo(infoMessage);
                    }
                }
            }
            catch (RouteException e)
            {
                if (e.InvalidObjects != null) // if exception throw because any Routes or Orders are invalid
                {
                    _ShowSolveValidationResult(e.InvalidObjects);
                }
                else
                {
                    _ShowErrorMsg(RoutingCmdHelpers.FormatRoutingExceptionMsg(e));
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                if ((e is LicenseException) || (e is AuthenticationException) || (e is CommunicationException))
                {
                    CommonHelpers.AddRoutingErrorMessage(e);
                }
                else
                {
                    throw;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Method starts moving orders.
        /// </summary>
        /// <param name="ordersToAssign">Collection of orders to move.</param>
        /// <param name="targetRoutes">Target routes.</param>
        /// <param name="sequence">Order sequence. Can be null.</param>
        private void _MoveOrders(Collection <Order> ordersToAssign, ICollection <Route> targetRoutes, int?sequence)
        {
            _RemoveRedundantOrders(ref ordersToAssign, targetRoutes, sequence);

            // if collection of dropping orders is empty - return
            if (ordersToAssign.Count == 0)
            {
                return;
            }

            // get current schedule
            OptimizeAndEditPage schedulePage = (OptimizeAndEditPage)(App.Current.MainWindow).GetPage(PagePaths.SchedulePagePath);
            Schedule            schedule     = schedulePage.CurrentSchedule;

            if (_CheckRoutingParams(schedule, targetRoutes, ordersToAssign))
            {
                SolveOptions options = new SolveOptions();
                options.GenerateDirections            = App.Current.MapDisplay.TrueRoute;
                options.FailOnInvalidOrderGeoLocation = false;

                // Update status.
                _SetOperationStartedStatus((string)App.Current.FindResource("AssignOrders"), (DateTime)schedule.PlannedDate);

                // Start solve.
                OperationsIds.Add(App.Current.Solver.AssignOrdersAsync(schedule, ordersToAssign,
                                                                       targetRoutes, sequence,
                                                                       false, options));

                IEnumerator <Route> rtEnum = targetRoutes.GetEnumerator();
                rtEnum.MoveNext();

                // Set solve started message.
                string infoMessage = RoutingMessagesHelper.GetAssignOperationStartedMessage(
                    ordersToAssign, rtEnum.Current.Name);

                if (!string.IsNullOrEmpty(infoMessage))
                {
                    App.Current.Messenger.AddInfo(infoMessage);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Method starts unassigning orders.
        /// </summary>
        /// <param name="ordersToAssign">Collection of orders to unassign.</param>
        private void _UnassignOrders(Collection <Order> ordersToUnassign)
        {
            // Get current schedule.
            OptimizeAndEditPage schedulePage = (OptimizeAndEditPage)(App.Current.MainWindow).GetPage(PagePaths.SchedulePagePath);
            Schedule            schedule     = schedulePage.CurrentSchedule;

            // Remove unassigned orders from collection of orders to unassign.
            _RemoveUnassignedOrders(ref ordersToUnassign, schedule);

            // If all orders in selection are unassigned - just return.
            if (ordersToUnassign.Count == 0)
            {
                return;
            }

            ICollection <Route> routes = ViolationsHelper.GetRouteForUnassignOrders(schedule, ordersToUnassign);

            if (_CheckRoutingParams(schedule, routes, ordersToUnassign))
            {
                SolveOptions options = new SolveOptions();
                options.GenerateDirections            = App.Current.MapDisplay.TrueRoute;
                options.FailOnInvalidOrderGeoLocation = false;

                // Update status.
                _SetOperationStartedStatus((string)App.Current.FindResource(UNASSIGN_ORDERS), (DateTime)schedule.PlannedDate);

                // Start solve.
                OperationsIds.Add(App.Current.Solver.UnassignOrdersAsync(schedule, ordersToUnassign, options));

                // Set solve started message
                string infoMessage = RoutingMessagesHelper.GetUnassignOperationStartedMessage(ordersToUnassign);

                if (!string.IsNullOrEmpty(infoMessage))
                {
                    App.Current.Messenger.AddInfo(infoMessage);
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Method formats success message.
        /// </summary>
        /// <param name="schedule">Edited schedule.</param>
        /// <param name="info">Operation info.</param>
        /// <returns>Info string.</returns>
        protected override string _FormatSuccessSolveCompletedMsg(Schedule schedule, AsyncOperationInfo info)
        {
            string message = string.Empty;

            // If oreders was assigned to any route.
            if (info.OperationType == SolveOperationType.AssignOrders)
            {
                message = RoutingMessagesHelper.GetAssignOperationCompletedMessage(info);
            }

            // If orders was unassigned.
            else if (info.OperationType == SolveOperationType.UnassignOrders)
            {
                message = RoutingMessagesHelper.GetUnassignOperationCompletedMessage(info);
            }

            else
            {
                // Not supported yet.
                Debug.Assert(false);
            }

            return(message);
        }
Exemple #5
0
        /// <summary>
        /// Excecutes command.
        /// </summary>
        /// <param name="args"></param>
        protected override void _Execute(params object[] args)
        {
            try
            {
                OptimizeAndEditPage schedulePage = (OptimizeAndEditPage)App.Current.MainWindow.GetPage(PagePaths.SchedulePagePath);
                Schedule            schedule     = schedulePage.CurrentSchedule;

                // Get selected orders.
                Collection <Order> selectedOrders = _GetOrdersWhichCanBeMovedFromSelection(schedulePage.SelectedItems);
                selectedOrders = RoutingCmdHelpers.GetOrdersIncludingPairs(schedule, selectedOrders) as Collection <Order>;
                bool keepViolOrdrsUnassigned = false;

                Debug.Assert(args[0] != null);
                ICollection <Route> targetRoutes = args[0] as ICollection <Route>;
                Debug.Assert(targetRoutes != null);

                string routeName = args[1] as string;

                if (_CheckRoutingParams(schedule, targetRoutes, selectedOrders))
                {
                    SolveOptions options = new SolveOptions();
                    options.GenerateDirections            = App.Current.MapDisplay.TrueRoute;
                    options.FailOnInvalidOrderGeoLocation = false;

                    _SetOperationStartedStatus((string)App.Current.FindResource(ASSIGN_ORDERS), (DateTime)schedule.PlannedDate);

                    // Start "Assign to best other route" operation.
                    OperationsIds.Add(App.Current.Solver.AssignOrdersAsync(schedule, selectedOrders,
                                                                           targetRoutes, null,
                                                                           keepViolOrdrsUnassigned,
                                                                           options));
                    // Set solve started message
                    string infoMessage = RoutingMessagesHelper.GetAssignOperationStartedMessage(selectedOrders, routeName);

                    if (!string.IsNullOrEmpty(infoMessage))
                    {
                        App.Current.Messenger.AddInfo(infoMessage);
                    }
                }
            }
            catch (RouteException e)
            {
                if (e.InvalidObjects != null) // If exception throw because any Routes or Orders are invalid
                {
                    _ShowSolveValidationResult(e.InvalidObjects);
                }
                else
                {
                    _ShowErrorMsg(RoutingCmdHelpers.FormatRoutingExceptionMsg(e));
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
                if ((e is LicenseException) || (e is AuthenticationException) || (e is CommunicationException))
                {
                    CommonHelpers.AddRoutingErrorMessage(e);
                }
                else
                {
                    throw;
                }
            }
        }
Exemple #6
0
 /// <summary>
 /// Gets message string about solve completed successfully.
 /// </summary>
 /// <param name="schedule">Edited schedule.</param>
 /// <param name="info">Operation info.</param>
 /// <returns>Success solve string.</returns>
 protected override string _FormatSuccessSolveCompletedMsg(Schedule schedule, ESRI.ArcLogistics.Routing.AsyncOperationInfo info)
 {
     return(RoutingMessagesHelper.GetAssignOperationCompletedMessage(info));
 }
 /// <summary>
 /// Creates success unassigned complete message
 /// </summary>
 /// <param name="schedule"></param>
 /// <param name="info"></param>
 /// <returns></returns>
 private string _FormatSuccessSolveCompletedMsg(
     Schedule schedule, AsyncOperationInfo info)
 {
     return(RoutingMessagesHelper.GetMultipleUnassignOperationCompletedMessage(schedule, info));
 }
Exemple #8
0
 /// <summary>
 /// Gets message about Solve completed successfully.
 /// </summary>
 /// <param name="schedule">Edited schedule.</param>
 /// <param name="info">Operation info.</param>
 /// <returns>Message string.</returns>
 protected override string _FormatSuccessSolveCompletedMsg(Schedule schedule, AsyncOperationInfo info)
 {
     return(RoutingMessagesHelper.GetUnassignOperationCompletedMessage(info));
 }