public static void CopyProperty(this IVsWritableSettingsStore store, SettingsStoreProperty from, string toName)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var fromName       = from.Name;
            var collectionPath = from.CollectionPath;

            switch (from.Type)
            {
            case __VsSettingsType.SettingsType_String:
                ErrorHandler.ThrowOnFailure(store.GetString(collectionPath, fromName, out var stringValue));
                ErrorHandler.ThrowOnFailure(store.SetString(collectionPath, toName, stringValue));
                break;

            case __VsSettingsType.SettingsType_Int:
                ErrorHandler.ThrowOnFailure(store.GetInt(collectionPath, fromName, out var intValue));
                ErrorHandler.ThrowOnFailure(store.SetInt(collectionPath, toName, intValue));
                break;

            case __VsSettingsType.SettingsType_Int64:
                ErrorHandler.ThrowOnFailure(store.GetInt64(collectionPath, fromName, out var longValue));
                ErrorHandler.ThrowOnFailure(store.SetInt64(collectionPath, toName, longValue));
                break;

            case __VsSettingsType.SettingsType_Binary:
                uint[] actualByteLength = { 0 };
                ErrorHandler.ThrowOnFailure(store.GetBinary(collectionPath, fromName, 0, null, actualByteLength));
                byte[] bytes = new byte[actualByteLength[0]];
                ErrorHandler.ThrowOnFailure(store.GetBinary(collectionPath, fromName, actualByteLength[0], bytes, actualByteLength));
                ErrorHandler.ThrowOnFailure(store.SetBinary(collectionPath, toName, actualByteLength[0], bytes));
                break;
            }
        }
 public void WriteBytes(string name, byte[] value)
 {
     if (_settingsStore == null)
     {
         return;
     }
     _settingsStore.SetBinary(SettingsRoot, name, (uint)value.Length, value);
 }
        public static void CopyProperties(this IVsWritableSettingsStore writableSettingsStore, SettingsStoreSubCollection from, SettingsStoreSubCollection to)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var fromStore = from.Root.SettingsStore;
            var fromPath  = from.Path;
            var toPath    = to.Path;

            for (uint index = 0; ; index++)
            {
                if (ErrorHandler.Failed(fromStore.GetPropertyName(fromPath, index, out var name)))
                {
                    break;
                }

                if (ErrorHandler.Failed(fromStore.GetPropertyType(fromPath, name, out var type)))
                {
                    break;
                }

                switch ((__VsSettingsType)type)
                {
                case __VsSettingsType.SettingsType_String:
                    ErrorHandler.ThrowOnFailure(fromStore.GetString(fromPath, name, out var stringValue));
                    ErrorHandler.ThrowOnFailure(writableSettingsStore.SetString(toPath, name, stringValue));
                    break;

                case __VsSettingsType.SettingsType_Int:
                    ErrorHandler.ThrowOnFailure(fromStore.GetInt(fromPath, name, out var intValue));
                    ErrorHandler.ThrowOnFailure(writableSettingsStore.SetInt(toPath, name, intValue));
                    break;

                case __VsSettingsType.SettingsType_Int64:
                    ErrorHandler.ThrowOnFailure(fromStore.GetInt64(fromPath, name, out var longValue));
                    ErrorHandler.ThrowOnFailure(writableSettingsStore.SetInt64(toPath, name, longValue));
                    break;

                case __VsSettingsType.SettingsType_Binary:
                    uint[] actualByteLength = { 0 };
                    ErrorHandler.ThrowOnFailure(fromStore.GetBinary(fromPath, name, 0, null, actualByteLength));
                    byte[] bytes = new byte[actualByteLength[0]];
                    ErrorHandler.ThrowOnFailure(fromStore.GetBinary(fromPath, name, actualByteLength[0], bytes, actualByteLength));
                    ErrorHandler.ThrowOnFailure(writableSettingsStore.SetBinary(toPath, name, actualByteLength[0], bytes));
                    break;
                }
            }
        }
示例#4
0
        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());
        }
        public static void ShowModifyPropertyDialog(SettingsStoreProperty property, IVsWritableSettingsStore writableStore)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            switch (property.Type)
            {
            case __VsSettingsType.SettingsType_String:
            {
                Telemetry.Client.TrackPageView(nameof(EditStringDialog));
                var dialog = new EditStringDialog(property);
                if (dialog.ShowModal() == true)
                {
                    ErrorHandler.ThrowOnFailure(writableStore.SetString(property.CollectionPath, property.Name, (string)property.Value));
                    Telemetry.Client.TrackEvent("PropertyModified", new Dictionary <string, string> {
                            ["Type"] = property.Type.ToString()
                        });
                }
            }
            break;

            case __VsSettingsType.SettingsType_Int:
            {
                Telemetry.Client.TrackPageView(nameof(EditIntegerDialog) + "(32)");
                var dialog = new EditIntegerDialog("Edit DWORD (32-bit) Value", DwordToStringConverter.Instance, property);
                if (dialog.ShowModal() == true)
                {
                    ErrorHandler.ThrowOnFailure(writableStore.SetUnsignedInt(property.CollectionPath, property.Name, (uint)property.Value));
                    Telemetry.Client.TrackEvent("PropertyModified", new Dictionary <string, string> {
                            ["Type"] = property.Type.ToString()
                        });
                }
            }
            break;

            case __VsSettingsType.SettingsType_Int64:
            {
                Telemetry.Client.TrackPageView(nameof(EditIntegerDialog) + "(64)");
                var dialog = new EditIntegerDialog("Edit QWORD (64-bit) Value", QwordToStringConverter.Instance, property);
                if (dialog.ShowModal() == true)
                {
                    ErrorHandler.ThrowOnFailure(writableStore.SetUnsignedInt64(property.CollectionPath, property.Name, (ulong)property.Value));
                    Telemetry.Client.TrackEvent("PropertyModified", new Dictionary <string, string> {
                            ["Type"] = property.Type.ToString()
                        });
                }
            }
            break;

            case __VsSettingsType.SettingsType_Binary:
            {
                Telemetry.Client.TrackPageView(nameof(EditBinaryDialog));
                var dialog = new EditBinaryDialog(property);
                if (dialog.ShowModal() == true)
                {
                    var binary = (byte[])property.Value;
                    ErrorHandler.ThrowOnFailure(writableStore.SetBinary(property.CollectionPath, property.Name, (uint)binary.Length, binary));
                    Telemetry.Client.TrackEvent("PropertyModified", new Dictionary <string, string> {
                            ["Type"] = property.Type.ToString()
                        });
                }
            }
            break;

            default:
                break;
            }
        }