コード例 #1
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());
        }
コード例 #2
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);
                    }
                }
            }
        }
コード例 #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 RegistryObject(RegistryObjectId identity) : base(new SimpleProviderPropertyBag())
 {
     if (identity != null)
     {
         this.propertyBag[SimpleProviderObjectSchema.Identity] = identity;
     }
 }
コード例 #5
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);
        }
コード例 #6
0
        public IConfigurable[] Find <T>(QueryFilter filter, ObjectId rootId, bool deepSearch, SortBy sortBy) where T : IConfigurable, new()
        {
            if (filter != null || !deepSearch || sortBy != null)
            {
                throw new NotSupportedException();
            }
            RegistryObjectId     registryId = rootId as RegistryObjectId;
            List <IConfigurable> list       = new List <IConfigurable>();

            foreach (T t in this.Find <T>(registryId))
            {
                list.Add(t);
            }
            return(list.ToArray());
        }
コード例 #7
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);
        }
コード例 #8
0
        public override bool Equals(object obj)
        {
            RegistryObjectId registryObjectId = obj as RegistryObjectId;

            return(registryObjectId != null && (object.ReferenceEquals(this, registryObjectId) || (string.Equals(this.RegistryKeyPath, registryObjectId.RegistryKeyPath, StringComparison.OrdinalIgnoreCase) && string.Equals(this.Name, registryObjectId.Name, StringComparison.OrdinalIgnoreCase))));
        }