예제 #1
0
        private async Task <(string, TimeSpan)> RunUrl(CheckRegister data)
        {
            string status = string.Empty;
            var    client = _httpClientFactory.CreateClient();

            try
            {
                var policy = Policy.Handle <HttpRequestException>()
                             .OrResult <HttpResponseMessage>(r => r.StatusCode != HttpStatusCode.OK)
                             .WaitAndRetryAsync(_appSettings.RetryAttempt, retryAttempt => TimeSpan.FromMilliseconds(3000));


                var stopWatch = Stopwatch.StartNew();
                var response  = await policy.ExecuteAsync(async() => await client.GetAsync(new Uri(data.Url)));


                status = response.StatusCode == HttpStatusCode.OK ? UrlStatus.UP.ToString() : UrlStatus.Down.ToString();
                return(status, stopWatch.Elapsed);
            }
            catch (HttpRequestException)
            {
                return(UrlStatus.BadUrl.ToString(), TimeSpan.FromMilliseconds(0));
            }
            catch (Exception)
            {
                return(UrlStatus.BadUrl.ToString(), TimeSpan.FromMilliseconds(0));
            }
            finally
            {
                client.Dispose();
            }
        }
예제 #2
0
 private static IJobDetail CreateJob(JobSchedule schedule, CheckRegister item)
 {
     return(JobBuilder
            .Create(schedule.JobType)
            .WithIdentity($"{item.Id}")
            .WithDescription($"Job{item.Id}-{item.Name}")
            .Build());
 }
예제 #3
0
        private static ITrigger CreateTrigger(JobSchedule schedule, CheckRegister item)
        {
            var frequency = item.FrequencyType == "mm" ? item.Frequency : item.Frequency * 60;

            return(TriggerBuilder
                   .Create()
                   .WithIdentity($"{item.Name}{item.Id}.trigger")
                   .StartNow()
                   .WithSimpleSchedule(x => x.WithIntervalInSeconds(frequency).RepeatForever())
                   .WithDescription($"the trigger {item.Name} and {schedule.JobType}")
                   .Build());
        }
예제 #4
0
        public async Task AddCheck(CheckRegister check)
        {
            if (_context.CheckRegister.Any(x => x.Url == check.Url && x.Name == check.Name))
            {
                throw new AppException("Name \"" + check.Name + "\" and Url \"" + check.Url + "\" is already exists.");
            }


            check.IsScheduled = false;
            check.IsActive    = true;
            check.Id          = Guid.NewGuid();
            check.CreatedOn   = DateTime.UtcNow;
            _context.CheckRegister.Add(check);
            await _context.SaveChangesAsync();
        }
예제 #5
0
파일: Register.cs 프로젝트: Zorzin/KCK
 private bool GetSwim()
 {
     while (true)
     {
         ShowOnConsole("your divider for swim workout");
         SwimDivider = CheckData.ChengeDot(Console.ReadLine());
         if (!CheckEsc(SwimDivider))
         {
             return(false);
         }
         if (CheckRegister.CheckFloat(SwimDivider))
         {
             return(true);
         }
         Console.Clear();
         string s      = "Divider must be bigger than 0.";
         int    middle = (Console.WindowWidth - s.Length) / 2;
         Console.SetCursorPosition(middle, Console.CursorTop);
         Console.WriteLine(s);
     }
 }
예제 #6
0
파일: Register.cs 프로젝트: Zorzin/KCK
 private bool GetGoal()
 {
     while (true)
     {
         ShowOnConsole("your monthly goal(km)");
         Goal = CheckData.ChengeDot(Console.ReadLine());
         if (!CheckEsc(Goal))
         {
             return(false);
         }
         if (CheckRegister.CheckFloat(Goal))
         {
             return(true);
         }
         Console.Clear();
         string s      = "Goal must be bigger than 0.";
         int    middle = (Console.WindowWidth - s.Length) / 2;
         Console.SetCursorPosition(middle, Console.CursorTop);
         Console.WriteLine(s);
     }
 }
예제 #7
0
파일: Register.cs 프로젝트: Zorzin/KCK
 private bool GetRePassword()
 {
     while (true)
     {
         ShowOnConsole("Password again");
         RePassword = Console.ReadLine();
         if (!CheckEsc(RePassword))
         {
             return(false);
         }
         if (CheckRegister.CheckRePassword(Password, RePassword))
         {
             return(true);
         }
         Console.Clear();
         string s      = "Passwords are not the same.";
         int    middle = (Console.WindowWidth - s.Length) / 2;
         Console.SetCursorPosition(middle, Console.CursorTop);
         Console.WriteLine(s);
     }
 }
예제 #8
0
파일: Register.cs 프로젝트: Zorzin/KCK
 private bool GetPassword()
 {
     while (true)
     {
         ShowOnConsole("Password");
         Password = Console.ReadLine();
         if (!CheckEsc(Password))
         {
             return(false);
         }
         if (CheckRegister.CheckPassword(Password))
         {
             return(true);
         }
         Console.Clear();
         string s      = "Your password must be at least 6 characters long.";
         int    middle = (Console.WindowWidth - s.Length) / 2;
         Console.SetCursorPosition(middle, Console.CursorTop);
         Console.WriteLine(s);
     }
 }
예제 #9
0
파일: Register.cs 프로젝트: Zorzin/KCK
 private bool GetName()
 {
     while (true)
     {
         ShowOnConsole("your Name");
         Name = Console.ReadLine();
         if (!CheckEsc(Name))
         {
             return(false);
         }
         if (CheckRegister.CheckName(Name))
         {
             return(true);
         }
         Console.Clear();
         string s      = "Your name must be at least 5 characters long.";
         int    middle = (Console.WindowWidth - s.Length) / 2;
         Console.SetCursorPosition(middle, Console.CursorTop);
         Console.WriteLine(s);
     }
 }