コード例 #1
0
        public override AnyStatus Save(StackAppContext appContext, EntityModelBase model)
        {
            if (model.IsNew)
            {
                var entityId  = model.GetValue <int>("entityid", 0);
                var length    = model.GetValue <int>("length", 0);
                var type      = model.GetValue <int>("fieldtype", 0);
                var fieldInfo = EntityMetaData.CreateField((FieldType)type);
                var baseType  = fieldInfo.BaseType;
                model.SetTempInfo("basetypecode", baseType);

                if (length == 0)
                {
                    if (baseType == TypeCode.String)
                    {
                        length = GetDefaultVarCharLength((FieldType)type);
                    }
                    else if (baseType == TypeCode.Decimal)
                    {
                        length = 6;
                    }

                    model.SetValue("length", length);
                }

                var fieldName = model.GetValue("fieldname", "");
                var tableName = this.GetEntity(entityId).DBName;
                model.SetValue("tablename", tableName);
                model.SetValue("dbname", fieldName);
            }

            return(base.Save(appContext, model));
        }
コード例 #2
0
 protected void SetMergeRelevant(EntityMetaData metaData, Member member, bool value)
 {
     if (member != null)
     {
         metaData.SetMergeRelevant(member, value);
     }
 }
コード例 #3
0
        private void GetField(PropertyInfo propertyInfo, EntityMetaData metaData)
        {
            var fieldMetaData = new EntityFieldMetaData(metaData);

            fieldMetaData.Name         = propertyInfo.Name;
            fieldMetaData.DbColumnName = propertyInfo.Name;
            GetDefaultSqlType(propertyInfo.PropertyType, fieldMetaData);

            var attributes = propertyInfo.GetCustomAttributes();

            foreach (var attribute in attributes)
            {
                if (attribute is IgnoreAttribute)
                {
                    return;
                }

                var attributeType = attribute.GetType();
                if (_attributeHandlers.ContainsKey(attributeType))
                {
                    _attributeHandlers[attributeType](attribute, fieldMetaData);
                }
            }

            metaData.Fields.Add(fieldMetaData);
        }
コード例 #4
0
ファイル: SQLinqInsert.cs プロジェクト: zqlovejyc/SQLinq
        public ISQLinqResult ToSQL(int existingParameterCount = 0, string parameterNamePrefix = SqlExpressionCompiler.DefaultParameterNamePrefix)
        {
            int parameterNumber = existingParameterCount;

            parameterNumber++;

            var parameters = new Dictionary <string, object>();
            var fields     = new Dictionary <string, string>();

            // Get Table / View Name
            var tableName = TableNameOverride ?? EntityMetaData <T> .TableName;

            tableName = Dialect.ParseTableName(tableName);

            foreach (var p in EntityMetaData <T> .GetFiledInfos())
            {
                var parameterName = this.Dialect.ParameterPrefix + parameterNamePrefix + parameterNumber.ToString();

                fields.Add(p.Item1, parameterName);
                parameters.Add(parameterName, p.Item2.GetValue(this.Data, null));

                parameterNumber++;
            }

            return(new SQLinqInsertResult(this.Dialect)
            {
                Table = tableName,
                Fields = fields,
                Parameters = parameters
            });
        }
コード例 #5
0
        public static List <ViewPageDataOnly> GetData(StackAppContext appContext, RequestQueryString requestQuery)
        {
            var baseEntity  = EntityMetaData.Get(requestQuery.EntityId);
            var baseField   = baseEntity.GetFieldSchema(requestQuery.FieldName);
            var childEntity = EntityMetaData.Get(baseField.RefObject);

            var ids   = FetchDataModel(appContext, requestQuery.ItemId, baseField, childEntity);
            var pages = new List <ViewPageDataOnly>();

            var lConext = new LayoutContext(appContext, 0, baseField.RefObject);

            lConext.Build();

            foreach (var id in ids)
            {
                var query = new RequestQueryString()
                {
                    EntityId = baseField.RefObject, ItemId = id
                };

                var context = new EditFormContext(appContext, baseField.RefObject, query);
                context.Build();
                context.CreateDataModel();

                context.LayoutContext = lConext;

                var renderer = new EditFormRenderer(context);
                renderer.Generate(lConext);

                pages.Add(renderer.GetViewPageOnlyData());
            }

            return(pages);
        }
コード例 #6
0
        private void addEntityToProject(EntityMetaData entity, SerializationContext serializationContext)
        {
            if (entity.IsAnImplementationOf <SimulationMetaData>())
            {
                return;
            }

            var deserializedEntity = deserializeContent <object>(entity.Content, serializationContext);

            if (deserializedEntity.IsAnImplementationOf <CurveChart>())
            {
                addChartToProject(deserializedEntity);
            }

            else if (deserializedEntity.IsAnImplementationOf <ParameterIdentification>())
            {
                _project.AddParameterIdentification(deserializedEntity as ParameterIdentification);
            }

            else if (deserializedEntity.IsAnImplementationOf <SensitivityAnalysis>())
            {
                _project.AddSensitivityAnalysis(deserializedEntity as SensitivityAnalysis);
            }

            else if (deserializedEntity.IsAnImplementationOf <IWithId>())
            {
                _project.AddBuildingBlock(deserializedEntity as IBuildingBlock);
            }

            else
            {
                throw new MoBiException($"Don't know what to do with {deserializedEntity.GetType()}");
            }
        }
コード例 #7
0
        public static DesignerViewPage BuildPage(StackAppContext appContext, RequestQueryString requestQuery)
        {
            var layoutModel = EntityMetaData.Get(EntityCode.EntityLayout).GetSingle(appContext, requestQuery.ItemId);
            var entity      = EntityMetaData.Get(requestQuery.RelatedEntityId);

            var view = TView.ParseFromJSON(layoutModel.GetValue("layoutjson", ""));

            if (view == null)
            {
                view = entity.GetDefaultLayoutView(0);
            }

            var pallet = BuildPallet(appContext, entity);

            var page = new DesignerViewPage(pallet, view);

            page.LayoutFields = view.Fields;
            page.Actions      = new InvariantDictionary <Model.Form.ActionInfo>();

            var saveAction = new ActionInfo("Studio/SaveDesigner", requestQuery, "BTN_SAVE")
            {
                Title         = "Save",
                ActionType    = ActionType.Save,
                ExecutionType = ActionExecutionType.Custom
            };

            page.Actions.Add("BTN_SAVE", saveAction);

            return(page);
        }
コード例 #8
0
        protected void ReadConfig(IOrmConfigGroup ormConfigGroup)
        {
            LinkedHashSet <IEntityConfig> entities = new LinkedHashSet <IEntityConfig>();

            entities.AddAll(ormConfigGroup.GetLocalEntityConfigs());
            entities.AddAll(ormConfigGroup.GetExternalEntityConfigs());

            foreach (IEntityConfig entityConfig in entities)
            {
                Type entityType = entityConfig.EntityType;
                if (EntityMetaDataProvider.GetMetaData(entityType, true) != null)
                {
                    continue;
                }
                Type realType = entityConfig.RealType;

                EntityMetaData metaData = new EntityMetaData();
                metaData.EntityType  = entityType;
                metaData.RealType    = realType;
                metaData.LocalEntity = entityConfig.Local;

                EntityMetaDataReader.AddMembers(metaData, entityConfig);

                managedEntityMetaData.Add(metaData);
                lock (EntityMetaDataExtendable)
                {
                    EntityMetaDataExtendable.RegisterEntityMetaData(metaData);
                }
            }
        }
コード例 #9
0
        private void GetFields(Type entityType, EntityMetaData metaData)
        {
            var properties = entityType.GetProperties();

            foreach (var property in properties)
            {
                GetField(property, metaData);
            }
        }
コード例 #10
0
        private EntityMetaData mapFrom(CurveChart chart)
        {
            var entityMetaData = new EntityMetaData {
                Id = ShortGuid.NewGuid()
            };

            serialize(entityMetaData, chart);
            return(entityMetaData);
        }
コード例 #11
0
        private EntityMetaData mapFrom(IWithId entityWithId)
        {
            var entityMetaData = new EntityMetaData {
                Id = entityWithId.Id
            };

            serialize(entityMetaData, entityWithId);
            return(entityMetaData);
        }
コード例 #12
0
        public string Build(EntityMetaData metaData)
        {
            if (!string.IsNullOrWhiteSpace(metaData.SchemaName))
            {
                return($"[{metaData.SchemaName}].[{metaData.TableName}]");
            }

            return($"[{metaData.TableName}]");
        }
コード例 #13
0
        public string Build(EntityMetaData metaData, bool useRowVersion)
        {
            var whereFields = GetFields(metaData, useRowVersion);

            if (whereFields.Count > 0)
            {
                return("WHERE " + string.Join(" AND ", whereFields.Select(pk => pk.DbColumnName + "=@" + pk.DbColumnName)));
            }

            return(string.Empty);
        }
コード例 #14
0
        public List <EntityFieldMetaData> GetFields(EntityMetaData metaData, bool useRowVersion)
        {
            var whereFields = metaData.PrimaryKey;

            if (useRowVersion)
            {
                whereFields = whereFields.Concat(metaData.Fields.Where(field => field.IsRowVersion)).Distinct().ToList();
            }

            return(whereFields);
        }
コード例 #15
0
        public EntityMetaData Build(Type entityType)
        {
            var metaData = new EntityMetaData();

            metaData.EntityType = entityType;

            GetTableName(entityType, metaData);
            GetFields(entityType, metaData);
            GetPrimaryKey(metaData);

            return(metaData);
        }
コード例 #16
0
        public IEnumerable <EntityMetaData> GetMetaData(String EntityName)
        {
            var query = from meta in ObjectContext.MetadataWorkspace.GetItems(DataSpace.CSpace)
                        .Where(m => m.BuiltInTypeKind == BuiltInTypeKind.EntityType)
                        from p in (meta as EntityType).Properties.Where(p => p.DeclaringType.Name.Equals(EntityName, StringComparison.OrdinalIgnoreCase))
                        select new EntityMetaData()
            {
                IsKey             = (meta as EntityType).KeyMembers.Contains(p.Name),
                IsInVisible       = (meta as EntityType).KeyMembers.Contains(p.Name),
                IsForeignKey      = IsForeignKey(meta as EntityType, p.Name),
                ForeignEntityType = GetForeignEntityType(meta as EntityType, p.Name),
                ForeingEntitySet  = GetEntitySetName(GetForeignEntityType(meta as EntityType, p.Name)),
                // EntityTypeName = p.DeclaringType.Name,
                PropertyName  = p.Name,
                Nullable      = p.Nullable,
                TypeUsageName = p.TypeUsage.EdmType.Name,
                DefaultValue  = p.DefaultValue != null?p.DefaultValue.ToString() : null,
                                    Documentation = p.Documentation != null ? p.Documentation.LongDescription : null
            };

            MetadataWorkspace mw = ObjectContext.MetadataWorkspace;
            var items            = mw.GetItems <EntityType>(DataSpace.CSpace).Where(i => i.Name.Equals(EntityName, StringComparison.OrdinalIgnoreCase));
            IList <EntityMetaData> collectionProperties = new List <EntityMetaData>();

            foreach (var item in items)
            {
                foreach (var navigationProprty in item.NavigationProperties)
                {
                    if (navigationProprty.GetDependentProperties().Count() == 0)
                    {
                        EntityMetaData m = new EntityMetaData();
                        m.PropertyName       = navigationProprty.Name;
                        m.ForeignEntityType  = GetEntityTypeName(navigationProprty.Name);
                        m.ForeingEntitySet   = navigationProprty.Name;
                        m.IsKey              = false;
                        m.Nullable           = true;
                        m.TypeUsageName      = navigationProprty.TypeUsage.EdmType.Name;
                        m.Documentation      = navigationProprty.Documentation != null ? navigationProprty.Documentation.LongDescription : null;
                        m.IsCollectionEntity = true;
                        m.IsInVisible        = true;
                        collectionProperties.Add(m);
                    }
                }
            }


            return(query.Concat <EntityMetaData>(collectionProperties));
        }
コード例 #17
0
        private static void AddEntityActions(ref IDictionary <int, DBEntity> entities)
        {
            string entityName = "entityaction";
            int    entId      = 6;
            var    fs         = new Dictionary <string, BaseField>();

            var dbo = DbObject.FromJSON(@"{""fieldtype"": 1,""fieldname"": ""text"",""isrequired"": true,""dbname"": ""text""}");
            var f   = EntityMetaData.BuildField(entityName, entityName, dbo, null);

            fs.Add("TEXT", f);

            dbo = DbObject.FromJSON(@"{""fieldtype"": 2,""fieldname"": ""entityid"",""isrequired"": true,""dbname"": ""entityid"",""viewtype"":-1}");
            f   = EntityMetaData.BuildField(entityName, entityName, dbo, null);
            fs.Add("ENTITYID", f);

            dbo = DbObject.FromJSON(@"{""fieldtype"": 9,""fieldname"": ""viewtype"",""isrequired"": false,""dbname"": ""viewtype"", ""collectionid"": 5}");
            f   = EntityMetaData.BuildField(entityName, entityName, dbo, null);
            fs.Add("VIEWTYPE", f);

            dbo = DbObject.FromJSON(@"{""fieldtype"": 9,""fieldname"": ""actiontype"",""isrequired"": false,""dbname"": ""actiontype"", ""collectionid"": 4}");
            f   = EntityMetaData.BuildField(entityName, entityName, dbo, null);
            fs.Add("ACTIONTYPE", f);

            dbo = DbObject.FromJSON(@"{""fieldtype"": 1,""fieldname"": ""action"",""isrequired"": false,""dbname"": ""action""}");
            f   = EntityMetaData.BuildField(entityName, entityName, dbo, null);
            fs.Add("ACTION", f);

            dbo = DbObject.FromJSON(@"{""fieldtype"": 1,""fieldname"": ""queryparam"",""isrequired"": false,""dbname"": ""queryparam""}");
            f   = EntityMetaData.BuildField(entityName, entityName, dbo, null);
            fs.Add("QUERYPARAM", f);

            dbo = DbObject.FromJSON(@"{""fieldtype"": 1,""fieldname"": ""dataparam"",""isrequired"": false,""dbname"": ""dataparam""}");
            f   = EntityMetaData.BuildField(entityName, entityName, dbo, null);
            fs.Add("DATAPARAM", f);

            dbo = DbObject.FromJSON(@"{""fieldtype"": 1,""fieldname"": ""confirmmessage"",""isrequired"": false,""dbname"": ""confirmmessage""}");
            f   = EntityMetaData.BuildField(entityName, entityName, dbo, null);
            fs.Add("CONFIRMMESSAGE", f);

            var entDbo1 = new DbObject();

            entDbo1.Add("tablename", "t_entityactions");
            entDbo1.Add("namefield", "text");
            var d = new EntityActionEntity(entId, entityName, fs, EntityType.MetadataEntity, entDbo1);

            EntityCode.AllEntities.Add(entityName.ToUpper(), entId);
            entities.Add(entId, d);
        }
コード例 #18
0
        private void GetTableName(Type entityType, EntityMetaData metaData)
        {
            var typeInfo = entityType.GetTypeInfo();

            var tableAttribute = typeInfo.GetCustomAttribute(typeof(TableAttribute)) as TableAttribute;

            if (tableAttribute == null)
            {
                metaData.SchemaName = "";
                metaData.TableName  = entityType.Name;
                return;
            }

            metaData.SchemaName = tableAttribute.Schema;
            metaData.TableName  = tableAttribute.Name;
        }
コード例 #19
0
        private static void AddEntityList(ref IDictionary <int, DBEntity> entities)
        {
            string entityName = "entitylist";
            int    entId      = 5;
            var    fs         = new Dictionary <string, BaseField>();

            var dbo = DbObject.FromJSON(@"{""fieldtype"": 1,""fieldname"": ""name"",""isrequired"": true,""dbname"": ""name""}");
            var f   = EntityMetaData.BuildField(entityName, entityName, dbo, null);

            fs.Add("NAME", f);

            dbo = DbObject.FromJSON(@"{""fieldtype"": 1,""fieldname"": ""idfield"",""isrequired"": true,""dbname"": ""idfield""}");
            f   = EntityMetaData.BuildField(entityName, entityName, dbo, null);
            fs.Add("IDFIELD", f);

            dbo = DbObject.FromJSON(@"{""fieldtype"": 2,""fieldname"": ""entityid"",""isrequired"": true,""dbname"": ""idfield"",""viewtype"":-1}");
            f   = EntityMetaData.BuildField(entityName, entityName, dbo, null);
            fs.Add("ENTITYID", f);

            dbo = DbObject.FromJSON(@"{""fieldtype"": 1,""fieldname"": ""viewfield"",""isrequired"": false,""dbname"": ""viewfield""}");
            f   = EntityMetaData.BuildField(entityName, entityName, dbo, null);
            fs.Add("VIEWFIELD", f);

            dbo = DbObject.FromJSON(@"{""fieldtype"": 1,""fieldname"": ""orderby"",""isrequired"": false,""dbname"": ""orderby""}");
            f   = EntityMetaData.BuildField(entityName, entityName, dbo, null);
            fs.Add("ORDERBY", f);

            dbo = DbObject.FromJSON(@"{""fieldtype"": 18,""fieldname"": ""layoutxml"",""isrequired"": true,""dbname"": ""layoutxml""}");
            f   = EntityMetaData.BuildField(entityName, entityName, dbo, null);
            fs.Add("LAYOUTXML", f);

            dbo = DbObject.FromJSON(@"{""fieldtype"": 1,""fieldname"": ""fixedfilter"",""isrequired"": false,""dbname"": ""fixedfilter""}");
            f   = EntityMetaData.BuildField(entityName, entityName, dbo, null);
            fs.Add("FIXEDFILTER", f);

            dbo = DbObject.FromJSON(@"{""fieldtype"": 13,""fieldname"": ""filterpolicy"",""isrequired"": false,""dbname"": ""filterpolicy""}");
            f   = EntityMetaData.BuildField(entityName, entityName, dbo, null);
            fs.Add("FILTERPOLICY", f);

            var entDbo = new DbObject();

            entDbo.Add("tablename", "t_entitylist");
            var d = new EntityListEntity(entId, entityName, fs, EntityType.MetadataEntity, entDbo);

            EntityCode.AllEntities.Add(entityName.ToUpper(), entId);
            entities.Add(entId, d);
        }
コード例 #20
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseSession();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();

                // endpoints.MapControllerRoute(
                //     name: "web",
                //     pattern: "web/{c?}/{a?}",
                //     defaults: new { controller = "App", action = "Index" });

                endpoints.MapControllerRoute(
                    name: "studio",
                    pattern: "entitystudio/{a}/{id?}",
                    defaults: new { controller = "EntityStudio", action = "Index" });

                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Entity}/{action=Index}/{id?}");
            });

            //app.InitStackApp(this.Configuration);
            StackErp.Core.App.ConfigureDB(this.Configuration.GetValue <string>("DBInfo:ConnectionString"));

            EntityMetaData.Build();
            ViewModel.RegisterStackScriptRef.Register();
        }
コード例 #21
0
                    public static EntityMetaData FromBaseObject(BaseObject baseObj)
                    {
                        if (baseObj == null || baseObj.NativeObject == IntPtr.Zero)
                        {
                            return(null);
                        }
                        EntityMetaData obj = baseObj as  EntityMetaData;

                        if (object.Equals(obj, null))
                        {
                            obj = new EntityMetaData(CreatedWhenConstruct.CWC_NotToCreate);
                            obj.BindNativeObject(baseObj.NativeObject, "CEntityMetaData");
                            obj.IncreaseCast();
                        }

                        return(obj);
                    }
コード例 #22
0
        public IEntityMetaData GetMetaData(Type entityType, bool tryOnly)
        {
            EntityMetaData metadata = null;

            if (typeof(Material).Equals(entityType))
            {
                metadata            = new EntityMetaData();
                metadata.EntityType = entityType;
            }
            else if (typeof(Material).Equals(entityType))
            {
                metadata            = new EntityMetaData();
                metadata.EntityType = entityType;
            }
            else if (!tryOnly)
            {
                throw new Exception("No metadata found for type '" + entityType.Name);
            }
            return(metadata);
        }
コード例 #23
0
        public List <EntityMetaData> GetEntitiesMetDataList()
        {
            List <EntityMetaData> list = new List <EntityMetaData>();

            EntityMetadata[] entities = GetEntitiesMetData();

            foreach (var metaEntity in entities)
            {
                EntityMetaData entity = new EntityMetaData();
                entity.LogicalName    = metaEntity.LogicalName;
                entity.DisplayName    = metaEntity?.DisplayName?.UserLocalizedLabel?.Label;
                entity.SchemaName     = metaEntity.SchemaName;
                entity.FieldsCount    = metaEntity.Attributes != null ? metaEntity.Attributes.Length : 0;
                entity.ObjectTypeCode = metaEntity.ObjectTypeCode;
                entity.GroupName      = entity.DisplayName != null && Utility.EntityGroups.ContainsKey(entity.DisplayName) && metaEntity.LogicalName.IndexOf("_") < 0  ?
                                        Utility.EntityGroups[entity.DisplayName]: "Custom Entities";
                list.Add(entity);
            }
            return(list);
        }
コード例 #24
0
        public Command Build(EntityMetaData metaData)
        {
            var sb = new StringBuilder();

            sb.AppendLine($"UPDATE {_tableNameBuilder.Build(metaData)} SET");

            var updatedFields = metaData.Fields.
                                Where(field => !field.IsPrimaryKey && !field.IsRowVersion);

            sb.AppendLine(string.Join(", ", updatedFields.Select(field =>
                                                                 field.DbColumnName + "=@" + field.DbColumnName)));

            if (Options.UseRowVersionForUpdate)
            {
                var outputFields = metaData.Fields.Where(field => field.IsRowVersion).Select(field => field.DbColumnName).Distinct().ToArray();
                if (outputFields.Length > 0)
                {
                    sb.Append("OUTPUT ");
                    sb.Append(string.Join(",", outputFields.Select(field => "inserted." + field)));
                    sb.AppendLine();
                }
            }

            sb.AppendLineIfNotNullOrWhiteSpace(_whereClauseBuilder.Build(metaData, Options.UseRowVersionForUpdate));

            var result = new Command
            {
                CommandText = sb.ToString()
            };

            var parameterFields = updatedFields.Concat(_whereClauseBuilder.GetFields(metaData, Options.UseRowVersionForUpdate));

            foreach (var pkField in parameterFields)
            {
                result.Parameters.Add(new CommandParameter {
                    Name = "@" + pkField.DbColumnName
                });
            }

            return(result);
        }
コード例 #25
0
        public Command Build(EntityMetaData metaData)
        {
            var insertFields = metaData.Fields
                               .Where(field => !field.IsDatabaseGeneratedKey && !field.IsRowVersion)
                               .Select(field => field.DbColumnName)
                               .ToArray();

            var sb = new StringBuilder();

            sb.Append($"INSERT INTO {_tableNameBuilder.Build(metaData)}(");
            sb.Append(string.Join(",", insertFields));
            sb.Append(")");

            var outputFields = metaData.PrimaryKey.Where(field => field.IsDatabaseGeneratedKey).Concat(
                metaData.Fields.Where(field => field.IsRowVersion)).Select(field => field.DbColumnName).Distinct().ToArray();

            if (outputFields.Length > 0)
            {
                sb.Append(" OUTPUT ");
                sb.Append(string.Join(",", outputFields.Select(field => "inserted." + field)));
            }

            sb.Append(" VALUES (");
            sb.Append(string.Join(",", insertFields.Select(field => "@" + field)));
            sb.Append(")");

            var result = new Command
            {
                CommandText = sb.ToString()
            };

            foreach (var field in insertFields)
            {
                result.Parameters.Add(new CommandParameter {
                    Name = "@" + field
                });
            }

            return(result);
        }
コード例 #26
0
        public IEntityMetaData CreateEntityMetaData(Type entityType)
        {
            lock (syncRoot)
            {
                Type derivedType = this.GetType();
                Dictionary<Type, IEntityMetaData> tempCache;
                if (!_cache.TryGetValue(derivedType, out tempCache))
                {
                    tempCache = new Dictionary<Type, IEntityMetaData>();
                   _cache.Add(derivedType, tempCache);
                }

                IEntityMetaData metaData;
                if (!tempCache.TryGetValue(entityType, out metaData))
                {
                    int order = 0;
                    EntityMetaData temp = new EntityMetaData(entityType);
                    foreach (PropertyInfo pi in entityType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
                    {
                        ++order;
                        SchemaInfo schema = this.FromPropertyInfo(pi);
                        if (null == schema) //NotMapped.
                            continue;

                        schema.Order = order; //Order parametere isimlarine ardışıklık için çok önemli. Oyüzden base de atamasını yaptık.
                        schema.Lock();
                        temp.Add(schema, pi);
                    }

                    this.SetExtendedMetaData(temp);

                    tempCache.Add(entityType, temp);
                    metaData = temp;
                }

                return metaData;
            }
        }
コード例 #27
0
        public ClaimsIdentity Authenticate(AppKeySetting appKey, string username, string password, out int userId)
        {
            var    userEntity = EntityMetaData.GetAs <UserDbEntity>(EntityCode.User);
            string email;

            userId = userEntity.AuthenticateUser(username, password, out email);

            if (userId <= 0)
            {
                return(null);
            }

            var claims = new List <System.Security.Claims.Claim>
            {
                new System.Security.Claims.Claim(ClaimTypes.Name, username),
                new System.Security.Claims.Claim(ClaimTypes.Sid, userId.ToString())
            };

            var claimsIdentity = new ClaimsIdentity(
                claims, CookieAuthenticationDefaults.AuthenticationScheme);

            return(claimsIdentity);
        }
コード例 #28
0
        private static DBEntity BuildEntitySchemaFields(List <DbObject> dbentities)
        {
            var entityName = "entityschema";

            var fs = new Dictionary <string, BaseField>();

            var list = GetEntitySchemaData();

            foreach (var dbo in list)
            {
                var f = EntityMetaData.BuildField(entityName, entityName, dbo, dbentities);
                fs.Add(f.Name.ToUpper(), f);
            }

            var entDbo = new DbObject();

            entDbo.Add("tablename", "t_entityschema");
            entDbo.Add("namefield", "fieldname");

            var d = new EntitySchemaEntity(2, entityName, fs, EntityType.MetadataEntity, entDbo);

            return(d);
        }
コード例 #29
0
        public Command Build(EntityMetaData metaData)
        {
            var sb = new StringBuilder();

            sb.AppendLine($"DELETE FROM {_tableNameBuilder.Build(metaData)}");
            sb.AppendLineIfNotNullOrWhiteSpace(_whereClauseBuilder.Build(metaData, Options.UseRowVersionForDelete));

            var result = new Command
            {
                CommandText = sb.ToString()
            };

            var parameterFields = _whereClauseBuilder.GetFields(metaData, Options.UseRowVersionForDelete);

            foreach (var pkField in parameterFields)
            {
                result.Parameters.Add(new CommandParameter {
                    Name = "@" + pkField.DbColumnName
                });
            }

            return(result);
        }
コード例 #30
0
        public static ActionResponse SaveLayout(StackAppContext appContext, RequestQueryString requestQuery, JObject data)
        {
            var view = data["Layout"].ToObject <TView>();

            if (view != null)
            {
                var tFields = data["Fields"].ToObject <List <TField> >();
                view.Fields = tFields;

                view.ClearBlankRows();

                var entity = EntityMetaData.GetAs <EntityLayoutEntity>(EntityCode.EntityLayout);
                var sts    = entity.SaveLayoutData(appContext, requestQuery, view);

                if (sts == AnyStatus.Success)
                {
                    var res = new SubmitActionResponse(null)
                    {
                        Status  = SubmitStatus.Success,
                        Message = "Layout saved successfully"
                    };

                    return(res);
                }
                else
                {
                    return(new ErrorResponse(null)
                    {
                        Message = sts.Message
                    });
                }
            }
            return(new ErrorResponse(null)
            {
                Message = "Invalid parameters."
            });
        }
コード例 #31
0
        private void RegisterType(Type type)
        {
            var link = type.GetCustomAttribute <LinkEntityToClassAttribute>();

            if (_entityTypes.ContainsKey(link.Name))
            {
                throw new InvalidOperationException($"Entity class \"{link.Name}\" already exists");
            }

            if (!type.IsClass || typeof(Delegate).IsAssignableFrom(type))
            {
                throw new NotSupportedException($"Entity class \"{link.Name}\"'s underlying type {type.FullName} is not a class");
            }

            //Detect missing constructor early
            if (type.GetConstructor(Type.EmptyTypes) == null)
            {
                throw new NotSupportedException($"Entity class \"{link.Name}\"'s underlying type {type.FullName} does not have a parameterless constructor, required to create instances");
            }

            var metaData = new EntityMetaData(type, link.Name);

            _entityTypes.Add(link.Name, metaData);
        }
コード例 #32
0
 protected virtual void SetExtendedMetaData(EntityMetaData metaData) { }
コード例 #33
0
            private static IEntityMetaData FromEdmx(IObjectContextAdapter contextAdapter, Type entityType)
            {
                List<SchemaInfo> schemas = new List<SchemaInfo>();

                MetadataWorkspace mw = contextAdapter.ObjectContext.MetadataWorkspace;

                EntityType et = mw.GetItems<EntityType>(DataSpace.CSpace).FirstOrDefault(e => String.Equals(e.Name, entityType.Name));
                if (null != et)
                {
                    foreach (EdmProperty edmProperty in et.Properties)
                    {
                        SchemaInfo schema = new SchemaInfo(edmProperty.Name);
                        schema.DataType = Type.GetType("System." + edmProperty.TypeUsage.EdmType.Name);

                        ReadOnlyMetadataCollection<Facet> facets = edmProperty.TypeUsage.Facets;
                        Facet facet;
                        if (facets.TryGetValue("Nullable", true, out facet))
                        {
                            schema.IsNullable = (bool)facet.Value;
                        }
                        if (facets.TryGetValue("MaxLength", true, out facet))
                        {
                            schema.MaxLength = (int)facet.Value;
                        }

                        schemas.Add(schema);
                    }

                    foreach (EdmMember keyInfo in et.KeyMembers)
                    {
                        schemas.First(s => s.ColumnName == keyInfo.Name).IsKey = true;
                    }

                    if (et.KeyMembers.Count == 1)
                    {
                        SchemaInfo key = schemas.First(s => s.IsKey);
                        if (key.DataType != CachedTypes.Guid)
                            key.DatabaseGeneratedOption = Data.StoreGeneratedPattern.Identity;
                    }

                    if (schemas.Count != 0)
                    {
                        EntityMetaData ret = new EntityMetaData(entityType, entityType.Name);
                        foreach (SchemaInfo schema in schemas)
                        {
                            ret.Add(schema, entityType.GetProperty(schema.ColumnName));
                        }
                        return ret;
                    }
                }

                return null;
            }