/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// 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(); } }
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); } }