private void WorkerInspactionDriver()
        {
            LogEr.Logerr("Info1", "Start Servse WorkParser Inspaction", "WorkerInspactionDriver", DateTime.Now.ToShortTimeString());
            int horseInmMiliSeconds = 60000 * 60;

            Task.Run(() =>
            {
                while (true)
                {
                    try
                    {
                        LogEr.Logerr("Info1", "Check Time", "WorkerInspactionDriver", DateTime.Now.ToShortTimeString());
                        List <Driver> drivers = sqlCommandParser.GetDriverInDb();
                        if (CheckTodayTime() && drivers != null)
                        {
                            RefreshInspectionTodayTimeDriver(drivers);
                        }
                        if (CheckTime() && drivers != null)
                        {
                            RefreshInspectionTimeDriver(drivers);
                        }
                        Thread.Sleep(horseInmMiliSeconds);
                    }
                    catch
                    {
                        LogEr.Logerr("Info1", "Error", "WorkerInspactionDriver", DateTime.Now.ToShortTimeString());
                    }
                }
            }).GetAwaiter().GetResult();
        }
Beispiel #2
0
        public async void AddOrder(Shipping shipping)
        {
            bool isCheckOrder = CheckUrlOrder(shipping);

            if (CheckOrder(shipping) && !isCheckOrder)
            {
                shipping.Id += new Random().Next(0, 1000);
            }
            try
            {
                if (!isCheckOrder)
                {
                    LogEr.Logerr("Info", $"Order added to database, Load Id {shipping.Id}", "ParseDataInUrl", DateTime.Now.ToShortTimeString());
                    await context.Shipping.AddAsync(shipping);

                    await context.SaveChangesAsync();
                }
                else
                {
                    LogEr.Logerr("Info", $"Order already exists in the database, Load Id {shipping.Id}", "AddOrder", DateTime.Now.ToShortTimeString());
                }
            }
            catch (Exception e)
            {
                LogEr.Logerr("Info", $"{e.Message}, Load Id {shipping.Id}", "AddOrder", DateTime.Now.ToShortTimeString());
            }
        }
        private async void RefreshInspectionTodayTimeDriver(List <Driver> drivers)
        {
            foreach (var driver in drivers)
            {
                LogEr.Logerr("Info1", $"driver status change \"{driver.Id}\"", "RefreshInspectionTodayTimeDriver", DateTime.Now.ToShortTimeString());
                await sqlCommandParser.RefreshInspectionToDayDriverInDb(driver.Id);

                SendNotyfyInspactionDrive(driver.TokenShope, "Truck Inspection", "You can pass the truck inspection now");
            }
        }
        private bool CheckTime()
        {
            bool isTime = false;

            if (11 <= DateTime.Now.Hour && 12 > DateTime.Now.Hour)
            {
                LogEr.Logerr("Info1", $"Time 11 <= DateTime.Now.Hour && 12 > DateTime.Now.Hour", "CheckTime", DateTime.Now.ToShortTimeString());
                isTime = true;
            }
            return(isTime);
        }
Beispiel #5
0
        public async Task RefreshInspectionDriverInDb(int idDriver)
        {
            Driver driver = context.Drivers.FirstOrDefault(d => d.Id == idDriver);

            if (driver != null)
            {
                LogEr.Logerr("Info1", $"Refresh the driver \"{driver.Id}\" to pass inspection", "RefreshInspectionDriverInDb", DateTime.Now.ToShortTimeString());
                driver.IsInspectionDriver = false;
                await context.SaveChangesAsync();
            }
        }
        private async void RefreshInspectionTimeDriver(List <Driver> drivers)
        {
            foreach (var driver in drivers)
            {
                if (!driver.IsInspectionToDayDriver)
                {
                    LogEr.Logerr("Info1", $"check on the driver \"{driver.Id}\" to pass inspection", "RefreshInspectionTimeDriver", DateTime.Now.ToShortTimeString());
                    await sqlCommandParser.RefreshInspectionDriverInDb(driver.Id);

                    SendNotyfyInspactionDrive(driver.TokenShope, "Truck Inspection", "Immediately go truck inspection or else you will not be able to continue working");
                }
            }
        }
 public void SendNotyfyInspactionDrive(string tokenShope, string title, string body)
 {
     if (tokenShope != null && tokenShope != "")
     {
         LogEr.Logerr("Info1", $"Send notyfy {body}", "SendNotyfyInspactionDrive", DateTime.Now.ToShortTimeString());
         var payload = new
         {
             to = tokenShope,
             content_available = true,
             notification      = new
             {
                 click_action = "Driver",
                 body         = body,
                 title        = title
             },
         };
         string postbody  = JsonConvert.SerializeObject(payload).ToString();
         Byte[] byteArray = Encoding.UTF8.GetBytes(postbody);
         tRequest.ContentLength = byteArray.Length;
         using (Stream dataStream = tRequest.GetRequestStream())
         {
             dataStream.Write(byteArray, 0, byteArray.Length);
             using (WebResponse tResponse = tRequest.GetResponse())
             {
                 using (Stream dataStreamResponse = tResponse.GetResponseStream())
                 {
                     if (dataStreamResponse != null)
                     {
                         using (StreamReader tReader = new StreamReader(dataStreamResponse))
                         {
                             String sResponseFromServer = tReader.ReadToEnd();
                         }
                     }
                 }
             }
         }
     }
     InitReqvest();
 }