public void TestThatSharedSettingOpensXmlDataTypeAsSharedXml() { const string dbName = "ProjectSharingTest"; SureRemoveDb(dbName); var preExistingDirs = new List <string>(Directory.GetDirectories(m_projectsDirectory)); try { // create project string dbFileName = LcmCache.CreateNewLangProj(new DummyProgressDlg(), dbName, m_lcmDirectories, new SingleThreadedSynchronizeInvoke()); // Set up test file for project sharing setting var testFileStore = new FileSettingsStore(LexiconSettingsFileHelper.GetProjectLexiconSettingsPath(Path.GetDirectoryName(dbFileName))); var dataMapper = new ProjectLexiconSettingsDataMapper(testFileStore); dataMapper.Write(new ProjectLexiconSettings { ProjectSharing = true }); // SUT // Request XML backend with project settings that have ProjectSharing set to true var projectId = new TestProjectId(BackendProviderType.kXML, dbFileName); using (var cache = LcmCache.CreateCacheFromExistingData(projectId, "en", m_ui, m_lcmDirectories, new LcmSettings(), new DummyProgressDlg())) { var dataSetup = cache.ServiceLocator.GetInstance <IDataSetup>(); Assert.IsTrue(dataSetup is SharedXMLBackendProvider, "The project should have been opened as shared xml."); } } finally { RemoveTestDirs(preExistingDirs, Directory.GetDirectories(m_projectsDirectory)); } }
// public MonoDevelop.Projects.CodeGeneration.CodeGenerator CreateCodeGenerator () // { // return MonoDevelop.Projects.CodeGeneration.CodeGenerator.CreateGenerator (Editor.Document.MimeType, // Editor.Options.TabsToSpaces, Editor.Options.TabSize, Editor.EolMarker); // } /// <summary> /// If the document shouldn't restore the settings after the load it can be disabled with this method. /// That is useful when opening a document and programmatically scrolling to a specified location. /// </summary> public void DisableAutoScroll() { if (IsFile) { FileSettingsStore.Remove(FileName); } }
/// <summary> /// Gets the display name of the storage location for an <see cref="ISettingsStore"/> /// instance. This includes optional flags. /// </summary> /// <param name="settingsStore">The settings store instance of which to return the location.</param> /// <returns></returns> public static string GetLocationDisplayName(this ISettingsStore settingsStore) { if (settingsStore == null) { throw new ArgumentNullException("settingsStore"); } FileSettingsStore fileStore = settingsStore as FileSettingsStore; if (fileStore != null) { return(fileStore.FileName + (fileStore.IsReadOnly ? " [RO]" : "") + (fileStore.IsEncrypted ? " [ENC]" : "")); } RegistrySettingsStore registryStore = settingsStore as RegistrySettingsStore; if (registryStore != null) { return((registryStore.IsGlobal ? "HKEY_LOCAL_MACHINE" : "HKEY_CURRENT_USER") + "\\" + registryStore.BaseKey + (registryStore.IsReadOnly ? " [RO]" : "")); } return(settingsStore.ToString()); }
public void FileSettingsStoreEmptyFallback() { File.Delete("fallback.conf"); using (var store = new FileSettingsStore("fallback.conf")) { CommonMethods.EmptyFallback(store); } }
public void FileSettingsStoreRemovePattern() { File.Delete("pattern.conf"); using (var store = new FileSettingsStore("pattern.conf")) { CommonMethods.RemovePattern(store); } }
/// <summary/> public static bool IsProjectSharingEnabled(string projectFolder) { ISettingsStore settingStore = new FileSettingsStore(LexiconSettingsFileHelper.GetProjectLexiconSettingsPath(projectFolder)); var settingsMapper = new ProjectLexiconSettingsDataMapper(settingStore); var settings = new ProjectLexiconSettings(); settingsMapper.Read(settings); return settings.ProjectSharing; }
public void RunFile() { File.Delete("settings.xml"); File.Delete("settings.xml.bak"); ISettingsStore settingsStore = new FileSettingsStore("settings.xml"); IAppSettings settings = SettingsAdapterFactory.New<IAppSettings>(settingsStore); AccessSettings(settingsStore, settings); settings.SettingsStore.Dispose(); }
public void RunFile() { File.Delete("settings.xml"); File.Delete("settings.xml.bak"); ISettingsStore settingsStore = new FileSettingsStore("settings.xml"); IAppSettings settings = SettingsAdapterFactory.New <IAppSettings>(settingsStore); AccessSettings(settingsStore, settings); settings.SettingsStore.Dispose(); }
public void WriteComplexState() { var state = new State(1, "<<something weird<> which breaks xml {}"); var store = new FileSettingsStore(new NullLogger()); store.Save("wierdfile", state); var restored = store.Load("wierdfile"); restored.Should().Be(state); }
public void WriteState() { var state = new State(1, "Test"); var store = new FileSettingsStore(new NullLogger()); store.Save("testfile", state); var restored = store.Load("testfile"); restored.Should().Be(state); }
/// <summary> /// Gets the display name of the storage location for an <see cref="ISettingsStore"/> /// instance. This includes optional flags. /// </summary> /// <param name="settingsStore">The settings store instance of which to return the location.</param> /// <returns></returns> public static string GetLocationDisplayName(this ISettingsStore settingsStore) { if (settingsStore == null) { throw new ArgumentNullException("settingsStore"); } FileSettingsStore fileStore = settingsStore as FileSettingsStore; if (fileStore != null) { return(fileStore.FileName + (fileStore.IsReadOnly ? " [RO]" : "") + (fileStore.IsEncrypted ? " [ENC]" : "")); } return(settingsStore.ToString()); }
/// <summary> /// Returns an object for the specified interface type with a backing file store. /// </summary> /// <typeparam name="TSettings">The settings interface type to implement.</typeparam> /// <param name="directory">The directory in the application data base directory. May /// include backslashes or slashes for subdirectories.</param> /// <param name="fileName">The settings file name.</param> /// <param name="userLevel">Specifies whether a user-level path is returned instead of a /// system-level path.</param> /// <param name="readOnly">true to open the settings file in read-only mode. This prevents /// any write access to the settings and will never save the file back.</param> /// <returns></returns> /// <remarks> /// This method generates platform-default paths for Windows (%AppData% and %ProgramData%) /// and Unix/Linux systems ($HOME/.* and /etc). /// </remarks> public static TSettings NewFile <TSettings>(string directory, string fileName, bool userLevel, bool readOnly) where TSettings : class { string path; if (userLevel) { path = GetAppDataPath(directory, fileName); } else { path = GetProgramDataPath(directory, fileName); } FileSettingsStore store = new FileSettingsStore(path, readOnly); return(SettingsAdapterFactory.New <TSettings>(store)); }
public void FileSettingsStoreAdapter() { File.Delete("adapter.conf"); using (var store = new FileSettingsStore("adapter.conf")) { IAppSettings settings = SettingsAdapterFactory.New<IAppSettings>(store); Assert.IsNotNull(settings); CommonMethods.AdapterEmptyDefault(settings); CommonMethods.AdapterSet(settings); CommonMethods.AdapterGetTest(settings); } using (var store = new FileSettingsStore("adapter.conf")) { IAppSettings settings = SettingsAdapterFactory.New<IAppSettings>(store); Assert.IsNotNull(settings); CommonMethods.AdapterGetTest(settings); } }
public void FileSettingsStoreAdapter() { File.Delete("adapter.conf"); using (var store = new FileSettingsStore("adapter.conf")) { IAppSettings settings = SettingsAdapterFactory.New <IAppSettings>(store); Assert.IsNotNull(settings); CommonMethods.AdapterEmptyDefault(settings); CommonMethods.AdapterSet(settings); CommonMethods.AdapterGetTest(settings); } using (var store = new FileSettingsStore("adapter.conf")) { IAppSettings settings = SettingsAdapterFactory.New <IAppSettings>(store); Assert.IsNotNull(settings); CommonMethods.AdapterGetTest(settings); } }
public void FileSettingsStoreSetGet() { File.Delete("setget.conf"); using (var store = new FileSettingsStore("setget.conf")) { CommonMethods.Set1(store); CommonMethods.GetTest1(store); } using (var store = new FileSettingsStore("setget.conf")) { CommonMethods.GetTest1(store); } using (var store = new FileSettingsStore("setget.conf")) { CommonMethods.Set2(store); CommonMethods.GetTest2(store); } using (var store = new FileSettingsStore("setget.conf")) { CommonMethods.GetTest2(store); } }
void ScrollToRequestedCaretLocation(Document doc, FileOpenInformation info) { if (info.Line < 1 && info.Offset < 0) { return; } if (editorOperationsFactoryService == null) { editorOperationsFactoryService = CompositionManager.Instance.GetExportedValue <IEditorOperationsFactoryService> (); } FileSettingsStore.Remove(doc.FileName); doc.DisableAutoScroll(); doc.RunWhenContentAdded <ITextView> (textView => { var ipos = doc.Editor; if (ipos != null) { var loc = new DocumentLocation(info.Line, info.Column >= 1 ? info.Column : 1); if (info.Offset >= 0) { loc = ipos.OffsetToLocation(info.Offset); } if (loc.IsEmpty) { return; } ipos.SetCaretLocation(loc, info.Options.HasFlag(OpenDocumentOptions.HighlightCaretLine), info.Options.HasFlag(OpenDocumentOptions.CenterCaretLine)); } else { var offset = info.Offset; if (offset < 0) { var line = textView.TextSnapshot.GetLineFromLineNumber(info.Line - 1); if (info.Column >= 1) { offset = line.Start + info.Column - 1; } else { offset = line.Start; } } if (editorOperationsFactoryService != null) { var editorOperations = editorOperationsFactoryService.GetEditorOperations(textView); var point = new VirtualSnapshotPoint(textView.TextSnapshot, offset); editorOperations.SelectAndMoveCaret(point, point, TextSelectionMode.Stream, EnsureSpanVisibleOptions.AlwaysCenter); } else { LoggingService.LogError("Missing editor operations"); } } }); /* var navigator = (ISourceFileNavigator)newContent.GetContent (typeof (ISourceFileNavigator)); * if (fileInfo.Offset >= 0) * navigator.JumpToOffset (fileInfo.Offset); * else * navigator.JumpToLine (fileInfo.Line, fileInfo.Column);*/ }
void ScrollToRequestedCaretLocation(Document doc, FileOpenInformation info) { if (info.Line < 1 && info.Offset < 0) { return; } if (editorOperationsFactoryService == null) { editorOperationsFactoryService = CompositionManager.Instance.GetExportedValue <IEditorOperationsFactoryService> (); } FileSettingsStore.Remove(doc.FileName); doc.DisableAutoScroll(); doc.RunWhenContentAdded <ITextView> (textView => { var ipos = doc.Editor; if (ipos != null) { var loc = new DocumentLocation(info.Line, info.Column >= 1 ? info.Column : 1); if (info.Offset >= 0) { loc = ipos.OffsetToLocation(info.Offset); } if (loc.IsEmpty) { return; } ipos.SetCaretLocation(loc, info.Options.HasFlag(OpenDocumentOptions.HighlightCaretLine), info.Options.HasFlag(OpenDocumentOptions.CenterCaretLine)); } else { var offset = info.Offset; if (offset < 0) { try { if (info.Line - 1 > (textView?.TextSnapshot?.LineCount ?? 0)) { LoggingService.LogInfo($"ScrollToRequestedCaretLocation line was over the snapshot's line count. " + $"Called with {info.Line - 1} but line count was {textView?.TextSnapshot?.LineCount}"); return; } var line = textView.TextSnapshot.GetLineFromLineNumber(info.Line - 1); if (info.Column >= 1) { offset = line.Start + Math.Min(info.Column - 1, line.Length); } else { offset = line.Start; } } catch (ArgumentException ae) { LoggingService.LogError($"Calling GetLineFromLineNumber resulted in an argument exception." + $"We tried calling with line number: {info.Line - 1}", ae); // we should just abort in this case, since we can't really do anything return; } } if (editorOperationsFactoryService != null) { var editorOperations = editorOperationsFactoryService.GetEditorOperations(textView); var point = new VirtualSnapshotPoint(textView.TextSnapshot, offset); editorOperations.SelectAndMoveCaret(point, point, TextSelectionMode.Stream, EnsureSpanVisibleOptions.AlwaysCenter); } else { LoggingService.LogError("Missing editor operations"); } } }); /* var navigator = (ISourceFileNavigator)newContent.GetContent (typeof (ISourceFileNavigator)); * if (fileInfo.Offset >= 0) * navigator.JumpToOffset (fileInfo.Offset); * else * navigator.JumpToLine (fileInfo.Line, fileInfo.Column);*/ }
public void PerformMigration(IDomainObjectDTORepository repoDto) { DataMigrationServices.CheckVersionNumber(repoDto, 7000070); // Skip migrating the global repository if we're just running tests. Slow and may not be wanted. // In a real project we do this first; thus if by any chance a WS is differently renamed in // the two folders, the renaming that is right for this project wins. if (!repoDto.ProjectFolder.StartsWith(Path.GetTempPath())) { var globalMigrator = new GlobalWritingSystemRepositoryMigrator(GlobalWritingSystemRepository.DefaultBasePath, versionToMigrateTo: 3); // first migrate any existing global writing systems in the new global writing system directory if (globalMigrator.NeedsMigration()) { globalMigrator.Migrate(); } string migratedFilePath = Path.Combine(LcmFileHelper.OldGlobalWritingSystemStoreDirectory, ".migrated"); if (Directory.Exists(LcmFileHelper.OldGlobalWritingSystemStoreDirectory) && !File.Exists(migratedFilePath)) { // copy over all FW global writing systems from the old directory to the new directory and migrate string globalRepoPath = Path.Combine(GlobalWritingSystemRepository.DefaultBasePath, "3"); if (!Directory.Exists(globalRepoPath)) { GlobalWritingSystemRepository.CreateGlobalWritingSystemRepositoryDirectory(globalRepoPath); } CopyDirectoryContents(LcmFileHelper.OldGlobalWritingSystemStoreDirectory, globalRepoPath); globalMigrator.Migrate(); // add ".migrated" file to indicate that this folder has been migrated already File.WriteAllText(migratedFilePath, string.Format("The writing systems in this directory have been migrated to {0}.", globalRepoPath)); } } string ldmlFolder = Path.Combine(repoDto.ProjectFolder, LcmFileHelper.ksWritingSystemsDir); var migrator = new LdmlInFolderWritingSystemRepositoryMigrator(ldmlFolder, NoteMigration, 3); migrator.Migrate(); string sharedSettingsPath = LexiconSettingsFileHelper.GetSharedSettingsPath(repoDto.ProjectFolder); if (!Directory.Exists(sharedSettingsPath)) { Directory.CreateDirectory(sharedSettingsPath); } var projectSettingsStore = new FileSettingsStore(LexiconSettingsFileHelper.GetProjectLexiconSettingsPath(repoDto.ProjectFolder)); var userSettingsStore = new FileSettingsStore(LexiconSettingsFileHelper.GetUserLexiconSettingsPath(repoDto.ProjectFolder)); var repo = new CoreLdmlInFolderWritingSystemRepository(ldmlFolder, projectSettingsStore, userSettingsStore); migrator.ResetRemovedProperties(repo); // migrate local keyboard settings from CoreImpl application settings to new lexicon user settings file // skip if we're running unit tests, could interfere with the test results string localKeyboards; if (!repoDto.ProjectFolder.StartsWith(Path.GetTempPath()) && TryGetLocalKeyboardsSetting(out localKeyboards)) { if (localKeyboards.Length > 0) { XElement keyboardsElem = XElement.Parse(localKeyboards); foreach (XElement keyboardElem in keyboardsElem.Elements("keyboard")) { var wsId = (string)keyboardElem.Attribute("ws"); CoreWritingSystemDefinition ws; if (repo.TryGet(wsId, out ws)) { var layout = (string)keyboardElem.Attribute("layout"); var locale = (string)keyboardElem.Attribute("locale"); string keyboardId = string.IsNullOrEmpty(locale) ? layout : $"{locale}_{layout}"; IKeyboardDefinition keyboard; if (!Keyboard.Controller.TryGetKeyboard(keyboardId, out keyboard)) { keyboard = Keyboard.Controller.CreateKeyboard(keyboardId, KeyboardFormat.Unknown, Enumerable.Empty <string>()); } ws.LocalKeyboard = keyboard; } } } repo.Save(); } var wsIdMigrator = new WritingSystemIdMigrator(repoDto, TryGetNewLangTag, "*.fwlayout"); wsIdMigrator.Migrate(); DataMigrationServices.IncrementVersionNumber(repoDto); }