/// <summary>
        /// Create a zip file containing a dictionary configuration for the user to share, into destinationZipPath. LT-17397.
        /// </summary>
        internal static void ExportConfiguration(DictionaryConfigurationModel configurationToExport, string destinationZipPath, FdoCache cache)
        {
            if (configurationToExport == null)
            {
                throw new ArgumentNullException("configurationToExport");
            }
            if (destinationZipPath == null)
            {
                throw new ArgumentNullException("destinationZipPath");
            }
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }
            if (destinationZipPath == string.Empty)
            {
                throw new ArgumentException("destinationDirectory");
            }

            using (var zip = new ZipFile())
            {
                zip.AddFile(configurationToExport.FilePath, "/");
                PrepareCustomFieldsExport(cache).ForEach(file => zip.AddFile(file, "/"));
                zip.AddFile(PrepareStylesheetExport(cache), "/");
                zip.Save(destinationZipPath);
            }
        }
Пример #2
0
        public void PrepareImport_SuggestsUniqueLabelIfSameLabelAlreadyExists()
        {
            // More test setup

            var alreadyExistingModelWithSameLabel = new DictionaryConfigurationModel
            {
                Label        = configLabel,
                Publications = new List <string>(),
            };
            var anotherAlreadyExistingModel = new DictionaryConfigurationModel
            {
                Label        = "importexportConfiguration-Imported1",
                Publications = new List <string>(),
            };

            _controller._configurations.Add(alreadyExistingModelWithSameLabel);
            _controller._configurations.Add(anotherAlreadyExistingModel);

            // SUT
            _controller.PrepareImport(_zipFile);

            Assert.That(_controller._originalConfigLabel, Is.EqualTo(configLabel),
                        "This should have been the original label of the config to import.");
            Assert.That(_controller.NewConfigToImport.Label, Is.EqualTo("importexportConfiguration-Imported2"),
                        "This should be a new and different label since the original label is already taken.");
        }
        /// <summary>
        /// Helper.
        /// </summary>
        public UploadToWebonaryModel SetUpModel()
        {
            ConfiguredXHTMLGenerator.AssemblyFile = "xWorksTests";

            var testConfig = new Dictionary <string, DictionaryConfigurationModel>();

            testConfig["Test Config"] = new DictionaryConfigurationModel
            {
                Parts = new List <ConfigurableDictionaryNode> {
                    new ConfigurableDictionaryNode {
                        FieldDescription = "SIL.FieldWorks.XWorks.TestRootClass"
                    }
                }
            };

            return(new UploadToWebonaryModel(m_mediator)
            {
                SiteName = "site",
                UserName = "******",
                Password = "******",
                SelectedPublication = "Test publication",
                SelectedConfiguration = "Test Config",
                Configurations = testConfig
            });
        }
Пример #4
0
        private string UserRequestsOverwrite_Helper()
        {
            // This model has the same label but a non-colliding filename. Proves overwrite the code will always overwrite.
            var alreadyExistingModelWithSameLabel = new DictionaryConfigurationModel
            {
                Label        = configLabel,
                Publications = new List <string> {
                    "Main Dictionary", "unknown pub 1", "unknown pub 2"
                },
                FilePath = Path.Combine(_projectConfigPath, "Different" + configFilename)
            };

            FileUtils.WriteStringtoFile(alreadyExistingModelWithSameLabel.FilePath, "arbitrary file content", Encoding.UTF8);
            var anotherAlreadyExistingModel = new DictionaryConfigurationModel
            {
                Label        = "importexportConfiguration-Imported1",
                Publications = new List <string> {
                    "Main Dictionary", "unknown pub 1", "unknown pub 2"
                },
                FilePath = Path.GetTempPath() + configFilename
            };

            DictionaryConfigurationManagerController.GenerateFilePath(_projectConfigPath, _controller._configurations,
                                                                      anotherAlreadyExistingModel);
            FileUtils.WriteStringtoFile(anotherAlreadyExistingModel.FilePath, "arbitrary file content", Encoding.UTF8);

            _controller._configurations.Add(alreadyExistingModelWithSameLabel);
            _controller._configurations.Add(anotherAlreadyExistingModel);

            _controller.PrepareImport(_zipFile);

            return(alreadyExistingModelWithSameLabel.FilePath);
        }
Пример #5
0
 public HeadwordNumbersController(IHeadwordNumbersView view, DictionaryConfigurationModel model, LcmCache cache)
 {
     if (view == null || model == null || cache == null)
     {
         throw new ArgumentNullException();
     }
     _view             = view;
     _model            = model;
     _cache            = cache;
     _homographConfig  = GetHeadwordConfiguration();
     _view.Description = string.Format(xWorksStrings.ConfigureHomograph_ConfigDescription,
                                       model.IsReversal ? xWorksStrings.ReversalIndex : xWorksStrings.Dictionary,
                                       Environment.NewLine,
                                       model.Label);
     _view.SetWsFactoryForCustomDigits(cache.WritingSystemFactory);
     _view.AvailableWritingSystems = cache.LangProject.CurrentAnalysisWritingSystems.Union(cache.LangProject.CurrentVernacularWritingSystems);
     _view.CustomDigits            = _homographConfig.CustomHomographNumberList;
     if (_cache.LangProject.AllWritingSystems.Any(ws => ws.Id == _homographConfig.HomographWritingSystem))
     {
         _view.HomographWritingSystem = string.IsNullOrEmpty(_homographConfig.HomographWritingSystem)
                                 ? null
                                 : _cache.LangProject.AllWritingSystems.First(ws => ws.Id == _homographConfig.HomographWritingSystem).DisplayLabel;
     }
     else
     {
         _view.HomographWritingSystem = _cache.LangProject.AllWritingSystems.First().DisplayLabel;
     }
     _view.HomographBefore         = _homographConfig.HomographNumberBefore;
     _view.ShowHomograph           = _homographConfig.ShowHwNumber;
     _view.ShowHomographOnCrossRef = _model.IsReversal ? _homographConfig.ShowHwNumInReversalCrossRef : _homographConfig.ShowHwNumInCrossRef;
     _view.ShowSenseNumber         = _model.IsReversal ? _homographConfig.ShowSenseNumberReversal : _homographConfig.ShowSenseNumber;
     _view.OkButtonEnabled         = _homographConfig.CustomHomographNumberList == null ||
                                     !_homographConfig.CustomHomographNumberList.Any() || _homographConfig.CustomHomographNumberList.Count == 10;
     _view.CustomDigitsChanged += OnViewCustomDigitsChanged;
 }
Пример #6
0
        /// <summary>
        /// This method will copy configuration node values from newDefaultModelPath over the matching nodes in oldDefaultModelPath.
        /// </summary>
        /// <remarks>Intended to be used only on defaults, not on data with user changes.</remarks>
        internal static DictionaryConfigurationModel LoadConfigWithCurrentDefaults(string oldDefaultModelPath, LcmCache cache, string newDefaultPath)
        {
            var oldDefaultConfigs = new DictionaryConfigurationModel(oldDefaultModelPath, cache);
            var newDefaultConfigs = new DictionaryConfigurationModel(newDefaultPath, cache);

            return(LoadConfigWithCurrentDefaults(oldDefaultConfigs, newDefaultConfigs));
        }
Пример #7
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>";
            }
        }
Пример #8
0
        /// <summary>
        /// When a user selects a Reversal Index configuration in the Reversal Indexes area
        /// to describe how to arrange and show their
        /// reversal index entries, or in the
        /// Bulk Edit Reversal Entries area, we also need to set the Reversal Index Guid property to set which
        /// set of reversal index entries should be shown in the XhtmlDocView.
        /// Do that.
        /// </summary>
        public static void SetReversalIndexGuidBasedOnReversalIndexConfiguration(PropertyTable propertyTable, LcmCache cache)
        {
            var reversalIndexConfiguration = propertyTable.GetStringProperty("ReversalIndexPublicationLayout", string.Empty);

            if (string.IsNullOrEmpty(reversalIndexConfiguration))
            {
                return;
            }

            var model = new DictionaryConfigurationModel(reversalIndexConfiguration, cache);
            var reversalIndexConfigWritingSystemLanguage = model.WritingSystem;

            var currentAnalysisWsList = cache.LanguageProject.AnalysisWritingSystems;
            var wsObj = currentAnalysisWsList.FirstOrDefault(ws => ws.Id == reversalIndexConfigWritingSystemLanguage);

            if (wsObj == null || wsObj.DisplayLabel.ToLower().Contains("audio"))
            {
                return;
            }
            var riRepo     = cache.ServiceLocator.GetInstance <IReversalIndexRepository>();
            var mHvoRevIdx = riRepo.FindOrCreateIndexForWs(wsObj.Handle).Hvo;
            var revGuid    = cache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(mHvoRevIdx).Guid;

            propertyTable.SetProperty("ReversalIndexGuid", revGuid.ToString(), true);
            propertyTable.SetPropertyPersistence("ReversalIndexGuid", true);
        }
Пример #9
0
        internal static void SetWritingSystemForReversalModel(DictionaryConfigurationModel convertedModel, LcmCache cache)
        {
            if (!convertedModel.IsReversal || !string.IsNullOrEmpty(convertedModel.WritingSystem))             // don't change existing WS's
            {
                return;
            }
            var writingSystem = cache.ServiceLocator.WritingSystems.AnalysisWritingSystems
                                .Where(x => x.DisplayLabel == convertedModel.Label).Select(x => x.IcuLocale).FirstOrDefault();

            // If the label didn't get us a writing system then we need to attempt to extract the writing system from the filename
            if (writingSystem == null)
            {
                // old copies looked like this 'my name-French-#frenc343.extension'
                var fileParts = convertedModel.FilePath.Split('-');
                if (fileParts.Length == 3)
                {
                    writingSystem = cache.ServiceLocator.WritingSystems.AnalysisWritingSystems
                                    .Where(x => x.DisplayLabel == fileParts[1]).Select(x => x.IcuLocale).FirstOrDefault();
                }
                else
                {
                    writingSystem = "";
                }
            }
            convertedModel.WritingSystem = writingSystem;
        }
Пример #10
0
        public void Save_SetsModelContents()
        {
            var testConfig = new DictionaryHomographConfiguration
            {
                HomographNumberBefore = true,
                ShowHwNumInCrossRef   = false,
                ShowSenseNumber       = false,
            };
            var view = new TestHeadwordNumbersView {
                HomographBefore = false, ShowHomograph = true, ShowSenseNumber = true
            };
            var model = new DictionaryConfigurationModel {
                HomographConfiguration = testConfig
            };
            // ReSharper disable once UnusedVariable
            var testController = new HeadwordNumbersController(view, model, Cache);

            view.Show();
            view.HomographBefore         = false;
            view.ShowHomographOnCrossRef = true;
            view.ShowSenseNumber         = true;
            // SUT
            testController.Save();
            // Verify save in Dictionary Config
            Assert.IsFalse(model.HomographConfiguration.HomographNumberBefore);
            Assert.IsTrue(model.HomographConfiguration.ShowHwNumInCrossRef);
            Assert.IsTrue(model.HomographConfiguration.ShowSenseNumber);
        }
        /// <summary>Returns a deep clone of this DCM. Caller is responsible to choose a unique FilePath</summary>
        public DictionaryConfigurationModel DeepClone()
        {
            var clone = new DictionaryConfigurationModel();

            // Copy everything over at first, importantly handling strings and primitives.
            var properties = typeof(DictionaryConfigurationModel).GetProperties();

            foreach (var property in properties.Where(prop => prop.CanWrite))             // Skip any read-only properties
            {
                var originalValue = property.GetValue(this, null);
                property.SetValue(clone, originalValue, null);
            }

            // Deep-clone SharedItems
            if (SharedItems != null)
            {
                clone.SharedItems = SharedItems.Select(node => node.DeepCloneUnderParent(null, true)).ToList();
            }

            // Deep-clone Parts
            if (Parts != null)
            {
                clone.Parts = Parts.Select(node => node.DeepCloneUnderParent(null, true)).ToList();
                SpecifyParentsAndReferences(clone.Parts, clone.SharedItems);
            }

            // Clone Publications
            if (Publications != null)
            {
                clone.Publications = new List <string>(Publications);
            }

            return(clone);
        }
Пример #12
0
 public int CountDictionaryEntries(DictionaryConfigurationModel config)
 {
     int[] entries;
     using (ClerkActivator.ActivateClerkMatchingExportType(DictionaryType, m_mediator))
         ConfiguredXHTMLGenerator.GetPublicationDecoratorAndEntries(m_mediator, out entries, DictionaryType);
     return(entries.Count(e => IsGenerated(m_cache, config, e)));
 }
 private static bool IsAllReversalIndexConfig(DictionaryConfigurationModel configurationToDelete)
 {
     if (Path.GetFileNameWithoutExtension(configurationToDelete.FilePath) == "AllReversalIndexes")
     {
         return(true);
     }
     return(false);
 }
Пример #14
0
 private void ClearValuesOnError()
 {
     ImportHappened                 = false;
     NewConfigToImport              = null;
     _originalConfigLabel           = null;
     _temporaryImportConfigLocation = null;
     _newPublications               = null;
 }
Пример #15
0
 public void SelectConfiguration(DictionaryConfigurationModel configuration)
 {
     m_cbDictConfig.SelectedItem = configuration;
     if (treeControl.Tree.Nodes.Count > 0)
     {
         treeControl.Tree.Nodes[0].Expand();
     }
 }
 /// <summary>Get list of publications using a dictionary configuration.</summary>
 internal List <string> GetPublications(DictionaryConfigurationModel dictionaryConfiguration)
 {
     if (dictionaryConfiguration == null)
     {
         throw new ArgumentNullException();
     }
     return(dictionaryConfiguration.Publications);
 }
Пример #17
0
        public void ConstructorRejectsNulls()
        {
            var view  = new TestHeadwordNumbersView();
            var model = new DictionaryConfigurationModel();

            Assert.Throws <ArgumentNullException>(() => new HeadwordNumbersController(view, model, null));
            Assert.Throws <ArgumentNullException>(() => new HeadwordNumbersController(null, model, Cache));
            Assert.Throws <ArgumentNullException>(() => new HeadwordNumbersController(view, null, Cache));
        }
Пример #18
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);
     }
 }
Пример #19
0
        /// <summary>
        /// Determines how many times the entry with the given HVO is generated for the given config (usually 0 or 1,
        /// but can be more if the entry matches more than one Minor Entry node)
        /// </summary>
        internal static bool IsGenerated(FdoCache cache, DictionaryConfigurationModel config, int hvo)
        {
            var entry = (ILexEntry)cache.ServiceLocator.GetObject(hvo);

            if (ConfiguredXHTMLGenerator.IsMainEntry(entry, config))
            {
                return(config.Parts[0].IsEnabled && (!entry.ComplexFormEntryRefs.Any() || ConfiguredXHTMLGenerator.IsListItemSelectedForExport(config.Parts[0], entry)));
            }
            return(entry.PublishAsMinorEntry && config.Parts.Skip(1).Any(part => ConfiguredXHTMLGenerator.IsListItemSelectedForExport(part, entry)));
        }
Пример #20
0
 /// <summary>
 /// This method will copy configuration node values from newDefaultConfigs over the matching nodes in oldDefaultConfigs
 /// </summary>
 /// <remarks>Intended to be used only on defaults, not on data with user changes.</remarks>
 internal static DictionaryConfigurationModel LoadConfigWithCurrentDefaults(DictionaryConfigurationModel oldDefaultConfigs,
                                                                            DictionaryConfigurationModel newDefaultConfigs)
 {
     foreach (var partNode in oldDefaultConfigs.Parts)
     {
         OverwriteDefaultsWithMatchingNode(partNode, newDefaultConfigs.Parts);
     }
     oldDefaultConfigs.FilePath = newDefaultConfigs.FilePath;
     oldDefaultConfigs.Label    = newDefaultConfigs.Label;
     return(oldDefaultConfigs);
 }
Пример #21
0
        private void ExportConfiguredXhtml(string xhtmlPath, DictionaryConfigurationModel configuration, string exportType, IThreadedProgress progress)
        {
            int[] entriesToSave;
            var   publicationDecorator = ConfiguredXHTMLGenerator.GetPublicationDecoratorAndEntries(m_mediator, out entriesToSave, exportType);

            if (progress != null)
            {
                progress.Maximum = entriesToSave.Length;
            }
            ConfiguredXHTMLGenerator.SavePublishedHtmlWithStyles(entriesToSave, publicationDecorator, int.MaxValue, configuration, m_mediator, xhtmlPath, progress);
        }
        /// <summary>
        /// Whether a configuration is, or is a customization of, a shipped default configuration,
        /// such as the shipped Root-based, Lexeme-based, or Bartholomew configurations.
        /// </summary>
        public static bool IsConfigurationACustomizedShippedDefault(DictionaryConfigurationModel configuration, string defaultConfigDir)
        {
            if (configuration.FilePath == null)
            {
                return(false);
            }

            var defaultConfigurationFiles = FileUtils.GetFilesInDirectory(defaultConfigDir).Select(Path.GetFileName);

            var filename = Path.GetFileName(configuration.FilePath);

            return(defaultConfigurationFiles.Contains(filename));
        }
Пример #23
0
        public void KnowsWhenIsAShippedDefault()
        {
            var configuration = new DictionaryConfigurationModel
            {
                Label    = "configuration",
                FilePath = Path.Combine("whateverdir", "Root" + DictionaryConfigurationModel.FileExtension)
            };

            // SUT
            var claimsToBeDerived = _controller.IsConfigurationACustomizedOriginal(configuration);

            Assert.That(claimsToBeDerived, Is.True, "Should have reported this as a shipped default configuration.");
        }
Пример #24
0
        public void NotAShippedDefaultIfNullFilePath()
        {
            var configuration = new DictionaryConfigurationModel
            {
                Label    = "configuration",
                FilePath = null
            };

            // SUT
            var claimsToBeDerived = _controller.IsConfigurationACustomizedOriginal(configuration);

            Assert.That(claimsToBeDerived, Is.False, "Should not have reported this as a shipped default configuration.");
        }
Пример #25
0
        public void ConstructorSetsDescriptionTextInView_Reversal()
        {
            var view  = new TestHeadwordNumbersView();
            var model = new DictionaryConfigurationModel {
                WritingSystem = "en", Label = "PrincePauper"
            };
            // ReSharper disable once UnusedVariable
            // SUT
            var testController = new HeadwordNumbersController(view, model, Cache);

            Assert.That(view.Description, Is.StringContaining("Reversal Index"), "Description should say current 'Reversal Index' configuration");
            Assert.That(view.Description, Is.StringContaining("PrincePauper"), "Description should include the current configuration label");
        }
Пример #26
0
        public void ConstructorSetsDefaultWritingSystemInView()
        {
            var view  = new TestHeadwordNumbersView();
            var model = new DictionaryConfigurationModel {
                HomographConfiguration = new DictionaryHomographConfiguration {
                    HomographWritingSystem = "pt"
                }
            };
            // SUT
            var testController = new HeadwordNumbersController(view, model, Cache);

            Assert.That(view.HomographWritingSystem, Is.StringContaining("English"),
                        "The default writing system 'English' should be in the view when given HomographWritingSystem is missing.");
        }
Пример #27
0
        public void ReversalOfInvalidLanguageIsNotACustomizedOriginal()
        {
            var configuration = new DictionaryConfigurationModel
            {
                Label         = "English",
                WritingSystem = "enz1a",
                FilePath      = Path.Combine("whateverdir", "enz1a" + DictionaryConfigurationModel.FileExtension)
            };

            // SUT
            var claimsToBeDerived = _controller.IsConfigurationACustomizedOriginal(configuration);

            Assert.That(claimsToBeDerived, Is.False, "Should have reported this as a shipped default configuration.");
        }
Пример #28
0
        public void ReversalOfLanguageWithRegionIsACustomizedOriginal()
        {
            var configuration = new DictionaryConfigurationModel
            {
                Label         = "German (Algeria)",
                WritingSystem = "de-DZ",
                FilePath      = Path.Combine("whateverdir", "de-DZ" + DictionaryConfigurationModel.FileExtension)
            };

            // SUT
            var claimsToBeDerived = _controller.IsConfigurationACustomizedOriginal(configuration);

            Assert.That(claimsToBeDerived, Is.True, "Should have reported this as a shipped default configuration.");
        }
Пример #29
0
        public void ReversalNotMatchingLanguageIsACustomizedOriginal()
        {
            var configuration = new DictionaryConfigurationModel
            {
                Label         = "English (copy)",
                WritingSystem = "en",
                FilePath      = Path.Combine("whateverdir", "English-Copy" + DictionaryConfigurationModel.FileExtension)
            };

            // SUT
            var claimsToBeDerived = _controller.IsConfigurationACustomizedOriginal(configuration);

            Assert.That(claimsToBeDerived, Is.False, "This is a copy and not a customized original and should have reported false.");
        }
Пример #30
0
        public void ReversalCopyIsNotACustomizedOriginal()
        {
            var configuration = new DictionaryConfigurationModel
            {
                Label         = "English Copy",
                WritingSystem = "en",
                FilePath      = Path.Combine("whateverdir", "Copy of English" + DictionaryConfigurationModel.FileExtension)
            };

            // SUT
            var claimsToBeDerived = _controller.IsConfigurationACustomizedOriginal(configuration);

            Assert.That(claimsToBeDerived, Is.False, "Copy of a reversal should not claim to be a customized original");
        }