/// <summary>
        /// React on async solve completed.
        /// </summary>
        private void _Cmd_AsyncSolveCompleted(object sender, AsyncSolveCompletedEventArgs e)
        {
            if (_operationID.Equals(e.OperationId))
            {
                _app.Solver.AsyncSolveCompleted -= _Cmd_AsyncSolveCompleted;

                if (e.Cancelled)
                {
                    _app.MainWindow.Unlock();
                    WorkingStatusHelper.SetReleased();

                    _app.Messenger.AddInfo((string)_app.FindResource("GenerateDirectionsCancelledText"));
                }
                else if (e.Error != null)
                {
                    _OnSolveError(e.Error);
                }
                else
                {
                    _app.Messenger.AddInfo((string)_app.FindResource("GenerateDirectionsCompletedText"));

                    _app.Project.Save();
                    _app.MainWindow.Unlock();
                    WorkingStatusHelper.SetReleased();

                    _StartSendProcess();
                }
            }
        }
        /// <summary>
        /// React on new version button click.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Ignored.</param>
        private void _NewVersionButtonClick(object sender, RoutedEventArgs e)
        {
            try
            {
                XceedGrid.EndEdit();
                WorkingStatusHelper.SetBusy((string)App.Current.FindResource("CreatingScheduleVersionStatus"));

                _UnsubscribeFromGridSelection();

                // Make version, add to project and save.
                Debug.Assert(_SelectedSchedule != null);
                Schedule newSchedule = _MakeScheduleVersion(_SelectedSchedule, _ScheduleVersions);
                App.Current.Project.Schedules.Add(newSchedule);
                App.Current.Project.Save();

                _SubscribeToGridSelection();

                // Select new schedule.
                XceedGrid.SelectedItem = newSchedule;
            }
            finally
            {
                WorkingStatusHelper.SetReleased();
            }
        }
        /// <summary>
        /// Unlock UI and set default status.
        /// </summary>
        private void _ReturnUIToDefaultState()
        {
            // Unlock application UI.
            App.Current.UIManager.Unlock();

            // Remove routing status.
            WorkingStatusHelper.SetReleased();
        }
示例#4
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        protected override void _Execute(params object[] args)
        {
            bool   needClearBusyState = false;
            string projectName        = null;

            try
            {
                Debug.Assert(args.Length > 0);

                string projectPath = args[0] as string;
                Debug.Assert(projectPath != null);

                // get project name
                projectName = Path.GetFileNameWithoutExtension(projectPath);

                // get project configuration
                ProjectConfiguration config = _FindConfigByName(projectName);
                if (config != null)
                {
                    // check if we need to auto-archive project
                    if (_NeedToAutoArchive(config))
                    {
                        // set status
                        string statusMessage = string.Format((string)_Application.FindResource("ArchiveMessageProcessStatusFormat"), projectName);
                        WorkingStatusHelper.SetBusy(statusMessage);
                        needClearBusyState = true;

                        ProjectArchivingSettings arSet = config.ProjectArchivingSettings;
                        DateTime date = DateTime.Now.Date.AddMonths(-arSet.TimeDomain);

                        ArchiveResult result = ProjectFactory.ArchiveProject(config, date);
                        _ShowResult(projectName, result);

                        if (result.IsArchiveCreated)
                        {   // Update project page
                            ProjectsPage projectsPage = (ProjectsPage)_Application.MainWindow.GetPage(PagePaths.ProjectsPagePath);
                            projectsPage.UpdateView();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);

                Collection <MessageDetail> details = new Collection <MessageDetail>();
                details.Add(new MessageDetail(MessageType.Error, ex.Message));

                string message = string.Format((string)_Application.FindResource("ArchiveMessageProcessFailedFromat"), projectName);
                _Application.Messenger.AddMessage(MessageType.Warning, message, details);
            }

            if (needClearBusyState)
            {
                WorkingStatusHelper.SetReleased();
            }
        }
        /// <summary>
        /// Change type of current schedule to current.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Ignored.</param>
        private void _CommitToCurrentButtonClick(object sender, RoutedEventArgs e)
        {
            try
            {
                WorkingStatusHelper.SetBusy((string)App.Current.FindResource("CommitingScheduleVersionStatus"));

                // Remove all schedules except one with Original type and curently selected one.
                Collection <Schedule> removingSchedules = new Collection <Schedule>();
                foreach (Schedule schedule in _ScheduleVersions)
                {
                    if (schedule.Type == ScheduleType.Current &&
                        !schedule.Equals(_SelectedSchedule))
                    {
                        removingSchedules.Add(schedule);
                    }
                }

                // Unsubscribe from selection since data grid raises this event when data source changes.
                _UnsubscribeFromGridSelection();

                // Workaround: data grid changes selection for some reason, so we need to save current selection
                Schedule selectedItem = _SelectedSchedule;

                foreach (Schedule schedule in removingSchedules)
                {
                    if (schedule.UnassignedOrders != null)
                    {
                        schedule.UnassignedOrders.Dispose();
                    }
                    App.Current.Project.Schedules.Remove(schedule);
                }

                // Select remembered item.
                XceedGrid.SelectedItem = selectedItem;

                // Subscribe to SelectionChanged event again.
                _SubscribeToGridSelection();

                Schedule newCurrentSchedule = _MakeScheduleVersion(_SelectedSchedule, _ScheduleVersions);
                newCurrentSchedule.Name = (string)App.Current.FindResource("CurrentScheduleName");
                newCurrentSchedule.Type = ScheduleType.Current;

                App.Current.Project.Schedules.Add(newCurrentSchedule);
                App.Current.Project.Save(); // need to save before seleting
                XceedGrid.SelectedItem = newCurrentSchedule;

                // Save all changes.
                App.Current.Project.Save();

                _UpdateButtonsState();
            }
            finally
            {
                WorkingStatusHelper.SetReleased();
            }
        }
        /// <summary>
        /// Handles solve error occured upond directions report generation.
        /// </summary>
        /// <param name="exception">The exception occured upon solving.</param>
        private void _OnSolveError(Exception exception)
        {
            Debug.Assert(exception != null);

            _app.MainWindow.Unlock();
            WorkingStatusHelper.SetReleased();

            var service = (string)_app.FindResource("ServiceNameRouting");

            _ReportServiceError(service, exception);
        }
示例#7
0
        private void GetWorkingStatus()
        {
            Login  login = (Login)Session[DataCleaningConstant.LoginInfoSession];
            string step  = Request.QueryString["step"];
            WorkingStatusHelper working = new WorkingStatusHelper();
            WorkingStatus       status  = working.GetWorkingStatus(login.UserLogin.user_name, step);

            status.total_time = Math.Round(status.total_time, 1);
            status.speed      = Math.Round(status.speed, 1);
            var jsonSerialiser = new JavaScriptSerializer();
            var json           = jsonSerialiser.Serialize(status);

            Response.Write(json);
            Response.End();
        }
示例#8
0
        private void _DoExport(Profile profile, ICollection <Schedule> exportedSchedule)
        {
            string statusMessage = (string)App.Current.FindResource("ExportStartMessage");

            WorkingStatusHelper.SetBusy(statusMessage);

            try
            {
                MapLayer currentMapLayer = null;
                foreach (MapLayer layer in App.Current.Map.Layers)
                {
                    if (layer.IsVisible && layer.IsBaseMap)
                    {
                        currentMapLayer = layer;
                        break;
                    }
                }

                App.Current.Exporter.DoExport(profile, exportedSchedule, currentMapLayer);

                string format = (string)App.Current.FindResource("ExportMessageFormatSucceded");
                statusMessage = string.Format(format, ExportProfilesEditPage.GetTypeFaceName(profile.Type), profile.FilePath);
                App.Current.Messenger.AddInfo(statusMessage);
            }
            catch (Exception ex)
            {
                string format = (string)App.Current.FindResource("ExportMessageFormatFailed");
                statusMessage = string.Format(format, ExportProfilesEditPage.GetTypeFaceName(profile.Type), profile.FilePath);

                if (ex is AuthenticationException || ex is CommunicationException)
                {
                    string service = (string)App.Current.FindResource("ServiceNameMap");
                    CommonHelpers.AddServiceMessageWithDetail(statusMessage, service, ex);
                    Logger.Error(ex);
                }
                else
                {
                    string message = string.Format("{0} {1}", statusMessage, ex.Message);
                    App.Current.Messenger.AddError(message);
                    Logger.Critical(ex);
                }
            }

            WorkingStatusHelper.SetReleased();
            App.Current.MainWindow.StatusBar.SetStatus(this, statusMessage);
        }
        /// <summary>
        /// Occurs when user press enter in inserion row.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DataGridCollectionViewSource_CommittingNewItem(object sender, DataGridCommittingNewItemEventArgs e)
        {
            try
            {
                WorkingStatusHelper.SetBusy((string)App.Current.FindResource("LoadingProjectStatus"));

                ProjectCatalog projectBrowser = App.Current.ProjectCatalog;

                List <ProjectDataWrapper> source = e.CollectionView.SourceCollection as List <ProjectDataWrapper>;
                ProjectDataWrapper        projectDataTemplate = e.Item as ProjectDataWrapper;

                App.Current.NewProject(projectDataTemplate.Name,
                                       projectBrowser.FolderPath,
                                       projectDataTemplate.Description);

                source.Add(projectDataTemplate);

                // update layout
                UpdateView();

                e.Index    = source.Count - 1;
                e.NewCount = source.Count;
                e.Handled  = true;
            }
            catch (ApplicationException ex)
            {
                Logger.Info(ex);
                App.Current.Messenger.AddWarning(ex.Message);
            }
            catch (Exception ex)
            {
                Logger.Info(ex);
                App.Current.Messenger.AddWarning(ex.Message);
            }
            finally
            {
                WorkingStatusHelper.SetReleased();
                App.Current.MainWindow.StatusBar.SetStatus(this, null);
            }
        }
        /// <summary>
        /// Runs report core to real report creation (call after <c>CreateReportsAsync</c>).
        /// </summary>
        /// <param name="description">Created report description.</param>
        public void RunReport(ReportStateDescription description)
        {
            Debug.Assert(null != description);
            Debug.Assert(null == description.Report);

            using (WorkingStatusHelper.EnterBusyState(null))
            {
                try
                {
                    // load report structure
                    var rpt = _LoadReportStructure(description.ReportInfo.TemplatePath);

                    // update connection string
                    var ds = (DataDynamics.ActiveReports.DataSources.OleDBDataSource)rpt.DataSource;
                    ds.ConnectionString = _UpdateConnectionString(description.SourceFilePath,
                                                                  ds.ConnectionString);
                    string connectionString = ds.ConnectionString;

                    // set sub reports
                    Section section = rpt.Sections[REPORT_SECTION_NAME_DETAIL];
                    _InitSubReports(description.ReportInfo.SubReports, connectionString, section);

                    // run report building
                    rpt.Document.Name = description.ReportName;
                    rpt.Run();

                    description.Report = rpt;

                    GC.Collect();
                    GC.WaitForFullGCApproach();
                }
                catch
                {
                    DisposeReport(description);

                    throw; // exception
                }
            }
        }
        /// <summary>
        /// Reloads project when user checks any CheckBox.
        /// </summary>
        protected void _LoadProject(string checkedProjectName)
        {
            try
            {
                WorkingStatusHelper.SetBusy((string)App.Current.FindResource("LoadingProjectStatus"));

                // init old project path
                string oldProjectPath = String.Empty;
                if (App.Current.Project != null)
                {
                    oldProjectPath = App.Current.Project.Path;
                }

                if (!checkedProjectName.Equals(CurrentProjectName, StringComparison.OrdinalIgnoreCase))
                {
                    _TryToLoadProject(oldProjectPath, checkedProjectName);
                }
            }
            finally
            {
                WorkingStatusHelper.SetReleased();
                _CheckPageComplete();
            }
        }
        /// <summary>
        /// Does generation directions. Start solver operation.
        /// </summary>
        private void _DoGenerateDirections(IList <Route> routes)
        {
            WorkingStatusHelper.SetBusy((string)_app.FindResource("GenerateDirections"));

            var message = string.Format((string)_app.FindResource("GenerateDirectionsStartText"),
                                        routes.First().Schedule.PlannedDate.Value.ToShortDateString());

            _app.Messenger.AddInfo(message);

            _app.MainWindow.Lock(true);

            _app.Solver.AsyncSolveCompleted += _Cmd_AsyncSolveCompleted;

            try
            {
                _operationID = _app.Solver.GenerateDirectionsAsync(routes);
            }
            catch (Exception ex)
            {
                _app.Solver.AsyncSolveCompleted -= _Cmd_AsyncSolveCompleted;

                _OnSolveError(ex);
            }
        }
        /// <summary>
        /// Executes command.
        /// </summary>
        /// <param name="args">Arguments passed to the command.</param>
        public void Execute(params object[] args)
        {
            Debug.Assert(this.IsEnabled);

            try
            {
                using (WorkingStatusHelper.EnterBusyState(_executionStatusMessage))
                {
                    if (_RoutesMustBeSent())
                    {
                        _sendRoutesTask.Execute();
                        _UpdateState();
                    }
                }
            }
            catch (Exception e)
            {
                var handler = _application.WorkflowManagementExceptionHandler;
                if (!handler.HandleException(e))
                {
                    throw;
                }
            }
        }
        protected override void _Execute(params object[] args)
        {
            Debug.Assert(null != _projectsPage);

            string filePath           = null;
            bool   needClearBusyState = false;
            string projectName        = null;
            bool   isAutoArchive      = false;

            try
            {
                // select project to archiving
                isAutoArchive = ((1 == args.Length) && (null != args[0]));
                projectName   = (isAutoArchive) ? args[0] as string : _projectsPage.SelectedProjectName;
                // prescribed for command or selected project

                Debug.Assert(null != projectName);

                // find checked project configuration
                ProjectConfiguration config = _FindConfigByName(projectName);
                Debug.Assert(null != config);

                // set status
                string statusMessage = string.Format((string)_Application.FindResource("ArchiveMessageProcessStatusFormat"), projectName);
                WorkingStatusHelper.SetBusy(statusMessage);
                needClearBusyState = true;

                bool routingOperationsInProgress = false;
                if (projectName.Equals(_projectsPage.CurrentProjectName, StringComparison.InvariantCultureIgnoreCase))
                {   // check some routing operation is on progress
                    if (_Application.Solver.HasPendingOperations)
                    {
                        _Application.Messenger.AddWarning((string)_Application.FindResource("ArchiveMessageRoutingOperationsInProgress"));
                        routingOperationsInProgress = true;
                    }
                    else
                    {
                        // since archiving requires project to be closed, the command must close the project at first
                        _Application.CloseCurProject();
                        filePath = config.FilePath;
                    }
                }

                if (!routingOperationsInProgress)
                {   // archive it
                    ProjectArchivingSettings archivingSettings = config.ProjectArchivingSettings;
                    Debug.Assert(!archivingSettings.IsArchive);

                    DateTime      date   = DateTime.Now.Date.AddMonths(-archivingSettings.TimeDomain);
                    ArchiveResult result = ProjectFactory.ArchiveProject(config, date);
                    if (result.IsArchiveCreated)
                    {   // project was successfully archived
                        string message = string.Format((string)_Application.FindResource("ArchiveMessageProcessDoneFromat"),
                                                       projectName, Path.GetFileNameWithoutExtension(result.ArchivePath));
                        _Application.Messenger.AddInfo(message);
                        _projectsPage.UpdateView();
                    }
                    else
                    {   // command run for a project and there is nothing to archive actually
                        string message = string.Format((string)_Application.FindResource("ArchiveMessageNothingArchiveFormat"), projectName);
                        _Application.Messenger.AddWarning(message);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Critical(ex);

                Collection <MessageDetail> details = new Collection <MessageDetail>();
                details.Add(new MessageDetail(MessageType.Error, ex.Message));
                string      message = string.Format((string)_Application.FindResource("ArchiveMessageProcessFailedFromat"), projectName);
                MessageType type    = (isAutoArchive)? MessageType.Warning : MessageType.Error;
                _Application.Messenger.AddMessage(type, message, details);
            }
            if (needClearBusyState)
            {
                WorkingStatusHelper.SetReleased();
            }

            // open it again
            if (!string.IsNullOrEmpty(filePath))
            {
                _Application.OpenProject(filePath, false);
            }
        }
        protected override void _Execute(params object[] args)
        {
            // If editing is process in optimize and edit page - cancel editing.
            if (OptimizePage.IsEditingInProgress)
            {
                ((ICancelDataObjectEditing)OptimizePage).CancelObjectEditing();
            }

            Collection <Route> selected = _GetRoutesFromSelection();

            if (0 < selected.Count)
            {
                bool doProcess = true;
                if (Settings.Default.IsAllwaysAskBeforeDeletingEnabled)
                {
                    // show warning dialog
                    doProcess = DeletingWarningHelper.Execute(selected, "Route", "Routes");
                }

                if (doProcess)
                {
                    WorkingStatusHelper.SetBusy((string)App.Current.FindResource("DeletingRoutesStatus"));

                    // Workaround: Xceed throw exception when deleting expanded details view.
                    //      Collapse route details before deleting.
                    List <Xceed.Wpf.DataGrid.DataGridContext> dataGridContexts = new List <Xceed.Wpf.DataGrid.DataGridContext>(OptimizePage.RoutesView.RoutesGrid.GetChildContexts());
                    foreach (Xceed.Wpf.DataGrid.DataGridContext dataGridContext in dataGridContexts)
                    {
                        for (int index = 0; index < selected.Count; ++index)
                        {
                            if (dataGridContext.ParentItem.Equals(selected[index]))
                            {
                                dataGridContext.ParentDataGridContext.CollapseDetails(dataGridContext.ParentItem);
                                break; // Exit. For this data grid context all done.
                            }
                        }
                    }

                    // Save current selected index.
                    int previousSelectedIndex = OptimizePage.RoutesView.RoutesGrid.SelectedIndex;

                    // Delete routes.
                    for (int index = 0; index < selected.Count; ++index)
                    {
                        CurrentSchedule.Routes.Remove(selected[index]);
                    }

                    Project project = App.Current.Project;
                    project.Save();

                    // Set unassigned orders.
                    if (CurrentSchedule.UnassignedOrders != null)
                    {
                        CurrentSchedule.UnassignedOrders.Dispose();
                    }

                    CurrentSchedule.UnassignedOrders = project.Orders.SearchUnassignedOrders(CurrentSchedule, true);

                    WorkingStatusHelper.SetReleased();

                    // Schedule has changed - all views should be refreshed.
                    OptimizePage.OnScheduleChanged(CurrentSchedule);

                    // Select item, which goes after deleted. Special logic used for routes, because schedule reloads.
                    int newSelectedIndex = OptimizePage.RoutesView.RoutesGrid.Items.Count - 1;
                    if (OptimizePage.RoutesView.RoutesGrid.Items.Count > previousSelectedIndex)
                    {
                        newSelectedIndex = previousSelectedIndex;
                    }

                    if (newSelectedIndex != -1)
                    {
                        OptimizePage.Dispatcher.BeginInvoke(new ParamsDelegate(_SelectItem),
                                                            DispatcherPriority.Input, OptimizePage.RoutesView.RoutesGrid.Items[newSelectedIndex]);
                    }
                }
            }
        }
示例#16
0
 /// <summary>
 /// Occurs when user select other month/year
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ArcLogisticsCalendar_DisplayDateChanged(object sender, CalendarDateChangedEventArgs e)
 {
     WorkingStatusHelper.SetBusy(null);
     _UpdateCalendarView();
     WorkingStatusHelper.SetReleased();
 }
示例#17
0
        /// <summary>
        /// Deletes mobile devices
        /// </summary>
        protected override void _Delete(IList <MobileDevice> selectedObjects)
        {
            Debug.Assert(selectedObjects != null);

            var deletionChecker = _Application.Project.DeletionCheckingService;

            var device = deletionChecker.QueryAssignedToDriver(selectedObjects)
                         .FirstOrDefault();

            if (device != null)
            {
                var message = _Application.GetString(ASSIGNED_TO_DRIVER_KEY, device);
                _Application.Messenger.AddError(message);

                return;
            }

            device = deletionChecker.QueryAssignedToVehicle(selectedObjects)
                     .FirstOrDefault();
            if (device != null)
            {
                var message = _Application.GetString(ASSIGNED_TO_VEHICLE_KEY, device);
                _Application.Messenger.AddError(message);

                return;
            }

            try
            {
                // cast to an array to detach enumerable from selected objects collection.
                var delettees = selectedObjects.ToArray();

                var busyMessage = _Application.FindString(COMMAND_EXECUTING_STATUS_NAME);
                using (WorkingStatusHelper.EnterBusyState(busyMessage))
                {
                    // Delete devices from the project.
                    var project = _Application.Project;
                    foreach (var item in delettees)
                    {
                        project.MobileDevices.Remove(item);
                    }

                    project.Save();

                    // Now we should have less devices locally than on WFMS so they should be
                    // deleted there also.
                    var syncService        = _Application.Tracker.SynchronizationService;
                    var deletedTrackingIds = delettees
                                             .Where(deletedDevice => deletedDevice.SyncType == SyncType.WMServer)
                                             .Select(deletedDevice => deletedDevice.TrackingId);
                    syncService.DeleteDevices(project, deletedTrackingIds);
                }
            }
            catch (Exception e)
            {
                if (!_exceptionHandler.HandleException(e))
                {
                    throw;
                }
            }
        }