예제 #1
0
        public void Delete(IConfigurable instance)
        {
            RegistryObject   registryObject   = instance as RegistryObject;
            RegistryObjectId registryObjectId = registryObject.Identity as RegistryObjectId;

            using (RegistryKey registryKey = this.RootKey.OpenSubKey(registryObjectId.RegistryKeyPath, true))
            {
                if (registryKey != null)
                {
                    foreach (PropertyDefinition propertyDefinition in registryObject.ObjectSchema.AllProperties)
                    {
                        SimpleProviderPropertyDefinition simpleProviderPropertyDefinition = (SimpleProviderPropertyDefinition)propertyDefinition;
                        if (!this.excludedPersistentProperties.Contains(simpleProviderPropertyDefinition))
                        {
                            RegistryWriter.Instance.DeleteValue(registryKey, registryObjectId.Name, simpleProviderPropertyDefinition.Name);
                        }
                    }
                    bool flag = false;
                    using (RegistryKey registryKey2 = registryKey.OpenSubKey(registryObjectId.Name, false))
                    {
                        if (registryKey2.GetValueNames().Length == 0 && registryKey2.GetSubKeyNames().Length == 0)
                        {
                            flag = true;
                        }
                    }
                    if (flag)
                    {
                        registryKey.DeleteSubKey(registryObjectId.Name, true);
                    }
                }
            }
        }
예제 #2
0
        public T[] Find <T>(RegistryObjectId registryId) where T : IConfigurable, new()
        {
            string[] array = null;
            using (RegistryKey registryKey = this.RootKey.OpenSubKey(registryId.RegistryKeyPath, true))
            {
                if (registryKey == null)
                {
                    return(new T[0]);
                }
                array = registryKey.GetSubKeyNames();
            }
            List <T> list = new List <T>();

            if (array != null)
            {
                foreach (string folderName in array)
                {
                    T t = (default(T) == null) ? Activator.CreateInstance <T>() : default(T);
                    RegistryObject registryObject = t as RegistryObject;
                    this.ReadObject(registryId.RegistryKeyPath, folderName, this.IgnoreReadErrors, ref registryObject);
                    list.Add(t);
                }
            }
            return(list.ToArray());
        }
예제 #3
0
        public void Save(IConfigurable instance)
        {
            RegistryObject   registryObject   = instance as RegistryObject;
            RegistryObjectId registryObjectId = registryObject.Identity as RegistryObjectId;
            string           folderPath       = (registryObjectId != null) ? registryObjectId.RegistryKeyPath : registryObject.RegistrySchema.DefaultRegistryKeyPath;
            string           text             = (registryObjectId != null) ? registryObjectId.Name : registryObject.RegistrySchema.DefaultName;

            using (RegistryKey registryKey = this.CreateRegistryPathIfMissing(folderPath))
            {
                if (!registryKey.GetSubKeyNames().Contains(text, StringComparer.OrdinalIgnoreCase))
                {
                    RegistryWriter.Instance.CreateSubKey(registryKey, text);
                }
                ObjectState objectState = instance.ObjectState;
                foreach (PropertyDefinition propertyDefinition in registryObject.ObjectSchema.AllProperties)
                {
                    SimpleProviderPropertyDefinition simpleProviderPropertyDefinition = (SimpleProviderPropertyDefinition)propertyDefinition;
                    if (!simpleProviderPropertyDefinition.IsCalculated && !this.excludedPersistentProperties.Contains(simpleProviderPropertyDefinition))
                    {
                        if ((registryObject[simpleProviderPropertyDefinition] != null && registryObject[simpleProviderPropertyDefinition].Equals(simpleProviderPropertyDefinition.DefaultValue)) || (registryObject[simpleProviderPropertyDefinition] == null && simpleProviderPropertyDefinition.DefaultValue == null))
                        {
                            RegistryWriter.Instance.DeleteValue(registryKey, text, simpleProviderPropertyDefinition.Name);
                        }
                        else
                        {
                            RegistryWriter.Instance.SetValue(registryKey, text, simpleProviderPropertyDefinition.Name, registryObject[simpleProviderPropertyDefinition], RegistryValueKind.String);
                        }
                    }
                }
            }
        }
예제 #4
0
        public T Read <T>(RegistryObjectId identity) where T : RegistryObject, new()
        {
            T t = Activator.CreateInstance <T>();
            RegistryObject registryObject = t;

            this.ReadObject(identity.RegistryKeyPath ?? registryObject.RegistrySchema.DefaultRegistryKeyPath, identity.Name ?? registryObject.RegistrySchema.DefaultName, this.IgnoreReadErrors, ref registryObject);
            return(t);
        }
예제 #5
0
        public IConfigurable Read <T>(ObjectId identity) where T : IConfigurable, new()
        {
            T t = (default(T) == null) ? Activator.CreateInstance <T>() : default(T);
            RegistryObject   registryObject = t as RegistryObject;
            RegistryObjectId registryObjectId;

            if (identity != null)
            {
                registryObjectId = (identity as RegistryObjectId);
            }
            else
            {
                registryObjectId = new RegistryObjectId(registryObject.RegistrySchema.DefaultRegistryKeyPath, registryObject.RegistrySchema.DefaultName);
            }
            this.ReadObject(registryObjectId.RegistryKeyPath, registryObjectId.Name, this.IgnoreReadErrors, ref registryObject);
            return(t);
        }
예제 #6
0
        private void ReadObject(string folderPath, string folderName, ref RegistryObject instance)
        {
            RegistryObjectSchema registrySchema = instance.RegistrySchema;

            using (RegistryKey registryKey = this.RootKey.OpenSubKey(folderPath))
            {
                if (registryKey == null || !registryKey.GetSubKeyNames().Contains(folderName, StringComparer.OrdinalIgnoreCase))
                {
                    return;
                }
                foreach (PropertyDefinition propertyDefinition in registrySchema.AllProperties)
                {
                    SimpleProviderPropertyDefinition simpleProviderPropertyDefinition = (SimpleProviderPropertyDefinition)propertyDefinition;
                    if (!simpleProviderPropertyDefinition.IsCalculated && !this.excludedPersistentProperties.Contains(simpleProviderPropertyDefinition))
                    {
                        object obj = RegistryReader.Instance.GetValue <object>(registryKey, folderName, simpleProviderPropertyDefinition.Name, simpleProviderPropertyDefinition.DefaultValue);
                        try
                        {
                            obj = ValueConvertor.ConvertValue(obj, simpleProviderPropertyDefinition.Type, null);
                        }
                        catch (Exception ex)
                        {
                            instance.AddValidationError(new PropertyValidationError(DataStrings.ErrorCannotConvertFromString(obj as string, simpleProviderPropertyDefinition.Type.Name, ex.Message), simpleProviderPropertyDefinition, obj));
                            continue;
                        }
                        try
                        {
                            instance[simpleProviderPropertyDefinition] = obj;
                        }
                        catch (DataValidationException ex2)
                        {
                            instance.AddValidationError(ex2.Error);
                        }
                    }
                }
            }
            instance.propertyBag[SimpleProviderObjectSchema.Identity] = new RegistryObjectId(folderPath, folderName);
            instance.ResetChangeTracking(true);
        }
예제 #7
0
 private void ReadObject(string folderPath, string folderName, bool ignoreErrors, ref RegistryObject instance)
 {
     if (!this.IgnoreReadErrors)
     {
         this.ReadObject(folderPath, folderName, ref instance);
         return;
     }
     try
     {
         this.ReadObject(folderPath, folderName, ref instance);
     }
     catch (IOException)
     {
     }
     catch (SecurityException)
     {
     }
     catch (UnauthorizedAccessException)
     {
     }
 }