Ejemplo n.º 1
0
        public static XmlNode LocateOrCreateNode(TypeReflectionCacheItem item, IPersistable instance, out bool created)
        {
            XmlDocument doc = systemSettings;

            if (item.PersistanceInformation.File == OptionsFile.User)
            {
                doc = userSettings;
            }

            string categoryName = item.PersistanceInformation.Category;
            string instanceName = instance.InstanceName;
            string valueName    = item.PersistanceInformation.Name;

            XmlNode settingsNode = doc.SelectSingleNode("//settings");
            XmlNode categoryNode = GetOrCreateNode(doc, settingsNode, "category", categoryName);
            XmlNode instanceNode = GetOrCreateNode(doc, categoryNode, "instance", instanceName);
            XmlNode valueNode    = GetOrCreateNode(doc, instanceNode, "value", valueName, out created);

            if (created)
            {
                SetNodeValue(valueNode, item.PersistanceInformation.DefaultValue.ToString(),
                             item.PersistanceInformation.Encrypted);
            }

            return(valueNode);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a TypeReflectionCache object from the specified IPersistable instance.
        /// </summary>
        public TypeReflectionCache(IPersistable instance)
        {
            type = instance.GetType();
            EventInfo[] events = type.GetEvents();
            foreach (PropertyInfo pi in type.GetProperties())
            {
                List <PropertyInfo> cachedProperties = new List <PropertyInfo>();

                object[] attributes = pi.GetCustomAttributes(typeof(PersistableOption), true);
                if (attributes.Length > 0)
                {
                    // This is a persistable option.
                    PersistableOption optAtt = attributes[0] as PersistableOption;

                    // Add this property to the cache list.
                    TypeReflectionCacheItem item = new TypeReflectionCacheItem();
                    item.PropertyInfo           = pi;
                    item.PersistanceInformation = optAtt;

                    // Link up any events tagged with with UpdateHandler attribute.
                    foreach (EventInfo info in events)
                    {
                        if (info.EventHandlerType == typeof(EventHandler))
                        {
                            // Check to see if the event is tagged as an OptionUpdateNotifier.
                            object[] eventAttributes = info.GetCustomAttributes(typeof(OptionUpdateNotifier), true);
                            if (eventAttributes.Length > 0)
                            {
                                // If has the proper attribute - if the name matches, we have a linked event.
                                OptionUpdateNotifier updateAtt = eventAttributes[0] as OptionUpdateNotifier;
                                if (updateAtt.LinkedOptionName == optAtt.Name)
                                {
                                    // A linked event was found.
                                    item.EventInfo = info;
                                }
                            }
                        }
                    }

                    // Add the cache item to the properties list.
                    properties.Add(item);
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Locates the XML node that contains persistance information for the specified item.
 /// If the node is not found, it will be created.
 /// </summary>
 private static XmlNode LocateOrCreateNode(TypeReflectionCacheItem item, IPersistable instance, out bool created)
 {
     return(OptionsMerger.LocateOrCreateNode(item, instance, out created));
 }