Пример #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();
        }
Пример #2
0
        static int Execute(string options)
        {
            Dictionary <string, Toptout> tm = null;

            if (!File.Exists(Const.Default_LocalDataFilename))
            {
                Console.WriteLine("[!] Warning. Can not find local database. Use the `force`, Luke.");
                return(1); // TODO define errorlevels
            }

            try {
                tm = new LocalDataProvider(Const.Default_LocalDataFilename)
                     .LoadLocalData();
            }
            catch {
                Console.WriteLine("[!] Error. Can not load local database. Should try to `update`.");
                return(2); // TODO define errorlevels
            }

#if DEBUG
            Console.WriteLine($"Loaded {tm?.Count} apps."); // TODO STUB
#endif

            Dictionary <string, UserOptions.OptionPair> rules;

            if (File.Exists(options))
            {
                var uo = new UserOptions(options);
                uo.LoadFromFile();
                rules = uo.Rules;
                // ProcessApp(appId, UserOptions.Option.TOptOut);
            }
            else
            {
                rules = new ();
                //foreach(var appId in tm.Keys)
                //    ProcessApp(appId, UserOptions.Option.TOptOut);
            }

            return(0);
        }