예제 #1
0
        /// <summary>
        /// Configure all targets in the specified object using the given ElementTree
        /// as source. If a Type is passed in obj, static members will be configured.
        /// If an object instance is passed in obj, instance members will be configured.
        /// </summary>
        /// <param name="handlers">The list of handlers providing the source values</param>
        /// <param name="obj">The object to be configured</param>
        public void Configure(IList handlers, object obj)
        {
            IList targets = obj is Type ? staticTargets : instanceTargets;

            foreach (ElementTarget target in targets)
            {
                int maxHandlerIndex = target is MethodTarget ? handlers.Count : 1;
                for (int i = 0; i < maxHandlerIndex; i++)
                {
                    BaseSectionHandler handler = handlers[i] as BaseSectionHandler;
                    bool keyFound = false;
                    if (target is MethodTarget)
                    {
                        XmlNodeList nodes = handler.GetNodes(target.XmlNodePath);
                        if (nodes != null && nodes.Count > 0)
                        {
                            target.Configure(obj, nodes);
                            keyFound = true;
                            break;
                        }
                    }
                    else
                    {
                        XmlNode node = handler.GetNode(target.XmlNodePath);
                        if (node != null)
                        {
                            target.Configure(obj, node);
                            keyFound = true;
                            break;
                        }
                    }
                    VerifyKeyPresence(target, keyFound);
                }
            }
        }
예제 #2
0
 private static void AddHandler(string configStoreName, BaseSectionHandler handler, bool isFirst)
 {
     lock (cfgLock)
     {
         if (handler != null && handler.IsValid)
         {
             handlers.Insert(isFirst ? 0 : handlers.Count, handler);
             if (configStoreName != null)
             {
                 namedHandlers[configStoreName] = handler;
             }
         }
         else
         {
             LogMessage("Attempt to add configuration handler failed.");
             if (handler != null)
             {
                 LogMessage("Handler: {0}  IsValid: {1}", handler.GetType(), handler.IsValid);
             }
         }
     }
 }
예제 #3
0
        /// <summary>
        /// Esse método cria um handler de configuração para um sessão especifica
        /// do arquivo de configuração padrão do .NET.
        /// </summary>
        /// <param name="configStoreName">O nome em que o handler está associado. Se for null
        /// o handler será usado para as conigurações do GDA, senão quando o método configure for
        /// chamado com o nome especificado</param>
        /// <param name="sectionName">Nome da sessão GDASectionHandler está declarada no arquivo de
        /// configuração padrão do .NET.</param>
        public static void AddSectionHandler(string configStoreName, string sectionName)
        {
            string errorMsg = String.Format("Unable to create handler for section " + "named \"{0}\" in file \"{1}\".{2}", sectionName, AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, CRLF);

            try
            {
                BaseSectionHandler handler = (BaseSectionHandler)System.Configuration.ConfigurationManager.GetSection(sectionName);
                if (handler != null && handler.IsValid)
                {
                    AddHandler(configStoreName, handler, false);
                }
                else
                {
                    LogMessage(errorMsg);
                }
            }
            catch (Exception e)
            {
                LogMessage(errorMsg);
                LogException(e);
            }
        }