Exemple #1
0
        private BasePlugInFactory GetFactory(string name)
        {
            BasePlugInFactory factory = ObjectUtil.TryGetValue(fAllFactories, name);

            TkDebug.AssertNotNull(factory, string.Format(ObjectUtil.SysCulture,
                                                         "没有找到名称为{0}的代码工厂", name), this);
            return(factory);
        }
Exemple #2
0
        public bool AddCodePlugIn(BasePlugInAttribute attribute, Type type)
        {
            TkDebug.AssertArgumentNull(attribute, "attribute", this);
            TkDebug.AssertArgumentNull(type, "type", this);

            BasePlugInFactory factory = GetFactory(attribute.FactoryName);

            return(factory.Add(attribute, type));
        }
Exemple #3
0
        public BasePlugInFactory GetCodeFactory(string factoryName)
        {
            TkDebug.AssertArgumentNullOrEmpty(factoryName, "factoryName", this);

            BasePlugInFactory result = ObjectUtil.TryGetValue(fCodeFactories, factoryName);

            TkDebug.AssertNotNull(result, string.Format(ObjectUtil.SysCulture,
                                                        "没有找到名称为{0}的代码插件工厂", factoryName), this);
            return(result);
        }
Exemple #4
0
        public static T CreateInstance <T>(string factoryName, string regName) where T : class
        {
            TkDebug.AssertArgumentNullOrEmpty(factoryName, "factoryName", null);
            TkDebug.AssertArgumentNullOrEmpty(regName, "regName", null);

            TkDebug.ThrowIfNoGlobalVariable();
            BasePlugInFactory factory = BaseGlobalVariable.Current.FactoryManager.GetFactory(factoryName);

            return(factory.CreateInstance <T>(regName));
        }
Exemple #5
0
 internal static void AddPlugInFactory(PlugInFactoryManager manager, Assembly assembly)
 {
     Attribute[] attrs = Attribute.GetCustomAttributes(assembly,
                                                       typeof(AssemblyPlugInFactoryAttribute));
     if (attrs.Length > 0)
     {
         foreach (AssemblyPlugInFactoryAttribute attribute in attrs)
         {
             BasePlugInFactory factory = ObjectUtil.CreateObject(
                 attribute.PlugInFactoryType).Convert <BasePlugInFactory>();
             TkTrace.LogInfo($"添加工厂:{factory.Description}");
             manager.Add(factory);
         }
     }
 }
Exemple #6
0
        public void Add(BasePlugInFactory factory)
        {
            TkDebug.AssertArgumentNull(factory, "factory", this);

            lock (this)
            {
                TkDebug.Assert(!fAllFactories.ContainsKey(factory.Name), string.Format(ObjectUtil.SysCulture,
                                                                                       "{0}已经注册,请检查代码", factory.Name), factory);

                BaseXmlConfigFactory config = factory as BaseXmlConfigFactory;
                if (config != null)
                {
                    fXmlConfigs.Add(config.Name, config);
                }
                else
                {
                    fCodeFactories.Add(factory.Name, factory);
                }
                fAllFactories.Add(factory.Name, factory);
            }
        }
Exemple #7
0
        internal bool InternalAddCodePlugIn(BaseGlobalVariable globalVariable,
                                            BasePlugInAttribute attribute, Type type)
        {
            BasePlugInFactory factory = ObjectUtil.TryGetValue(fAllFactories, attribute.FactoryName);

            if (factory == null)
            {
                globalVariable.AddCodeError(attribute, type, PlugInErrorType.NoFactory);
                return(false);
            }

            bool result = factory.Add(attribute, type);

            if (!result)
            {
                globalVariable.AddCodeError(attribute, type, PlugInErrorType.Duplicate);
            }
            else
            {
                TkTrace.LogInfo($"在工程[{factory.Description}]中添加注册名为[{attribute.GetRegName(type)}]类型[{type}]");
            }
            return(result);
        }