コード例 #1
0
        protected override bool Add(string regName, BasePlugInAttribute attribute, Type type)
        {
            Attribute instanceAttr = Attribute.GetCustomAttribute(type, typeof(InstancePlugInAttribute));

            if (instanceAttr != null)
            {
                BindingFlags flags     = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
                FieldInfo    fieldInfo = type.GetField("Instance", flags);
                if (fieldInfo == null)
                {
                    fieldInfo = type.GetField("INSTANCE", flags);
                    if (fieldInfo == null)
                    {
                        return(false);
                    }
                }
                object value = ObjectUtil.GetStaticValue(fieldInfo);
                if (value == null)
                {
                    return(false);
                }
                ICacheDependency dependency = CacheUtil.GetDependency(type, null);
                if (dependency == null)
                {
                    dependency = AlwaysDependency.Dependency;
                }

                return(AddInstance(regName, attribute, value, dependency) != null);
            }
            else
            {
                return(base.Add(regName, attribute, type));
            }
        }
コード例 #2
0
ファイル: ErrorPlugInInfo.cs プロジェクト: madiantech/tkcore
 internal ErrorPlugInInfo(BasePlugInAttribute attribute, Type type, PlugInErrorType errorType)
 {
     RegName      = attribute.GetRegName(type);
     Type         = type.ToString();
     AssemblyName = type.Assembly.FullName;
     Error        = errorType;
 }
コード例 #3
0
ファイル: InstanceRegItem.cs プロジェクト: madiantech/tkcore
 /// <summary>
 /// Initializes a new instance of the InstanceRegItem class.
 /// </summary>
 public InstanceRegItem(string regName, BasePlugInAttribute attribute,
                        object instance, ICacheDependency dependency)
     : base(regName, attribute)
 {
     fInstance     = instance;
     fInstanceType = instance.GetType();
     Dependency    = dependency;
 }
コード例 #4
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));
        }
コード例 #5
0
 private void TryAddSection(string regName, Type type, BasePlugInAttribute attribute)
 {
     if (attribute is FactoryDefaultValueAttribute factoryAttr)
     {
         AddSection(factoryAttr.SectionName, factoryAttr.ConfigFactoryName);
     }
     else if (attribute is DefaultValueAttribute)
     {
         fObjectConfig.Add(regName, type);
     }
 }
コード例 #6
0
        public bool Add(BasePlugInAttribute attribute, Type type)
        {
            TkDebug.AssertArgumentNull(attribute, "attribute", this);
            TkDebug.AssertArgumentNull(type, "type", this);

            TkDebug.Assert(attribute.FactoryName == Name, string.Format(ObjectUtil.SysCulture,
                                                                        "调用错误,Attribute的工厂名{0}和当前工厂的不一致", attribute.FactoryName), this);

            string regName = attribute.GetRegName(type);

            return(Add(regName, attribute, type));
        }
コード例 #7
0
 private void AddAdditionObj(string regName, Type type, BasePlugInAttribute attr)
 {
     if (ObjectUtil.IsSubType(typeof(EvaluateAdditionType), type))
     {
         EvaluateAdditionType add = CreateInstance <EvaluateAdditionType>(regName);
         EvaluatorUtil.AddAdditionObj(add.CreateAdditionObject());
     }
     else
     {
         string name = type.Name;
         EvaluatorUtil.AddAdditionObj((name, type));
     }
 }
コード例 #8
0
 protected virtual bool Add(string regName, BasePlugInAttribute attribute, Type type)
 {
     lock (this)
     {
         if (!Contains(regName))
         {
             CodeRegItem regItem = new CodeRegItem(regName, attribute, type);
             InternalAddPlugIn(regName, regItem);
             return(true);
         }
         return(false);
     }
 }
コード例 #9
0
 internal InstanceRegItem AddInstance(string regName, BasePlugInAttribute attribute,
                                      object instance, ICacheDependency dependency)
 {
     lock (this)
     {
         if (!Contains(regName))
         {
             InstanceRegItem instanceRegItem = new InstanceRegItem(regName,
                                                                   attribute, instance, dependency);
             fInstancePlugIns.Add(regName, instanceRegItem);
             return(instanceRegItem);
         }
         return(null);
     }
 }
コード例 #10
0
        //internal void AddElements(ObjectElementInfo elements, Type type,
        //    PropertyInfo property, string modelName, DynamicElementAttribute dynamic)
        //{
        //    EnumableCodePlugIn((regName, regType, attr) =>
        //    {
        //        ObjectElementAttribute objectAttr = attr.Convert<BaseObjectElementAttribute>()
        //            .ConvertTo(regName, regType, dynamic);
        //        elements.Add(type, property, objectAttr, modelName);
        //    });
        //}

        //internal void AddElements(Dictionary<string, ObjectElementAttribute> dictionary, string factoryName)
        //{
        //    DynamicElementAttribute dynamic = new DynamicElementAttribute(factoryName);
        //    EnumableCodePlugIn((regName, regType, attr) =>
        //    {
        //        ObjectElementAttribute objectAttr = attr.Convert<BaseObjectElementAttribute>()
        //            .ConvertTo(regName, regType, dynamic);
        //        dictionary.Add(regName, objectAttr);
        //    });
        //}

        protected override bool Add(string regName, BasePlugInAttribute attribute, Type type)
        {
            BaseObjectElementAttribute elementAttr = attribute.Convert <BaseObjectElementAttribute>();
            string newRegName;

            if (SupportVersion)
            {
                VersionRegName version = new VersionRegName(regName, GetVersion(elementAttr));
                newRegName = version.WriteJson();
            }
            else
            {
                newRegName = regName;
            }
            var result = base.Add(newRegName, attribute, type);

            if (result)
            {
                fConfigData.Add(this, regName, elementAttr, type);
            }
            return(result);
        }
コード例 #11
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);
        }
コード例 #12
0
 internal void AddCodeError(BasePlugInAttribute attribute, Type type, PlugInErrorType errorType)
 {
     fPlugInErrorLog.AddCodeError(attribute, type, errorType);
 }
コード例 #13
0
ファイル: BaseRegItem.cs プロジェクト: madiantech/tkcore
 protected BaseRegItem(string regName, BasePlugInAttribute attribute)
 {
     RegName   = regName;
     Attribute = attribute;
 }
コード例 #14
0
 internal void AddCodeError(BasePlugInAttribute attribute, Type type, PlugInErrorType errorType)
 {
     Code.Add(new ErrorPlugInInfo(attribute, type, errorType));
 }
コード例 #15
0
 public CodeRegItem(string regName, BasePlugInAttribute attribute, Type regType)
     : base(regName, attribute)
 {
     RegType = regType;
 }