コード例 #1
0
        public bool TryRestoreExisting(out IProjectPersister persister)
        {
            var dialog = new CommonOpenFileDialog();

            dialog.IsFolderPicker = true;
            dialog.Title          = "Выберите папку сохраненного ранее проекта";

            CommonFileDialogResult result = dialog.ShowDialog();

            switch (result)
            {
            case CommonFileDialogResult.Ok:

                string path = dialog.FileName;

                persister = new FolderPersister(path);

                System.IO.Directory.SetCurrentDirectory(path);

                return(true);

            default:
                persister = null;
                return(false);
            }
        }
コード例 #2
0
        private void LoadProjectWithPersister(IProjectPersister persister)
        {
            vm.ActivePersister = persister;

            vm.CurrentProjectVM = persister.LoadProject();
            menuVM             = new ProjectMenuVM(vm.CurrentProjectVM);
            vm.ActiveSectionVM = menuVM;

            vm.CurrentProjectVM.BoreIntervalsVM.ActivateIntervalImagesCommand =
                new DelegateCommand(arg =>
            {
                Intervals.PhotoCalibratedBoreIntervalVM intervalVM = arg as Intervals.PhotoCalibratedBoreIntervalVM;
                vm.ActiveSectionVM = intervalVM;
            });


            menuVM.ActivateBoreIntervalsCommand = new DelegateCommand(() =>
            {
                vm.ActiveSectionVM = vm.CurrentProjectVM.BoreIntervalsVM;
            });

            menuVM.ExitAppCommand = ExitCommand;

            menuVM.SaveCommand = new DelegateCommand(() =>
            {
                vm.ActivePersister.SaveProject(vm.CurrentProjectVM);
                MessageBox.Show("Проект успешно сохранен", "Успешно", MessageBoxButton.OK, MessageBoxImage.Information);
            });

            menuVM.ActivateAnnotationPlaneCommand = this.ActivateAnnotationPlaneDelegateCommand;

            vm.CurrentProjectVM.PlaneColumnSettingsVM.ActivateAnnotationPlaneCommand = menuVM.ActivateAnnotationPlaneCommand;

            menuVM.ActivateReportGenerationCommand = ActivateReportGenerationDelegateCommand;
        }
コード例 #3
0
        public bool TryCreateNew(out IProjectPersister persister)
        {
            var dialog = new CommonOpenFileDialog();

            dialog.IsFolderPicker = true;
            dialog.Title          = "Выберите папку для нового проекта";

            bool done = false;

            while (!done)
            {
                CommonFileDialogResult result = dialog.ShowDialog();
                switch (result)
                {
                case CommonFileDialogResult.Ok:

                    string path = dialog.FileName;
                    if (!System.IO.Directory.Exists(path))
                    {
                        System.IO.Directory.CreateDirectory(path);
                    }
                    else
                    {
                        var files = System.IO.Directory.GetFiles(path);
                        var dirs  = System.IO.Directory.GetDirectories(path);
                        if (files.Length + dirs.Length > 0)
                        {
                            MessageBox.Show("Выбранная папка не пуста. Выберите пустую папку для нового проекта", "Папка не пуста", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                            continue;
                        }
                    }
                    persister = new FolderPersister(path);
                    var imageStorage = new FolderImageStorage(System.IO.Path.Combine(path, imagesDirectory));

                    //coping default layer template
                    string exeLocation         = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
                    string defaultTemplatePath = Path.Combine(exeLocation, "DefaultLayersTemplate");
                    PathUtils.DeepCopy(defaultTemplatePath, Path.Combine(path, layersTemplateDirectory));
                    var layersTemplate = new FolderLayersTemplateSource(Path.Combine(path, layersTemplateDirectory));

                    //copying layer ranks
                    File.Copy(Path.Combine(exeLocation, "DefaultLayerRanks.csv"), Path.Combine(path, layersRankFile));
                    var layerRanks = new CsvFileLayerRankSource(Path.Combine(path, layersRankFile));

                    //copying default clumn settings
                    Directory.CreateDirectory(Path.Combine(path, JsonFileColumnSettings.TamplatesDir));
                    File.Copy(
                        Path.Combine(exeLocation, "DefaultColumnSettings.json"),
                        Path.Combine(path, JsonFileColumnSettings.TamplatesDir, JsonFileColumnSettings.DefaultSettingsFile));

                    var colSettingsPersister = new JsonFileColumnSettings();
                    Directory.SetCurrentDirectory(path);     //after this the paths in project will be relative

                    persister.SaveProject(
                        new ProjectVM(imageStorage, layersTemplate, layerRanks, colSettingsPersister));     //new clean project is dumped to disk

                    return(true);

                default:
                    done = true;
                    break;
                }
            }
            persister = null;
            return(false);
        }