protected bool TryFetch(OptionKey optionKey, Func<RegistryKey, string, IOption, object> valueGetter, out object value)
        {
            if (this.RegistryKey == null)
            {
                throw new InvalidOperationException();
            }

            var collectionPathAndPropertyName = GetCollectionPathAndPropertyNameForOption(optionKey.Option, optionKey.Language);
            if (collectionPathAndPropertyName == null)
            {
                value = null;
                return false;
            }

            lock (Gate)
            {
                using (var subKey = this.RegistryKey.OpenSubKey(collectionPathAndPropertyName.Item1))
                {
                    if (subKey == null)
                    {
                        value = null;
                        return false;
                    }

                    value = valueGetter(subKey, collectionPathAndPropertyName.Item2, optionKey.Option);
                    return true;
                }
            }
        }
        bool IOptionSerializer.TryFetch(OptionKey optionKey, out object value)
        {
            var collectionPath = GetCollectionPathForOption(optionKey);
            if (collectionPath == null)
            {
                value = null;
                return false;
            }

            lock (_gate)
            {
                using (var subKey = this._registryKey.OpenSubKey(collectionPath))
                {
                    if (subKey == null)
                    {
                        value = null;
                        return false;
                    }

                    // Options that are of type bool have to be serialized as integers
                    if (optionKey.Option.Type == typeof(bool))
                    {
                        value = subKey.GetValue(optionKey.Option.Name, defaultValue: (bool)optionKey.Option.DefaultValue ? 1 : 0).Equals(1);
                        return true;
                    }
                    else
                    {
                        // Otherwise we can just store normally
                        value = subKey.GetValue(optionKey.Option.Name, defaultValue: optionKey.Option.DefaultValue);
                        return true;
                    }
                }
            }
        }
        protected bool TryPersist(OptionKey optionKey, object value, Action<RegistryKey, string, IOption, object> valueSetter)
        {
            // We ignore languageName, since the current use of this class is only for
            // language-specific options that apply to a single language. The underlying option
            // service has already ensured the languageName is right, so we'll drop it on the floor.
            if (this.RegistryKey == null)
            {
                throw new InvalidOperationException();
            }

            var collectionPathAndPropertyName = GetCollectionPathAndPropertyNameForOption(optionKey.Option, optionKey.Language);
            if (collectionPathAndPropertyName == null)
            {
                return false;
            }

            lock (Gate)
            {
                using (var subKey = this.RegistryKey.CreateSubKey(collectionPathAndPropertyName.Item1))
                {
                    valueSetter(subKey, collectionPathAndPropertyName.Item2, optionKey.Option, value);
                    return true;
                }
            }
        }
예제 #4
0
        protected override string GetCollectionPathForOption(OptionKey key)
        {
            if (key.Option.Feature == EditorComponentOnOffOptions.OptionName)
            {
                return @"Roslyn\Internal\OnOff\Components";
            }
            else if (key.Option.Feature == InternalFeatureOnOffOptions.OptionName)
            {
                return @"Roslyn\Internal\OnOff\Features";
            }
            else if (key.Option.Feature == PerformanceFunctionIdOptionsProvider.Name)
            {
                return @"Roslyn\Internal\Performance\FunctionId";
            }
            else if (key.Option.Feature == LoggerOptions.FeatureName)
            {
                return @"Roslyn\Internal\Performance\Logger";
            }
            else if (key.Option.Feature == InternalDiagnosticsOptions.OptionName)
            {
                return @"Roslyn\Internal\Diagnostics";
            }
            else if (key.Option.Feature == InternalSolutionCrawlerOptions.OptionName)
            {
                return @"Roslyn\Internal\SolutionCrawler";
            }
            else if (key.Option.Feature == CacheOptions.FeatureName)
            {
                return @"Roslyn\Internal\Performance\Cache";
            }

            throw ExceptionUtilities.Unreachable;
        }
        public virtual bool TryPersist(OptionKey optionKey, object value)
        {
            // We ignore languageName, since the current use of this class is only for
            // language-specific options that apply to a single language. The underlying option
            // service has already ensured the languageName is right, so we'll drop it on the floor.
            if (this.RegistryKey == null)
            {
                throw new InvalidOperationException();
            }

            var collectionPathAndPropertyName = GetCollectionPathAndPropertyNameForOption(optionKey.Option, optionKey.Language);
            if (collectionPathAndPropertyName == null)
            {
                return false;
            }

            lock (Gate)
            {
                using (var subKey = this.RegistryKey.CreateSubKey(collectionPathAndPropertyName.Item1))
                {
                    subKey.SetValue(collectionPathAndPropertyName.Item2, (bool)value ? 1 : 0, RegistryValueKind.DWord);
                }

                return true;
            }
        }
예제 #6
0
        public override OptionSet WithChangedOption(OptionKey optionAndLanguage, object value)
        {
            // make sure we first load this in current optionset
            this.GetOption(optionAndLanguage);

            return new WorkspaceOptionSet(_service, _values.SetItem(optionAndLanguage, value));
        }
            public bool TryGetDocumentOption(Document document, OptionKey option, out object value)
            {
                var editorConfigPersistence = option.Option.StorageLocations.OfType<EditorConfigStorageLocation>().SingleOrDefault();

                if (editorConfigPersistence == null)
                {
                    value = null;
                    return false;
                }

                if (_codingConventionSnapshot.TryGetConventionValue(editorConfigPersistence.KeyName, out value))
                {
                    try
                    {
                        value = editorConfigPersistence.ParseValue(value.ToString(), option.Option.Type);
                        return true;
                    }
                    catch (Exception)
                    {
                        // TODO: report this somewhere?
                        return false;
                    }
                }
                else
                {
                    return false;
                }
            }
        public virtual bool TryFetch(OptionKey optionKey, out object value)
        {
            if (this.RegistryKey == null)
            {
                throw new InvalidOperationException();
            }

            var collectionPathAndPropertyName = GetCollectionPathAndPropertyNameForOption(optionKey.Option, optionKey.Language);
            if (collectionPathAndPropertyName == null)
            {
                value = null;
                return false;
            }

            lock (Gate)
            {
                using (var openSubKey = this.RegistryKey.OpenSubKey(collectionPathAndPropertyName.Item1))
                {
                    if (openSubKey == null)
                    {
                        value = null;
                        return false;
                    }

                    value = openSubKey.GetValue(collectionPathAndPropertyName.Item2, defaultValue: (bool)optionKey.Option.DefaultValue ? 1 : 0).Equals(1);
                    return true;
                }
            }
        }
        bool IOptionSerializer.TryPersist(OptionKey optionKey, object value)
        {
            if (this._registryKey == null)
            {
                throw new InvalidOperationException();
            }

            var collectionPath = GetCollectionPathForOption(optionKey);
            if (collectionPath == null)
            {
                return false;
            }

            lock (_gate)
            {
                using (var subKey = this._registryKey.CreateSubKey(collectionPath))
                {
                    // Options that are of type bool have to be serialized as integers
                    if (optionKey.Option.Type == typeof(bool))
                    {
                        subKey.SetValue(optionKey.Option.Name, (bool)value ? 1 : 0, RegistryValueKind.DWord);
                        return true;
                    }
                    else
                    {
                        subKey.SetValue(optionKey.Option.Name, value);
                        return true;
                    }
                }
            }
        }
예제 #10
0
 private static KeyValueLogMessage Create(OptionKey optionKey, object oldValue, object currentValue)
 {
     return KeyValueLogMessage.Create(m =>
     {
         m[Name] = optionKey.Option.Name;
         m[Language] = optionKey.Language ?? All;
         m[Change] = CreateOptionValue(oldValue, currentValue);
     });
 }
        public bool TryFetch(OptionKey optionKey, out object value)
        {
            if (this._settingManager == null)
            {
                Debug.Fail("Manager field is unexpectedly null.");
                value = null;
                return false;
            }

            // Do we roam this at all?
            var roamingSerialization = optionKey.Option.StorageLocations.OfType<RoamingProfileStorageLocation>().SingleOrDefault();

            if (roamingSerialization == null)
            {
                value = null;
                return false;
            }

            var storageKey = roamingSerialization.GetKeyNameForLanguage(optionKey.Language);

            RecordObservedValueToWatchForChanges(optionKey, storageKey);

            value = this._settingManager.GetValueOrDefault(storageKey, optionKey.Option.DefaultValue);

            // VS's ISettingsManager has some quirks around storing enums.  Specifically,
            // it *can* persist and retrieve enums, but only if you properly call 
            // GetValueOrDefault<EnumType>.  This is because it actually stores enums just
            // as ints and depends on the type parameter passed in to convert the integral
            // value back to an enum value.  Unfortunately, we call GetValueOrDefault<object>
            // and so we get the value back as boxed integer.
            //
            // Because of that, manually convert the integer to an enum here so we don't
            // crash later trying to cast a boxed integer to an enum value.
            if (optionKey.Option.Type.IsEnum)
            {
                if (value != null)
                {
                    value = Enum.ToObject(optionKey.Option.Type, value);
                }
            }
            else if (optionKey.Option.Type == typeof(CodeStyleOption<bool>))
            {
                // We store these as strings, so deserialize
                var serializedValue = value as string;

                if (serializedValue != null)
                {
                    value = CodeStyleOption<bool>.FromXElement(XElement.Parse(serializedValue));
                }
                else
                {
                    value = optionKey.Option.DefaultValue;
                }
            }

            return true;
        }
예제 #12
0
 public void GettingOptionWithChangedOption()
 {
     var optionService = TestOptionService.GetService();
     var optionSet = optionService.GetOptions();
     var option = new Option<bool>("Test Feature", "Test Name", false);
     var key = new OptionKey(option);
     Assert.False(optionSet.GetOption(option));
     optionSet = optionSet.WithChangedOption(key, true);
     Assert.True((bool)optionSet.GetOption(key));
 }
예제 #13
0
        public override bool TryFetch(OptionKey optionKey, out object value)
        {
            switch (optionKey.Option.Feature)
            {
                case CacheOptions.FeatureName:
                case InternalSolutionCrawlerOptions.OptionName:
                    return TryFetch(optionKey, (r, k, o) => r.GetValue(k, defaultValue: o.DefaultValue), out value);
            }

            return base.TryFetch(optionKey, out value);
        }
예제 #14
0
        public override bool TryPersist(OptionKey optionKey, object value)
        {
            switch (optionKey.Option.Feature)
            {
                case CacheOptions.FeatureName:
                case InternalSolutionCrawlerOptions.OptionName:
                    return TryPersist(optionKey, value, (r, k, o, v) => r.SetValue(k, v, o.Type == typeof(int) ? RegistryValueKind.DWord : RegistryValueKind.QWord));
            }

            return base.TryPersist(optionKey, value);
        }
예제 #15
0
        public bool TryFetch(OptionKey optionKey, out object value)
        {
            value = string.Empty;
            if (optionKey != TodoCommentOptions.TokenList)
            {
                return false;
            }

            value = _taskTokenList;
            return true;
        }
        private void SetChangedOption(IOptionService optionService, IOption option, string languageName)
        {
            OptionKey key = new OptionKey(option, languageName);

            object currentValue;
            if (this.TryFetch(key, out currentValue))
            {
                OptionSet optionSet = optionService.GetOptions();
                optionSet = optionSet.WithChangedOption(key, currentValue);

                optionService.SetOptions(optionSet);
            }
        }
예제 #17
0
        public override object GetOption(OptionKey optionKey)
        {
            lock (_gate)
            {
                if (!_values.TryGetValue(optionKey, out var value))
                {
                    value = _service != null ? _service.GetOption(optionKey) : optionKey.Option.DefaultValue;
                    _values = _values.Add(optionKey, value);
                }

                return value;
            }
        }
예제 #18
0
 public int CreateOption(OptionKey option)
 {
     using (var db = Context)
     {
         var dataOption = _mapperService.Map <Data.OptionKey>(option);
         dataOption = db.OptionKey.Add(dataOption);
         dataOption.CreationDate = DateTime.UtcNow;
         foreach (var val in dataOption.OptionValues)
         {
             val.CreationDate = DateTime.UtcNow;
             db.OptionValue.Add(val);
         }
         db.SaveChanges();
         return(dataOption.Id);
     }
 }
예제 #19
0
        public override bool TryPersist(OptionKey optionKey, object value)
        {
            if (optionKey.Option.Feature == CacheOptions.FeatureName)
            {
                lock (Gate)
                {
                    using (var subKey = this.RegistryKey.CreateSubKey(CachePath))
                    {
                        subKey.SetValue(optionKey.Option.Name, value, optionKey.Option.Type == typeof(int) ? RegistryValueKind.DWord : RegistryValueKind.QWord);
                        return true;
                    }
                }
            }

            return base.TryPersist(optionKey, value);
        }
예제 #20
0
        public override bool TryPersist(OptionKey optionKey, object value)
        {
            if (optionKey.Option.Feature == CacheOptions.FeatureName)
            {
                lock (Gate)
                {
                    using (var subKey = this.RegistryKey.CreateSubKey(CachePath))
                    {
                        subKey.SetValue(optionKey.Option.Name, value, optionKey.Option.Type == typeof(int) ? RegistryValueKind.DWord : RegistryValueKind.QWord);
                        return(true);
                    }
                }
            }

            return(base.TryPersist(optionKey, value));
        }
예제 #21
0
                static string GetSectionHeader(OptionKey optionKey)
                {
                    if (optionKey.Option.IsPerLanguage)
                    {
                        switch (optionKey.Language)
                        {
                        case LanguageNames.CSharp:
                            return("[*.cs]");

                        case LanguageNames.VisualBasic:
                            return("[*.vb]");
                        }
                    }

                    return("[*]");
                }
        bool IOptionPersister.TryPersist(OptionKey optionKey, object value)
        {
            if (this._registryKey == null)
            {
                throw new InvalidOperationException();
            }

            if (!TryGetKeyPathAndName(optionKey.Option, out var path, out var key))
            {
                value = null;
                return(false);
            }

            lock (_gate)
            {
                using var subKey = this._registryKey.CreateSubKey(path);
                // Options that are of type bool have to be serialized as integers
                if (optionKey.Option.Type == typeof(bool))
                {
                    subKey.SetValue(key, (bool)value ? 1 : 0, RegistryValueKind.DWord);
                    return(true);
                }
                else if (optionKey.Option.Type == typeof(long))
                {
                    subKey.SetValue(key, value, RegistryValueKind.QWord);
                    return(true);
                }
                else if (optionKey.Option.Type.IsEnum)
                {
                    // If the enum is larger than an int, store as a QWord
                    if (Marshal.SizeOf(Enum.GetUnderlyingType(optionKey.Option.Type)) > Marshal.SizeOf(typeof(int)))
                    {
                        subKey.SetValue(key, (long)value, RegistryValueKind.QWord);
                    }
                    else
                    {
                        subKey.SetValue(key, (int)value, RegistryValueKind.DWord);
                    }
                    return(true);
                }
                else
                {
                    subKey.SetValue(key, value);
                    return(true);
                }
            }
        }
예제 #23
0
        void ConfigureWorkspaceForDocument(Document document, FileConfiguration config)
        {
            // Microsoft.CodeAnalysis.Options.IOptionService
            var optionService = workspace
                                .AsDynamicReflection()
                                ._workspaceOptionService;

            // Get the registered options in the roslyn workspace
            IEnumerable <IOption> registeredOptions = optionService.GetRegisteredOptions();

            foreach (var option in registeredOptions.Where(x => x.StorageLocations != null))
            {
                // Get the EditorConfig storage of the option
                OptionStorageLocation editorConfigStorageLocation = option
                                                                    .StorageLocations
                                                                    .FirstOrDefault(x => x.GetType().Name == "EditorConfigStorageLocation`1");

                // If it's null, it means that the option in the workspace does not have a corresponding storage in the .editorconfig file.
                if (editorConfigStorageLocation != null)
                {
                    string editorConfigKey = editorConfigStorageLocation.AsDynamicReflection().KeyName;

                    // Get the value in the .editorconfig associated with the editorConfig storage key
                    if (config.Properties.TryGetValue(editorConfigKey, out var editorConfigValue))
                    {
                        // Map the value in the .editorconfig file to the Option value in the roslyn workspace
                        // by invoking Microsoft.CodeAnalysis.Options.EditorConfigStorageLocation<T>.TryOption(...)
                        object optionValue = default(object);
                        if (editorConfigStorageLocation.AsDynamicReflection().TryGetOption(
                                option,
                                new ReadOnlyDictionary <string, object>(new Dictionary <string, object>
                        {
                            { editorConfigKey, editorConfigValue }
                        }),
                                option.Type,
                                OutValue.Create <object>(x => optionValue = x)))
                        {
                            var optionKey = new OptionKey(
                                option,
                                option.IsPerLanguage ? document.Project.Language : null);

                            workspace.Options = workspace.Options.WithChangedOption(optionKey, optionValue);
                        }
                    }
                }
            }
        }
예제 #24
0
        private void RefreshLanguageSettings(LANGPREFERENCES3[] langPrefs)
        {
            this.AssertIsForeground();

            string languageName;

            if (_languageMap.TryGetKey(langPrefs[0].guidLang, out languageName))
            {
                foreach (var option in _supportedOptions)
                {
                    var    keyWithLanguage = new OptionKey(option, languageName);
                    object newValue        = GetValueForOption(option, langPrefs[0]);

                    _optionService.RefreshOption(keyWithLanguage, newValue);
                }
            }
        }
예제 #25
0
        public bool TryPersist(OptionKey optionKey, object value)
        {
            // Property bindings
            if (preferences.TryGetUpdater(optionKey, out string storageKey, out var updater))
            {
                MonitorChanges(storageKey, optionKey);
                try {
                    var serializedValue = Serialize(value, optionKey.Option.Type);
                    updater(serializedValue);
                    return(true);
                } catch (Exception ex) {
                    LoggingService.LogError($"Failed to serialize key: {storageKey} type: {optionKey.Option.Type}", ex);
                }
            }

            return(false);
        }
        public void OrderingOfEditorConfigMaintained()
        {
            using var tempRoot = new TempRoot();
            var tempDirectory = tempRoot.CreateDirectory();

            // Write out an .editorconfig. We'll write out 100 random GUIDs
            var expectedKeysInOrder = new List <string>();

            using (var writer = new StreamWriter(tempDirectory.CreateFile(".editorconfig").Path))
            {
                writer.WriteLine("root = true");
                writer.WriteLine("[*.cs]");

                for (int i = 0; i < 100; i++)
                {
                    var key = Guid.NewGuid().ToString();
                    expectedKeysInOrder.Add(key);
                    writer.WriteLine($"{key} = value");
                }
            }

            // Create a workspace with a file in that path
            var codingConventionsCatalog = ExportProviderCache.GetOrCreateAssemblyCatalog(typeof(ICodingConventionsManager).Assembly).WithPart(typeof(MockFileWatcher));
            var exportProvider           = ExportProviderCache.GetOrCreateExportProviderFactory(TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithParts(codingConventionsCatalog)).CreateExportProvider();

            using var workspace = TestWorkspace.CreateWorkspace(
                      new XElement("Workspace",
                                   new XElement("Project", new XAttribute("Language", "C#"),
                                                new XElement("Document", new XAttribute("FilePath", tempDirectory.CreateFile("Test.cs").Path)))), exportProvider: exportProvider);

            var document = workspace.CurrentSolution.Projects.Single().Documents.Single();

            var providerFactory = workspace.ExportProvider.GetExportedValues <IDocumentOptionsProviderFactory>().OfType <LegacyEditorConfigDocumentOptionsProviderFactory>().Single();
            var provider        = providerFactory.TryCreate(workspace);

            var option    = new Option <List <string> >(nameof(LegacyEditorConfigDocumentOptionsProviderTests), nameof(OrderingOfEditorConfigMaintained), null, new[] { new KeysReturningStorageLocation() });
            var optionKey = new OptionKey(option);

            // Fetch the underlying option order with a "option" that returns the keys
            provider.GetOptionsForDocumentAsync(document, CancellationToken.None).Result.TryGetDocumentOption(optionKey, workspace.Options, out object actualKeysInOrderObject);

            var actualKeysInOrder = Assert.IsAssignableFrom <IEnumerable <string> >(actualKeysInOrderObject);

            Assert.Equal(expectedKeysInOrder, actualKeysInOrder);
        }
        public bool TryPersist(OptionKey optionKey, object value)
        {
            if (_settingManager == null)
            {
                Debug.Fail("Manager field is unexpectedly null.");
                return(false);
            }

            // Do we roam this at all?
            var roamingSerialization = optionKey.Option.StorageLocations.OfType <RoamingProfileStorageLocation>().SingleOrDefault();

            if (roamingSerialization == null)
            {
                value = null;
                return(false);
            }

            var storageKey = roamingSerialization.GetKeyNameForLanguage(optionKey.Language);

            RecordObservedValueToWatchForChanges(optionKey, storageKey);

            if (optionKey.Option.Type == typeof(CodeStyleOption <bool>))
            {
                // We store these as strings, so serialize
                var valueToSerialize = value as CodeStyleOption <bool>;

                if (value != null)
                {
                    value = valueToSerialize.ToXElement().ToString();
                }
            }
            else if (optionKey.Option.Type == typeof(NamingStylePreferences))
            {
                // We store these as strings, so serialize
                var valueToSerialize = value as NamingStylePreferences;

                if (value != null)
                {
                    value = valueToSerialize.CreateXElement().ToString();
                }
            }

            _settingManager.SetValueAsync(storageKey, value, isMachineLocal: false);
            return(true);
        }
예제 #28
0
        static void PrintOptionKey(OptionKey optionKey)
        {
            Console.WriteLine($"Name '{optionKey.Option.Name}' Language '{optionKey.Language}' LanguageSpecific'{optionKey.Option.IsPerLanguage}'");

            var locations = optionKey.Option.StorageLocations;

            if (locations.IsDefault)
            {
                return;
            }

            foreach (var loc in locations)
            {
                switch (loc)
                {
                case RoamingProfileStorageLocation roaming:
                    Console.WriteLine($"    roaming: {roaming.GetKeyNameForLanguage (optionKey.Language)}");
                    break;

                case LocalUserProfileStorageLocation local:
                    Console.WriteLine($"    local: {local.KeyName}");
                    break;

                case EditorConfigStorageLocation <int> edconf:
                    Console.WriteLine($"    editorconfig: {edconf.KeyName}");
                    break;

                case EditorConfigStorageLocation <string> edconf:
                    Console.WriteLine($"    editorconfig: {edconf.KeyName}");
                    break;

                case EditorConfigStorageLocation <bool> edconf:
                    Console.WriteLine($"    editorconfig: {edconf.KeyName}");
                    break;

                case EditorConfigStorageLocation <Microsoft.CodeAnalysis.CodeStyle.CodeStyleOption <bool> > edconf:
                    Console.WriteLine($"    editorconfig: {edconf.KeyName}");
                    break;

                default:
                    Console.WriteLine($"    unknown: {loc.GetType ()}");
                    break;
                }
            }
        }
 public bool TryGetDocumentOption(OptionKey option, [NotNullWhen(true)] out object?value)
 {
     if (option == _useTabsOptionKey)
     {
         value = _editorSettings.IndentWithTabs;
         return(true);
     }
     else if (option == _tabSizeOptionKey || option == _indentationSizeOptionKey)
     {
         value = _editorSettings.IndentSize;
         return(true);
     }
     else
     {
         value = null;
         return(false);
     }
 }
예제 #30
0
        public virtual bool TryPersist(OptionKey optionKey, object value)
        {
            if (this.Manager == null)
            {
                Debug.Fail("Manager field is unexpectedly null.");
                return(false);
            }

            if (!SupportsOption(optionKey.Option, optionKey.Language))
            {
                return(false);
            }

            var storageKey = GetStorageKeyForOption(optionKey.Option);

            this.Manager.SetValueAsync(storageKey, value, isMachineLocal: false);
            return(true);
        }
예제 #31
0
        public static void Load()
        {
            ModConfig config = new ModConfig();
            int       v      = (int)KeyCode.K;

            config.TryGetConfig <int>("musicKeycode", ref v);
            musicKeycode = (KeyCode)v;

            OptionKey musicKey = new OptionKey("Music Controller toggle", "TerraWave", musicKeycode);

            musicKey.onValueSaved.AddListener(() =>
            {
                musicKeycode           = musicKey.SavedValue;
                config["musicKeycode"] = (int)musicKeycode;
                config.WriteConfigJsonFile();
            });

            var harmony = HarmonyInstance.Create("Exund.ModOptionsTab");

            harmony.PatchAll(Assembly.GetExecutingAssembly());

            var materials       = Resources.FindObjectsOfTypeAll <Material>();
            var Skydome_Planets = materials.First(m => m.name == "Skydome_Planets");
            var Moon            = materials.First(m => m.name == "Moon");

            assets_path = Path.Combine(Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName, "Assets");

            var Skydome_Planets_Albedo = new Texture2D(0, 0);

            Skydome_Planets_Albedo.LoadImage(File.ReadAllBytes(Path.Combine(assets_path, "Skydome_Planets_Albedo.png")));
            Skydome_Planets.mainTexture = Skydome_Planets_Albedo;

            var moon_texture = new Texture2D(0, 0);

            moon_texture.LoadImage(File.ReadAllBytes(Path.Combine(assets_path, "moon_texture.png")));
            Moon.mainTexture = moon_texture;
            Moon.SetTexture("_MainTex", moon_texture);

            var handler = new GameObject();

            handler.AddComponent <AudioSource>();
            handler.AddComponent <MusicLoader>();
            GameObject.DontDestroyOnLoad(handler);
        }
        internal bool TryGet(OptionKey key, out string propertyKey, out object value)
        {
            // Check for roaming/profile properties
            propertyKey = key.GetPropertyName();
            if (propertyKey != null)
            {
                var defaultValue = key.Option.DefaultValue;
                if (TryGetSerializationMethods <object> (key.Option.Type, out var serializer, out var deserializer))
                {
                    defaultValue = serializer(defaultValue);
                }

                value = PropertyService.Get(propertyKey, defaultValue);
                return(true);
            }

            value = default(object);
            return(false);
        }
예제 #33
0
        public void UpdateOption(OptionKey option)
        {
            using (var db = Context)
            {
                var dataOption = _mapperService.Map <Data.OptionKey>(option);
                dataOption = db.OptionKey.Attach(dataOption);
                db.Entry(dataOption).State = EntityState.Modified;

                foreach (var val in dataOption.OptionValues)
                {
                    val.OptionKeyId = dataOption.Id;
                }

                //D
                var optValues = db.OptionValue.Where(x => x.OptionKeyId == option.Id);
                foreach (var optValue in optValues)
                {
                    if (!option.OptionValues.Any(x => x.Id == optValue.Id))
                    {
                        db.OptionValue.Remove(optValue);
                    }
                }

                foreach (var optValue in option.OptionValues)
                {
                    if (optValue.Id == 0)
                    {
                        //C
                        var dataOptValue = _mapperService.Map <Data.OptionValue>(optValue);
                        dataOptValue.CreationDate = DateTime.UtcNow;
                        db.OptionValue.Add(dataOptValue);
                    }
                    else
                    {
                        //U
                        var dataOptValue = dataOption.OptionValues.Single(x => x.Id == optValue.Id);
                        db.Entry(dataOptValue).State = EntityState.Modified;
                    }
                }

                db.SaveChanges();
            }
        }
예제 #34
0
        public void RefreshOption(OptionKey optionKey, object newValue)
        {
            lock (_gate) {
                if (_currentValues.TryGetValue(optionKey, out var oldValue))
                {
                    if (object.Equals(oldValue, newValue))
                    {
                        // Value is still the same, no reason to raise events
                        return;
                    }
                }

                _currentValues = _currentValues.SetItem(optionKey, newValue);
            }

            RaiseEvents(new List <OptionChangedEventArgs> {
                new OptionChangedEventArgs(optionKey, newValue)
            });
        }
예제 #35
0
        public void TestRoslynPropertyWithMultipleKeys()
        {
            var(preferences, persister) = Setup();

            var option    = new PerLanguageOption <bool> ("test", "name", false, new RoamingProfileStorageLocation("feature.%LANGUAGE%.test"), new RoamingProfileStorageLocation("feature.test"));
            var optionKey = new OptionKey(option, LanguageNames.CSharp);

            var propertyNames = optionKey.GetPropertyNames().ToArray();

            Assert.AreEqual(2, propertyNames.Length);
            Assert.AreEqual("feature.CSharp.test", propertyNames [0]);
            Assert.AreEqual("feature.test", propertyNames [1]);

            PropertyService.Set(propertyNames [1], true);

            var success = persister.TryFetch(optionKey, out object value);

            Assert.AreEqual(true, success);
            Assert.AreEqual(true, value);
        }
예제 #36
0
                private protected override object?GetOptionCore(OptionKey optionKey)
                {
                    // If we already know the document specific value, we're done
                    if (_values.TryGetValue(optionKey, out var value))
                    {
                        return(value);
                    }

                    foreach (var documentOptionSource in _documentOptions)
                    {
                        if (documentOptionSource.TryGetDocumentOption(optionKey, out value))
                        {
                            // Cache and return
                            return(ImmutableInterlocked.GetOrAdd(ref _values, optionKey, value));
                        }
                    }

                    // We don't have a document specific value, so forward
                    return(_underlyingOptions.GetOption(optionKey));
                }
예제 #37
0
        public static IEnumerable <string> GetPropertyNames(this OptionKey optionKey)
        {
            // Prevent NRE being thrown on iteration.
            if (optionKey.Option.StorageLocations.IsDefaultOrEmpty)
            {
                yield break;
            }

            foreach (var storageLocation in optionKey.Option.StorageLocations)
            {
                if (storageLocation is RoamingProfileStorageLocation roamingLocation)
                {
                    yield return(roamingLocation.GetKeyNameForLanguage(optionKey.Language));
                }
                if (storageLocation is LocalUserProfileStorageLocation userLocation)
                {
                    yield return(userLocation.KeyName);
                }
            }
        }
예제 #38
0
                public bool TryGetDocumentOption(OptionKey option, out object?value)
                {
                    var editorConfigPersistence = option.Option.StorageLocations.OfType <IEditorConfigStorageLocation>().SingleOrDefault();

                    if (editorConfigPersistence == null)
                    {
                        value = null;
                        return(false);
                    }

                    try
                    {
                        return(editorConfigPersistence.TryGetOption(_options.AsNullable(), option.Option.Type, out value));
                    }
                    catch (Exception e) when(FatalError.ReportWithoutCrash(e))
                    {
                        value = null;
                        return(false);
                    }
                }
                public bool TryGetDocumentOption(OptionKey option, out object?value)
                {
                    var editorConfigPersistence = option.Option.StorageLocations.OfType <IEditorConfigStorageLocation>().SingleOrDefault();

                    if (editorConfigPersistence == null)
                    {
                        value = null;
                        return(false);
                    }

                    try
                    {
                        return(editorConfigPersistence.TryGetOption(_options, option.Option.Type, out value));
                    }
                    catch (Exception ex)
                    {
                        _errorLogger?.LogException(this, ex);
                        value = null;
                        return(false);
                    }
                }
예제 #40
0
        public void GettingOptionWithoutChangedOption()
        {
            var optionService = TestOptionService.GetService();
            var optionSet     = optionService.GetOptions();

            var optionFalse = new Option <bool>("Test Feature", "Test Name", false);

            Assert.False(optionSet.GetOption(optionFalse));

            var optionTrue = new Option <bool>("Test Feature", "Test Name", true);

            Assert.True(optionSet.GetOption(optionTrue));

            var falseKey = new OptionKey(optionFalse);

            Assert.False((bool)optionSet.GetOption(falseKey));

            var trueKey = new OptionKey(optionTrue);

            Assert.True((bool)optionSet.GetOption(trueKey));
        }
        public async Task TestFullSolutionAnalysis(string language, bool enabledByDefault)
        {
            var pref            = IdeApp.Preferences.Roslyn;
            var perLanguagePref = pref.For(language);

            using (var mdw = await IdeApp.TypeSystemService.CreateEmptyWorkspace()) {
                var key = new OptionKey(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, language);

                var old = mdw.Options.GetOption(key);
                try {
                    // Set the closed file diagnostics to default.
                    mdw.Options = mdw.Options.WithChangedOption(key, null);

                    Assert.IsTrue(pref.FullSolutionAnalysisRuntimeEnabled);
                    Assert.IsTrue(mdw.Options.GetOption(RuntimeOptions.FullSolutionAnalysis));
                    Assert.AreEqual(enabledByDefault, perLanguagePref.SolutionCrawlerClosedFileDiagnostic.Value);

                    // Set closed file diagnostics to false, this should not impact runtime options
                    mdw.Options = mdw.Options.WithChangedOption(key, false);

                    Assert.IsTrue(pref.FullSolutionAnalysisRuntimeEnabled);
                    Assert.IsTrue(mdw.Options.GetOption(RuntimeOptions.FullSolutionAnalysis));
                    Assert.IsFalse(perLanguagePref.SolutionCrawlerClosedFileDiagnostic.Value);

                    // Set closed file diagnostics to true, this should turn on everything
                    // Ensure FSA is off at this point.
                    mdw.Options = mdw.Options.WithChangedOption(RuntimeOptions.FullSolutionAnalysis, false);
                    pref.FullSolutionAnalysisRuntimeEnabled = false;
                    mdw.Options = mdw.Options.WithChangedOption(key, true);

                    Assert.IsTrue(pref.FullSolutionAnalysisRuntimeEnabled);
                    Assert.IsTrue(mdw.Options.GetOption(RuntimeOptions.FullSolutionAnalysis));
                    Assert.IsTrue(perLanguagePref.SolutionCrawlerClosedFileDiagnostic.Value);
                } finally {
                    mdw.Options = mdw.Options.WithChangedOption(key, old);
                    pref.FullSolutionAnalysisRuntimeEnabled = true;
                    mdw.Options = mdw.Options.WithChangedOption(RuntimeOptions.FullSolutionAnalysis, true);
                }
            }
        }
예제 #42
0
        public bool TryFetch(OptionKey optionKey, out object?value)
        {
            // This option is refreshed via the constructor to avoid UI dependencies when retrieving option values. If
            // we happen to reach this point before the value is available, try to obtain it without blocking, and
            // otherwise fall back to the default.
            if (optionKey.Option == SolutionCrawlerOptions.SolutionBackgroundAnalysisScopeOption)
            {
                if (_lazyRoslynPackage is not null)
                {
                    value = _lazyRoslynPackage.AnalysisScope;
                    return(true);
                }
                else
                {
                    value = SolutionCrawlerOptions.SolutionBackgroundAnalysisScopeOption.DefaultValue;
                    return(true);
                }
            }

            value = null;
            return(false);
        }
예제 #43
0
        public override bool TryFetch(OptionKey optionKey, out object value)
        {
            if (optionKey.Option.Feature == CacheOptions.FeatureName)
            {
                lock (Gate)
                {
                    using (var openSubKey = this.RegistryKey.OpenSubKey(CachePath))
                    {
                        if (openSubKey == null)
                        {
                            value = null;
                            return false;
                        }

                        value = openSubKey.GetValue(optionKey.Option.Name, defaultValue: optionKey.Option.DefaultValue);
                        return true;
                    }
                }
            }

            return base.TryFetch(optionKey, out value);
        }
예제 #44
0
        public virtual bool TryFetch(OptionKey optionKey, out object value)
        {
            value = null;

            if (this.Manager == null)
            {
                Debug.Fail("Manager field is unexpectedly null.");
                return(false);
            }

            if (!SupportsOption(optionKey.Option, optionKey.Language))
            {
                value = null;
                return(false);
            }

            var storageKey = GetStorageKeyForOption(optionKey.Option);

            value = this.Manager.GetValueOrDefault(storageKey, optionKey.DefaultValue);

            return(true);
        }
예제 #45
0
        /// <summary>
        ///     Asks the server to retrieve an integer config key, producing a task that waits until either
        ///     the config cache receives it or the given timeout period elapses.
        /// </summary>
        /// <param name="key">The key to retrieve.</param>
        /// <param name="timeout">A time-span that, will be used as the timeout for this poll.</param>
        /// <param name="fallback">A fallback value to use if the timeout elapses.</param>
        /// <param name="index">If given, the specific index to retrieve.</param>
        /// <returns>A task that completes with the retrieved integer value.</returns>
        public int PollInt(OptionKey key, TimeSpan timeout, int fallback = -1, int index = ConfigCache.NoIndex)
        {
            var mainObservable = Observable.FromEventPattern <ConfigCache.IntChangeEventArgs>(
                ev =>
            {
                _cache.IntChanged += ev;
                // This is a strange place to put this, but necessary;
                // the BapsNet conversation that results in receiving the config setting has to
                // take place within the time window that 'ev' is registered.
                var cmd = new NonIndexedConfigCommand(ConfigOp.GetConfigSetting, false);
                Send(new MessageBuilder(cmd).Add((uint)key));
            },
                ev => _cache.IntChanged -= ev
                ).FirstAsync(
                ev => ev.EventArgs.Key == key && ev.EventArgs.Index == index
                ).Select(
                ev => ev.EventArgs.Value
                );
            var fallbackObservable = Observable.Return(fallback).Delay(timeout);

            return(mainObservable.Amb(fallbackObservable).Wait());
        }
예제 #46
0
        public override bool TryFetch(OptionKey optionKey, out object value)
        {
            if (optionKey.Option.Feature == CacheOptions.FeatureName)
            {
                lock (Gate)
                {
                    using (var openSubKey = this.RegistryKey.OpenSubKey(CachePath))
                    {
                        if (openSubKey == null)
                        {
                            value = null;
                            return(false);
                        }

                        value = openSubKey.GetValue(optionKey.Option.Name, defaultValue: optionKey.Option.DefaultValue);
                        return(true);
                    }
                }
            }

            return(base.TryFetch(optionKey, out value));
        }
예제 #47
0
        public void SetOptionAndUpdatePreview <T>(T value, IOption option, string preview)
        {
            var key = new OptionKey(option, option.IsPerLanguage ? Language : null);

            if (option.DefaultValue is ICodeStyleOption codeStyleOption)
            {
                // The value provided is either an ICodeStyleOption OR the underlying ICodeStyleOption.Value
                if (value is ICodeStyleOption newCodeStyleOption)
                {
                    OptionStore.SetOption(key, codeStyleOption.WithValue(newCodeStyleOption.Value).WithNotification(newCodeStyleOption.Notification));
                }
                else
                {
                    OptionStore.SetOption(key, codeStyleOption.WithValue(value));
                }
            }
            else
            {
                OptionStore.SetOption(key, value);
            }

            UpdateDocument(preview);
        }
            public bool TryGetDocumentOption(Document document, OptionKey option, out object value)
            {
                var editorConfigPersistence = option.Option.StorageLocations.OfType <EditorConfigStorageLocation>().SingleOrDefault();

                if (editorConfigPersistence == null)
                {
                    value = null;
                    return(false);
                }

                var allRawConventions = _codingConventionSnapshot.AllRawConventions;

                try
                {
                    return(editorConfigPersistence.TryParseReadonlyDictionary(allRawConventions, option.Option.Type, out value));
                }
                catch (Exception ex)
                {
                    _errorLogger?.LogException(this, ex);
                    value = null;
                    return(false);
                }
            }
예제 #49
0
 private bool TryGetOptionForBuffer(ITextBuffer textBuffer, OptionKey option, out object?value)
 {
     if (option.Option == FormattingOptions.UseTabs)
     {
         value = !_indentationManagerService.UseSpacesForWhitespace(textBuffer, explicitFormat: false);
         return(true);
     }
     else if (option.Option == FormattingOptions.TabSize)
     {
         value = _indentationManagerService.GetTabSize(textBuffer, explicitFormat: false);
         return(true);
     }
     else if (option.Option == FormattingOptions.IndentationSize)
     {
         value = _indentationManagerService.GetIndentSize(textBuffer, explicitFormat: false);
         return(true);
     }
     else
     {
         value = null;
         return(false);
     }
 }
        bool IOptionPersister.TryFetch(OptionKey optionKey, out object value)
        {
            string path;
            string key;

            if (!TryGetKeyPathAndName(optionKey.Option, out path, out key))
            {
                value = null;
                return false;
            }

            lock (_gate)
            {
                using (var subKey = this._registryKey.OpenSubKey(path))
                {
                    if (subKey == null)
                    {
                        value = null;
                        return false;
                    }

                    // Options that are of type bool have to be serialized as integers
                    if (optionKey.Option.Type == typeof(bool))
                    {
                        value = subKey.GetValue(key, defaultValue: (bool)optionKey.Option.DefaultValue ? 1 : 0).Equals(1);
                        return true;
                    }
                    else
                    {
                        // Otherwise we can just store normally
                        value = subKey.GetValue(key, defaultValue: optionKey.Option.DefaultValue);
                        return true;
                    }
                }
            }
        }
예제 #51
0
 internal override bool ShouldPersistOption(OptionKey key)
 {
     return key.Option.Feature == CSharpFormattingOptions.NewLineFormattingFeatureName;
 }
예제 #52
0
 internal IDictionary<OptionKey, object> OptionSet(OptionKey option, object value)
 {
     var options = new Dictionary<OptionKey, object>();
     options.Add(option, value);
     return options;
 }
        public bool TryPersist(OptionKey optionKey, object value)
        {
            if (this._settingManager == null)
            {
                Debug.Fail("Manager field is unexpectedly null.");
                return false;
            }

            // Do we roam this at all?
            var roamingSerialization = optionKey.Option.StorageLocations.OfType<RoamingProfileStorageLocation>().SingleOrDefault();

            if (roamingSerialization == null)
            {
                value = null;
                return false;
            }

            var storageKey = roamingSerialization.GetKeyNameForLanguage(optionKey.Language);

            RecordObservedValueToWatchForChanges(optionKey, storageKey);

            if (optionKey.Option.Type == typeof(CodeStyleOption<bool>))
            {
                // We store these as strings, so serialize
                var valueToSerialize = value as CodeStyleOption<bool>;

                if (value != null)
                {
                    value = valueToSerialize.ToXElement().ToString();
                }
            }

            this._settingManager.SetValueAsync(storageKey, value, isMachineLocal: false);
            return true;
        }
        protected IDictionary<OptionKey, object> OptionsSet(params Tuple<IOption, bool, NotificationOption>[] optionsToSet)
        {
            var options = new Dictionary<OptionKey, object>();
            foreach (var triple in optionsToSet)
            {
                var option = triple.Item1;
                var value = triple.Item2;
                var notification = triple.Item3;
                var optionKey = new OptionKey(option, option.IsPerLanguage ? GetLanguage() : null);
                options.Add(optionKey, new CodeStyleOption<bool>(value, notification));
            }

            return options;
        }
        public virtual bool TryFetch(OptionKey optionKey, out object value)
        {
            value = null;

            if (this.Manager == null)
            {
                Debug.Fail("Manager field is unexpectedly null.");
                return false;
            }

            if (!SupportsOption(optionKey.Option, optionKey.Language))
            {
                value = null;
                return false;
            }

            var storageKey = GetStorageKeyForOption(optionKey.Option);
            value = this.Manager.GetValueOrDefault(storageKey, optionKey.Option.DefaultValue);

            return true;
        }
        public virtual bool TryPersist(OptionKey optionKey, object value)
        {
            if (this.Manager == null)
            {
                Debug.Fail("Manager field is unexpectedly null.");
                return false;
            }

            if (!SupportsOption(optionKey.Option, optionKey.Language))
            {
                return false;
            }

            var storageKey = GetStorageKeyForOption(optionKey.Option);
            this.Manager.SetValueAsync(storageKey, value, isMachineLocal: false);
            return true;
        }
예제 #57
0
        private void RefreshLanguageSettings(LANGPREFERENCES3[] langPrefs)
        {
            this.AssertIsForeground();
            if (_languageMap.TryGetKey(Tuple.Create(langPrefs[0].guidLang), out var languageName))
            {
                foreach (var option in _supportedOptions)
                {
                    var keyWithLanguage = new OptionKey(option, languageName);
                    object newValue = GetValueForOption(option, langPrefs[0]);

                    _optionService.RefreshOption(keyWithLanguage, newValue);
                }
            }
        }
예제 #58
0
 private IDictionary<OptionKey, object> Options(OptionKey option, object value)
 {
     var options = new Dictionary<OptionKey, object>();
     options.Add(option, value);
     return options;
 }
예제 #59
0
        public bool TryPersist(OptionKey optionKey, object value)
        {
            if (!_supportedOptions.Contains(optionKey.Option))
            {
                value = null;
                return false;
            }

            if (!_languageMap.TryGetValue(optionKey.Language, out var languageServiceGuid))
            {
                value = null;
                return false;
            }

            var languagePreferences = new LANGPREFERENCES3[1];
            languagePreferences[0].guidLang = languageServiceGuid.Item1;
            Marshal.ThrowExceptionForHR(_textManager.GetUserPreferences4(null, languagePreferences, null));

            SetValueForOption(optionKey.Option, ref languagePreferences[0], value);
            SetUserPreferencesMaybeAsync(languagePreferences);

            // Even if we didn't call back, say we completed the persist
            return true;
        }
예제 #60
0
        public bool TryFetch(OptionKey optionKey, out object value)
        {
            // This particular serializer is a bit strange, since we have to initially read things out on the UI thread.
            // Therefore, we refresh the values in the constructor, meaning that this should never get called for our values.

            Contract.ThrowIfTrue(_supportedOptions.Contains(optionKey.Option));

            value = null;
            return false;
        }