示例#1
0
        private StateManagerStatus SetRestorePoint(RestorePointInfo info)
        {
            StateManagerStatus status;

            if (!this._service.SetRestorePoint(info, out status))
            {
                throw new Win32Exception(status.ErrorCode);
            }

            return(status);
        }
示例#2
0
        /// <summary>
        /// Begins a system restore point.
        /// </summary>
        /// <param name="type">The type of restore point to create.</param>
        /// <param name="description">Optional description for the restore point. The default value is the assembly title.</param>
        /// <param name="service">The service provider to create or modify restore points. The default calls info the system service.</param>
        /// <returns>Information about the restore point or null if the service is disabled.</returns>
        /// <exception cref="Win32Exception">Failed to create the system restore point.</exception>
        internal static SystemRestorePoint Create(RestorePointType type, string description = null, ISystemRestoreService service = null)
        {
            if (RestorePointType.CancelledOperation == type)
            {
                throw new InvalidEnumArgumentException("type", (int)type, type.GetType());
            }

            if (string.IsNullOrEmpty(description))
            {
                // Get the assembly title metadata value.
                var title = (AssemblyTitleAttribute)Assembly.GetExecutingAssembly()
                            .GetCustomAttributes(typeof(AssemblyTitleAttribute), false)
                            .FirstOrDefault();

                if (null != title)
                {
                    description = title.Title;
                }
            }

            var info = new RestorePointInfo()
            {
                Description    = description,
                EventType      = RestorePointEventType.BeginSystemChange,
                SequenceNumber = 0,
                Type           = type,
            };

            var instance = new SystemRestorePoint()
            {
                _service = service ?? SystemRestorePoint.DefaultServiceProvider,
                _info    = info,
            };

            // Create the system restore point.
            var status = instance.SetRestorePoint(info);

            // Update the sequence number.
            info.SequenceNumber = status.SequenceNumber;
            instance._info      = info;

            return(instance);
        }
示例#3
0
 public bool SetRestorePoint(RestorePointInfo info, out StateManagerStatus status)
 {
     return(NativeMethods.SRSetRestorePoint(ref info, out status));
 }
示例#4
0
 internal static extern bool SRSetRestorePoint(
     [In] ref RestorePointInfo pRestorePtSpec,
     out StateManagerStatus pSMgrStatus
     );