protected void Cmd_AsyncSolveCompleted(object sender, AsyncSolveCompletedEventArgs e) { // check is completed operation was started by this command if (OperationsIds.Contains(e.OperationId)) { _operationsIds.Remove(e.OperationId); AsyncOperationInfo info = null; Schedule schedule = null; if (App.Current.Solver.GetAsyncOperationInfo(e.OperationId, out info)) { schedule = info.Schedule; } IsEnabled = true; if (e.Cancelled) { App.Current.Messenger.AddInfo(_FormatCancelMsg(schedule)); } else if (e.Error != null) { _HandleSolveError(e.Error); } else { SolveResult res = e.Result; if (schedule != null) { _SaveSchedule(res, schedule, info); } } } }
/// <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; } } }
/// <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); } } }
/// <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); } } }
/// <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; } } }
protected override void _Execute(params object[] args) { try { ICollection <Route> routes = _GetRoutesFromSelection(_schedulePage.SelectedItems); // get unlocked routes from selected routes // and all orders assigned to converting routes List <Order> orders = new List <Order>(); foreach (Route route in routes) { if (!route.IsLocked) { // get assigned orders List <Order> routeOrders = new List <Order>(); foreach (Stop stop in route.Stops) { if (stop.StopType == StopType.Order) { routeOrders.Add(stop.AssociatedObject as Order); } } orders.AddRange(routeOrders); } } // get current schedule Schedule schedule = _schedulePage.CurrentSchedule; if (_CheckRoutingParams(schedule, routes, orders)) { SolveOptions options = new SolveOptions(); options.GenerateDirections = App.Current.MapDisplay.TrueRoute; options.FailOnInvalidOrderGeoLocation = false; _SetOperationStartedStatus((string)App.Current.FindResource("SequenceRoutes"), (DateTime)schedule.PlannedDate); OperationsIds.Add(App.Current.Solver.SequenceRoutesAsync(schedule, routes, options)); // set solve started message string infoMessage = _FormatSuccesSolveStartedMsg(schedule, routes.Count); 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; } } }
protected override void _Execute(params object[] args) { AsyncOperationInfo info = null; // Check whether operation can be started. if (!_CanBuildRoutesBeStarted(out info)) // If BuildRoutes operation cannot be started - show warning and return. { Debug.Assert(info != null); // Must be defined in _CanBuildRoutesBeStarted method. App.Current.MainWindow.MessageWindow.AddWarning( string.Format((string)App.Current.FindResource(ALREADY_BUILDING_ROUTES_MESSAGE_RESOURCE), info.Schedule.PlannedDate.Value.ToShortDateString())); return; } try { Schedule schedule = _optimizeAndEditPage.CurrentSchedule; var inputParams = _GetBuildRoutesParameters(schedule); var routes = inputParams.TargetRoutes; var orders = inputParams.OrdersToAssign; if (_CheckRoutingParams(schedule, routes, orders)) { SolveOptions options = new SolveOptions(); options.GenerateDirections = App.Current.MapDisplay.TrueRoute; options.FailOnInvalidOrderGeoLocation = false; _SetOperationStartedStatus((string)App.Current.FindResource(BUILD_ROUTES_STRING), (DateTime)schedule.PlannedDate); OperationsIds.Add(App.Current.Solver.BuildRoutesAsync( schedule, options, inputParams)); // set solve started message string infoMessage = _FormatSuccesSolveStartedMsg(schedule, inputParams); 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; } } }