Пример #1
0
        private bool OpenPartProjectFile(string projectFilePath)
        {
            if (!CloseCurrentProject())
            {
                return(false);
            }

            if (MultiInstanceManager.InstanceCount > 1)
            {
                if (MultiInstanceManager.CheckFileIsOpen(projectFilePath))
                {
                    MessageBoxEX.ShowDetails(this,
                                             Messages.Error_OpeningProject,
                                             Messages.Caption_OpeningProject,
                                             "The file is already opened in another instance."); //TODO: translate
                    return(false);
                }
            }

            PartProject loadedProject = null;

            try
            {
                loadedProject = PartProject.Open(projectFilePath);
            }
            catch (Exception ex)
            {
                MessageBoxEX.ShowDetails(this,
                                         Messages.Error_OpeningProject,
                                         Messages.Caption_OpeningProject, ex.ToString());
            }

            if (loadedProject != null)
            {
                LoadPartProject(loadedProject);
            }

            return(loadedProject != null);
        }
Пример #2
0
        private void CheckCanRecoverProject()
        {
            SettingsManager.CleanUpFilesHistory();

            if (SettingsManager.Current.OpenedProjects.Count > 0)
            {
                bool projectWasLoaded = false;

                foreach (var fileInfo in SettingsManager.Current.OpenedProjects.ToArray())
                {
                    //project was not correctly closed
                    if (File.Exists(fileInfo.TemporaryPath))
                    {
                        if (projectWasLoaded)
                        {
                            continue;
                        }

                        if (MultiInstanceManager.InstanceCount > 1)
                        {
                            bool isOpenInOtherInstance = MultiInstanceManager.CheckFileIsOpen(fileInfo.TemporaryPath);
                            if (isOpenInOtherInstance)
                            {
                                return;
                            }
                        }

                        bool projectRestored = false;

                        if (MessageBoxEX.Show(this,
                                              Messages.Message_RecoverProject,
                                              Messages.Caption_RecoverLastProject,
                                              MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            PartProject loadedProject = null;
                            try
                            {
                                loadedProject             = PartProject.Open(fileInfo.TemporaryPath);
                                loadedProject.ProjectPath = fileInfo.ProjectFile;

                                if (LoadPartProject(loadedProject, fileInfo.TemporaryPath))
                                {
                                    projectRestored  = true;
                                    projectWasLoaded = true;
                                }
                            }
                            catch (Exception ex)
                            {
                                MessageBoxEX.ShowDetails(this,
                                                         Messages.Error_OpeningProject,
                                                         Messages.Caption_OpeningProject, ex.ToString());
                                //exceptionThrown = true;
                            }
                        }

                        if (!projectRestored)
                        {
                            ProjectManager.DeleteTemporaryProject(fileInfo.TemporaryPath);
                        }

                        break;
                    }
                }
            }
        }