Beispiel #1
0
        private void ConfirmPump()
        {
            Task.Run(() =>
            {
                while (true)
                {
                    try
                    {
                        if (!UnsafeNativeMethods.IsUserLoggedOn())
                        {
                            System.Threading.Thread.Sleep(60 * 60000);
                            continue;
                        }

                        var needConfirm = false;
                        var arg         = "/ShowConfirmWindow";

                        var allPendingSchedules    = SqlCe.GetPendingSchedules();
                        var fourHourLimitSchedules = allPendingSchedules.Where(x => x.EnforcementTime <= DateTime.Now.AddHours(4) && !x.HasRaisedConfirm);

                        foreach (var schedule in fourHourLimitSchedules)
                        {
                            SqlCe.SetHasRaisedConfirm(schedule.Id);
                            needConfirm = true;
                        }

                        var dtServiceTime = CommonUtils.GetNextServiceCycleAsDateTime();

                        if (dtServiceTime != null)
                        {
                            var tempServiceAck = SqlCe.GetLastServiceAck();
                            var lastServiceAck = tempServiceAck == DateTime.MaxValue ? DateTime.MinValue : tempServiceAck.AddHours(4);

                            if (dtServiceTime <= DateTime.Now.AddHours(4) && lastServiceAck <= DateTime.Now)
                            {
                                arg += " /ServiceSchedule";
                                SqlCe.SetLastServiceAck();
                                needConfirm = true;
                            }
                        }

                        if (needConfirm)
                        {
                            Globals.Log.Information("Confirmation required, launching confirm dialog.");
                            UnsafeNativeMethods.Run(_userApp, arg, false);
                        }
                    }
                    catch (Exception ex)
                    {
                        Globals.Log.Error(ex.Message);
                    }

                    System.Threading.Thread.Sleep(60 * 60000);
                }
            });
        }