/// <summary>
        /// Registers an application for recovery by Application Restart and Recovery.
        /// </summary>
        /// <param name="settings">An object that specifies
        /// the callback method, an optional parameter to pass to the callback
        /// method and a time interval.</param>
        /// <exception cref="System.ArgumentException">
        /// The registration failed due to an invalid parameter.
        /// </exception>
        /// <exception cref="System.ComponentModel.Win32Exception">
        /// The registration failed.</exception>
        /// <remarks>The time interval is the period of time within
        /// which the recovery callback method
        /// calls the <see cref="ApplicationRecoveryInProgress"/> method to indicate
        /// that it is still performing recovery work.</remarks>
        public static void RegisterForApplicationRecovery(RecoverySettings settings)
        {
            // Throw PlatformNotSupportedException if the user is not running Vista or beyond
            CoreHelpers.ThrowIfNotVista();

            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            GCHandle handle = GCHandle.Alloc(settings.RecoveryData);

            HRESULT hr = AppRestartRecoveryNativeMethods.RegisterApplicationRecoveryCallback(AppRestartRecoveryNativeMethods.internalCallback, (IntPtr)handle, settings.PingInterval, (uint)0);

            if (!CoreErrorHelper.Succeeded((int)hr))
            {
                if (hr == HRESULT.E_INVALIDARG)
                {
                    throw new ArgumentException("Application was not registered for recovery due to bad parameters.");
                }
                else
                {
                    throw new ExternalException("Application failed to register for recovery.");
                }
            }
        }
        /// <summary>
        /// Registers an application for recovery by Application Restart and Recovery.
        /// </summary>
        /// <param name="settings">An object that specifies
        /// the callback method, an optional parameter to pass to the callback
        /// method and a time interval.</param>
        /// <exception cref="System.ArgumentException">
        /// The registration failed due to an invalid parameter.
        /// </exception>
        /// <exception cref="System.ComponentModel.Win32Exception">
        /// The registration failed.</exception>
        /// <remarks>The time interval is the period of time within 
        /// which the recovery callback method 
        /// calls the <see cref="ApplicationRecoveryInProgress"/> method to indicate
        /// that it is still performing recovery work.</remarks>        
        public static void RegisterForApplicationRecovery(RecoverySettings settings)
        {
            if (settings == null) { throw new ArgumentNullException(nameof(settings)); }

            GCHandle handle = GCHandle.Alloc(settings.RecoveryData);

            HResult hr = AppRestartRecoveryNativeMethods.RegisterApplicationRecoveryCallback(
                AppRestartRecoveryNativeMethods.InternalCallback, (IntPtr)handle, settings.PingInterval, (uint)0);

            if (!CoreErrorHelper.Succeeded(hr))
            {
                if (hr == HResult.InvalidArguments)
                {
                    throw new ArgumentException(LocalizedMessages.ApplicationRecoveryBadParameters, nameof(settings));
                }

                throw new ApplicationRecoveryException(LocalizedMessages.ApplicationRecoveryFailedToRegister);
            }
        }
        /// <summary>
        /// Registers an application for recovery by Application Restart and Recovery.
        /// </summary>
        /// <param name="settings">An object that specifies
        /// the callback method, an optional parameter to pass to the callback
        /// method and a time interval.</param>
        /// <exception cref="System.ArgumentException">
        /// The registration failed due to an invalid parameter.
        /// </exception>
        /// <exception cref="System.ComponentModel.Win32Exception">
        /// The registration failed.</exception>
        /// <remarks>The time interval is the period of time within 
        /// which the recovery callback method 
        /// calls the <see cref="ApplicationRecoveryInProgress"/> method to indicate
        /// that it is still performing recovery work.</remarks>
        public static void RegisterForApplicationRecovery(RecoverySettings settings)
        {
            // Throw PlatformNotSupportedException if the user is not running Vista or beyond
            CoreHelpers.ThrowIfNotVista();

            if (settings == null)
                throw new ArgumentNullException("settings");

            GCHandle handle = GCHandle.Alloc(settings.RecoveryData);

            HRESULT hr = AppRestartRecoveryNativeMethods.RegisterApplicationRecoveryCallback(AppRestartRecoveryNativeMethods.internalCallback, (IntPtr)handle, settings.PingInterval, (uint)0);

            if (!CoreErrorHelper.Succeeded((int)hr))
            {
                if (hr == HRESULT.E_INVALIDARG)
                    throw new ArgumentException("Application was not registered for recovery due to bad parameters.");
                else
                    throw new ExternalException("Application failed to register for recovery.");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Registers an application for recovery by Application Restart and Recovery.
        /// </summary>
        /// <param name="settings">An object that specifies
        /// the callback method, an optional parameter to pass to the callback
        /// method and a time interval.</param>
        /// <exception cref="System.ArgumentException">
        /// The registration failed due to an invalid parameter.
        /// </exception>
        /// <exception cref="System.ComponentModel.Win32Exception">
        /// The registration failed.</exception>
        /// <remarks>The time interval is the period of time within 
        /// which the recovery callback method 
        /// calls the <see cref="ApplicationRecoveryInProgress"/> method to indicate
        /// that it is still performing recovery work.</remarks>        
        public static void RegisterForApplicationRecovery(RecoverySettings settings)
        {           
            CoreHelpers.ThrowIfNotVista();

            if (settings == null) { throw new ArgumentNullException("settings"); }

            GCHandle handle = GCHandle.Alloc(settings.RecoveryData);

            HResult hr = AppRestartRecoveryNativeMethods.RegisterApplicationRecoveryCallback(
                AppRestartRecoveryNativeMethods.InternalCallback, (IntPtr)handle, settings.PingInterval, (uint)0);

            if (!CoreErrorHelper.Succeeded(hr))
            {
                if (hr == HResult.InvalidArguments)
                {
                    throw new ArgumentException(LocalizedMessages.ApplicationRecoveryBadParameters, "settings");
                }

                throw new ApplicationRecoveryException(LocalizedMessages.ApplicationRecoveryFailedToRegister);
            }
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
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");
        }
Ejemplo n.º 7
0
 private void RegisterRecovery()
 {
     var settings = new RecoverySettings(new RecoveryData(SaveState, AppConfigs.Configuration), 0);
     ApplicationRestartRecoveryManager.RegisterForApplicationRecovery(settings);
     AppLogger.Log.Info("Recovery Registered");
 }