Exemple #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);
                }
            });
        }
Exemple #2
0
        public static void NotifyComingInstallation()
        {
            var enforcemets  = SqlCe.GetPendingSchedules();
            var validToToast = enforcemets.Where(x => x.EnforcementTime < DateTime.Today.AddDays(2)).First();

            // Construct the visuals of the toast
            var toastContent = new ToastContent()
            {
                // Arguments when the user taps body of toast
                Launch = new QueryString()
                {
                    { "action", "ok" },
                    { "appidrevision", $"close" },
                }.ToString(),

                Visual = new ToastVisual()
                {
                    BindingGeneric = new ToastBindingGeneric()
                    {
                        Children =
                        {
                            new AdaptiveText()
                            {
                                Text = "Reminder",
                            },

                            new AdaptiveText()
                            {
                                Text = $"You have an upcomming scheduled installation at '{validToToast.EnforcementTime}'",
                            },
                        },
                    },
                },
            };

            var doc = new XmlDocument();

            doc.LoadXml(toastContent.GetContent());

            // And create the toast notification
            var toast = new ToastNotification(doc)
            {
                ExpirationTime = DateTimeOffset.Now.AddSeconds(15)
            };

            // And then show it
            DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast);
        }
Exemple #3
0
        protected override void OnSessionChange(SessionChangeDescription changeDescription)
        {
            if (changeDescription.Reason == SessionChangeReason.SessionLogon || changeDescription.Reason == SessionChangeReason.SessionUnlock)
            {
                var enforcemets = SqlCe.GetPendingSchedules();

                if (enforcemets.Where(x => x.EnforcementTime < DateTime.Today.AddDays(2)).Any())
                {
                    Task.Run(() =>
                    {
                        System.Threading.Thread.Sleep(20000);
                        UnsafeNativeMethods.Run(_userApp, $"/ToastNotifyComingInstallation", false);
                    });
                }

                if (SqlCe.GetAutoEnforceFlag())
                {
                    UnsafeNativeMethods.Run(_userApp, $"/ToastServiceRunningNotification", false);
                }

                _rebootToastDelay = 0;

                var rs = SqlCe.GetRestartSchedule();

                if (rs != null)
                {
                    if (rs.IsExpress)
                    {
                        SqlCe.DeleteRestartSchedule();
                    }

                    RestartRequired();
                }
            }

            if (changeDescription.Reason == SessionChangeReason.SessionLogon)
            {
                UnsafeNativeMethods.Run(_trayApp, null, false);

                if (_settings.IpuApplication.ShowProgress && _ipuRunning)
                {
                    UnsafeNativeMethods.Run(_progressApp, string.Empty, false);
                }
            }
        }
Exemple #4
0
        private void RestartWnd_Loaded(object sender, RoutedEventArgs e)
        {
            if (Globals.Args.Exist("ServiceSchedule"))
            {
                var nextServiceTime = CommonUtils.GetNextServiceCycleAsDateTime();

                if (nextServiceTime != null)
                {
                    RestartText.Text = _settings.InfoText.Replace("%TIME%", nextServiceTime.ToString());
                    _dtClose         = ((DateTime)nextServiceTime).AddMinutes(-2);
                }
            }
            else
            {
                var allPendingSchedules = SqlCe.GetPendingSchedules();
                var first = allPendingSchedules.Where(x => x.EnforcementTime <= DateTime.Now.AddHours(4) && x.HasRaisedConfirm).First();

                RestartText.Text = _settings.InfoText.Replace("%TIME%", first.EnforcementTime.ToString());
                _dtClose         = first.EnforcementTime.AddMinutes(-2);
            }

            AutoCloseLoop();
        }