public override async Task ExecuteAsync(ILogger logger, ChangeSettingsOptions options)
        {
            try
            {
                BaseSettings oldSettings = null;

                if (options.SettingsName == null)
                {
                    var settingsList = await SettingsManager.GetAboutAllSettings().ToArrayAsync();

                    if (settingsList.Length == 0)
                    {
                        logger.Print("</crossmark/> No settings found");
                        return;
                    }

                    var selection = new VerticalSettingsSelector(settingsList.Select(x => new SettingsSelectionItem(x.name, x.type)).ToArray());
                    SettingsSelectionItem selectedItem = selection.GetUserSelection();

                    if (await SettingsManager.SettingsExists(selectedItem.Name))
                    {
                        oldSettings = await SettingsManager.ReadAsync <BaseSettings>(selectedItem.Name);
                    }
                }
                else
                {
                    if (await SettingsManager.SettingsExists(options.SettingsName))
                    {
                        oldSettings = await SettingsManager.ReadAsync <BaseSettings>(options.SettingsName);
                    }
                }

                if (oldSettings == null)
                {
                    throw new SettingsNotFoundException(options.SettingsName);
                }

                BaseSettings newSettings = null;
                if (oldSettings.Type == SettingsType.Application)
                {
                    var settingsChanger = new SettingsChanger <ApplicationSettings>();
                    newSettings = settingsChanger.Change((ApplicationSettings)oldSettings);
                }
                else if (oldSettings.Type == SettingsType.Component)
                {
                    var settingsChanger = new SettingsChanger <ComponentSettings>();
                    newSettings = settingsChanger.Change((ComponentSettings)oldSettings);
                }

                if (oldSettings.Name != newSettings.Name)
                {
                    await SettingsManager.ChangeSettingsNameAsync(oldSettings.Name, newSettings.Name);
                }

                await SettingsManager.SaveAsync(newSettings);
            }
            catch (Exception ex)
            {
            }
        }
Exemple #2
0
        public override async Task ExecuteAsync(ILogger logger, WatchOptions options)
        {
            _logger = logger;
            BaseSettings settings = null;

            if (options.SettingsName == null)
            {
                var settingsList = await SettingsManager.GetAboutAllSettings().ToArrayAsync();

                if (settingsList.Length == 0)
                {
                    logger.Print("</crossmark/> No settings found");
                    return;
                }

                var selection = new VerticalSettingsSelector(settingsList.Select(x => new SettingsSelectionItem(x.name, x.type)).ToArray());
                SettingsSelectionItem selectedItem = selection.GetUserSelection();

                if (await SettingsManager.SettingsExists(selectedItem.Name))
                {
                    settings = await SettingsManager.ReadAsync <BaseSettings>(selectedItem.Name);
                }
            }
            else
            {
                if (await SettingsManager.SettingsExists(options.SettingsName))
                {
                    settings = await SettingsManager.ReadAsync <BaseSettings>(options.SettingsName);
                }
            }

            if (settings == null)
            {
                throw new SettingsNotFoundException(options.SettingsName);
            }

            if (settings.Type == SettingsType.Application)
            {
                await WatchApplication((ApplicationSettings)settings);
            }
            else if (settings.Type == SettingsType.Component)
            {
                await WatchComponent((ComponentSettings)settings);
            }
            else
            {
                logger.Print($"Settings contains type \"{options.SettingsName}\" which not supported");
                logger.Print("Available types:");
                foreach (string enumValue in Enum.GetValues(typeof(SettingsType)))
                {
                    logger.Print(" - " + enumValue);
                }
            }
        }