private bool CheckKegStatus() { Debug.WriteLine(" Refreshing CheckKeg Status ..."); this.WarningBorderBrush.Visibility = Visibility.Collapsed; this.warningTitle.Visibility = Visibility.Collapsed; this.PintsText.Style = App.Current.Resources["AppSubheaderTextBlockStyle"] as Style; //TODO: check all validations in Async bool valid = false; if (Common.KegSettings == null) { Task.Run(() => Common.GetKegSettings()).Wait(); } //Maintenance Mode if (Common.KegSettings.MaintenanceMode) { this.Maintenance = true; return(valid); } //Evalaute KegSettings //Core Hours: Allowed Only if outside corehours //12T14;16T18 //To decode entry to readable format StringBuilder entryToReadable = new StringBuilder(); if (Common.KegSettings.CoreHours != null) { string[] coreHours = Common.KegSettings.CoreHours.Split(Common.semiColonDelimiter, StringSplitOptions.RemoveEmptyEntries); //Int32 currentHour = DateTime.Now; //Validation if (coreHours.Length == 0) { valid = false; } foreach (var itemEntry in coreHours) { //Split into string[] entry = itemEntry.Split(Common.timeTDelimiter); DateTime startTime = DateTime.Today; //12AM DateTime endTime = DateTime.Today.AddDays(1); //11:59PM if (entry.Length > 1) { if (entry[0].Trim().Length > 0) { int[] hrmin = entry[0].Split(Common.colonDelimiter).Select(x => int.Parse(x.ToString())).ToArray(); startTime = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, hrmin[0], (hrmin.Length > 1 ? hrmin[1] : 0), 0); } if (entry[1].Trim().Length > 0) { int[] hrmin = entry[1].Split(Common.colonDelimiter).Select(x => int.Parse(x.ToString())).ToArray(); endTime = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, hrmin[0], (hrmin.Length > 1 ? hrmin[1] : 0), 0); } entryToReadable.Append(startTime.ToString("hh:mm tt")); entryToReadable.Append(" To "); entryToReadable.Append(endTime.ToString("hh:mm tt")); entryToReadable.Append(","); //If multiple corehours are supplied, then all should be satisifed valid = !(DateTime.Now.Ticks > startTime.Ticks && DateTime.Now.Ticks < endTime.Ticks); } else { //reject valid = false; } } } if (!valid) { //debugging purpose if (!App.IgnoreCoreHours) { string coreHoursDisplay = entryToReadable.ToString(); if (coreHoursDisplay.EndsWith(",")) { coreHoursDisplay = coreHoursDisplay.Substring(0, coreHoursDisplay.Length - 1); } this.startScanTitle.Text = string.Format(this["CoreHoursException"], coreHoursDisplay); this.WarningBorderBrush.BorderBrush = App.Current.Resources["BorderBrush"] as SolidColorBrush; return(valid); } } //Validate CoreDays //ex: Mon,Tue, Wed, Thu,Fri string[] coreDays = Common.KegSettings.CoreDays.Split(Common.commaDelimiter, StringSplitOptions.RemoveEmptyEntries).Select(x => x.ToLowerInvariant().Trim()).ToArray(); string charToday = DateTime.Today.ToString("ddd").ToLowerInvariant().Trim(); if (coreDays.Contains(charToday)) { valid = true; } else { //debugging purpose if (!App.IgnoreCoreHours) { valid = false; this.startScanTitle.Text = string.Format(this["CoreDaysException"], Common.KegSettings.CoreDays); this.WarningBorderBrush.BorderBrush = App.Current.Resources["BorderBrush"] as SolidColorBrush; return(valid); //throw new Exception(string.Format(Common.GetResourceText("CoreDaysException"), Common.KegSettings.CoreDays)); } } //Avaialble Pints //TODO: Measurement wtMeasurement = App._weight.GetWeight(); if (wtMeasurement != null) { //float percentage = wtMeasurement.Amount * 10 / (Common.KegSettings.MaxKegWeight - Common.KegSettings.EmptyKegWeight); float percentage = wtMeasurement.Amount / (Common.KegSettings.MaxKegWeight - Common.KegSettings.EmptyKegWeight); Debug.WriteLine($"Percentage1: {percentage}"); //TODO : Check the calibration if (percentage > 100.00f) { PintsText.Text = $"99% full"; } else { PintsText.Text = $"{Math.Round(percentage)}% full"; } if (wtMeasurement.Amount < Common.MINIMUMLIMITTOEMPTY) { //this.startScanTitle.Text = string.Format(Common.GetResourceText("Page1KegEmpty")); this.warningTitle.Visibility = Visibility.Visible; this.warningTitle.Text = string.Format(this["Page1KegEmpty"]); this.WarningBorderBrush.BorderBrush = App.Current.Resources["BorderBrush"] as SolidColorBrush; this.PintsText.Foreground = App.Current.Resources["BorderBrush"] as SolidColorBrush; //DONT Stop user to proceed further as Weight can be not too accurate and helps user to get drink //valid = false; //return valid; } } try { Debug.WriteLine(" Refreshing LocalDB entries..."); //Clean localDB SqLiteHelper localDB = new SqLiteHelper(); //Log Metrics //localDB.LogExpiredUserConsumption(Common.USERTIMEBASELINE); localDB.LogExpiredUserConsumption(Common.KegSettings.UserConsumptionReset); //Clean entries of user consumptions older than x minutes localDB.DeleteExpiredUserConsumption(Common.KegSettings.UserConsumptionReset); } catch (Exception ex) { KegLogger.KegLogException(ex, "MainPage:CheckKegStatus:DeleteExpiredUserConsumption", SeverityLevel.Error); // new dictionary<string, string>() { // {"userbaseline", common.usertimebaseline.tostring() } //}); } if (valid) { this.startScanTitle.Text = this["Page1BodyText"]; } return(valid); }