Example #1
0
        internal ProjectConfiguration(string name, string folderPath, string description,
                                      string databasePath, Dictionary <string, string> propertiesMap,
                                      DateTime creationTime)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException();
            }

            if (string.IsNullOrEmpty(folderPath))
            {
                throw new ArgumentException();
            }

            if (string.IsNullOrEmpty(databasePath))
            {
                throw new ArgumentException();
            }

            _name         = name;
            _folderPath   = folderPath;
            _description  = description;
            _creationTime = creationTime;

            // make project database path. By default it has common path with project xml file
            _databasePath             = databasePath;
            _projectProperties        = new ProjectProperties(propertiesMap);
            _projectArchivingSettings = new ProjectArchivingSettings(_projectProperties);
            _breaksSettings           = new BreaksSettings(_projectProperties);
        }
Example #2
0
        /// <summary>
        /// Updates archive settings.
        /// </summary>
        private void _UpdateArchiveSettings()
        {
            checkBoxRunAuto.Click         -= _CheckBoxRunAutoClick;
            textBoxPeriod.TextChanged     -= _PeriodTextChanged;
            textBoxTimeDomain.TextChanged -= _TimeDomainTextChanged;

            IProject project = App.Current.Project;

            bool setAsDefault = true;

            if (null != project)
            {
                if ((null != project.ProjectArchivingSettings) && !project.ProjectArchivingSettings.IsArchive)
                {
                    setAsDefault = false;
                }
            }

            // update archiving settings
            if (setAsDefault)
            {   // to default state
                textArchivingSettings.Text = App.Current.FindString("ArchivingSettingsString");

                foreach (UIElement child in stackPanelArchivingSettings.Children)
                {
                    child.IsEnabled = false;
                }

                checkBoxRunAuto.IsChecked = false;
                textBoxPeriod.Text        = string.Empty;
                textBoxTimeDomain.Text    = string.Empty;
            }
            else
            {
                textArchivingSettings.Text = App.Current.GetString("ArchivingSettingsFormatString",
                                                                   project.Name);

                foreach (UIElement child in stackPanelArchivingSettings.Children)
                {
                    child.IsEnabled = true;
                }

                System.Diagnostics.Debug.Assert(null != project.ProjectArchivingSettings);

                ProjectArchivingSettings settings = project.ProjectArchivingSettings;
                checkBoxRunAuto.IsChecked = settings.IsAutoArchivingEnabled;
                textBoxPeriod.Text        = settings.AutoArchivingPeriod.ToString();
                textBoxTimeDomain.Text    = settings.TimeDomain.ToString();

                bool isChecked = (true == checkBoxRunAuto.IsChecked);
                labelMonths.IsEnabled   = isChecked;
                textBoxPeriod.IsEnabled = isChecked;
            }

            checkBoxRunAuto.Click         += new RoutedEventHandler(_CheckBoxRunAutoClick);
            textBoxPeriod.TextChanged     += new TextChangedEventHandler(_PeriodTextChanged);
            textBoxTimeDomain.TextChanged += new TextChangedEventHandler(_TimeDomainTextChanged);
        }
Example #3
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();
            }
        }
Example #4
0
        /// <summary>
        /// Handler for the Click event of the checkBoxRunAuto control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">Event data.</param>
        private void _CheckBoxRunAutoClick(object sender, RoutedEventArgs e)
        {
            bool isChecked = (true == checkBoxRunAuto.IsChecked);

            labelMonths.IsEnabled   = isChecked;
            textBoxPeriod.IsEnabled = isChecked;

            ProjectArchivingSettings settings = App.Current.Project.ProjectArchivingSettings;

            if (null != settings)
            {
                settings.IsAutoArchivingEnabled = isChecked;
                App.Current.Project.Save();
            }
        }
Example #5
0
 /// <summary>
 /// Handler for the TextChanged event of the textBoxTimeDomain control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">Event data.</param>
 private void _TimeDomainTextChanged(object sender, TextChangedEventArgs e)
 {
     if (!textBoxTimeDomain.HasParsingError && !textBoxTimeDomain.HasValidationError &&
         !string.IsNullOrEmpty(textBoxTimeDomain.Text))
     {
         int?value = _ConvertStringToInt(textBoxTimeDomain.Text);
         if (value.HasValue)
         {
             ProjectArchivingSettings settings = App.Current.Project.ProjectArchivingSettings;
             if (null != settings)
             {
                 settings.TimeDomain = value.Value;
                 App.Current.Project.Save();
             }
         }
     }
 }
Example #6
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        private bool _NeedToAutoArchive(ProjectConfiguration config)
        {
            Debug.Assert(config != null);

            bool needToArchive = false;

            ProjectArchivingSettings arSet = config.ProjectArchivingSettings;

            if (arSet.IsAutoArchivingEnabled &&
                !arSet.IsArchive)
            {
                DateTime lastArchiveDate = arSet.LastArchivingDate != null ?
                                           (DateTime)arSet.LastArchivingDate : config.CreationTime;

                DateTime mustArchiveDate = DateTime.Now.AddMonths(-arSet.AutoArchivingPeriod);
                if (mustArchiveDate.Date >= lastArchiveDate.Date)
                {
                    needToArchive = true;
                }
            }

            return(needToArchive);
        }
Example #7
0
        /// <summary>
        /// Archives project.
        /// If original database does not contain data to archive, archive file
        /// will not be created and ArchiveResult.IsArchiveCreated property
        /// will be set to "false".
        /// Method throws an exception if failure occures.
        /// </summary>
        /// <param name="projectConfig">
        /// Configuration of project to archive.
        /// </param>
        /// <param name="date">
        /// Schedules older than this date will be archived.
        /// </param>
        /// <returns>
        /// ArchiveResult object.
        /// </returns>
        public static ArchiveResult ArchiveProject(ProjectConfiguration projectConfig,
                                                   DateTime date)
        {
            Debug.Assert(projectConfig != null);

            // archive database
            DbArchiveResult dbRes = DatabaseArchiver.ArchiveDatabase(
                projectConfig.DatabasePath,
                date);

            string archConfigPath = null;

            if (dbRes.IsArchiveCreated)
            {
                bool archConfigSaved = false;
                try
                {
                    // create archive configuration
                    string archConfigName = Path.GetFileNameWithoutExtension(
                        dbRes.ArchivePath);

                    // format description
                    string firstDate = String.Empty;
                    if (dbRes.FirstDateWithRoutes != null)
                    {
                        firstDate = ((DateTime)dbRes.FirstDateWithRoutes).ToString("d");
                    }

                    string lastDate = String.Empty;
                    if (dbRes.LastDateWithRoutes != null)
                    {
                        lastDate = ((DateTime)dbRes.LastDateWithRoutes).ToString("d");
                    }

                    string archConfigDesc = String.Format(
                        Properties.Resources.ArchiveDescription,
                        firstDate,
                        lastDate);

                    // clone project properties
                    Dictionary <string, string> archProps = new Dictionary <string, string>();
                    ICollection <string>        propNames = projectConfig.ProjectProperties.GetPropertiesName();
                    foreach (string propName in propNames)
                    {
                        archProps.Add(propName, projectConfig.ProjectProperties[propName]);
                    }

                    ProjectConfiguration archConfig = new ProjectConfiguration(
                        archConfigName,
                        projectConfig.FolderPath,
                        archConfigDesc,
                        dbRes.ArchivePath,
                        archProps,
                        DateTime.Now);

                    // update archive settings
                    ProjectArchivingSettings arSet = archConfig.ProjectArchivingSettings;
                    Debug.Assert(arSet != null);

                    arSet.IsArchive = true;
                    arSet.IsAutoArchivingEnabled = false;
                    arSet.LastArchivingDate      = null;

                    // save archive configuration
                    archConfigPath = Path.ChangeExtension(dbRes.ArchivePath,
                                                          ProjectConfiguration.FILE_EXTENSION);

                    archConfig.Save(archConfigPath);
                    archConfigSaved = true;

                    // update configuration of archived project
                    projectConfig.ProjectArchivingSettings.LastArchivingDate = DateTime.Now.Date;
                    projectConfig.Save();
                }
                catch
                {
                    FileHelpers.DeleteFileSilently(dbRes.ArchivePath);

                    if (archConfigSaved)
                    {
                        FileHelpers.DeleteFileSilently(archConfigPath);
                    }

                    throw;
                }
            }

            return(new ArchiveResult(archConfigPath, dbRes.IsArchiveCreated));
        }
        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);
            }
        }