Пример #1
0
        static void Execute(DataSource provider, string repo, string path, string options)
        {
            ITelemetryApi api;

            switch (provider)
            {
            case DataSource.Swagger:
                api = new SwaggerTelemetryAdapter();
                break;

            case DataSource.Github:
                api = new GithubTelemetryAdapter(new GithubDataProvider(repo, path));
                break;

            default:
            case DataSource.Local:
                api = new LocalTelemetryAdapter(new LocalDataProvider(Const.Default_LocalDataFilename));
                break;
            }

            var apps = api.ListTelemetryAsync().GetAwaiter().GetResult();

            if (apps == null)
            {
                Console.WriteLine("ERROR: Can not update data."); // TODO swagger-api not avilable error message
                return;
            }

            File.WriteAllText(Const.Default_LocalDataFilename, JsonConvert.SerializeObject(apps));

            var userOpts = new UserOptions(options);

            if (File.Exists(options))
            {
                userOpts.LoadFromFile();
            }

            foreach (var appId in apps.Keys)
            {
                if (!userOpts.Rules.ContainsKey(appId))
                {
                    userOpts.AddDefaultRule(appId);
                }
            }

            userOpts.SaveRules();
        }