public void WriteString(string name, string value) { if (_settingsStore == null) { return; } int exists; _settingsStore.CollectionExists(SettingsRoot, out exists); if (exists != 1) { _settingsStore.CreateCollection(SettingsRoot); } _settingsStore.SetString(SettingsRoot, name, value); }
private void EnsureCollectionExists(string collection) { _store.CollectionExists(collection, out int ivalue); if (ivalue == 0) { _store.CreateCollection(collection); } }
public void CreateCollection(string collection) { NuGetUIThreadHelper.JoinableTaskFactory.Run(async() => { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); _store.CreateCollection(collection); }); }
/// <summary> /// Save a list of UIContext items in the settings store. /// </summary> /// <param name="settingsStore"></param> /// <param name="list"></param> /// <param name="name"></param> private void SaveContextIDList(IVsWritableSettingsStore settingsStore, ObservableCollection <UIContextInformation> list, string name) { ThreadHelper.ThrowIfNotOnUIThread(); string collectionRoot = SettingsRoot + "\\" + name; // rewrite the collection settingsStore.DeleteCollection(collectionRoot); settingsStore.CreateCollection(collectionRoot); for (int iContext = 0; iContext < list.Count; iContext++) { string guidString = list[iContext].Guid.ToString(); settingsStore.SetString(collectionRoot, guidString, list[iContext].Name); } }
public void Save(string name, object data) { int exists = 0; _writableSettingsStore.CollectionExists(_collectionName, out exists); if (exists != 1) { _writableSettingsStore.CreateCollection(_collectionName); } BinaryFormatter binaryFormatter = new BinaryFormatter(); MemoryStream memoryStream = new MemoryStream(); binaryFormatter.Serialize(memoryStream, data); _writableSettingsStore.SetBinary(_collectionName, name, (uint)memoryStream.Length, memoryStream.ToArray()); }
private void InPlaceEditSubCollectionName(SettingsStoreSubCollection subCollection, IVsWritableSettingsStore settingsStore) { _control.InPlaceEditTreeViewItem(subCollection, subCollection.Name, newName => { ThreadHelper.ThrowIfNotOnUIThread(); if (newName.Length == 0) { var uiShell = (IVsUIShell)GetService(typeof(SVsUIShell)); ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(0, Guid.Empty, "Error renaming collection", $"A collection name cannot be blank. Try again with a different name.", null, 0, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_CRITICAL, 0, out int result)); return; } if (newName.IndexOfAny(s_invalidCollectionNameChars) >= 0) { var uiShell = (IVsUIShell)GetService(typeof(SVsUIShell)); ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(0, Guid.Empty, "Error renaming collection", $"A collection name cannot contain a backslash character (\\). Try again with a different name.", null, 0, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_CRITICAL, 0, out int result)); return; } // Create a sibling and check for duplicate names. var parent = subCollection.Parent; var renamedSubCollection = new SettingsStoreSubCollection(parent, newName); if (settingsStore.CollectionExists(renamedSubCollection.Path)) { var uiShell = (IVsUIShell)GetService(typeof(SVsUIShell)); ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(0, Guid.Empty, "Error renaming collection", $"There is already a collection called '{newName}'. Try again with a different name.", null, 0, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST, OLEMSGICON.OLEMSGICON_CRITICAL, 0, out int result)); return; } // Clone and recreate the entire tree beneath this collection and then delete the original. ErrorHandler.ThrowOnFailure(settingsStore.CreateCollection(renamedSubCollection.Path)); settingsStore.CopyTree(subCollection, renamedSubCollection); ErrorHandler.ThrowOnFailure(settingsStore.DeleteCollection(subCollection.Path)); // Update the view model. subCollection.Rename(newName); // Select the newly-renamed sub-collection. _control.SetTreeViewSelection(subCollection); Telemetry.Client.TrackEvent("RenameSubCollection"); }); }
public static void CopyTree(this IVsWritableSettingsStore writableSettingsStore, SettingsStoreSubCollection from, SettingsStoreSubCollection to) { ThreadHelper.ThrowIfNotOnUIThread(); writableSettingsStore.CopyProperties(from, to); var fromStore = from.Root.SettingsStore; var fromPath = from.Path; for (uint index = 0; ; index++) { if (ErrorHandler.Failed(fromStore.GetSubCollectionName(fromPath, index, out var name))) { break; } var newSubCollection = new SettingsStoreSubCollection(to, name); ErrorHandler.ThrowOnFailure(writableSettingsStore.CreateCollection(newSubCollection.Name)); writableSettingsStore.CopyTree(new SettingsStoreSubCollection(from, name), newSubCollection); } }
public void CreateCollection(string collection) { _store.CreateCollection(collection); }