Ejemplo n.º 1
0
        private PropertyExtractor GetAttributeExtractBy(Type type, PropertyInfo property)
        {
            PropertyExtractor propertyExtractor = null;
            var extractBy = AttributeUtil.GetAttribute <ExtractByAttribute>(property);

            if (extractBy != null)
            {
                var selector  = ExtractorUtils.GetSelector(extractBy);
                var sourceTmp = extractBy.Source;
                if (extractBy.Type == ExtractType.JsonPath)
                {
                    sourceTmp = ExtractSource.RawText;
                }
                Source source = Source.Html;
                switch (sourceTmp)
                {
                case ExtractSource.RawText:
                    source = Source.RawText;
                    break;

                case ExtractSource.RawHtml:
                    source = Source.RawHtml;
                    break;

                case ExtractSource.SelectedHtml:
                    source = Source.Html;
                    break;
                }
                propertyExtractor = new PropertyExtractor(property, selector, source,
                                                          extractBy.NotNull, true);
            }
            return(propertyExtractor);
        }
Ejemplo n.º 2
0
        private PropertyExtractor GetAttributeExtractCombo(Type type, PropertyInfo property)
        {
            PropertyExtractor propertyExtractor = null;
            var comboExtract = AttributeUtil.GetAttribute <ComboExtractAttribute>(property);

            if (comboExtract != null)
            {
                var       extractBys = comboExtract.Value;
                var       selectors  = ExtractorUtils.GetSelectors(extractBys);
                ISelector selector   = new AndSelector(selectors);
                switch (comboExtract.Op)
                {
                case Op.And:
                    selector = new AndSelector(selectors);
                    break;

                case Op.Or:
                    selector = new OrSelector(selectors);
                    break;
                }
                var source = comboExtract.Source == ExtractSource.RawHtml ? Source.RawHtml : Source.Html;
                propertyExtractor = new PropertyExtractor(property, selector, source,
                                                          comboExtract.NotNull, comboExtract.IsMulti ||
                                                          typeof(List <object>).IsAssignableFrom(property.GetType()));
            }
            return(propertyExtractor);
        }
Ejemplo n.º 3
0
        public static ZType CreateZType(Type type)
        {
            ZClassAttribute zAttr = AttributeUtil.GetAttribute <ZClassAttribute>(type);

            if (zAttr != null)
            {
                if (type.IsEnum)
                {
                    return(new ZEnumGenType(type));
                }
                else
                {
                    return(new ZClassGenType(type));
                }
            }
            else
            {
                ZMappingAttribute mAttr = AttributeUtil.GetAttribute <ZMappingAttribute>(type);
                if (mAttr == null)
                {
                    return(null);
                }
                if (type.IsEnum)
                {
                    return(new ZEnumMappingType(type));
                }
                else
                {
                    return(new ZEnumGenType(type));
                }
            }
            //return null;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 创建并补全<paramref name="objectType"/>定义的远程能力特性,特性会被加到索引表
        /// </summary>
        /// <param name="objectType"></param>
        /// <returns></returns>
        private static RemotableAttribute Create(Type objectType)
        {
            var tip = AttributeUtil.GetAttribute <RemotableAttribute>(objectType);

            if (tip != null)
            {
                string typeNamespace = string.Empty;
                string typeName      = objectType.Name;

                if (!string.IsNullOrEmpty(tip.TypeNamespace))
                {
                    typeNamespace = tip.TypeNamespace;
                }
                if (!string.IsNullOrEmpty(tip.TypeName))
                {
                    typeName = tip.TypeName;
                }

                tip.TypeNamespace = typeNamespace; //重新赋值一次
                tip.TypeName      = typeName;      //重新赋值一次
                tip.RemoteType    = new RemoteType(typeNamespace, typeName);
                tip.ObjectType    = objectType;
            }
            return(tip);
        }
Ejemplo n.º 5
0
        public override TKTProcDesc[] GetProces()
        {
            List <TKTProcDesc> list = new List <TKTProcDesc>();
            var methodArray         = this.SharpType.GetMethods();

            foreach (var method in methodArray)
            {
                if (!ReflectionUtil.IsDeclare(SharpType, method))
                {
                    continue;
                }
                /* 编译器生成的类肯定有标注 */
                ZCodeAttribute     procAttr = AttributeUtil.GetAttribute <ZCodeAttribute>(method);
                ProcDescCodeParser parser   = new ProcDescCodeParser();
                parser.InitType(SharpType, method);
                TKTProcDesc  typeProcDesc = parser.Parser(procAttr.Code);
                ExMethodInfo exMethod     = ZTypeUtil.CreatExMethodInfo(method, this.SharpType);
                typeProcDesc.ExMethod = exMethod;
                list.Add(typeProcDesc);
            }
            if (ParentMapping != null)
            {
                TKTProcDesc[] epi = ParentMapping.GetProces();
                foreach (var pitem in epi)
                {
                    pitem.ExMethod.IsSelf = false;
                }
                list.AddRange(epi);
            }
            return(list.ToArray());
        }
Ejemplo n.º 6
0
        private FieldExtractor GetAttributeExtractCombo(Type type, FieldInfo field)
        {
            FieldExtractor fieldExtractor = null;
            var            comboExtract   = AttributeUtil.GetAttribute <ComboExtractAttribute>(field);

            if (comboExtract != null)
            {
                var       extractBys = comboExtract.Value;
                var       selectors  = ExtractorUtils.GetSelectors(extractBys);
                ISelector selector   = new AndSelector(selectors);
                switch (comboExtract.Op)
                {
                case Op.And:
                    selector = new AndSelector(selectors);
                    break;

                case Op.Or:
                    selector = new OrSelector(selectors);
                    break;
                }
                var source = comboExtract.Source == ExtractSource.RawHtml ? Source.RawHtml : Source.Html;
                fieldExtractor = new FieldExtractor(field, selector, source,
                                                    comboExtract.NotNull, comboExtract.IsMulti ||
                                                    typeof(List <object>).IsAssignableFrom(field.GetType()))
                {
                    SetterMethod = GetSetterMethod(type, field) ?? null
                };
            }
            return(fieldExtractor);
        }
Ejemplo n.º 7
0
        //public static IZDescType CreateZDescType(Type type)
        //{
        //    if (ztypeCache.ContainsKey(type))
        //    {
        //        return ztypeCache[type];
        //    }
        //    else
        //    {
        //        IZDescType ztype = CreateZTypeImp(type);
        //        if (ztype != null)
        //        {
        //            if (!sharpCache.ContainsKey(ztype.SharpType))
        //                sharpCache.Add(ztype.SharpType, ztype);
        //            if (!ztypeCache.ContainsKey(type))
        //                ztypeCache.Add(type, ztype);
        //        }
        //        return ztype;
        //    }
        //}

        private static IZDescType CreateZTypeImp(Type type)
        {
            if (AttributeUtil.HasAttribute <ZDimAttribute>(type))
            {
                ZDimType zdim = new ZDimType(type);
                return(zdim);
            }
            else if (AttributeUtil.HasAttribute <ZEnumAttribute>(type))
            {
                ZEnumType zenum = new ZEnumType(type);
                return(zenum);
            }
            else if (AttributeUtil.HasAttribute <ZStaticAttribute>(type))
            {
                ZStaticAttribute zAttr     = AttributeUtil.GetAttribute <ZStaticAttribute>(type);
                Type             sharpType = (zAttr.SharpType == null ? type : zAttr.SharpType);
                ZClassType       zclass    = new ZClassType(type, sharpType, true);
                return(zclass);
            }
            else if (AttributeUtil.HasAttribute <ZInstanceAttribute>(type))
            {
                ZInstanceAttribute zAttr = AttributeUtil.GetAttribute <ZInstanceAttribute>(type);
                Type       sharpType     = (zAttr.SharpType == null ? type : zAttr.SharpType);
                ZClassType zclass        = new ZClassType(type, sharpType, false);
                return(zclass);
            }
            return(null);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 检查类型是否为并发访问安全的
        /// </summary>
        /// <param name="type"></param>
        public static void CheckUp(Type type)
        {
            var access = AttributeUtil.GetAttribute <AppSessionAccessAttribute>(type);

            if (access == null)
            {
                throw new TypeUnAppSessionAccessException(type);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 检查类型是否为并发访问安全的
        /// </summary>
        /// <param name="type"></param>
        public static void CheckUp(Type type)
        {
            var access = AttributeUtil.GetAttribute <SafeAccessAttribute>(type, false);

            if (access == null)
            {
                throw new TypeUnsafeAccessException(type);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 得到仓储定义的数据映射器的类型
        /// </summary>
        /// <param name="repository"></param>
        /// <returns></returns>
        internal static Type GetDataMapperType(IRepository repository)
        {
            var attribute = AttributeUtil.GetAttribute <DataMapperAttribute>(repository.GetType());

            if (attribute == null)
            {
                return(null);
            }
            return(attribute.DataMapperType);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 根据对象标记的验证器特性,得到验证器
        /// </summary>
        /// <returns></returns>
        internal static IEnumerable <IObjectValidator> GetValidators(Type objectType)
        {
            var attribute = AttributeUtil.GetAttribute <ObjectValidatorAttribute>(objectType);

            if (attribute == null)
            {
                return(Array.Empty <IObjectValidator>());
            }
            return(attribute.Validators);
        }
Ejemplo n.º 12
0
        public ZClassGenType(Type type)
        {
            this.SharpType      = type;
            this.ClassAttribute = AttributeUtil.GetAttribute <ZClassAttribute>(type);

            Type       baseType = ClassAttribute.BaseMappingType != null ? ClassAttribute.BaseMappingType : typeof(Z语言系统.事物);
            ZClassType zc       = ZType.CreateZType(baseType) as ZClassType;

            ZClassTypeCache.One.Set(baseType, zc);
            this.ParentMapping = ZClassTypeCache.One.Get(baseType);
        }
Ejemplo n.º 13
0
            public PropertyInjectionSite(PropertyInfo info, MonoBehaviour script)
            {
                _info = info;
                var attr = AttributeUtil.GetAttribute <InjectAttribute>(info);

                FromSource   = attr.From;
                SearchMethod = attr.Search;
                HintPath     = attr.HintPath;
                Script       = script;
                Required     = attr.Required;
            }
Ejemplo n.º 14
0
        public static void Initialize()
        {
            var eventTypes = AssemblyUtil.GetTypesByAttribute <EventAttribute>();

            List <EventAttribute> tips = new List <EventAttribute>(eventTypes.Count());

            foreach (var eventType in eventTypes)
            {
                var tip = AttributeUtil.GetAttribute <EventAttribute>(eventType);
                tip.EventType = eventType;
                tips.Add(tip);
                _typeTips.Add(tip.EventType, tip);
                _nameTips.Add(tip.Name, tip);
            }
            Tips = tips;
        }
Ejemplo n.º 15
0
        public ZLEnumInfo(Type type)
        {
            MarkType      = type;
            MarkAttribute = AttributeUtil.GetAttribute <ZEnumAttribute>(type);
            if (MarkAttribute.ForType == null)
            {
                SharpType = type;
            }
            else
            {
                SharpType = MarkAttribute.ForType;
            }

            EnumElements    = GetEnumElements(MarkType, SharpType);
            AccessAttribute = ReflectionUtil.GetAccessAttributeEnum(type);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 创建类型<typeparamref name="T"/>的实例
        /// <para>如果类型标记了并发访问安全标签,那么会自动以单例的形式创建对象,同一类型不会创建多份实例</para>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="objType"></param>
        /// <returns></returns>
        public static T CreateInstance <T>()
        {
            var    objType = typeof(T);
            object obj     = null;
            var    attr    = AttributeUtil.GetAttribute <SafeAccessAttribute>(objType);

            if (attr != null)
            {
                obj = _getSingleInstance(objType);
            }
            else
            {
                obj = Activator.CreateInstance(objType, true);//设置true,表示就算是私有的构造函数也能匹配
            }
            return((T)obj);
        }
Ejemplo n.º 17
0
        public IObjectFormatter Build()
        {
            var formatter = AttributeUtil.GetAttribute <FormatterAttribute>(field);

            if (formatter?.Formatter.Equals(FormatterAttribute.DefaultFormatterType) == true)
            {
                return(InitFormatter(formatter.Formatter, formatter.Value));
            }
            if (formatter == null && formatter.SubType.Equals(typeof(void)))
            {
                return(InitFormatterForType(field.GetType(), formatter?.Value));
            }
            else
            {
                return(InitFormatterForType(formatter.SubType, formatter.Value));
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 将类型<paramref name="objType"/>创建为<typeparamref name="T"/>的实例
        /// <para>如果类型标记了并发访问安全标签,那么会自动以单例的形式创建对象,同一类型不会创建多份实例</para>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="objType"></param>
        /// <returns></returns>
        public static T CreateInstance <T>(Type objType) where T : class
        {
            T   obj  = null;
            var attr = AttributeUtil.GetAttribute <SafeAccessAttribute>(objType);

            if (attr != null)
            {
                obj = _getSingleInstance(objType) as T;
            }
            else
            {
                obj = Activator.CreateInstance(objType, true) as T;//设置true,表示就算是私有的构造函数也能匹配
            }
            if (obj == null)
            {
                throw new TypeMismatchException(objType, typeof(T));
            }
            return(obj);
        }
Ejemplo n.º 19
0
        private PropertyExtractor GetAttributeExtractByUrl(Type type, PropertyInfo property)
        {
            PropertyExtractor propertyExtractor = null;
            var extractByUrlAttr = AttributeUtil.GetAttribute <ExtractByUrlAttribute>(property);

            if (extractByUrlAttr != null)
            {
                var regexPattern = extractByUrlAttr.Value;
                if (regexPattern.Trim().Equals(""))
                {
                    regexPattern = ".*";
                }
                propertyExtractor = new PropertyExtractor(property,
                                                          new RegexSelector(regexPattern), Source.Url,
                                                          extractByUrlAttr.NotNull, extractByUrlAttr.IsMulti ||
                                                          typeof(List <object>).IsAssignableFrom(property.GetType()));
            }
            return(propertyExtractor);
        }
Ejemplo n.º 20
0
        private void InitClassExtractors()
        {
            var targeturlAttr = AttributeUtil.GetAttribute <TargetUrlAttribute>(type);

            if (targeturlAttr == null)
            {
                targetUrlRegexs.Add(new Regex(".*"));
            }
            else
            {
                var values = (targeturlAttr as TargetUrlAttribute).Value;
                foreach (var value in values)
                {
                    targetUrlRegexs.Add(new Regex(value.Replace(".", "\\.").Replace("*", "[^\"'#]*")));
                }
                if (!(targeturlAttr as TargetUrlAttribute).SourceRegion.Equals(""))
                {
                    targetUrlRegionSelector = new XPathSelector((targeturlAttr as TargetUrlAttribute).SourceRegion);
                }
            }
            var helpUrlAttr = AttributeUtil.GetAttribute <HelpUrlAttribute>(type);

            if (helpUrlAttr != null)
            {
                var values = helpUrlAttr.Value;
                foreach (var value in values)
                {
                    helpUrlRegexs.Add(new Regex(value.Replace(".", "\\.").Replace("*", "[^\"'#]*")));
                }
                if (!helpUrlAttr.SourceRegion.Equals(""))
                {
                    helpUrlRegionSelector = new XPathSelector(helpUrlAttr.SourceRegion);
                }
            }
            var extractByAttr = AttributeUtil.GetAttribute <ExtractByAttribute>(type);

            if (extractByAttr != null)
            {
                objectExtractor = new Extractor(new XPathSelector(extractByAttr.Value),
                                                Source.Html, extractByAttr.NotNull, extractByAttr.IsMulti);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="objectType">需要扩展的领域对象类型,也可以是一个扩展类型,当<paramref name="objectOrExtensionType"/>是扩展类型时,这表示三次或三次以上的扩展</param>
        public ExtendedClassAttribute(Type objectOrExtensionType, Type extensionType)
        {
            if (objectOrExtensionType.IsImplementOrEquals(typeof(IDomainObject)))
            {
                this.ObjectType = objectOrExtensionType;
            }
            else
            {
                //objectOrExtensionType是扩展类型,取得特性
                var attr = AttributeUtil.GetAttribute <ExtendedClassAttribute>(objectOrExtensionType);
                if (attr == null)
                {
                    throw new DomainDrivenException(string.Format(Strings.ObjectExtensionAttributeFirstParamError, objectOrExtensionType.FullName));
                }
                this.ObjectType = attr.ObjectType;
            }

            this.ExtensionType = extensionType;
            AddExtensionType(this.ObjectType, extensionType);
        }
Ejemplo n.º 22
0
        private RemoteType GetRemoteType()
        {
            string typeNamespace = string.Empty;
            string typeName      = this.TypeName;

            var attr = AttributeUtil.GetAttribute <RemoteTypeAttribute>(this.GetType());

            if (attr != null)
            {
                if (!string.IsNullOrEmpty(attr.TypeNamespace))
                {
                    typeNamespace = attr.TypeNamespace;
                }
                if (!string.IsNullOrEmpty(attr.TypeName))
                {
                    typeName = attr.TypeName;
                }
            }
            //默认情况下命名空间为空,类型名等于本地类型名
            return(new RemoteType(typeNamespace, typeName));
        }
Ejemplo n.º 23
0
        public override TKTProcDesc SearchProc(TKTProcDesc procDesc)
        {
            var methodArray = this.SharpType.GetMethods( );

            foreach (var method in methodArray)
            {
                if (!ReflectionUtil.IsDeclare(SharpType, method))
                {
                    continue;
                }
                /* 编译器生成的类肯定有标注 */
                ZCodeAttribute procAttr = AttributeUtil.GetAttribute <ZCodeAttribute>(method);// Attribute.GetCustomAttribute(method, typeof(ZCodeAttribute)) as ZCodeAttribute;
                //if (procAttr == null)
                //{
                //    ExMethodInfo exMethod = ZTypeHelper.CreatExMethodInfo(method, this.SharpType);
                //    TKTProcDesc typeProcDesc = ProcDescHelper.CreateProcDesc(exMethod);
                //    if (typeProcDesc.Eq(procDesc))
                //    {
                //        return typeProcDesc;
                //    }
                //}
                //else
                //{
                ProcDescCodeParser parser = new ProcDescCodeParser();
                parser.InitType(SharpType, method);
                TKTProcDesc typeProcDesc = parser.Parser(procAttr.Code);
                if (typeProcDesc.Eq(procDesc))
                {
                    ExMethodInfo exMethod = ZTypeUtil.CreatExMethodInfo(method, this.SharpType);
                    typeProcDesc.ExMethod = exMethod;
                    return(typeProcDesc);
                }
                //}
            }
            if (ParentMapping != null)
            {
                return(ParentMapping.SearchProc(procDesc));
            }
            return(null);
        }
Ejemplo n.º 24
0
        private FieldExtractor GetAttributeExtractByUrl(Type type, FieldInfo field)
        {
            FieldExtractor fieldExtractor   = null;
            var            extractByUrlAttr = AttributeUtil.GetAttribute <ExtractByUrlAttribute>(field);

            if (extractByUrlAttr != null)
            {
                var regexPattern = extractByUrlAttr.Value;
                if (regexPattern.Trim().Equals(""))
                {
                    regexPattern = ".*";
                }
                fieldExtractor = new FieldExtractor(field,
                                                    new RegexSelector(regexPattern), Source.Url,
                                                    extractByUrlAttr.NotNull, extractByUrlAttr.IsMulti ||
                                                    typeof(List <object>).IsAssignableFrom(field.GetType()))
                {
                    SetterMethod = GetSetterMethod(type, field)
                };
            }
            return(fieldExtractor);
        }
Ejemplo n.º 25
0
        private static ZLType CreateZTypeImp(Type type)
        {
            if (AttributeUtil.HasAttribute <ZInstanceAttribute>(type))
            {
                ZInstanceAttribute zAttr = AttributeUtil.GetAttribute <ZInstanceAttribute>(type);
                Type        sharpType    = (zAttr.SharpType == null ? type : zAttr.SharpType);
                ZLClassInfo zclass       = new ZLClassInfo(type, sharpType, false);
                return(zclass);
            }
            else if (AttributeUtil.HasAttribute <ZEnumAttribute>(type))
            {
                ZLEnumInfo zenum = new ZLEnumInfo(type);
                return(zenum);
            }
            else if (AttributeUtil.HasAttribute <ZStaticAttribute>(type))
            {
                ZStaticAttribute zAttr     = AttributeUtil.GetAttribute <ZStaticAttribute>(type);
                Type             sharpType = (zAttr.SharpType == null ? type : zAttr.SharpType);
                ZLClassInfo      zclass    = new ZLClassInfo(type, sharpType, true);
                return(zclass);
            }

            return(null);
        }
Ejemplo n.º 26
0
 public void Process(ResultItems resultItems, ITask task)
 {
     foreach (var keyValuePair in pageModelPipelines)
     {
         var obj = resultItems.Get <object>(keyValuePair.Key.Name);
         if (obj != null)
         {
             var attr = AttributeUtil.
                        GetAttribute <ExtractByAttribute>(keyValuePair.Key);
             if (attr != null || !attr.IsMulti)
             {
                 keyValuePair.Value.Process((T)obj, task);
             }
             else
             {
                 var list = obj as List <object>;
                 foreach (var o in list)
                 {
                     keyValuePair.Value.Process((T)o, task);
                 }
             }
         }
     }
 }
Ejemplo n.º 27
0
        public void Process(ResultItems resultItems, ITask task)
        {
            var obj = resultItems.Get <object>(type.Name);

            if (obj != null)
            {
                var attr = AttributeUtil.GetAttribute <ExtractByAttribute>(type);
                if (attr == null || !attr.IsMulti)
                {
                    typePipeline.Process((T)obj, task);
                }
                else
                {
                    var list = obj as List <object>;
                    if (list?.Count > 0)
                    {
                        foreach (var o in list)
                        {
                            typePipeline.Process((T)o, task);
                        }
                    }
                }
            }
        }
Ejemplo n.º 28
0
        private FieldExtractor GetAttributeExtractBy(Type type, FieldInfo field)
        {
            FieldExtractor fieldExtractor = null;
            var            extractBy      = AttributeUtil.GetAttribute <ExtractByAttribute>(field);

            if (extractBy != null)
            {
                var selector  = ExtractorUtils.GetSelector(extractBy);
                var sourceTmp = extractBy.Source;
                if (extractBy.Type == ExtractType.JsonPath)
                {
                    sourceTmp = ExtractSource.RawText;
                }
                Source source = Source.Html;
                switch (sourceTmp)
                {
                case ExtractSource.RawText:
                    source = Source.RawText;
                    break;

                case ExtractSource.RawHtml:
                    source = Source.RawHtml;
                    break;

                case ExtractSource.SelectedHtml:
                    source = Source.Html;
                    break;
                }
                fieldExtractor = new FieldExtractor(field, selector, source,
                                                    extractBy.NotNull, true)
                {
                    SetterMethod = null
                };
            }
            return(fieldExtractor);
        }
Ejemplo n.º 29
0
 public static bool IsDefined(Type type)
 {
     return(AttributeUtil.GetAttribute <SafeAccessAttribute>(type) != null);
 }
Ejemplo n.º 30
0
 public static bool IsDefined(object obj)
 {
     return(AttributeUtil.GetAttribute <SafeAccessAttribute>(obj.GetType()) != null);
 }