示例#1
0
        public void GetDefaultConfigurationDirectory_ReportsCorrectlyForDictionaryAndReversal()
        {
            string configDir;

            m_propertyTable.SetProperty("currentContentControl", "lexiconEdit", true);
            configDir = Path.Combine(FwDirectoryFinder.DefaultConfigurations, "Dictionary");
            Assert.That(DictionaryConfigurationListener.GetDefaultConfigurationDirectory(m_propertyTable), Is.EqualTo(configDir), "did not return expected directory");

            m_propertyTable.SetProperty("currentContentControl", "reversalToolEditComplete", true);
            configDir = Path.Combine(FwDirectoryFinder.DefaultConfigurations, "ReversalIndex");
            Assert.That(DictionaryConfigurationListener.GetDefaultConfigurationDirectory(m_propertyTable), Is.EqualTo(configDir), "did not return expected directory");

            m_propertyTable.SetProperty("currentContentControl", "somethingElse", true);
            Assert.IsNull(DictionaryConfigurationListener.GetDefaultConfigurationDirectory(m_propertyTable), "Other areas should cause null return");
        }
示例#2
0
        /// <summary>
        /// Perform the configuration import that the controller has prepared to do.
        /// </summary>
        internal void DoImport()
        {
            Debug.Assert(NewConfigToImport != null);

            ImportCustomFields(_importLiftLocation);

            // If the configuration to import has the same label as an existing configuration in the project folder
            // then overwrite the existing configuration.
            var existingConfigurationInTheWay = _configurations.FirstOrDefault(config => config.Label == NewConfigToImport.Label &&
                                                                               Path.GetDirectoryName(config.FilePath) == _projectConfigDir);

            NewConfigToImport.Publications.ForEach(
                publication =>
            {
                AddPublicationTypeIfNotPresent(publication, _cache);
            });
            try
            {
                ImportStyles(_importStylesLocation);
                ImportHappened = true;
            }
            catch (InstallationException e)             // This is the exception thrown if the dtd guid in the style file doesn't match our program
            {
#if DEBUG
                if (_view == null)                 // _view is sometimes null in unit tests, and it's helpful to know what exactly went wrong.
                {
                    throw new Exception(xWorksStrings.kstidCannotImport, e);
                }
#endif
                _view.explanationLabel.Text = xWorksStrings.kstidCannotImport;
            }

            // We have re-loaded the model from disk to preserve custom field state so the Label must be set here
            NewConfigToImport.FilePath = _temporaryImportConfigLocation;
            NewConfigToImport.Load(_cache);
            if (existingConfigurationInTheWay != null)
            {
                _configurations.Remove(existingConfigurationInTheWay);
                if (existingConfigurationInTheWay.FilePath != null)
                {
                    FileUtils.Delete(existingConfigurationInTheWay.FilePath);
                }
            }
            else
            {
                NewConfigToImport.Label = _proposedNewConfigLabel;
            }

            // Set a filename for the new configuration. Use a unique filename that isn't either registered with another configuration, or existing on disk. Note that in this way, we ignore what the original filename was of the configuration file in the .zip file.
            DictionaryConfigurationManagerController.GenerateFilePath(_projectConfigDir, _configurations, NewConfigToImport);

            var outputConfigPath = existingConfigurationInTheWay != null ? existingConfigurationInTheWay.FilePath : NewConfigToImport.FilePath;

            File.Move(_temporaryImportConfigLocation, outputConfigPath);

            NewConfigToImport.FilePath = outputConfigPath;
            _configurations.Add(NewConfigToImport);

            // phone home (analytics)
            var configType = NewConfigToImport.Type;
            var configDir  = DictionaryConfigurationListener.GetDefaultConfigurationDirectory(
                configType == DictionaryConfigurationModel.ConfigType.Reversal
                                        ? DictionaryConfigurationListener.ReversalIndexConfigurationDirectoryName
                                        : DictionaryConfigurationListener.DictionaryConfigurationDirectoryName);
            var isCustomizedOriginal = DictionaryConfigurationManagerController.IsConfigurationACustomizedOriginal(NewConfigToImport, configDir, _cache);
            UsageReporter.SendEvent("DictionaryConfigurationImport", "Import", "Import Config",
                                    string.Format("Import of [{0}{1}]:{2}",
                                                  configType, isCustomizedOriginal ? string.Empty : "-Custom", ImportHappened ? "succeeded" : "failed"), 0);
        }