Example #1
0
        internal static string ToSerializedValue(this RestorePointType value)
        {
            switch (value)
            {
            case RestorePointType.CONTINUOUS:
                return("CONTINUOUS");

            case RestorePointType.DISCRETE:
                return("DISCRETE");
            }
            return(null);
        }
Example #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);
        }
Example #3
0
 /// <summary>
 ///     Creates a restore point on the local system.
 /// </summary>
 /// <param name="description">
 ///     The description to be displayed so the user can easily identify a restore
 ///     point.
 /// </param>
 /// <param name="eventType">
 ///     The type of event.
 /// </param>
 /// <param name="restorePointType">
 ///     The type of restore point.
 /// </param>
 public static void Create(string description, RestoreEventType eventType, RestorePointType restorePointType)
 {
     try
     {
         if (!IsEnabled)
         {
             throw new WarningException(ExceptionMessages.SystemRestoringIsDisabled);
         }
         var mScope  = new ManagementScope("\\\\localhost\\root\\default");
         var mPath   = new ManagementPath("SystemRestore");
         var options = new ObjectGetOptions();
         using var mClass               = new ManagementClass(mScope, mPath, options);
         using var parameters           = mClass.GetMethodParameters("CreateRestorePoint");
         parameters["Description"]      = description;
         parameters["EventType"]        = (int)eventType;
         parameters["RestorePointType"] = (int)restorePointType;
         mClass.InvokeMethod("CreateRestorePoint", parameters, null);
     }
     catch (Exception ex) when(ex.IsCaught())
     {
         Log.Write(ex);
     }
 }
Example #4
0
        public static HResult CreateRestorePoint(string restorePointName, EventType eventType, RestorePointType restorePointType)
        {
            // uint32 CreateRestorePoint([in] String Description, [in] uint32 RestorePointType, [in] uint32 EventType);

            var managementPath     = new ManagementPath(@"\\.\ROOT\DEFAULT:SystemRestore");
            var systemRestoreClass = new ManagementClass(managementPath);
            var methodParameters   = systemRestoreClass.Methods["CreateRestorePoint"].InParameters;

            methodParameters.Properties["Description"].Value      = restorePointName;
            methodParameters.Properties["EventType"].Value        = (uint)eventType;
            methodParameters.Properties["RestorePointType"].Value = (uint)restorePointType;

            var outParameters = systemRestoreClass.InvokeMethod("CreateRestorePoint", methodParameters, null);
            var hresult       = (HResult) unchecked ((int)(uint)outParameters["ReturnValue"]);

            return(hresult);
        }
Example #5
0
 public static string ToSerialString(this RestorePointType value) => value switch
 {