Esempio n. 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));
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a list of <see cref="InsuranceFile"/>s which are read from the specified <paramref name="folder"/>.
        /// </summary>
        /// <param name="folder"></param>
        /// <returns></returns>
        private static List <InsuranceFile> GetFileInsurances(string folder)
        {
            if (!Directory.Exists(folder))
            {
                return(new List <InsuranceFile>(0));
            }
            var identifiers = Directory.GetFiles(folder);
            var files       = new List <InsuranceFile>();

            foreach (var file in identifiers)
            {
                InsuranceFile insuranceFile;
                if (InsuranceFile.TryRead(file, out insuranceFile))
                {
                    files.Add(insuranceFile);
                }
            }
            return(files);
        }