Esempio n. 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();
            }
        }
Esempio n. 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());
 }
Esempio n. 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());
        }
Esempio n. 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();
        }
Esempio n. 5
0
 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);
     }
 }
Esempio n. 6
0
 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);
     }
 }
Esempio n. 7
0
 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);
     }
 }
Esempio n. 8
0
 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);
     }
 }
Esempio n. 9
0
 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);
     }
 }