Beispiel #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;
                }
            }
        }
Beispiel #2
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);
                }
            }
        }