Beispiel #1
0
        private void RegisterForRestart()
        {
            var settings = new RestartSettings("/restart", RestartRestrictions.None);

            ApplicationRestartRecoveryManager.RegisterForApplicationRestart(settings);
            AppLogger.Log.Info("Restart Registered");
        }
Beispiel #2
0
        /// <summary>
        ///     The run app.
        /// </summary>
        private static void RunApp()
        {
            try
            {
                // Application Services
                ApplicationRestartRecoveryManager.RegisterForApplicationRestart(
                    new RestartSettings(string.Empty, RestartRestrictions.None));
            }
            catch (Exception)
            {
            }
            try
            {
                Notify = new NotifyIcon {
                    Visible = false
                };
                defualtApp.InitializeComponent();
                defualtApp.DispatcherUnhandledException += (s, e) =>
                {
                    VDialog.Show(
                        e.Exception.Message + "\r\n\r\n" + e.Exception.StackTrace,
                        "FATAL ERROR",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    e.Handled = false;
                    End();
                };
                defualtApp.Run();
            }
            catch (Exception)
            {
            }

            End();
        }
Beispiel #3
0
        private void RegisterRecovery()
        {
            var settings = new RecoverySettings(new RecoveryData(SaveState, AppConfigs.Configuration), 0);

            ApplicationRestartRecoveryManager.RegisterForApplicationRecovery(settings);
            AppLogger.Log.Info("Recovery Registered");
        }
        public void WireUp()
        {
            TaskScheduler.UnobservedTaskException            += TaskSchedulerOnUnobservedTaskException;
            AppDomain.CurrentDomain.UnhandledException       += CurrentDomainOnUnhandledException;
            Application.Current.DispatcherUnhandledException += ApplicationOnDispatcherUnhandledException;

            ApplicationRestartRecoveryManager.RegisterForApplicationRestart(new RestartSettings("-died", RestartRestrictions.None));
        }
 private void Ping()
 {
     if (ApplicationRestartRecoveryManager.ApplicationRecoveryInProgress())
     {
         Debug.Write("Operation Cancelled");
         Environment.Exit(2);
     }
 }
Beispiel #6
0
 private void UnregisterApplicationRecoveryAndRestart()
 {
     if (CoreHelpers.RunningOnVista)
     {
         ApplicationRestartRecoveryManager.UnregisterApplicationRestart();
         ApplicationRestartRecoveryManager.UnregisterApplicationRecovery();
     }
 }
Beispiel #7
0
        private void RegisterForRecovery()
        {
            var settings = new RecoverySettings(new RecoveryData(DoRecovery, _tempPath), 0);

            ApplicationRestartRecoveryManager.RegisterForApplicationRecovery(settings);
            TraceTextBlock.Text += string.Format("{0:T}: Registered for recovery\n", DateTime.Now);
            App.Source.TraceEvent(TraceEventType.Verbose, 0, "Registered for recovery");
            // NOTE: Зарегистрировано для восстановления
        }
Beispiel #8
0
        /// <summary>The unregister application recovery and restart.</summary>
        static void UnregisterApplicationRecoveryAndRestart()
        {
            if (Environment.OSVersion.Version.Major < 6)
            {
                return;
            }

            ApplicationRestartRecoveryManager.UnregisterApplicationRestart();
        }
Beispiel #9
0
        private void RegisterForRestart()
        {
            var settings = new RestartSettings(string.Format("/restart:{0}", _tempPath),
                                               RestartRestrictions.NotOnReboot | RestartRestrictions.NotOnPatch);

            ApplicationRestartRecoveryManager.RegisterForApplicationRestart(settings);
            TraceTextBlock.Text += string.Format("{0:T}: Registered for restart\n", DateTime.Now);
            App.Source.TraceEvent(TraceEventType.Verbose, 0, "Registered for restart");
            // NOTE: Зарегистрировано для перезапуска
        }
Beispiel #10
0
        private void RegisterForRestart()
        {
            // Register for automatic restart if the
            // application was terminated for any reason
            // other than a system reboot or a system update.
            ApplicationRestartRecoveryManager.RegisterForApplicationRestart(
                new RestartSettings("/restart", RestartRestrictions.NotOnReboot | RestartRestrictions.NotOnPatch));

            Debug.WriteLine("ARR: Registered for restart");
        }
Beispiel #11
0
        /// <summary>Registers the application to use the Recovery Manager.</summary>
        static void RegisterApplicationRecoveryAndRestart()
        {
            if (Environment.OSVersion.Version.Major < 6)
            {
                return;
            }

            // register for Application Restart
            ApplicationRestartRecoveryManager.RegisterForApplicationRestart(
                new RestartSettings(string.Empty, RestartRestrictions.NotOnReboot));
        }
Beispiel #12
0
        // This method is called periodically to ensure
        // that WER knows that recovery is still in progress.
        private void PingSystem()
        {
            // Find out if the user canceled recovery.
            bool isCanceled = ApplicationRestartRecoveryManager.ApplicationRecoveryInProgress();

            if (isCanceled)
            {
                Console.WriteLine("Recovery has been canceled by user.");
                Environment.Exit(2);
            }
        }
Beispiel #13
0
        private void RegisterApplicationRecoveryAndRestart()
        {
            if (CoreHelpers.RunningOnVista)
            {
                // register for Application Restart and Recovery
                RestartSettings restartSettings = new RestartSettings(string.Empty, RestartRestrictions.None);
                ApplicationRestartRecoveryManager.RegisterForApplicationRestart(restartSettings);

                RecoverySettings recoverySettings = new RecoverySettings(new RecoveryData(PerformRecovery, null), c_keepAliveInterval);
                ApplicationRestartRecoveryManager.RegisterForApplicationRecovery(recoverySettings);
            }
        }
Beispiel #14
0
        private int RecoveryProcedure(object state)
        {
            PingSystem();
            var doc = new XDocument(
                new XDeclaration("1.0", "UTF-8", "yes"),
                new XElement("root",
                             new XElement("Name", dataContent.Name),
                             new XElement("about", dataContent.About)));

            doc.Save(recoveryFile, SaveOptions.DisableFormatting);
            ApplicationRestartRecoveryManager.ApplicationRecoveryFinished(true);
            return(0);
        }
        private int RecoverDataCallback(object state)
        {
            Ping();
            var recoveryfile = Path.Combine(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory), "Recoverydata.xml");
            var doc          = new XDocument(
                new XDeclaration("1.0", "UTF-8", "yes"),
                new XElement("root",
                             new XElement("FileName", _list.FilePath),
                             new XElement("Comment", txtComments.Text),
                             new XElement("Selected", Imgdisplay.Source)));

            doc.Save(recoveryfile, SaveOptions.DisableFormatting);
            ApplicationRestartRecoveryManager.ApplicationRecoveryFinished(true);
            return(0);
        }
Beispiel #16
0
        private void RegisterForRecovery()
        {
            // Don't pass any state. We'll use our static variable "CurrentFile" to determine
            // the current state of the application.
            // Since this registration is being done on application startup, we don't have a state currently.
            // In some cases it might make sense to pass this initial state.
            // Another approach: When doing "auto-save", register for recovery everytime, and pass
            // the current state at that time.
            RecoveryData     data     = new RecoveryData(new RecoveryCallback(RecoveryProcedure), null);
            RecoverySettings settings = new RecoverySettings(data, 0);

            ApplicationRestartRecoveryManager.RegisterForApplicationRecovery(settings);

            Debug.WriteLine("ARR: Registered for recovery");
        }
Beispiel #17
0
        /// <summary>
        /// Performs recovery by saving the state
        /// </summary>
        /// <param name="parameter">Unused.</param>
        /// <returns>Unused.</returns>
        private int PerformRecovery(object parameter)
        {
            try
            {
                ApplicationRestartRecoveryManager.ApplicationRecoveryInProgress();
                Storage.Save(m_rootViewModel.TaskData);
                ApplicationRestartRecoveryManager.ApplicationRecoveryFinished(true);
            }
            catch
            {
                ApplicationRestartRecoveryManager.ApplicationRecoveryFinished(false);
            }

            return(0);
        }
Beispiel #18
0
        /// <summary>Registers the application to use the Recovery Manager.</summary>
        static void RegisterApplicationRecoveryAndRestart()
        {
            if (Environment.OSVersion.Version.Major < 6)
            {
                return;
            }

            // register for Application Restart
            ApplicationRestartRecoveryManager.RegisterForApplicationRestart(
                new RestartSettings(string.Empty, RestartRestrictions.NotOnReboot));

            // register for Application Recovery
            var recoverySettings = new RecoverySettings(new RecoveryData(PerformRecovery, null), 4000);

            ApplicationRestartRecoveryManager.RegisterForApplicationRecovery(recoverySettings);
        }
Beispiel #19
0
        private int PerformRecovery(object parameter)
        {
            try
            {
                ApplicationRestartRecoveryManager.ApplicationRecoveryInProgress();

                RegistryUpdater.DisableImplicitLayer();

                ApplicationRestartRecoveryManager.ApplicationRecoveryFinished(true);
            }
            catch
            {
                ApplicationRestartRecoveryManager.ApplicationRecoveryFinished(false);
            }

            return(0);
        }
Beispiel #20
0
        /// <summary>Performs recovery by saving the state.</summary>
        /// <param name="parameter">This parameter is not used.</param>
        /// <returns>Return value is not used.</returns>
        static int PerformRecovery(object parameter)
        {
            try
            {
                ApplicationRestartRecoveryManager.ApplicationRecoveryInProgress();
                Core.SaveProject();

                // Save your work here for recovery
                ApplicationRestartRecoveryManager.ApplicationRecoveryFinished(true);
            }
            catch
            {
                ApplicationRestartRecoveryManager.ApplicationRecoveryFinished(false);
            }

            return(0);
        }
Beispiel #21
0
 private int SaveState(object state)
 {
     using (AppLogger.Log.ErrorCall())
     {
         AppLogger.Log.Error("Saving application state");
         var settings  = (SoundSwitchConfiguration)state;
         var cancelled = ApplicationRestartRecoveryManager.ApplicationRecoveryInProgress();
         if (cancelled)
         {
             AppLogger.Log.Error("Recovery Cancelled");
             ApplicationRestartRecoveryManager.ApplicationRecoveryFinished(false);
             return(0);
         }
         settings.Save();
         ApplicationRestartRecoveryManager.ApplicationRecoveryFinished(true);
         AppLogger.Log.Error("Recovery Success");
         return(0);
     }
 }
Beispiel #22
0
 /// <summary>
 ///     The end.
 /// </summary>
 public static void End()
 {
     if (jumpList != null && TaskbarManager.IsPlatformSupported)
     {
         jumpList.ClearAllUserTasks();
         jumpList.Refresh();
     }
     ApplicationRestartRecoveryManager.UnregisterApplicationRestart();
     if (Current != null && Current.MainWindow != null)
     {
         MainWindow cWindow = Current.MainWindow as MainWindow;
         if (cWindow != null)
         {
             cWindow.StopServer(true);
         }
         Current.Shutdown();
     }
     Environment.Exit(0);
 }
Beispiel #23
0
        public Form1()
        {
            InitializeComponent();

            recoveryFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "RecoveryData.xml");
            ApplicationRestartRecoveryManager.RegisterForApplicationRestart(
                new RestartSettings("/restart", RestartRestrictions.NotOnReboot | RestartRestrictions.NotOnPatch));

            var data     = new RecoveryData(RecoveryProcedure, null);
            var settings = new RecoverySettings(data, 0);

            ApplicationRestartRecoveryManager.RegisterForApplicationRecovery(settings);


            if (Environment.GetCommandLineArgs().Length > 1 && Environment.GetCommandLineArgs()[1] == "/restart")
            {
                RecoverLastSession(Environment.GetCommandLineArgs()[1]);
            }
        }
Beispiel #24
0
        // This method is invoked by WER.
        private int RecoveryProcedure(object state)
        {
            Debug.WriteLine("ARR: Recovery procedure called!!!");

            PingSystem();

            // Do recovery work here.
            // Signal to WER that the recovery
            // is still in progress.

            // Write the contents of the file, as well as some other data that we need
            File.WriteAllText(RecoveryFile, string.Format("{1}{0}{2}{0}{3}", DataSeparatorString, CurrentFile.Filename, CurrentFile.IsDirty, CurrentFile.Contents));

            Debug.WriteLine("File path: " + RecoveryFile);
            Debug.WriteLine("File exists: " + File.Exists(RecoveryFile));
            Debug.WriteLine("Application shutting down...");

            ApplicationRestartRecoveryManager.ApplicationRecoveryFinished(true);
            return(0);
        }
Beispiel #25
0
        private int DoRecovery(object state)
        {
            App.Source.TraceEvent(TraceEventType.Verbose, 0, "Begin recovery");
            _tempPath = state as string;
            var canceled = ApplicationRestartRecoveryManager.ApplicationRecoveryInProgress();

            if (canceled)
            {
                TraceTextBlock.Text += string.Format("{0:T}: Recovery canceled, shutting down\n", DateTime.Now);
                // NOTE: Восстановление отменено, завершение работы
                App.Source.TraceEvent(TraceEventType.Verbose, 0, "End recovery with cancel");
                ApplicationRestartRecoveryManager.ApplicationRecoveryFinished(false);
                return(0);
            }

            SaveFile(_tempPath);
            App.Source.TraceEvent(TraceEventType.Verbose, 0, "End recovery");
            ApplicationRestartRecoveryManager.ApplicationRecoveryFinished(true);

            return(0);
        }
Beispiel #26
0
        private int PerformRecovery(object parameter)
        {
            try
            {
                ApplicationRestartRecoveryManager.ApplicationRecoveryInProgress();
                if (System.IO.Directory.Exists("data") && System.IO.File.Exists("data/session.xml"))
                {
                    recovery = true;
                    new System.Threading.Thread(() =>
                    {
                        MessageBox.Show("Hands Free Leveler might be crashed during a sesion\nRecovering from last rotation\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "Recovery Restart", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }).Start();
                }

                ApplicationRestartRecoveryManager.ApplicationRecoveryFinished(true);
            }
            catch
            {
                ApplicationRestartRecoveryManager.ApplicationRecoveryFinished(false);
            }
            return(0);
        }
        public MainWindow()
        {
            InitializeComponent();

            //Register next Restart Recovery key (It ensures that application if application closes other than OnPatch/ OnReboot / NormalEnd
            // it pass the /recovery argument.
            ApplicationRestartRecoveryManager.RegisterForApplicationRestart(
                new RestartSettings("/recover", RestartRestrictions.NotOnPatch | RestartRestrictions.NotOnReboot));

            //Register Recovery data.
            var data   = new RecoveryData(RecoverDataCallback, null);
            var seting = new RecoverySettings(data, 0);

            ApplicationRestartRecoveryManager.RegisterForApplicationRecovery(seting);

            // Lets Check wheher recovery needed
            var args = Environment.GetCommandLineArgs();

            if (args.Length > 1 && args[1].Equals("/recovery", StringComparison.InvariantCultureIgnoreCase))
            {
                StartRecovery("/recovery");
            }
            SaveButton.IsEnabled = false;
        }
Beispiel #28
0
 private void RegisterARR()
 {
     ApplicationRestartRecoveryManager.RegisterForApplicationRestart(new RestartSettings(string.Empty, RestartRestrictions.None));
     ApplicationRestartRecoveryManager.RegisterForApplicationRecovery(new RecoverySettings(new RecoveryData(PerformRecovery, null), 5000));
 }
Beispiel #29
0
 private void UnregisterApplicationRecoveryAndRestart()
 {
     ApplicationRestartRecoveryManager.UnregisterApplicationRecovery();
 }
Beispiel #30
0
        private void RegisterApplicationRecoveryAndRestart()
        {
            RecoverySettings recoverySettings = new RecoverySettings(new RecoveryData(PerformRecovery, null), 5000);

            ApplicationRestartRecoveryManager.RegisterForApplicationRecovery(recoverySettings);
        }