Example #1
0
        public static void Start(SchemaBuilder sb)
        {
            DynamicLogic.Start(sb);
            DynamicSqlMigrationLogic.Start(sb);
            DynamicValidationLogic.Start(sb);
            DynamicViewLogic.Start(sb);
            DynamicTypeLogic.Start(sb);
            DynamicTypeConditionLogic.Start(sb);
            DynamicExpressionLogic.Start(sb);
            DynamicMixinConnectionLogic.Start(sb);

            DynamicCode.Namespaces.AddRange(new HashSet <string>
            {
                "Southwind.Entities",
                "Southwind.Logic",
            });

            DynamicCode.AssemblyTypes.AddRange(new HashSet <Type>
            {
                typeof(Database),
            });

            DynamicCode.AddFullAssembly(typeof(Entity));
            DynamicCode.AddFullAssembly(typeof(Database));
            DynamicCode.AddFullAssembly(typeof(AuthLogic));
            DynamicCode.AddFullAssembly(typeof(UserEntity));
            DynamicCode.AddFullAssembly(typeof(ApplicationConfigurationEntity));
            DynamicCode.AddFullAssembly(typeof(Starter));
        }
Example #2
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            DynamicLogic.Start(sb, dqm);
            DynamicSqlMigrationLogic.Start(sb, dqm);
            DynamicValidationLogic.Start(sb, dqm);
            DynamicViewLogic.Start(sb, dqm);
            DynamicTypeLogic.Start(sb, dqm);
            DynamicTypeConditionLogic.Start(sb, dqm);
            DynamicExpressionLogic.Start(sb, dqm);
            DynamicMixinConnectionLogic.Start(sb, dqm);

            DynamicCode.Namespaces.AddRange(new HashSet <string>
            {
                "Southwind.Entities",
                "Southwind.Logic",
            });

            DynamicCode.Assemblies.AddRange(new HashSet <string>
            {
                "Southwind.Entities.dll",
                "Southwind.Logic.dll",
            });
        }
Example #3
0
        public static void Register()
        {
            new Construct(DynamicTypeOperation.Create)
            {
                Construct = (_) => new DynamicTypeEntity {
                    BaseType = DynamicBaseType.Entity
                },
            }.Register();

            new ConstructFrom <DynamicTypeEntity>(DynamicTypeOperation.Clone)
            {
                Construct = (e, _) =>
                {
                    var def    = e.GetDefinition();
                    var result = new DynamicTypeEntity {
                        TypeName = null !, BaseType = e.BaseType
                    };
                    result.SetDefinition(def);
                    return(result);
                },
            }.Register();

            new Execute(DynamicTypeOperation.Save)
            {
                CanBeNew      = true,
                CanBeModified = true,
                Execute       = (e, _) =>
                {
                    var newDef = e.GetDefinition();
                    var duplicatePropertyNames = newDef.Properties
                                                 .GroupToDictionary(a => a.Name.ToLower())
                                                 .Where(a => a.Value.Count() > 1)
                                                 .ToList();

                    if (duplicatePropertyNames.Any())
                    {
                        throw new InvalidOperationException(ValidationMessage._0HasSomeRepeatedElements1.NiceToString(e.TypeName, duplicatePropertyNames.Select(a => a.Key.FirstUpper()).Comma(", ")));
                    }

                    if (!e.IsNew)
                    {
                        var old = e.ToLite().RetrieveAndRemember();
                        if (e.TypeName != old.TypeName)
                        {
                            DynamicSqlMigrationLogic.AddDynamicRename(TypeNameKey, old.TypeName, e.TypeName);
                        }

                        if (e.BaseType == DynamicBaseType.ModelEntity)
                        {
                            return;
                        }

                        var oldDef  = old.GetDefinition();
                        var newName = GetTableName(e, newDef);
                        var oldName = GetTableName(old, oldDef);

                        if (newName != oldName)
                        {
                            DynamicSqlMigrationLogic.AddDynamicRename(Replacements.KeyTables, oldName, newName);
                        }

                        var pairs = newDef.Properties
                                    .Join(oldDef.Properties, n => n.UID, o => o.UID, (n, o) => new { n, o })
                                    .Where(a => a.n !.Type == a.o !.Type); /*CSBUG*/

                        {
                            string ColName(DynamicProperty dp) => dp.ColumnName ?? dp.Name;

                            string replacementKey = (e.BaseType != DynamicBaseType.Entity || old.BaseType != DynamicBaseType.Entity) ? UnknownColumnKey : Replacements.KeyColumnsForTable(oldName);
                            foreach (var a in pairs.Where(a => ColName(a.n !) != ColName(a.o !)))
                            {
                                DynamicSqlMigrationLogic.AddDynamicRename(replacementKey, ColName(a.o !), ColName(a.n !));
                            }
                        }

                        {
                            string replacementKey = (e.BaseType != DynamicBaseType.Entity || old.BaseType != DynamicBaseType.Entity) ? UnknownPropertyKey : PropertyRouteLogic.PropertiesFor.FormatWith(old.TypeName);
                            foreach (var a in pairs.Where(a => a.n !.Name != a.o !.Name))
                            {
                                DynamicSqlMigrationLogic.AddDynamicRename(replacementKey, a.o !.Name, a.n !.Name);
                            }
                        }
                    }
                },
            }.Register();
Example #4
0
    public static void Start(SchemaBuilder sb)
    {
        if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
        {
            sb.Include <DynamicTypeConditionSymbolEntity>()
            .WithQuery(() => e => new
            {
                Entity = e,
                e.Id,
                e.Name,
            });

            sb.Include <DynamicTypeConditionEntity>()
            .WithSave(DynamicTypeConditionOperation.Save)
            .WithQuery(() => e => new
            {
                Entity = e,
                e.Id,
                e.SymbolName,
                e.EntityType,
                e.Eval.Script,
            });

            new Graph <DynamicTypeConditionEntity> .ConstructFrom <DynamicTypeConditionEntity>(DynamicTypeConditionOperation.Clone)
            {
                Construct = (e, args) => new DynamicTypeConditionEntity()
                {
                    SymbolName = e.SymbolName,
                    EntityType = e.EntityType,
                    Eval       = new DynamicTypeConditionEval()
                    {
                        Script = e.Eval.Script
                    },
                }
            }

            .Register();

            new Graph <DynamicTypeConditionSymbolEntity> .Execute(DynamicTypeConditionSymbolOperation.Save)
            {
                CanBeModified = true,
                CanBeNew      = true,
                Execute       = (e, _) =>
                {
                    if (!e.IsNew)
                    {
                        var old = e.ToLite().RetrieveAndRemember();
                        if (old.Name != e.Name)
                        {
                            DynamicSqlMigrationLogic.AddDynamicRename(typeof(TypeConditionSymbol).Name,
                                                                      $"CodeGenTypeCondition.{old.Name}",
                                                                      $"CodeGenTypeCondition.{e.Name}");
                        }
                    }
                }
            }

            .Register();

            DynamicLogic.GetCodeFiles          += GetCodeFiles;
            DynamicLogic.OnWriteDynamicStarter += WriteDynamicStarter;
            DynamicCode.RegisteredDynamicTypes.Add(typeof(DynamicTypeConditionEntity));
            sb.Schema.Table <TypeEntity>().PreDeleteSqlSync += type => Administrator.UnsafeDeletePreCommand(Database.Query <DynamicTypeConditionEntity>().Where(dtc => dtc.EntityType.Is(type)));
            sb.AddUniqueIndex((DynamicTypeConditionEntity e) => new { e.SymbolName, e.EntityType });
        }
    }