Esempio n. 1
0
        public void Deserialise(Type type, string key, IEnumerable <RegistryHive> hives)
        {
            if (type == null || key == null || hives == null)
            {
                throw new ArgumentNullException();
            }
            object o = (object)null;

            foreach (RegistryHive hive in hives)
            {
                RegistryKey key1 = RegistrySerialiser.GetKey(key, hive);
                if (key1 != null)
                {
                    if (o == null)
                    {
                        o = this.Deserialise(type, key1);
                    }
                    else
                    {
                        this.Deserialise(o, key1);
                    }
                }
            }
        }
Esempio n. 2
0
 protected override bool OnBeforeSerialise(RegistrySerialiser rs, RegistryKey key)
 {
     if (this.Application == null)
         throw new InvalidOperationException("The menu strip must have an application.");
     if (!this.Application.IsSaved || this.Application.IsDirty)
     {
         using (RegistryKey subKey = this.Application.RegHive.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Media Center\\Extensibility\\Applications"))
             this.Manager.RegistrySerialiser.Serialise((object)this.Application, subKey);
     }
     return true;
 }
Esempio n. 3
0
 protected override void OnAfterSerialise(RegistrySerialiser rs, RegistryKey key)
 {
     if (this.RegHive == Registry.CurrentUser)
         return;
     string regPath = this.RegPath;
     if (string.IsNullOrEmpty(regPath))
         return;
     foreach (object obj in Registry.Users.GetSubKeyNames())
     {
         string subkey = string.Format("{0}\\{1}", obj, (object)regPath);
         Registry.Users.DeleteSubKey(subkey, false);
     }
 }
Esempio n. 4
0
        public void Serialise(object o, RegistryKey parentKey, bool isParentKey)
        {
            if (o == null)
            {
                throw new ArgumentNullException("o");
            }
            if (parentKey == null)
            {
                throw new ArgumentNullException("parentKey");
            }
            PropertyInfo keyNameProperty = RegistrySerialiser.GetKeyNameProperty(o.GetType());

            if (keyNameProperty == null)
            {
                throw new ArgumentException("At least one property must have a RegistryKeyName attribute.");
            }
            RegistryKey key;

            if (isParentKey)
            {
                string subkey = keyNameProperty.GetValue(o, (object[])null) as string;
                if (subkey == null)
                {
                    throw new SerializationException("Key name cannot be null.");
                }
                key = parentKey.CreateSubKey(subkey);
            }
            else
            {
                key = parentKey;
            }
            try
            {
                IRegistryKeySerialisable registryKeySerialisable = o as IRegistryKeySerialisable;
                if (registryKeySerialisable != null && !registryKeySerialisable.BeforeSerialise(this, key))
                {
                    return;
                }
                foreach (PropertyInfo propertyInfo in o.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                {
                    object[] customAttributes = propertyInfo.GetCustomAttributes(typeof(RegistryValueAttribute), true);
                    if (customAttributes.Length > 0)
                    {
                        if (!propertyInfo.PropertyType.IsPrimitive && propertyInfo.PropertyType != typeof(string))
                        {
                            throw new SerializationException("Cannot serialise an object of type " + propertyInfo.PropertyType.FullName + " to a registry value.");
                        }
                        RegistryValueAttribute registryValueAttribute = (RegistryValueAttribute)customAttributes[0];
                        string name = registryValueAttribute.Name ?? propertyInfo.Name;
                        object obj  = propertyInfo.GetValue(o, (object[])null);
                        if (obj != null && registryValueAttribute.ValueKind != RegistryValueKind.Unknown && !RegistrySerialiser.GetRegistryType(registryValueAttribute.ValueKind).IsAssignableFrom(obj.GetType()))
                        {
                            obj = Convert.ChangeType(obj, RegistrySerialiser.GetRegistryType(registryValueAttribute.ValueKind));
                        }
                        object defaultValue;
                        RegistrySerialiser.TryGetDefaultValue((ICustomAttributeProvider)propertyInfo, out defaultValue);
                        if (obj != null && obj != defaultValue)
                        {
                            key.SetValue(name, obj);
                        }
                        else
                        {
                            key.DeleteValue(name, false);
                        }
                    }
                }
                if (registryKeySerialisable == null)
                {
                    return;
                }
                registryKeySerialisable.AfterSerialise(this, key);
            }
            finally
            {
                if (isParentKey)
                {
                    key.Close();
                }
            }
        }
Esempio n. 5
0
 protected override bool OnBeforeSerialise(RegistrySerialiser rs, RegistryKey key)
 {
     if (this.ID == null || this.ID.Trim() == string.Empty)
         throw new InvalidOperationException("The application must have an ID.");
     if (this.Title == null || this.Title.Trim() == string.Empty)
         throw new InvalidOperationException("The application must have a title.");
     else
         return true;
 }
Esempio n. 6
0
 protected override void OnAfterDeserialise(RegistrySerialiser rs, RegistryKey key)
 {
     this.EntryPoints.Clear();
     foreach (EntryPoint entryPoint in (Collection<EntryPoint>)this.Manager.EntryPoints)
     {
         if (entryPoint.ApplicationID == this.ID)
             this.EntryPoints.Add(entryPoint);
     }
 }