Ejemplo n.º 1
0
 /// <summary>
 /// Migrates old dictionary and reversal configurations if there are not already new dictionary and reversal configurations.
 /// </summary>
 public void MigrateOldConfigurationsIfNeeded()
 {
     using (m_logger = new SimpleLogger())
     {
         try
         {
             var versionProvider = new VersionInfoProvider(Assembly.GetExecutingAssembly(), true);
             // Further migration changes (especially Label changes) may need changes in multiple migrators:
             foreach (var migrator in m_migrators)
             {
                 migrator.MigrateIfNeeded(m_logger, m_propertyTable, versionProvider.ApplicationVersion);
             }
             CreateProjectCustomCssIfNeeded(m_propertyTable);
         }
         finally
         {
             if (m_logger.HasContent)
             {
                 var configurationDir = DictionaryConfigurationListener.GetProjectConfigurationDirectory(m_propertyTable,
                                                                                                         DictionaryConfigurationListener.DictionaryConfigurationDirectoryName);
                 Directory.CreateDirectory(configurationDir);
                 File.AppendAllText(Path.Combine(configurationDir, "ConfigMigrationLog.txt"), m_logger.Content);
             }
         }
     }
     m_logger = null;
 }
Ejemplo n.º 2
0
        /// <summary>Returns HVO's of the entries to publish. If there are none, returns an empty array.</summary>
        public int[] GetEntriesToPublish(Mediator mediator, int virtualFlid, string dictionaryType = null)
        {
            if (dictionaryType == null)
            {
                dictionaryType = DictionaryConfigurationListener.GetDictionaryConfigurationBaseType(mediator);
            }
            // LT-16426: Listener here needs to return a non-localized version or all non-English dictionaries will be empty!
            switch (dictionaryType)
            {
            case "Dictionary":
                return(VecProp(Cache.LangProject.LexDbOA.Hvo, virtualFlid));

            case "Reversal Index":
            {
                var reversalIndexGuid = ReversalIndexEntryUi.GetObjectGuidIfValid(mediator, "ReversalIndexGuid");
                if (reversalIndexGuid != Guid.Empty)
                {
                    var currentReversalIndex = Cache.ServiceLocator.GetObject(reversalIndexGuid) as IReversalIndex;
                    if (currentReversalIndex != null)
                    {
                        return(GetSortedAndFilteredReversalEntries(currentReversalIndex.Hvo, virtualFlid));
                    }
                }
                break;
            }
            }
            return(new int[] { });
        }
Ejemplo n.º 3
0
        protected override void ShowRecord()
        {
            if (!m_fullyInitialized || IsDisposed || m_mainView.IsDisposed || !Visible)
            {
                return;
            }
            base.ShowRecord();
            var cmo = Clerk.CurrentObject;

            // Don't steal focus
            Enabled = false;
            m_mainView.DocumentCompleted += EnableRecordDocView;
            if (cmo != null && cmo.Hvo > 0)
            {
                var configurationFile = DictionaryConfigurationListener.GetCurrentConfiguration(m_propertyTable);
                if (String.IsNullOrEmpty(configurationFile))
                {
                    m_mainView.DocumentText = String.Format("<html><body><p>{0}</p></body></html>",
                                                            xWorksStrings.ksNoConfiguration);
                    return;
                }
                var configuration = new DictionaryConfigurationModel(configurationFile, Cache);
                var xhtmlPath     = ConfiguredXHTMLGenerator.SavePreviewHtmlWithStyles(new [] { cmo.Hvo }, null, configuration, m_propertyTable);
                m_mainView.Url = new Uri(xhtmlPath);
                m_mainView.Refresh(WebBrowserRefreshOption.Completely);
            }
            else
            {
                m_mainView.DocumentText = "<html><body></body></html>";
            }
        }
Ejemplo n.º 4
0
 public void ExportDictionaryContent(string xhtmlPath, DictionaryConfigurationModel configuration = null, IThreadedProgress progress = null)
 {
     using (ClerkActivator.ActivateClerkMatchingExportType(DictionaryType, m_mediator))
     {
         configuration = configuration ?? new DictionaryConfigurationModel(
             DictionaryConfigurationListener.GetCurrentConfiguration(m_mediator, "Dictionary"), m_cache);
         ExportConfiguredXhtml(xhtmlPath, configuration, DictionaryType, progress);
     }
 }
Ejemplo n.º 5
0
 public void ExportReversalContent(string xhtmlPath, string reversalWs = null, DictionaryConfigurationModel configuration = null,
                                   IThreadedProgress progress          = null)
 {
     using (ClerkActivator.ActivateClerkMatchingExportType(ReversalType, m_mediator))
         using (ReversalIndexActivator.ActivateReversalIndex(reversalWs, m_mediator, m_cache))
         {
             configuration = configuration ?? new DictionaryConfigurationModel(
                 DictionaryConfigurationListener.GetCurrentConfiguration(m_mediator, "ReversalIndex"), m_cache);
             ExportConfiguredXhtml(xhtmlPath, configuration, ReversalType, progress);
         }
 }
        private void OnDeleteConfiguration(object sender, EventArgs eventArgs)         // REVIEW (Hasso) 2017.01: this should be two methods, since there are two buttons.
        {
            var configurationToDelete = SelectedConfiguration;

            if (configurationToDelete == null)
            {
                return;
            }

            using (var dlg = new ConfirmDeleteObjectDlg(_mediator.HelpTopicProvider))
            {
                dlg.WindowTitle = xWorksStrings.Confirm + " " + xWorksStrings.Delete;
                var kindOfConfiguration = DictionaryConfigurationListener.GetDictionaryConfigurationType(_mediator);
                dlg.TopBodyText = String.Format("{0} {1}: {2}", kindOfConfiguration, xWorksStrings.View, configurationToDelete.Label);

                if (IsConfigurationACustomizedOriginal(configurationToDelete))
                {
                    if (IsConfigurationAnOriginalReversal(configurationToDelete, _cache) && !IsAllReversalIndexConfig(configurationToDelete))
                    {
                        dlg.TopMessage = xWorksStrings.YouAreResettingReversal;
                    }
                    else
                    {
                        dlg.TopMessage = xWorksStrings.YouAreResetting;
                    }
                    dlg.BottomQuestion   = xWorksStrings.WantContinue;
                    dlg.DeleteButtonText = xWorksStrings.Reset;
                    dlg.WindowTitle      = xWorksStrings.Confirm + " " + xWorksStrings.Reset;
                }

                if (dlg.ShowDialog() != DialogResult.Yes)
                {
                    return;
                }
            }

            DeleteConfiguration(configurationToDelete);
            ReLoadConfigurations();

            // Re-select configuration that was reset, or select first configuration if we just deleted a
            // configuration.
            if (IsConfigurationACustomizedOriginal(configurationToDelete))
            {
                _view.configurationsListView.Items.Cast <ListViewItem>().First(item => item.Text == configurationToDelete.Label).Selected = true;
            }
            else
            {
                _view.configurationsListView.Items[0].Selected = true;
            }
        }
Ejemplo n.º 7
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");
        }
Ejemplo n.º 8
0
        /// <summary>Create custom CSS file in the project's folder</summary>
        private static void CreateProjectCustomCssIfNeeded(PropertyTable propertyTable)
        {
            var innerDirectories = new [] { "Dictionary", "ReversalIndex" };

            foreach (var innerDir in innerDirectories)
            {
                var configDir = DictionaryConfigurationListener.GetProjectConfigurationDirectory(propertyTable, innerDir);
                Directory.CreateDirectory(configDir);
                var customCssPath = Path.Combine(configDir, string.Format("Project{0}Overrides.css", innerDir == "ReversalIndex" ? "Reversal" : innerDir));
                if (!File.Exists(customCssPath))
                {
                    File.WriteAllText(customCssPath, "/* This file can be used to add custom css rules that will be applied to the xhtml export */");
                }
            }
        }
Ejemplo n.º 9
0
        public void GetDictionaryConfigurationBaseType_ReportsCorrectlyForDictionaryAndReversal()
        {
            m_propertyTable.SetProperty("currentContentControl", "lexiconEdit", true);
            Assert.AreEqual("Dictionary", DictionaryConfigurationListener.GetDictionaryConfigurationBaseType(m_propertyTable), "did not return expected type");
            m_propertyTable.SetProperty("currentContentControl", "lexiconBrowse", true);
            Assert.AreEqual("Dictionary", DictionaryConfigurationListener.GetDictionaryConfigurationBaseType(m_propertyTable), "did not return expected type");
            m_propertyTable.SetProperty("currentContentControl", "lexiconDictionary", true);
            Assert.AreEqual("Dictionary", DictionaryConfigurationListener.GetDictionaryConfigurationBaseType(m_propertyTable), "did not return expected type");

            m_propertyTable.SetProperty("currentContentControl", "reversalToolEditComplete", true);
            Assert.AreEqual("Reversal Index", DictionaryConfigurationListener.GetDictionaryConfigurationBaseType(m_propertyTable), "did not return expected type");
            m_propertyTable.SetProperty("currentContentControl", "reversalToolBulkEditReversalEntries", true);
            Assert.AreEqual("Reversal Index", DictionaryConfigurationListener.GetDictionaryConfigurationBaseType(m_propertyTable), "did not return expected type");

            m_propertyTable.SetProperty("currentContentControl", "somethingElse", true);
            Assert.IsNull(DictionaryConfigurationListener.GetDictionaryConfigurationBaseType(m_propertyTable), "Other areas should return null");
        }
Ejemplo n.º 10
0
        public void GetProjectConfigurationDirectory_ReportsCorrectlyForDictionaryAndReversal()
        {
            {
                string projectConfigDir;

                m_propertyTable.SetProperty("currentContentControl", "lexiconEdit", true);
                projectConfigDir = Path.Combine(LcmFileHelper.GetConfigSettingsDir(Cache.ProjectId.ProjectFolder), "Dictionary");
                Assert.That(DictionaryConfigurationListener.GetProjectConfigurationDirectory(m_propertyTable), Is.EqualTo(projectConfigDir), "did not return expected directory");

                m_propertyTable.SetProperty("currentContentControl", "reversalToolEditComplete", true);
                projectConfigDir = Path.Combine(LcmFileHelper.GetConfigSettingsDir(Cache.ProjectId.ProjectFolder), "ReversalIndex");
                Assert.That(DictionaryConfigurationListener.GetProjectConfigurationDirectory(m_propertyTable), Is.EqualTo(projectConfigDir), "did not return expected directory");

                m_propertyTable.SetProperty("currentContentControl", "somethingElse", true);
                Assert.IsNull(DictionaryConfigurationListener.GetProjectConfigurationDirectory(m_propertyTable), "Other areas should cause null return");
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates a DictionaryConfigurationModel with one Main and one of each neeeded Minor Entry nodes, all with enabled HeadWord children
        /// </summary>
        internal static DictionaryConfigurationModel CreateInterestingConfigurationModel(LcmCache cache, PropertyTable propertyTable        = null,
                                                                                         DictionaryConfigurationModel.ConfigType configType = DictionaryConfigurationModel.ConfigType.Root)
        {
            var mainHeadwordNode = new ConfigurableDictionaryNode
            {
                FieldDescription      = "HeadWord",
                CSSClassNameOverride  = "entry",
                DictionaryNodeOptions = GetWsOptionsForLanguages(new[] { "fr" }),
                Before = "MainEntry: ",
            };
            var subEntryNode = new ConfigurableDictionaryNode
            {
                Children = new List <ConfigurableDictionaryNode> {
                    mainHeadwordNode
                },
                FieldDescription = "Subentries"
            };
            var mainEntryNode = new ConfigurableDictionaryNode
            {
                Children = new List <ConfigurableDictionaryNode> {
                    mainHeadwordNode
                },
                FieldDescription = "LexEntry"
            };

            if (configType == DictionaryConfigurationModel.ConfigType.Hybrid || configType == DictionaryConfigurationModel.ConfigType.Root)
            {
                mainEntryNode.Children.Add(subEntryNode);
            }
            if (configType == DictionaryConfigurationModel.ConfigType.Hybrid || configType == DictionaryConfigurationModel.ConfigType.Lexeme)
            {
                mainEntryNode.DictionaryNodeOptions = GetFullyEnabledListOptions(cache, DictionaryNodeListOptions.ListIds.Complex);
            }

            CssGeneratorTests.PopulateFieldsForTesting(mainEntryNode);

            var minorEntryNode = mainEntryNode.DeepCloneUnderSameParent();

            minorEntryNode.CSSClassNameOverride = "minorentry";
            minorEntryNode.Before = "MinorEntry: ";
            minorEntryNode.DictionaryNodeOptions = GetFullyEnabledListOptions(cache, DictionaryNodeListOptions.ListIds.Complex);

            var minorSecondNode = minorEntryNode.DeepCloneUnderSameParent();

            minorSecondNode.Before = "HalfStep: ";
            minorSecondNode.DictionaryNodeOptions = GetFullyEnabledListOptions(cache, DictionaryNodeListOptions.ListIds.Variant);

            var model = new DictionaryConfigurationModel
            {
                AllPublications = true,
                Parts           = new List <ConfigurableDictionaryNode> {
                    mainEntryNode, minorEntryNode, minorSecondNode
                },
                FilePath = propertyTable == null ? null : Path.Combine(DictionaryConfigurationListener.GetProjectConfigurationDirectory(propertyTable),
                                                                       "filename" + DictionaryConfigurationModel.FileExtension),
                IsRootBased = configType == DictionaryConfigurationModel.ConfigType.Root
            };

            if (configType != DictionaryConfigurationModel.ConfigType.Root)
            {
                model.Parts.Remove(minorEntryNode);
            }

            return(model);
        }
Ejemplo n.º 12
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);
        }