Exemple #1
0
 public Program(VisitsRepo repo, StaffClient staffClient, int maxGiftsPerRun, JObject settings, GiftsTelegramBot telegramBot)
 {
     this.repo           = repo;
     this.staffClient    = staffClient;
     this.maxGiftsPerRun = maxGiftsPerRun;
     this.settings       = settings;
     this.telegramBot    = telegramBot;
 }
Exemple #2
0
        private static void Main(string[] args)
        {
            var settings            = JObject.Parse(File.ReadAllText("appsettings.json"));
            var hostLog             = settings["hostLog"].ToObject <HostLogConfiguration>();
            var graphiteServiceName = settings["graphiteServiceName"].Value <string>();

            LoggerSetup.Setup(hostLog, graphiteServiceName);
            try
            {
                var staff = new StaffClient(settings["staff"]["clientAuth"].Value <string>());
                if (args.Contains("-r"))
                {
                    Console.WriteLine("Username (example: KONTUR\\pe):");
                    var username = Console.ReadLine();
                    Console.WriteLine($"Password for {username}:");
                    var password     = GetConsolePassword();
                    var refreshToken = staff.GetRefreshToken(username, password);
                    Console.WriteLine($"RefreshToken: {refreshToken}");
                    return;
                }

                var telegramBot = new GiftsTelegramBot();
                try
                {
                    staff.UseRefreshToken(settings["staff"]["refreshToken"].Value <string>());
                    var maxGiftsPerRun = args.Length > 0 ? int.Parse(args[0]) : settings["maxGiftsPerRun"].Value <int>();
                    log.Info("UseGiftGrantsLimitPerRun\t" + maxGiftsPerRun);
                    var db      = new ULearnDb();
                    var repo    = new VisitsRepo(db);
                    var courses = settings["courses"].Values <string>();
                    var program = new Program(repo, staff, maxGiftsPerRun, settings, telegramBot);
                    foreach (var courseId in courses)
                    {
                        program.GrantGiftsForCourse(courseId);
                    }
                }
                catch (Exception e)
                {
                    telegramBot.PostToChannel($"Error while grant staff gifts.\n\n{e}");
                    log.Error(e, "UnhandledException");
                }
            }
            finally
            {
                FileLog.FlushAll();
            }
        }