public static void Restaurants(McDonaldsContext context) { List <Restaurant> restaurantList = new List <Restaurant>(); try { DataTable deploiementTable = ExcelParserHelper .ReadExcelFile(@"" + AppSettings.ReadSetting <string>(AppSettingConstants.ListRestaurantFile, default(string))) .Tables["Déploiement"]; for (int i = 2; i < deploiementTable.Rows.Count; i++) { restaurantList.Add(new Restaurant() { RestaurantId = Convert.ToInt32(deploiementTable.Rows[i][0]), ServerIpAddress = IpAddressHelper.CcToIp(Convert.ToInt32(deploiementTable.Rows[i][0]), 71).ToString(), Nom = Convert.ToString(deploiementTable.Rows[i][1]), }); } restaurantList.Add(new Restaurant() { RestaurantId = 9, ServerIpAddress = "10.19.9.71", Nom = "ParisC", }); context.Set <Restaurant>().AddOrUpdate(r => r.RestaurantId, restaurantList.Where(r => r.RestaurantId != 0).ToArray()); } catch (Exception ex) { throw ex; } }
public static bool IsValid(McDonaldsContext context, int restaurantId, DateTime dateTime) { DateTime days = dateTime.Date.AddDays(-15); return(context .ServerEvents .Where(r => r.RestaurantId == restaurantId && r.Event == Event.RedemarrageOK && r.UpTimes < days) .OrderByDescending(r => r.Date) .FirstOrDefault() != null); }
private static bool Holidays(McDonaldsContext context, DateTime currentDate) { DateTime dateDebut = currentDate.Date.AddDays(-1); DateTime dateFin = currentDate.Date.AddDays(1); return(context .Holydays .AsNoTracking() .Any(h => h.Date < dateDebut && h.Date > dateFin)); }
public static bool IsValid(McDonaldsContext context, DateTime dateTime) { DateTime dateDebut = dateTime.Date; DateTime dateFin = dateTime.Date.AddDays(1); return(context .ServerEvents .AsNoTracking() .Where(se => se.Date > dateDebut && se.Date < dateFin && se.Event == Event.RedemarrageOK) .Count() < AppSettings.ReadSetting(AppSettingConstants.MaxRestartPerDay, 200)); }
public static IEnumerable <int> GetPriorityRestaurant(McDonaldsContext context) { DateTime dateDebut = DateTime.Now.Date; DateTime DateFin = dateDebut.AddDays(-1); return(context .ServerEvents .Where(se => se.Date > DateFin && se.Date < dateDebut && (se.Event == Event.DemandeRejete || se.Event == Event.RedemarrageNOK)) .OrderByDescending(se => se.Date) .DistinctBy(se => se.RestaurantId) .Select(se => se.RestaurantId) .Take(200)); }
public static bool IsValid(McDonaldsContext context, string ipAddress, out int restaurantId) { var result = IpAddressHelper.IpToCc(IPAddress.Parse(ipAddress)); if (result != default(int)) { restaurantId = result; return(context .Restaurants .Any(r => r.RestaurantId.Equals(result))); } restaurantId = 0; return(false); }
public static void Holydays(McDonaldsContext context) { context.Set <Holyday>().AddOrUpdate(h => h.Code, new List <Holyday>() { new Holyday { HolydayId = 1, Code = "1erJanvier", Label = "1er janvier", Date = DateTime.ParseExact("2020-01-01", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) }, new Holyday { HolydayId = 2, Code = "LundiDePaques", Label = "Lundi de Pâques", Date = DateTime.ParseExact("2020-04-13", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) }, new Holyday { HolydayId = 3, Code = "1erMai", Label = "1er mai", Date = DateTime.ParseExact("2020-05-01", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) }, new Holyday { HolydayId = 4, Code = "8Mai", Label = "8 mai", Date = DateTime.ParseExact("2020-05-08", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) }, new Holyday { HolydayId = 5, Code = "Ascension", Label = "Ascension", Date = DateTime.ParseExact("2020-05-21", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) }, new Holyday { HolydayId = 6, Code = "LundiDePentecote", Label = "Lundi de Pentecôte", Date = DateTime.ParseExact("2020-06-01", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) }, new Holyday { HolydayId = 7, Code = "14Juillet", Label = "14 juillet", Date = DateTime.ParseExact("2020-07-14", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) }, new Holyday { HolydayId = 8, Code = "Assomption", Label = "Assomption", Date = DateTime.ParseExact("2020-08-15", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) }, new Holyday { HolydayId = 9, Code = "Toussaint", Label = "Toussaint", Date = DateTime.ParseExact("2020-11-01", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) }, new Holyday { HolydayId = 10, Code = "11Novembre", Label = "11 novembre", Date = DateTime.ParseExact("2020-11-11", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) }, new Holyday { HolydayId = 11, Code = "JourDeNoel", Label = "Jour de Noël", Date = DateTime.ParseExact("2020-12-25", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture) }, }.ToArray()); }
public static bool CheckLastServerUpTimes(McDonaldsContext context, int restaurantId, DateTime upTimes) { return(context .ServerEvents .Any(r => r.RestaurantId == restaurantId && r.UpTimes == upTimes)); }
public static bool CheckPriority(McDonaldsContext context, int restaurantId) { return(GetPriorityRestaurant(context).FirstOrDefault() == restaurantId); }
public static bool IsValid(McDonaldsContext context, DateTime currentDate) { return(WeekDates(context, currentDate) || !Holidays(context, currentDate)); }
private static bool WeekDates(McDonaldsContext context, DateTime currentDate) { string[] result = AppSettings.ReadSetting(AppSettingConstants.AuthorizedWeekDate, string.Empty).Split(','); return(result.Any(r => result.Contains(currentDate.ToString("dddd"), StringComparer.OrdinalIgnoreCase))); }