public ZendeskBackup(ZendeskConfig config, string backupFolder)
 {
     this.Config   = config;
     this.RestApi  = new ZendeskRestApi(this.Config);
     BackupPathZip = backupFolder;
     CurrentDate   = DateTime.Now.ToString("yyyy-MM-dd");
     BackupPath    = $"{BackupPathZip}{CurrentDate}\\";
 }
示例#2
0
        static void Main(string[] args)
        {
            var login      = "";
            var password   = "";
            var backupPath = @"c:\temp\backups\";
            var runNow     = false;

            for (var i = 0; i < args.Length; i = i + 2)
            {
                if (args[i] == "-l")
                {
                    login = (i + 1) < args.Length ? args[i + 1] : login;
                    continue;
                }
                if (args[i] == "-p")
                {
                    password = (i + 1) < args.Length ? args[i + 1]: password;
                    continue;
                }
                if (args[i] == "-b")
                {
                    backupPath = (i + 1) < args.Length?  args[i + 1]: backupPath;
                    continue;
                }
                if (args[i] == "-run")
                {
                    runNow = true;
                    continue;
                }
            }
            Console.WriteLine($"Login: {login}");
            Console.WriteLine($"Password: {password}");
            Console.WriteLine($"Backup path: {backupPath}");
            Console.WriteLine($"Run now: {runNow}");
            if (login == "" && password == "")
            {
                Console.WriteLine("Please run programm with argument");
                Console.WriteLine("-l login -p password -b backupPath -run(create backup right now)");
                return;
            }

            ZendeskConfig config = new ZendeskConfig()
            {
                Login    = login,
                Password = password,
                Url      = "https://support.travelline.ru"
            };

            BackupScheduler.Start(config, backupPath, runNow);
            while (true)
            {
                Thread.Sleep(int.MaxValue);
            }
        }
示例#3
0
        public static async void Start(ZendeskConfig config, string backupFolder, bool runNow = false)
        {
            int initHour    = 1;
            int initMinutes = 1;
            int initSeconds = 1;

            DateTime       dateNow         = DateTime.Now;
            DateTimeOffset dateNightOffset = new DateTimeOffset(new DateTime(
                                                                    dateNow.Year,
                                                                    dateNow.Month,
                                                                    dateNow.AddDays(1).Day,
                                                                    initHour,
                                                                    initMinutes,
                                                                    initSeconds));

            IScheduler scheduler = await StdSchedulerFactory.GetDefaultScheduler();

            await scheduler.Start();

            IJobDetail job = JobBuilder.Create <BackupCreator>()
                             .UsingJobData("login", config.Login)
                             .UsingJobData("password", config.Password)
                             .UsingJobData("url", config.Url)
                             .UsingJobData("backupFolder", backupFolder)
                             .Build();

            ITrigger trigger;

            if (runNow)
            {
                trigger = TriggerBuilder.Create()
                          .StartNow()
                          .WithSimpleSchedule(x => x
                                              .WithIntervalInHours(24)
                                              .RepeatForever())
                          .Build();
            }
            else
            {
                trigger = TriggerBuilder.Create()
                          .StartAt(dateNightOffset)
                          .WithSimpleSchedule(x => x
                                              .WithIntervalInHours(24)
                                              .RepeatForever())
                          .Build();
            }
            await scheduler.ScheduleJob(job, trigger);
        }
        public async Task Execute(IJobExecutionContext context)
        {
            await Task.Run(() => {
                JobDataMap dataMap = context.JobDetail.JobDataMap;

                ZendeskConfig zendeskConfig = new ZendeskConfig()
                {
                    Login    = dataMap.GetString("login"),
                    Password = dataMap.GetString("password"),
                    Url      = dataMap.GetString("url")
                };
                var backupFolder            = dataMap.GetString("backupFolder");
                ZendeskBackup zendeskBackup = new ZendeskBackup(zendeskConfig, backupFolder);
                zendeskBackup.Run();
            });
        }