/// <summary>
        /// Handle configuration import request by user.
        /// </summary>
        private void OnImportConfiguration(object sender, EventArgs e)
        {
            // Not capable of exporting new configurations yet.
            if (IsDirty)
            {
                MessageBox.Show(_view, xWorksStrings.kstidConfigsChangedImport);
                return;
            }

            var importController = new DictionaryConfigurationImportController(_cache, _projectConfigDir, _configurations);

            using (var importDialog = new DictionaryConfigurationImportDlg(_mediator.HelpTopicProvider)
            {
                HelpTopic = _view.HelpTopic
            })
            {
                importController.DisplayView(importDialog);
            }

            if (!importController.ImportHappened)
            {
                return;
            }
            CloseDialogAndRefreshProject();
        }
示例#2
0
 private ICmPossibility CreatePublicationType(string name)
 {
     return(DictionaryConfigurationImportController.AddPublicationType(name, Cache));
 }
示例#3
0
        public void Setup()
        {
            // Start out with a clean project configuration directory, and with a non-random name so it's easier to examine during testing.
            _projectConfigPath = Path.Combine(Path.GetTempPath(), "Dictionary");
            if (Directory.Exists(_projectConfigPath))
            {
                Directory.Delete(_projectConfigPath, true);
            }
            FileUtils.EnsureDirectoryExists(_projectConfigPath);

            _reversalProjectConfigPath = Path.Combine(Path.GetTempPath(), "ReversalIndex");
            if (Directory.Exists(_reversalProjectConfigPath))
            {
                Directory.Delete(_reversalProjectConfigPath, true);
            }
            FileUtils.EnsureDirectoryExists(_reversalProjectConfigPath);

            _controller = new DictionaryConfigurationImportController(Cache, _projectConfigPath,
                                                                      new List <DictionaryConfigurationModel>());

            _reversalController = new DictionaryConfigurationImportController(Cache, _reversalProjectConfigPath,
                                                                              new List <DictionaryConfigurationModel>());

            // Set up data for import testing.

            _zipFile         = null;
            _reversalZipFile = null;

            // Prepare configuration to export

            var configurationToExport = new DictionaryConfigurationModel
            {
                Label        = configLabel,
                Publications = new List <string> {
                    "Main Dictionary", "unknown pub 1", "unknown pub 2"
                },
                Parts = new List <ConfigurableDictionaryNode> {
                    new ConfigurableDictionaryNode {
                        FieldDescription = "LexEntry"
                    }
                },
                FilePath = Path.GetTempPath() + configFilename
            };

            CssGeneratorTests.PopulateFieldsForTesting(configurationToExport);

            _pathToConfiguration = configurationToExport.FilePath;

            // Create XML file
            configurationToExport.Save();

            // Prepare configuration to export
            var configurationReversalToExport = new DictionaryConfigurationModel
            {
                Label         = reversalConfigLabel,
                WritingSystem = "en",
                Publications  = new List <string> {
                    "Main Dictionary", "unknown pub 1", "unknown pub 2"
                },
                Parts = new List <ConfigurableDictionaryNode> {
                    new ConfigurableDictionaryNode {
                        FieldDescription = "LexEntry"
                    }
                },
                FilePath = Path.GetTempPath() + reversalConfigFilename
            };

            CssGeneratorTests.PopulateFieldsForTesting(configurationReversalToExport);
            _reversalPathToConfiguration = configurationReversalToExport.FilePath;
            configurationReversalToExport.Save();

            // Export a configuration that we know how to import

            _zipFile         = Path.GetTempFileName();
            _reversalZipFile = Path.GetTempFileName() + 1;

            // Add a test style to the cache
            NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () =>
            {
                var styleFactory = Cache.ServiceLocator.GetInstance <IStStyleFactory>();

                styleFactory.Create(Cache.LangProject.StylesOC, "Dictionary-Headword",
                                    ContextValues.InternalConfigureView, StructureValues.Undefined, FunctionValues.Line, true, 2, true);
                var testStyle = styleFactory.Create(Cache.LangProject.StylesOC, "TestStyle", ContextValues.InternalConfigureView, StructureValues.Undefined,
                                                    FunctionValues.Line, true, 2, false);
                testStyle.Usage.set_String(Cache.DefaultAnalWs, "Test Style");
                var normalStyle = styleFactory.Create(Cache.LangProject.StylesOC, "Normal", ContextValues.InternalConfigureView, StructureValues.Undefined,
                                                      FunctionValues.Line, false, 2, true);
                var propsBldr = TsPropsBldrClass.Create();
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptBackColor, (int)FwTextPropVar.ktpvDefault, 0x2BACCA);                 // arbitrary color to create para element
                normalStyle.Rules        = propsBldr.GetTextProps();
                var styleWithNamedColors = styleFactory.Create(Cache.LangProject.StylesOC, "Nominal", ContextValues.InternalConfigureView, StructureValues.Undefined,
                                                               FunctionValues.Line, false, 2, false);
                styleWithNamedColors.BasedOnRA = normalStyle;
                propsBldr = TsPropsBldrClass.Create();
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptBackColor, (int)FwTextPropVar.ktpvDefault, NamedRedBGR);
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, NamedRedBGR);
                styleWithNamedColors.Rules = propsBldr.GetTextProps();
                var styleWithCustomColors  = styleFactory.Create(Cache.LangProject.StylesOC, "Abnormal", ContextValues.InternalConfigureView, StructureValues.Undefined,
                                                                 FunctionValues.Line, false, 2, false);
                styleWithCustomColors.BasedOnRA = normalStyle;
                propsBldr = TsPropsBldrClass.Create();
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptBackColor, (int)FwTextPropVar.ktpvDefault, CustomRedBGR);
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault, CustomRedBGR);
                styleWithCustomColors.Rules = propsBldr.GetTextProps();
                DictionaryConfigurationManagerController.ExportConfiguration(configurationToExport, _zipFile, Cache);
                DictionaryConfigurationManagerController.ExportConfiguration(configurationReversalToExport, _reversalZipFile, Cache);
                Cache.LangProject.StylesOC.Clear();
            });
            Assert.That(File.Exists(_zipFile), "Unit test not set up right");
            Assert.That(new FileInfo(_zipFile).Length, Is.GreaterThan(0), "Unit test not set up right");

            // Clear the configuration away so we can see it gets imported

            File.Delete(_pathToConfiguration);
            Assert.That(!File.Exists(_pathToConfiguration),
                        "Unit test not set up right. Configuration should be out of the way for testing export.");
            Assert.That(_controller._configurations.All(config => config.Label != configLabel),
                        "Unit test not set up right. A config exists with the same label as the config we will import.");
            Assert.That(_controller._configurations.All(config => config.Label != configLabel),
                        "Unit test set up unexpectedly. Such a config should not be registered.");
            File.Delete(_reversalPathToConfiguration);
            Assert.That(!File.Exists(_reversalPathToConfiguration),
                        "Unit test not set up right. Reversal configuration should be out of the way for testing export.");
            Assert.That(_reversalController._configurations.All(config => config.Label != configLabel),
                        "Unit test not set up right. A reversal config exists with the same label as the reversal config we will import.");
            Assert.That(_reversalController._configurations.All(config => config.Label != configLabel),
                        "Unit test set up unexpectedly. Such a reversal config should not be registered.");
        }