/// <summary>
        ///   Hydrates the properties from the registry asynchronously.
        /// </summary>
        public virtual async Task LoadAsync()
        {
            s_log.Info("Load options from config file");
            OptionsFacade.CurrentOptions = await OptionsFacade.LoadAsync();

            foreach (var property in GetOptionProperties())
            {
                if (typeof(OptionsFacade).GetProperty(property.Name)?.PropertyType != property.PropertyType)
                {
                    continue;
                }

                var facadeProperty = typeof(OptionsFacade).GetProperty(property.Name);
                if (facadeProperty != null)
                {
                    property.SetValue(this, facadeProperty.GetValue(OptionsFacade.CurrentOptions));
                }
            }
        }
예제 #2
0
        private async Task MigrateOptionsAsync()
        {
            if (!File.Exists(OptionsFacade.DefaultCoreOptionsPath) || !File.Exists(OptionsFacade.DefaultVisualStudioOptionsPath))
            {
                var optionsPage = (OptionsPage)GetDialogPage(typeof(OptionsPage));
                var defaultLicenseHeaderPage = (DefaultLicenseHeaderPage)GetDialogPage(typeof(DefaultLicenseHeaderPage));
                var languagesPage            = (LanguagesPage)GetDialogPage(typeof(LanguagesPage));

                optionsPage.MigrateOptions();
                defaultLicenseHeaderPage.MigrateOptions();
                languagesPage.MigrateOptions();
            }
            else
            {
                OptionsFacade.CurrentOptions = await OptionsFacade.LoadAsync();
            }

            OptionsFacade.CurrentOptions.Version = Version;
            await OptionsFacade.SaveAsync(OptionsFacade.CurrentOptions);
        }
        /// <summary>
        ///   Saves the properties to the registry asynchronously.
        /// </summary>
        public virtual async Task SaveAsync()
        {
            s_log.Info("Save options to config file");
            foreach (var property in GetOptionProperties())
            {
                if (typeof(OptionsFacade).GetProperty(property.Name)?.PropertyType != property.PropertyType)
                {
                    continue;
                }

                var facadeProperty = typeof(OptionsFacade).GetProperty(property.Name);
                facadeProperty?.SetValue(OptionsFacade.CurrentOptions, property.GetValue(this));
            }

            await OptionsFacade.SaveAsync(OptionsFacade.CurrentOptions);

            var liveModel = await GetLiveInstanceAsync();

            if (this != liveModel)
            {
                await liveModel.LoadAsync();
            }
        }