zoukankan      html  css  js  c++  java
  • mojoPortalprovider模式学习之1.1之IndexBuilderManager

    第四步 Provider Manager 类

    这个类根据 第三步中的 Provider Configuration类中的配置信息,实例化Provider.

      public sealed class IndexBuilderManager
        
    {
            
    //private static bool isInitialized = false;
            
    //private static Exception initializationException;
            private static object initializationLock = new object();
            
    private static readonly ILog log
                
    = LogManager.GetLogger(typeof(IndexBuilderManager));


            
    //在构造函数中调用初始化方法
            static IndexBuilderManager()
            
    {
                Initialize();
            }


            
    //根据配置文件中的信息,实例化provider,并放到ProviderCollection中
            private static void Initialize()
            
    {
                providerCollection 
    = new IndexBuilderProviderCollection();

                
    try
                
    {
                    IndexBuilderConfiguration config 
                        
    = IndexBuilderConfiguration.GetConfig();

                    
    if (config != null)
                    
    {

                        
    if (
                            (config.Providers 
    == null)
                            
    || (config.Providers.Count < 1)
                            )
                        
    {
                            
    throw new ProviderException("No IndexBuilderProvider found.");
                        }


                        
    //实例化Provider的具体方法
                        ProvidersHelper.InstantiateProviders(
                            config.Providers,
                            providerCollection,
                            
    typeof(IndexBuilderProvider));

                    }

                    
    else
                    
    {
                        
    // config was null, not a good thing
                        log.Error("IndexBuilderConfiguration could not be loaded so empty provider collection was returned");

                    }

                }

                
    catch (NullReferenceException ex)
                
    {
                    log.Error(ex);
                }

                
    catch (TypeInitializationException ex)
                
    {
                    log.Error(ex);
                }

                
    catch (ProviderException ex)
                
    {
                    log.Error(ex);
                }

                
                providerCollection.SetReadOnly();
                    
                
    //}
                
    //catch (Exception ex)
                
    //{
                
    //    log.Error(ex);
                
    //    initializationException = ex;
                
    //    isInitialized = false;
                
    //    //throw ex;
                
    //    return;
                
    //}

                
    //isInitialized = true; 
            }



            
    private static IndexBuilderProviderCollection providerCollection;

            
    public static IndexBuilderProviderCollection Providers
            
    {
                
    get
                
    {
                    
    //try
                    
    //{
                        if (providerCollection == null) Initialize();
                        
    return providerCollection;
                    
    //}
                    
    //catch (NullReferenceException ex)
                    
    //{
                    
    //    log.Error(ex);  
                    
    //}
                    
    //catch (TypeInitializationException ex)
                    
    //{
                    
    //    log.Error(ex);
                    
    //}
                    
    //catch (ProviderException ex)
                    
    //{
                    
    //    log.Error(ex);  
                    
    //}

                    
    return null;
                }

            }

        }
  • 相关阅读:
    JS的(new Date()).toLocaleString,系统设置为24小时,仍然显示为12小时。
    js中获取时间new date()的用法
    Warning: require(): open_basedir restriction in effect. 宝塔错误
    未定义数组下标: 0
    layui 弹层组件文档
    TP5模版中的运算符
    tp5倒计时还有几天几时几分
    【原创】tp5软件过期提醒
    a标签的title属性 换行
    电子签章盖章之jQuery插件jquery.zsign
  • 原文地址:https://www.cnblogs.com/wenjie/p/1167562.html
Copyright © 2011-2022 走看看