Exemple #1
0
        /// <summary>
        /// Returns the <see cref="CleanUpInsurance"/> matching the identifier specified.
        /// If no match is found, null is returned.
        /// </summary>
        /// <exception cref="ArgumentException"></exception>
        /// <param name="trackingFilesFolder"></param>
        /// <param name="trackingRegistryKey"></param>
        /// <param name="insuranceId"></param>
        /// <returns></returns>
        public static CleanUpInsurance LoadFromSystem(string trackingFilesFolder, string trackingRegistryKey, Guid insuranceId)
        {
            if (insuranceId == Guid.Empty)
            {
                throw new ArgumentException("The specified insurance identifier is not a valid GUID", "insuranceId");
            }
            InsuranceFile        insuranceFile   = null;
            InsuranceRegistryKey insuranceRegKey = null;

            // Load from file
            if (trackingFilesFolder != null && File.Exists(Path.Combine(trackingFilesFolder, insuranceId.ToString())))
            {
                InsuranceFile.TryRead(Path.Combine(trackingFilesFolder, insuranceId.ToString()), out insuranceFile);
            }
            // Load from registry
            if (trackingRegistryKey != null)
            {
                using (var regKey = Registry.CurrentUser.OpenSubKey(trackingRegistryKey + insuranceId, false))
                    if (regKey != null) // Verify existence of the key
                    {
                        InsuranceRegistryKey.TryRead(regKey, out insuranceRegKey);
                    }
            }
            // Possible to check for a running process?
            // Return null if no CleanUpInsurance can be built from the retrieved data
            if (insuranceFile == null && insuranceRegKey == null)
            {
                return(null);
            }
            return(new CleanUpInsurance(insuranceFile, insuranceRegKey, null));
        }
Exemple #2
0
 /// <summary>
 /// Returns a list of <see cref="InsuranceRegistryKey"/>s which are read from the registrykey with the specified name.
 /// </summary>
 /// <param name="regKeyName">The name of a subkey of the CurrentUser rootkey.</param>
 /// <returns></returns>
 private static List <InsuranceRegistryKey> GetRegistryInsurances(string regKeyName)
 {
     using (var regKey = Registry.CurrentUser.OpenSubKey(regKeyName))
     {
         if (regKey == null)
         {
             return(new List <InsuranceRegistryKey>(0));
         }
         var items   = new List <InsuranceRegistryKey>();
         var subKeys = regKey.GetSubKeyNames();
         foreach (var subKeyName in subKeys)
         {
             using (var subKey = regKey.OpenSubKey(subKeyName))
             {
                 InsuranceRegistryKey item;
                 if (InsuranceRegistryKey.TryRead(subKey, out item))
                 {
                     items.Add(item);
                 }
             }
         }
         return(items);
     }
 }