public static string GetHelpText(Type configObjectType)
        {
            if (configObjectType == null)
            {
                return(null);
            }
            if (!typeof(ChoConfigurableObject).IsAssignableFrom(configObjectType))
            {
                return(null);
            }

            ChoConfigurationSectionAttribute configurationElementAttribute = ChoType.GetAttribute(configObjectType, typeof(ChoConfigurationSectionAttribute)) as ChoConfigurationSectionAttribute;

            if (configurationElementAttribute == null)
            {
                return(null);
            }

            ChoBaseConfigurationElement ele = configurationElementAttribute.GetMe(configObjectType);

            if (ele == null)
            {
                return(null);
            }

            return(ele.GetHelpText(configObjectType));
        }
Beispiel #2
0
        public static T CreateInstance <T>() where T : class
        {
            Type configObjType = typeof(T);

            if (typeof(ContextBoundObject).IsAssignableFrom(configObjType))
            {
                return(ChoSingleton <T> .GetInstance(SingletonTypeValidationRules.AllowAll));
            }
            else
            {
                if (!ChoObjectManagementFactory.IsCached(configObjType))
                {
                    //Load config file and assign values to object memebers
                    ChoConfigurationSectionAttribute configurationElement = ChoType.GetAttribute(configObjType, typeof(ChoConfigurationSectionAttribute)) as ChoConfigurationSectionAttribute;
                    if (configurationElement == null || configurationElement.GetMe(configObjType) == null)
                    {
                        throw new ChoConfigurationException(String.Format(CultureInfo.InvariantCulture, Resources.ES1001, configObjType.Name));
                    }

                    return((T)configurationElement.GetMe(configObjType).Construct(configObjType));
                }
                else
                {
                    return((T)ChoObjectManagementFactory.GetObject(configObjType));
                }
            }
        }
Beispiel #3
0
        public static void RefreshConfig(object configObject)
        {
            ChoGuard.ArgumentNotNull(configObject, "Config Object.");

            ChoConfigurationSectionAttribute configurationElementAttribute = ChoType.GetAttribute(configObject.GetType(), typeof(ChoConfigurationSectionAttribute))
                                                                             as ChoConfigurationSectionAttribute;

            if (configurationElementAttribute == null)
            {
                return;
            }

            configurationElementAttribute.GetMe(configObject.GetType()).Refresh(true);
        }
Beispiel #4
0
        public ChoConfigurableObject()
        {
            _configurationElementAttribute = ChoType.GetAttribute(GetType(), typeof(ChoConfigurationSectionAttribute)) as ChoConfigurationSectionAttribute;

            //Discover and Hook the event handlers
            if (BeforeConfigurationObjectMemberLoaded == null)
            {
                EventHandlerEx.LoadHandlers <ChoPreviewConfigurationObjectMemberEventArgs>(ref BeforeConfigurationObjectMemberLoaded, ChoType.GetMethods(GetType(), typeof(ChoBeforeConfigurationObjectMemberLoadedHandlerAttribute)), this);
            }
            if (AfterConfigurationObjectMemberLoaded == null)
            {
                EventHandlerEx.LoadHandlers <ChoConfigurationObjectMemberEventArgs>(ref AfterConfigurationObjectMemberLoaded, ChoType.GetMethods(GetType(), typeof(ChoAfterConfigurationObjectMemberLoadedHandlerAttribute)), this);
            }
            if (ConfigurationObjectMemberLoadError == null)
            {
                EventHandlerEx.LoadHandlers <ChoConfigurationObjectMemberErrorEventArgs>(ref ConfigurationObjectMemberLoadError, ChoType.GetMethods(GetType(), typeof(ChoConfigurationObjectMemberLoadErrorHandlerAttribute)), this);
            }

            if (BeforeConfigurationObjectPersisted == null)
            {
                EventHandlerEx.LoadHandlers <ChoPreviewConfigurationObjectEventArgs>(ref BeforeConfigurationObjectPersisted, ChoType.GetMethods(GetType(), typeof(ChoBeforeConfigurationObjectPersistedHandlerAttribute)), this);
            }
            if (AfterConfigurationObjectPersisted == null)
            {
                EventHandlerEx.LoadHandlers <ChoConfigurationObjectEventArgs>(ref AfterConfigurationObjectPersisted, ChoType.GetMethods(GetType(), typeof(ChoAfterConfigurationObjectPersistedHandlerAttribute)), this);
            }

            if (BeforeConfigurationObjectMemberPersist == null)
            {
                EventHandlerEx.LoadHandlers <ChoPreviewConfigurationObjectMemberEventArgs>(ref BeforeConfigurationObjectMemberPersist, ChoType.GetMethods(GetType(), typeof(ChoBeforeConfigurationObjectMemberPersistHandlerAttribute)), this);
            }
            if (AfterConfigurationObjectMemberPersist == null)
            {
                EventHandlerEx.LoadHandlers <ChoConfigurationObjectMemberEventArgs>(ref AfterConfigurationObjectMemberPersist, ChoType.GetMethods(GetType(), typeof(ChoAfterConfigurationObjectMemberPersistHandlerAttribute)), this);
            }

            if (AfterConfigurationObjectLoadedInternal == null)
            {
                EventHandlerEx.LoadHandlers <ChoConfigurationObjectEventArgs>(ref AfterConfigurationObjectLoadedInternal, ChoType.GetMethods(GetType(), typeof(ChoAfterConfigurationObjectLoadedHandlerAttribute)), this);
            }
            if (ConfigurationObjectLoadError == null)
            {
                EventHandlerEx.LoadHandlers <ChoConfigurationObjectErrorEventArgs>(ref ConfigurationObjectLoadError, ChoType.GetMethods(GetType(), typeof(ChoConfigurationObjectLoadErrorHandlerAttribute)), this);
            }
        }
Beispiel #5
0
        public static string GetConfigSectionName(Type type)
        {
            ChoGuard.ArgumentNotNull(type, "Type");

            string           sectionName = type.Name;
            XmlRootAttribute attribute   = ChoType.GetAttribute(type, typeof(XmlRootAttribute)) as XmlRootAttribute;

            if (attribute != null && !String.IsNullOrEmpty(attribute.ElementName))
            {
                sectionName = attribute.ElementName;
            }

            ChoConfigurationSectionAttribute configAttribute = ChoType.GetAttribute(type, typeof(ChoConfigurationSectionAttribute)) as ChoConfigurationSectionAttribute;

            if (configAttribute != null && !String.IsNullOrEmpty(configAttribute.ConfigElementPath))
            {
                sectionName = configAttribute.ConfigElementPath;
            }

            return(sectionName);
        }
        public ChoConfigurableObject()
        {
            _configurationElementAttribute = ChoType.GetAttribute(GetType(), typeof(ChoConfigurationSectionAttribute)) as ChoConfigurationSectionAttribute;
            if (_configurationElementAttribute == null)
            {
                throw new ChoFatalApplicationException("Missing configuration object attribute defined for '{0}' type.".FormatString(GetType().Name));
            }

            //Discover and Hook the event handlers
            if (BeforeConfigurationObjectMemberLoaded == null)
            {
                EventHandlerEx.LoadHandlers <ChoPreviewConfigurationObjectMemberEventArgs>(ref BeforeConfigurationObjectMemberLoaded, ChoType.GetMethods(GetType(), typeof(ChoBeforeConfigurationObjectMemberLoadedHandlerAttribute)), this);
            }
            if (BeforeConfigurationObjectMemberSet == null)
            {
                EventHandlerEx.LoadHandlers <ChoPreviewConfigurationObjectMemberEventArgs>(ref BeforeConfigurationObjectMemberSet, ChoType.GetMethods(GetType(), typeof(ChoBeforeConfigurationObjectMemberSetHandlerAttribute)), this);
            }
            if (AfterConfigurationObjectMemberLoaded == null)
            {
                EventHandlerEx.LoadHandlers <ChoConfigurationObjectMemberEventArgs>(ref AfterConfigurationObjectMemberLoaded, ChoType.GetMethods(GetType(), typeof(ChoAfterConfigurationObjectMemberLoadedHandlerAttribute)), this);
            }
            if (AfterConfigurationObjectMemberSet == null)
            {
                EventHandlerEx.LoadHandlers <ChoConfigurationObjectMemberEventArgs>(ref AfterConfigurationObjectMemberSet, ChoType.GetMethods(GetType(), typeof(ChoAfterConfigurationObjectMemberSetHandlerAttribute)), this);
            }
            if (ConfigurationObjectMemberLoadError == null)
            {
                EventHandlerEx.LoadHandlers <ChoConfigurationObjectMemberErrorEventArgs>(ref ConfigurationObjectMemberLoadError, ChoType.GetMethods(GetType(), typeof(ChoConfigurationObjectMemberLoadErrorHandlerAttribute)), this);
            }
            if (ConfigurationObjectMemberSetError == null)
            {
                EventHandlerEx.LoadHandlers <ChoConfigurationObjectMemberErrorEventArgs>(ref ConfigurationObjectMemberSetError, ChoType.GetMethods(GetType(), typeof(ChoConfigurationObjectMemberSetErrorHandlerAttribute)), this);
            }

            if (BeforeConfigurationObjectPersisted == null)
            {
                EventHandlerEx.LoadHandlers <ChoPreviewConfigurationObjectEventArgs>(ref BeforeConfigurationObjectPersisted, ChoType.GetMethods(GetType(), typeof(ChoBeforeConfigurationObjectPersistedHandlerAttribute)), this);
            }
            if (AfterConfigurationObjectPersisted == null)
            {
                EventHandlerEx.LoadHandlers <ChoConfigurationObjectEventArgs>(ref AfterConfigurationObjectPersisted, ChoType.GetMethods(GetType(), typeof(ChoAfterConfigurationObjectPersistedHandlerAttribute)), this);
            }

            if (BeforeConfigurationObjectMemberPersist == null)
            {
                EventHandlerEx.LoadHandlers <ChoPreviewConfigurationObjectMemberEventArgs>(ref BeforeConfigurationObjectMemberPersist, ChoType.GetMethods(GetType(), typeof(ChoBeforeConfigurationObjectMemberPersistHandlerAttribute)), this);
            }
            if (AfterConfigurationObjectMemberPersist == null)
            {
                EventHandlerEx.LoadHandlers <ChoConfigurationObjectMemberEventArgs>(ref AfterConfigurationObjectMemberPersist, ChoType.GetMethods(GetType(), typeof(ChoAfterConfigurationObjectMemberPersistHandlerAttribute)), this);
            }

            if (BeforeConfigurationObjectLoadedInternal == null)
            {
                EventHandlerEx.LoadHandlers <ChoPreviewConfigurationObjectEventArgs>(ref BeforeConfigurationObjectLoadedInternal, ChoType.GetMethods(GetType(), typeof(ChoBeforeConfigurationObjectLoadedHandlerAttribute)), this);
            }
            if (AfterConfigurationObjectLoadedInternal == null)
            {
                EventHandlerEx.LoadHandlers <ChoConfigurationObjectEventArgs>(ref AfterConfigurationObjectLoadedInternal, ChoType.GetMethods(GetType(), typeof(ChoAfterConfigurationObjectLoadedHandlerAttribute)), this);
            }
            if (ConfigurationObjectLoadError == null)
            {
                EventHandlerEx.LoadHandlers <ChoConfigurationObjectErrorEventArgs>(ref ConfigurationObjectLoadError, ChoType.GetMethods(GetType(), typeof(ChoConfigurationObjectLoadErrorHandlerAttribute)), this);
            }

            //Type configObjType = GetType();
            //ChoConfigurationSectionAttribute configurationElement = ChoType.GetAttribute(configObjType, typeof(ChoConfigurationSectionAttribute)) as ChoConfigurationSectionAttribute;
            //if (configurationElement == null || configurationElement.GetMe(configObjType) == null)
            //    throw new ChoConfigurationException(String.Format(CultureInfo.InvariantCulture, Resources.ES1001, configObjType.Name));

            //configurationElement.GetMe(configObjType).Construct(this);
        }