Ejemplo n.º 1
0
        public oModelFielInfo(string name, AttrFieldInfo attr)
        {
            this.Index            = attr.Index;
            this.IsFullTextSearch = attr.IsFullTextSearch;
            this.IsIndex          = attr.IsIndex;
            this.IsKey            = attr.IsKey;
            this.Name             = name;
            this.Title            = attr.Title;
            this.TypeName         = attr.TypeName;
            this.TypeCode         = (int)attr.TypeCode;
            this.GroupTitle       = attr.GroupTitle;

            switch (attr.TypeCode)
            {
            case AttrDataType.ENTITY:
            case AttrDataType.ENUM:
                this.TypeName = attr.EntityName;
                break;

            case AttrDataType.ENTITY_ARRAY:
            case AttrDataType.ENUM_ARRAY:
                this.TypeName = attr.EntityName + "[]";
                break;
            }

            this.EntityName           = attr.EntityName;
            this.ServiceLink          = attr.ServiceLink;
            this.ServiceLinkFieldName = attr.ServiceLinkFieldName;
        }
Ejemplo n.º 2
0
        string get_modelAttrsJson(string typeName = "")
        {
            oModelInfo model = new oModelInfo();

            Type typeModel = Type.GetType("MessageBroker." + typeName + ", MessageBroker");

            if (typeModel == null)
            {
                return("{}");
            }

            model.Name = typeModel.Name;

            object[] attrsModel = typeModel.GetCustomAttributes(true);
            foreach (var attr in attrsModel)
            {
                AttrModelInfo attrExt = attr as AttrModelInfo;
                if (attrExt != null)
                {
                    model.Title       = attrExt.Title;
                    model.ServiceName = attrExt.ServiceName;
                }
            }

            PropertyInfo[] props = typeModel.GetProperties();
            foreach (PropertyInfo prop in props)
            {
                object[] attrsField = prop.GetCustomAttributes(true);
                foreach (object attr in attrsField)
                {
                    AttrFieldInfo attrExt = attr as AttrFieldInfo;
                    if (attrExt != null)
                    {
                        model.Properties.Add(new oModelFielInfo(prop.Name, attrExt));
                    }
                }
            }
            string json = JsonConvert.SerializeObject(model);

            //cache file json
            string file = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "schema-" + typeName + ".json");

            File.WriteAllText(file, json);

            return(json);
        }