Ejemplo n.º 1
0
        public static async Task <int> UpdateDbWithNewLogEvents(DateTime trgDate, A0DbModel db) //todo: remove the dupes into central space
        {
            int rowsAddedSaved = 0;

            try
            {
                var t1 = trgDate;
                var t2 = trgDate.AddDays(.99999);
                await Task.Run(() => EvLogHelper.GetAllUpDnEvents(t1, t2)).ContinueWith(_ =>
                {
                    try
                    {
                        var dailyEvents = _.Result;
                        if (dailyEvents.Count < 1)
                        {
                            Debug.WriteLine($"==>{trgDate:MMM-dd, ddd}:   No events registered for the day.");
                        }
                        else
                        {
                            rowsAddedSaved = DbLogHelper.FindNewEventsToSaveToDb(_.Result, Environment.MachineName, $"Db.EvLog.Explr {trgDate}", db);
                        }
                    }
                    catch (Exception ex) { ex.Log(); rowsAddedSaved = -5; }
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }
            catch (Exception ex) { ex.Log(); rowsAddedSaved = -1; }

            return(rowsAddedSaved);
        }
Ejemplo n.º 2
0
        void jjj()
        {
            var h00 = DateTime.Today;
            var h24 = h00.AddDays(.9999999);
            var lst = EvLogHelper.GetAllUpDnEvents(h00, h24);

            foreach (var item in lst)
            {
                Debug.WriteLine($"---- {item.Key},  {item.Value}");
            }
        }
Ejemplo n.º 3
0
        });                                                                                                                                                                                                                                                                                //addArcDtl(hgt, left, width);

        void drawUpDnLine(DateTime trgDate, string pc, string rgb)
        {
            var pcClr = new SolidColorBrush((Color)ColorConverter.ConvertFromString(rgb));
            var ts    = new TimeSplit();

            //..Trace.Write($">>>-\tdrawUpDnLine():  {trgDate:d} ->> {pc,-16} \t");
            tbSummary.Text = "$@#";
            try
            {
                _ah = canvasBar.ActualHeight;
                _aw = canvasBar.ActualWidth;
                var timeA  = trgDate;
                var timeB  = trgDate.AddDays(.9999999);
                var isHere = Environment.MachineName.Equals(pc, StringComparison.OrdinalIgnoreCase);

                SortedList <DateTime, int> eois;
                if (isHere)
                {
                    var localEvLog = EvLogHelper.GetAllUpDnEvents(timeA, timeB);
                    var dbaseEvLog = DbLogHelper.GetAllUpDnEvents(timeA, timeB, pc);
                    eois = localEvLog.Count > dbaseEvLog.Count ? localEvLog : dbaseEvLog; // Jan 2020: whoever has more events wins!
                }
                else
                {
                    eois = DbLogHelper.GetAllUpDnEvents(timeA, timeB, pc);
                }

                if (trgDate == DateTime.Today && isHere)
                {
                    eois.Add(DateTime.Now, 2); // == ((int)EvOfIntFlag.ScreenSaverrUp)
                }
                if (eois.Count < 1)
                {
                    tbSummary.Text = $"{trgDate,16:ddd, MMM dd yyyy}  no activities logged on this date.";
                }
                else
                {
                    var eoi0     = eois.FirstOrDefault();
                    var prevEoiF = eoi0.Value == (int)EvOfIntFlag.ScreenSaverrDn ? EvOfIntFlag.ScreenSaverrUp :
                                   eoi0.Value == (int)EvOfIntFlag.BootAndWakeUps ? EvOfIntFlag.ShutAndSleepDn : EvOfIntFlag.Day1stAmbiguos;

                    foreach (var eoi in eois)
                    {
                        addWkTimeSegment(timeA, eoi.Key, prevEoiF, (EvOfIntFlag)eoi.Value, pcClr, ref ts);

                        timeA    = eoi.Key;
                        prevEoiF = (EvOfIntFlag)eoi.Value;
                    }

                    var lastScvrUp = (eois.Any(r => r.Value == (int)EvOfIntFlag.ScreenSaverrUp || r.Value == (int)EvOfIntFlag.ShutAndSleepDn) ?
                                      eois.Where(r => r.Value == (int)EvOfIntFlag.ScreenSaverrUp || r.Value == (int)EvOfIntFlag.ShutAndSleepDn).Last() : eois.Last()).Key;

                    var finalEvent = eois.Last().Key;

                    ts.TotalDaysUp = (lastScvrUp < finalEvent ? lastScvrUp : finalEvent) - eois.First().Key;

                    tbSummary.Text = $"{trgDate,16:ddd, MMM dd yyyy}    {ts.TotalDaysUp,5:h\\:mm}  ({ts.WorkedFor:h\\:mm})    ";
                }

                tbSummary.Foreground = (trgDate.DayOfWeek == DayOfWeek.Saturday || trgDate.DayOfWeek == DayOfWeek.Sunday) ? cWEd : cWDd;
                gridvroot.Background = (trgDate.DayOfWeek == DayOfWeek.Saturday || trgDate.DayOfWeek == DayOfWeek.Sunday) ? cPnk : cBlk;
            }
            catch (Exception ex) { ex.Pop(); }
            finally { Trace.WriteLine($" ==> { tbSummary.Text} "); }
        }