Beispiel #1
0
        public static void RegisterRoleTypeCondition(SchemaBuilder sb, TypeConditionSymbol typeCondition)
        {
            sb.Schema.Settings.AssertImplementedBy((UserChartEntity uq) => uq.Owner, typeof(RoleEntity));

            TypeConditionLogic.RegisterCompile <UserChartEntity>(typeCondition,
                                                                 uq => AuthLogic.CurrentRoles().Contains(uq.Owner) || uq.Owner == null);
        }
Beispiel #2
0
        string TypeAuthCache_StaticPropertyValidation(ModifiableEntity sender, PropertyInfo pi)
        {
            RuleTypeEntity rt = (RuleTypeEntity)sender;

            if (rt.Resource == null)
            {
                if (rt.Conditions.Any())
                {
                    return("Default {0} should not have conditions".FormatWith(typeof(RuleTypeEntity).NiceName()));
                }

                return(null);
            }

            Type type       = TypeLogic.EntityToType[rt.Resource];
            var  conditions = rt.Conditions.Where(a =>
                                                  a.Condition.FieldInfo != null && /*Not 100% Sync*/
                                                  !TypeConditionLogic.IsDefined(type, a.Condition));

            if (conditions.IsEmpty())
            {
                return(null);
            }

            return("Type {0} has no definitions for the conditions: {1}".FormatWith(type.Name, conditions.CommaAnd(a => a.Condition.Key)));
        }
Beispiel #3
0
        public static void RegisterUserTypeCondition(SchemaBuilder sb, TypeConditionSymbol typeCondition)
        {
            sb.Schema.Settings.AssertImplementedBy((NoteEntity uq) => uq.CreatedBy, typeof(UserEntity));

            TypeConditionLogic.RegisterCompile <NoteEntity>(typeCondition,
                                                            uq => uq.CreatedBy.Is(UserEntity.Current));
        }
Beispiel #4
0
        public static void RegisterRecipientTypeCondition(SchemaBuilder sb, TypeConditionSymbol typeCondition)
        {
            sb.Schema.Settings.AssertImplementedBy((AlertEntity a) => a.Recipient, typeof(UserEntity));

            TypeConditionLogic.RegisterCompile <AlertEntity>(typeCondition,
                                                             a => a.Recipient.Is(UserEntity.Current));
        }
Beispiel #5
0
        public static Expression IsAllowedExpression(Expression entity, TypeAllowedBasic requested, bool inUserInterface)
        {
            Type type = entity.Type;

            TypeAllowedAndConditions tac = GetAllowed(type);

            Expression baseValue = Expression.Constant(tac.FallbackOrNone.Get(inUserInterface) >= requested);

            var expression = tac.Conditions.Aggregate(baseValue, (acum, tacRule) =>
            {
                var lambda = TypeConditionLogic.GetCondition(type, tacRule.TypeCondition);

                var exp = (Expression)Expression.Invoke(lambda, entity);

                if (tacRule.Allowed.Get(inUserInterface) >= requested)
                {
                    return(Expression.Or(exp, acum));
                }
                else
                {
                    return(Expression.And(Expression.Not(exp), acum));
                }
            });

            var cleaned = DbQueryProvider.Clean(expression, false, null) !;

            var orsSimplified = AndOrSimplifierVisitor.SimplifyOrs(cleaned);

            return(orsSimplified);
        }
Beispiel #6
0
        public static void RegisterUserTypeCondition(SchemaBuilder sb, TypeConditionSymbol typeCondition)
        {
            sb.Schema.Settings.AssertImplementedBy((UserQueryEntity uq) => uq.Owner, typeof(UserEntity));

            TypeConditionLogic.RegisterCompile <UserQueryEntity>(typeCondition,
                                                                 uq => uq.Owner.RefersTo(UserEntity.Current));
        }
        public static void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                TypeLogic.AssertStarted(sb);
                AuthLogic.AssertStarted(sb);
                TypeConditionLogic.Start(sb);

                sb.Schema.EntityEventsGlobal.Saving    += Schema_Saving; //because we need Modifications propagated
                sb.Schema.EntityEventsGlobal.Retrieved += EntityEventsGlobal_Retrieved;
                sb.Schema.IsAllowedCallback            += Schema_IsAllowedCallback;

                sb.Schema.SchemaCompleted += () =>
                {
                    foreach (var type in TypeConditionLogic.Types)
                    {
                        miRegister.GetInvoker(type)(Schema.Current);
                    }
                };

                sb.Schema.Synchronizing += Schema_Synchronizing;

                sb.Schema.EntityEventsGlobal.PreUnsafeDelete += query =>
                {
                    return(TypeAuthLogic.OnIsDelete(query.ElementType));
                };

                cache = new TypeAuthCache(sb, merger: TypeAllowedMerger.Instance);

                AuthLogic.ExportToXml   += exportAll => cache.ExportXml(exportAll ? TypeLogic.TypeToEntity.Keys.ToList() : null);
                AuthLogic.ImportFromXml += (x, roles, replacements) => cache.ImportXml(x, roles, replacements);
            }
        }
        public static void RegisterUserTypeCondition(SchemaBuilder sb, TypeConditionSymbol typeCondition)
        {
            sb.Schema.Settings.AssertImplementedBy((DashboardEntity uq) => uq.Owner, typeof(UserEntity));

            TypeConditionLogic.RegisterCompile <DashboardEntity>(typeCondition,
                                                                 uq => uq.Owner.Is(UserEntity.Current));

            RegisterPartsTypeCondition(typeCondition);
        }
Beispiel #9
0
        public static void RegisterUserTypeCondition(SchemaBuilder sb, TypeConditionSymbol typeCondition)
        {
            TypeConditionLogic.RegisterCompile <ProcessEntity>(typeCondition,
                                                               pe => pe.User.RefersTo(UserEntity.Current));

            TypeConditionLogic.Register <PackageOperationEntity>(typeCondition,
                                                                 po => Database.Query <ProcessEntity>().WhereCondition(typeCondition).Any(pe => pe.Data == po));

            TypeConditionLogic.Register <PackageLineEntity>(typeCondition,
                                                            pl => ((PackageOperationEntity)pl.Package.Entity).InCondition(typeCondition));
        }
Beispiel #10
0
        public static void RegisterUserTypeCondition(SchemaBuilder sb, TypeConditionSymbol typeCondition)
        {
            sb.Schema.Settings.AssertImplementedBy((ToolbarEntity t) => t.Owner, typeof(UserEntity));

            TypeConditionLogic.RegisterCompile <ToolbarEntity>(typeCondition,
                                                               t => t.Owner.RefersTo(UserEntity.Current));

            sb.Schema.Settings.AssertImplementedBy((ToolbarMenuEntity t) => t.Owner, typeof(UserEntity));

            TypeConditionLogic.RegisterCompile <ToolbarMenuEntity>(typeCondition,
                                                                   t => t.Owner.RefersTo(UserEntity.Current));
        }
Beispiel #11
0
        public static void RegisterRoleTypeCondition(SchemaBuilder sb, TypeConditionSymbol typeCondition)
        {
            sb.Schema.Settings.AssertImplementedBy((ToolbarEntity t) => t.Owner, typeof(RoleEntity));

            TypeConditionLogic.RegisterCompile <ToolbarEntity>(typeCondition,
                                                               t => AuthLogic.CurrentRoles().Contains(t.Owner));

            sb.Schema.Settings.AssertImplementedBy((ToolbarMenuEntity t) => t.Owner, typeof(RoleEntity));

            TypeConditionLogic.RegisterCompile <ToolbarMenuEntity>(typeCondition,
                                                                   t => AuthLogic.CurrentRoles().Contains(t.Owner));
        }
Beispiel #12
0
        public static void RegisterPartsTypeCondition(TypeConditionSymbol typeCondition)
        {
            TypeConditionLogic.Register <ValueUserQueryListPartEntity>(typeCondition,
                                                                       cscp => Database.Query <DashboardEntity>().WhereCondition(typeCondition).Any(cp => cp.ContainsContent(cscp)));

            TypeConditionLogic.Register <LinkListPartEntity>(typeCondition,
                                                             llp => Database.Query <DashboardEntity>().WhereCondition(typeCondition).Any(cp => cp.ContainsContent(llp)));

            TypeConditionLogic.Register <UserChartPartEntity>(typeCondition,
                                                              ucp => Database.Query <DashboardEntity>().WhereCondition(typeCondition).Any(cp => cp.ContainsContent(ucp)));

            TypeConditionLogic.Register <UserQueryPartEntity>(typeCondition,
                                                              uqp => Database.Query <DashboardEntity>().WhereCondition(typeCondition).Any(cp => cp.ContainsContent(uqp)));
        }
Beispiel #13
0
        internal void GetRules(BaseRulePack <TypeAllowedRule> rules, IEnumerable <TypeEntity> resources)
        {
            RoleAllowedCache cache = runtimeRules.Value.GetOrThrow(rules.Role);

            rules.MergeStrategy = AuthLogic.GetMergeStrategy(rules.Role);
            rules.SubRoles      = AuthLogic.RelatedTo(rules.Role).ToMList();
            rules.Rules         = (from r in resources
                                   let type = TypeLogic.EntityToType.GetOrThrow(r)
                                              select new TypeAllowedRule()
            {
                Resource = r,
                AllowedBase = cache.GetAllowedBase(type),
                Allowed = cache.GetAllowed(type),
                AvailableConditions = TypeConditionLogic.ConditionsFor(type).ToReadOnly()
            }).ToMList();
        }
Beispiel #14
0
        private static Func <T, bool>?IsAllowedInMemory <T>(TypeAllowedAndConditions tac, TypeAllowedBasic allowed, bool inUserInterface) where T : Entity
        {
            if (tac.Conditions.Any(c => TypeConditionLogic.GetInMemoryCondition <T>(c.TypeCondition) == null))
            {
                return(null);
            }

            return(entity =>
            {
                foreach (var cond in tac.Conditions.Reverse())
                {
                    var func = TypeConditionLogic.GetInMemoryCondition <T>(cond.TypeCondition) !;

                    if (func(entity))
                    {
                        return cond.Allowed.Get(inUserInterface) >= allowed;
                    }
                }

                return tac.FallbackOrNone.Get(inUserInterface) >= allowed;
            });
        }
        internal static Expression IsAllowedExpressionDebug(Expression entity, TypeAllowedBasic requested, bool inUserInterface)
        {
            Type type = entity.Type;

            TypeAllowedAndConditions tac = GetAllowed(type);

            Expression baseValue = Expression.Constant(tac.FallbackOrNone.Get(inUserInterface) >= requested);

            var list = (from line in tac.Conditions
                        select Expression.New(ciGroupDebugData, Expression.Constant(line.TypeCondition, typeof(TypeConditionSymbol)),
                                              Expression.Invoke(TypeConditionLogic.GetCondition(type, line.TypeCondition), entity),
                                              Expression.Constant(line.Allowed))).ToArray();

            Expression newList = Expression.ListInit(Expression.New(typeof(List <ConditionDebugData>)), list);

            Expression liteEntity = Expression.Call(null, miToLite.MakeGenericMethod(entity.Type), entity);

            return(Expression.New(ciDebugData, liteEntity,
                                  Expression.Constant(requested),
                                  Expression.Constant(inUserInterface),
                                  Expression.Constant(tac.Fallback),
                                  newList));
        }
Beispiel #16
0
        string?TypeAuthCache_StaticPropertyValidation(ModifiableEntity sender, PropertyInfo pi)
        {
            RuleTypeEntity rt = (RuleTypeEntity)sender;

            if (rt.Resource == null)
            {
                if (rt.Conditions.Any())
                {
                    return("Default {0} should not have conditions".FormatWith(typeof(RuleTypeEntity).NiceName()));
                }

                return(null);
            }

            try
            {
                Type type       = TypeLogic.EntityToType.GetOrThrow(rt.Resource);
                var  conditions = rt.Conditions.Where(a =>
                                                      a.Condition.FieldInfo != null && /*Not 100% Sync*/
                                                      !TypeConditionLogic.IsDefined(type, a.Condition));

                if (conditions.IsEmpty())
                {
                    return(null);
                }

                return("Type {0} has no definitions for the conditions: {1}".FormatWith(type.Name, conditions.CommaAnd(a => a.Condition.Key)));
            }
            catch (Exception ex) when(StartParameters.IgnoredDatabaseMismatches != null)
            {
                //This try { throw } catch is here to alert developers.
                //In production, in some cases its OK to attempt starting an application with a slightly different schema (dynamic entities, green-blue deployments).
                //In development, consider synchronize.
                StartParameters.IgnoredDatabaseMismatches.Add(ex);
                return(null);
            }
        }
        static SqlPreCommand Schema_Synchronizing(Replacements rep)
        {
            var conds = (from rt in Database.Query <RuleTypeEntity>()
                         from c in rt.Conditions
                         select new { rt.Resource, c.Condition, rt.Role }).ToList();

            var errors = conds.GroupBy(a => new { a.Resource, a.Condition }, a => a.Role)
                         .Where(gr =>
            {
                if (gr.Key.Condition.FieldInfo == null)
                {
                    return(rep.TryGetC(typeof(TypeConditionSymbol).Name)?.TryGetC(gr.Key.Condition.Key) == null);
                }

                return(!TypeConditionLogic.IsDefined(gr.Key.Resource.ToType(), gr.Key.Condition));
            })
                         .ToList();

            using (rep.WithReplacedDatabaseName())
                return(errors.Select(a => Administrator.UnsafeDeletePreCommand((RuleTypeEntity rt) => rt.Conditions, Database.MListQuery((RuleTypeEntity rt) => rt.Conditions)
                                                                               .Where(mle => mle.Element.Condition.Is(a.Key.Condition) && mle.Parent.Resource.Is(a.Key.Resource)))
                                     .AddComment("TypeCondition {0} not defined for {1} (roles {2})".FormatWith(a.Key.Condition, a.Key.Resource, a.ToString(", "))))
                       .Combine(Spacing.Double));
        }
Beispiel #18
0
        public static void Start(string connectionString, bool isPostgres, bool includeDynamic = true, bool detectSqlVersion = true)
        {
            using (HeavyProfiler.Log("Start"))
                using (var initial = HeavyProfiler.Log("Initial"))
                {
                    StartParameters.IgnoredDatabaseMismatches = new List <Exception>();
                    StartParameters.IgnoredCodeErrors         = new List <Exception>();

                    string?logDatabase = Connector.TryExtractDatabaseNameWithPostfix(ref connectionString, "_Log");

                    SchemaBuilder sb = new CustomSchemaBuilder {
                        LogDatabaseName = logDatabase, Tracer = initial
                    };
                    sb.Schema.Version          = typeof(Starter).Assembly.GetName().Version !;
                    sb.Schema.ForceCultureInfo = CultureInfo.GetCultureInfo("en-US");

                    MixinDeclarations.Register <OperationLogEntity, DiffLogMixin>();
                    MixinDeclarations.Register <UserEntity, UserEmployeeMixin>();
                    MixinDeclarations.Register <OrderDetailEmbedded, OrderDetailMixin>();
                    MixinDeclarations.Register <BigStringEmbedded, BigStringMixin>();

                    ConfigureBigString(sb);
                    OverrideAttributes(sb);

                    if (!isPostgres)
                    {
                        var sqlVersion = detectSqlVersion ? SqlServerVersionDetector.Detect(connectionString) : SqlServerVersion.AzureSQL;
                        Connector.Default = new SqlServerConnector(connectionString, sb.Schema, sqlVersion !.Value);
                    }
                    else
                    {
                        var postgreeVersion = detectSqlVersion ? PostgresVersionDetector.Detect(connectionString) : null;
                        Connector.Default = new PostgreSqlConnector(connectionString, sb.Schema, postgreeVersion);
                    }

                    CacheLogic.Start(sb, cacheInvalidator: sb.Settings.IsPostgres ? new PostgresCacheInvalidation() : null);

                    DynamicLogicStarter.Start(sb);
                    if (includeDynamic)//Dynamic
                    {
                        DynamicLogic.CompileDynamicCode();

                        DynamicLogic.RegisterMixins();
                        DynamicLogic.BeforeSchema(sb);
                    }//Dynamic

                    // Framework modules

                    TypeLogic.Start(sb);

                    OperationLogic.Start(sb);
                    ExceptionLogic.Start(sb);
                    QueryLogic.Start(sb);

                    // Extensions modules

                    MigrationLogic.Start(sb);

                    CultureInfoLogic.Start(sb);
                    FilePathEmbeddedLogic.Start(sb);
                    BigStringLogic.Start(sb);
                    EmailLogic.Start(sb, () => Configuration.Value.Email, (template, target, message) => Configuration.Value.EmailSender);

                    AuthLogic.Start(sb, "System", "Anonymous"); /* null); anonymous*/

                    AuthLogic.StartAllModules(sb);
                    ResetPasswordRequestLogic.Start(sb);
                    UserTicketLogic.Start(sb);
                    SessionLogLogic.Start(sb);
                    WebAuthnLogic.Start(sb, () => Configuration.Value.WebAuthn);

                    ProcessLogic.Start(sb);
                    PackageLogic.Start(sb, packages: true, packageOperations: true);

                    SchedulerLogic.Start(sb);
                    OmniboxLogic.Start(sb);

                    UserQueryLogic.Start(sb);
                    UserQueryLogic.RegisterUserTypeCondition(sb, RG2Group.UserEntities);
                    UserQueryLogic.RegisterRoleTypeCondition(sb, RG2Group.RoleEntities);
                    UserQueryLogic.RegisterTranslatableRoutes();

                    ChartLogic.Start(sb, googleMapsChartScripts: false /*requires Google Maps API key in ChartClient */);
                    UserChartLogic.RegisterUserTypeCondition(sb, RG2Group.UserEntities);
                    UserChartLogic.RegisterRoleTypeCondition(sb, RG2Group.RoleEntities);
                    UserChartLogic.RegisterTranslatableRoutes();

                    DashboardLogic.Start(sb);
                    DashboardLogic.RegisterUserTypeCondition(sb, RG2Group.UserEntities);
                    DashboardLogic.RegisterRoleTypeCondition(sb, RG2Group.RoleEntities);
                    DashboardLogic.RegisterTranslatableRoutes();
                    ViewLogLogic.Start(sb, new HashSet <Type> {
                        typeof(UserQueryEntity), typeof(UserChartEntity), typeof(DashboardEntity)
                    });
                    DiffLogLogic.Start(sb, registerAll: true);
                    ExcelLogic.Start(sb, excelReport: true);
                    ToolbarLogic.Start(sb);
                    ToolbarLogic.RegisterTranslatableRoutes();
                    FileLogic.Start(sb);

                    TranslationLogic.Start(sb, countLocalizationHits: false);
                    TranslatedInstanceLogic.Start(sb, () => CultureInfo.GetCultureInfo("en"));

                    HelpLogic.Start(sb);
                    WordTemplateLogic.Start(sb);
                    MapLogic.Start(sb);
                    RestLogLogic.Start(sb);
                    RestApiKeyLogic.Start(sb);

                    WorkflowLogicStarter.Start(sb, () => Starter.Configuration.Value.Workflow);

                    ProfilerLogic.Start(sb,
                                        timeTracker: true,
                                        heavyProfiler: true,
                                        overrideSessionTimeout: true);

                    // RG2 modules

                    EmployeeLogic.Start(sb);
                    ProductLogic.Start(sb);
                    CustomerLogic.Start(sb);
                    OrderLogic.Start(sb);
                    ShipperLogic.Start(sb);
                    ItemLogic.Start(sb);
                    ItemCategoryLogic.Start(sb);

                    StartRG2Configuration(sb);

                    TypeConditionLogic.Register <OrderEntity>(RG2Group.UserEntities, o => o.Employee == EmployeeEntity.Current);
                    TypeConditionLogic.Register <EmployeeEntity>(RG2Group.UserEntities, e => EmployeeEntity.Current.Is(e));

                    TypeConditionLogic.Register <OrderEntity>(RG2Group.CurrentCustomer, o => o.Customer == CustomerEntity.Current);
                    TypeConditionLogic.Register <PersonEntity>(RG2Group.CurrentCustomer, o => o == CustomerEntity.Current);
                    TypeConditionLogic.Register <CompanyEntity>(RG2Group.CurrentCustomer, o => o == CustomerEntity.Current);

                    if (includeDynamic)//2
                    {
                        DynamicLogic.StartDynamicModules(sb);
                    }//2

                    SetupCache(sb);

                    Schema.Current.OnSchemaCompleted();

                    if (includeDynamic)//3
                    {
                        DynamicLogic.RegisterExceptionIfAny();
                    }//3
                }
        }
Beispiel #19
0
    public static void Start(string connectionString, bool isPostgres, string?azureStorageConnectionString, string?broadcastSecret, string?broadcastUrls, bool includeDynamic = true, bool detectSqlVersion = true)
    {
        AzureStorageConnectionString = azureStorageConnectionString;

        using (HeavyProfiler.Log("Start"))
            using (var initial = HeavyProfiler.Log("Initial"))
            {
                StartParameters.IgnoredDatabaseMismatches = new List <Exception>();
                StartParameters.IgnoredCodeErrors         = new List <Exception>();

                string?logDatabase = Connector.TryExtractDatabaseNameWithPostfix(ref connectionString, "_Log");

                SchemaBuilder sb = new CustomSchemaBuilder {
                    LogDatabaseName = logDatabase, Tracer = initial
                };
                sb.Schema.Version          = typeof(Starter).Assembly.GetName().Version !;
                sb.Schema.ForceCultureInfo = CultureInfo.GetCultureInfo("en-US");

                MixinDeclarations.Register <OperationLogEntity, DiffLogMixin>();
                MixinDeclarations.Register <UserEntity, UserEmployeeMixin>();
                MixinDeclarations.Register <OrderDetailEmbedded, OrderDetailMixin>();
                MixinDeclarations.Register <BigStringEmbedded, BigStringMixin>();

                ConfigureBigString(sb);
                OverrideAttributes(sb);

                if (!isPostgres)
                {
                    var sqlVersion = detectSqlVersion ? SqlServerVersionDetector.Detect(connectionString) : SqlServerVersion.AzureSQL;
                    Connector.Default = new SqlServerConnector(connectionString, sb.Schema, sqlVersion !.Value);
                }
                else
                {
                    var postgreeVersion = detectSqlVersion ? PostgresVersionDetector.Detect(connectionString) : null;
                    Connector.Default = new PostgreSqlConnector(connectionString, sb.Schema, postgreeVersion);
                }

                CacheLogic.Start(sb, serverBroadcast:
                                 sb.Settings.IsPostgres ? new PostgresBroadcast() :
                                 broadcastSecret != null && broadcastUrls != null ? new SimpleHttpBroadcast(broadcastSecret, broadcastUrls) :
                                 null);/*Cache*/

                /* LightDynamic
                *  DynamicLogic.Start(sb, withCodeGen: false);
                *  LightDynamic */
                DynamicLogicStarter.Start(sb);
                if (includeDynamic)//Dynamic
                {
                    DynamicLogic.CompileDynamicCode();

                    DynamicLogic.RegisterMixins();
                    DynamicLogic.BeforeSchema(sb);
                }//Dynamic

                // Framework modules

                TypeLogic.Start(sb);

                OperationLogic.Start(sb);
                ExceptionLogic.Start(sb);
                QueryLogic.Start(sb);

                // Extensions modules

                MigrationLogic.Start(sb);

                CultureInfoLogic.Start(sb);
                FilePathEmbeddedLogic.Start(sb);
                BigStringLogic.Start(sb);
                EmailLogic.Start(sb, () => Configuration.Value.Email, (template, target, message) => Configuration.Value.EmailSender);

                AuthLogic.Start(sb, "System", "Anonymous"); /* null); anonymous*/
                AuthLogic.Authorizer = new SouthwindAuthorizer(() => Configuration.Value.ActiveDirectory);
                AuthLogic.StartAllModules(sb, activeDirectoryIntegration: true);
                AzureADLogic.Start(sb, adGroups: true, deactivateUsersTask: true);
                ResetPasswordRequestLogic.Start(sb);
                UserTicketLogic.Start(sb);
                SessionLogLogic.Start(sb);
                TypeConditionLogic.RegisterCompile <UserEntity>(SouthwindTypeCondition.UserEntities, u => u.Is(UserEntity.Current));

                ProcessLogic.Start(sb);
                PackageLogic.Start(sb, packages: true, packageOperations: true);

                SchedulerLogic.Start(sb);
                OmniboxLogic.Start(sb);

                UserQueryLogic.Start(sb);
                UserQueryLogic.RegisterUserTypeCondition(sb, SouthwindTypeCondition.UserEntities);
                UserQueryLogic.RegisterRoleTypeCondition(sb, SouthwindTypeCondition.RoleEntities);
                UserQueryLogic.RegisterTranslatableRoutes();

                ChartLogic.Start(sb, googleMapsChartScripts: false /*requires Google Maps API key in ChartClient */);
                UserChartLogic.RegisterUserTypeCondition(sb, SouthwindTypeCondition.UserEntities);
                UserChartLogic.RegisterRoleTypeCondition(sb, SouthwindTypeCondition.RoleEntities);
                UserChartLogic.RegisterTranslatableRoutes();

                DashboardLogic.Start(sb, GetFileTypeAlgorithm(p => p.CachedQueryFolder));
                DashboardLogic.RegisterUserTypeCondition(sb, SouthwindTypeCondition.UserEntities);
                DashboardLogic.RegisterRoleTypeCondition(sb, SouthwindTypeCondition.RoleEntities);
                DashboardLogic.RegisterTranslatableRoutes();
                ViewLogLogic.Start(sb, new HashSet <Type> {
                    typeof(UserQueryEntity), typeof(UserChartEntity), typeof(DashboardEntity)
                });
                SystemEventLogLogic.Start(sb);
                DiffLogLogic.Start(sb, registerAll: true);
                ExcelLogic.Start(sb, excelReport: true);
                ToolbarLogic.Start(sb);
                ToolbarLogic.RegisterTranslatableRoutes();

                SMSLogic.Start(sb, null, () => Configuration.Value.Sms);

                NoteLogic.Start(sb, typeof(UserEntity), /*Note*/ typeof(OrderEntity));
                AlertLogic.Start(sb, typeof(UserEntity), /*Alert*/ typeof(OrderEntity));
                FileLogic.Start(sb);

                TranslationLogic.Start(sb, countLocalizationHits: false);
                TranslatedInstanceLogic.Start(sb, () => CultureInfo.GetCultureInfo("en"));

                HelpLogic.Start(sb);
                WordTemplateLogic.Start(sb);
                MapLogic.Start(sb);
                PredictorLogic.Start(sb, GetFileTypeAlgorithm(p => p.PredictorModelFolder));
                PredictorLogic.RegisterAlgorithm(TensorFlowPredictorAlgorithm.NeuralNetworkGraph, new TensorFlowNeuralNetworkPredictor());
                PredictorLogic.RegisterPublication(ProductPredictorPublication.MonthlySales, new PublicationSettings(typeof(OrderEntity)));

                RestLogLogic.Start(sb);
                RestApiKeyLogic.Start(sb);

                WorkflowLogicStarter.Start(sb, () => Starter.Configuration.Value.Workflow);

                ProfilerLogic.Start(sb,
                                    timeTracker: true,
                                    heavyProfiler: true,
                                    overrideSessionTimeout: true);

                // Southwind modules

                EmployeeLogic.Start(sb);
                ProductLogic.Start(sb);
                CustomerLogic.Start(sb);
                OrderLogic.Start(sb);
                ShipperLogic.Start(sb);

                StartSouthwindConfiguration(sb);

                TypeConditionLogic.Register <OrderEntity>(SouthwindTypeCondition.CurrentEmployee, o => o.Employee.Is(EmployeeEntity.Current));

                if (includeDynamic)//2
                {
                    DynamicLogic.StartDynamicModules(sb);
                }//2

                SetupCache(sb);

                Schema.Current.OnSchemaCompleted();

                if (includeDynamic)//3
                {
                    DynamicLogic.RegisterExceptionIfAny();
                }//3
            }
    }
Beispiel #20
0
        public static void Start(string connectionString, bool includeDynamic = true)
        {
            using (HeavyProfiler.Log("Start"))
            using (var initial = HeavyProfiler.Log("Initial"))
            {
                string? logDatabase = Connector.TryExtractDatabaseNameWithPostfix(ref connectionString, "_Log");

                SchemaBuilder sb = new CustomSchemaBuilder { LogDatabaseName = logDatabase, Tracer = initial };
                sb.Schema.Version = typeof(Starter).Assembly.GetName().Version!;
                sb.Schema.ForceCultureInfo = CultureInfo.GetCultureInfo("en-US");

                MixinDeclarations.Register<OperationLogEntity, DiffLogMixin>();
                MixinDeclarations.Register<UserEntity, UserEmployeeMixin>();

                OverrideAttributes(sb);

                var detector = SqlServerVersionDetector.Detect(connectionString);
                Connector.Default = new SqlConnector(connectionString, sb.Schema, detector!.Value);

                CacheLogic.Start(sb);
                }

                TypeLogic.Start(sb);

                OperationLogic.Start(sb);
                ExceptionLogic.Start(sb);

                MigrationLogic.Start(sb);

                CultureInfoLogic.Start(sb);
                FilePathEmbeddedLogic.Start(sb);
                EmailLogic.Start(sb, () => Configuration.Value.Email, (et, target) => Configuration.Value.EmailSender);

                AuthLogic.Start(sb, "System", null);

                AuthLogic.StartAllModules(sb);
                ResetPasswordRequestLogic.Start(sb);
                UserTicketLogic.Start(sb);
                ProcessLogic.Start(sb);
                PackageLogic.Start(sb, packages: true, packageOperations: true);

                SchedulerLogic.Start(sb);

                QueryLogic.Start(sb);
                UserQueryLogic.Start(sb);
                UserQueryLogic.RegisterUserTypeCondition(sb, AtTestGroup.UserEntities);
                UserQueryLogic.RegisterRoleTypeCondition(sb, AtTestGroup.RoleEntities);
                ChartLogic.Start(sb);


                UserChartLogic.RegisterUserTypeCondition(sb, AtTestGroup.UserEntities);
                UserChartLogic.RegisterRoleTypeCondition(sb, AtTestGroup.RoleEntities);
                DashboardLogic.Start(sb);
                DashboardLogic.RegisterUserTypeCondition(sb, AtTestGroup.UserEntities);
                DashboardLogic.RegisterRoleTypeCondition(sb, AtTestGroup.RoleEntities);
                ViewLogLogic.Start(sb, new HashSet<Type> { typeof(UserQueryEntity), typeof(UserChartEntity), typeof(DashboardEntity) });
                DiffLogLogic.Start(sb, registerAll: true);
                ExcelLogic.Start(sb, excelReport: true);
                ToolbarLogic.Start(sb);
                FileLogic.Start(sb);

                TranslationLogic.Start(sb, countLocalizationHits: false);
                TranslatedInstanceLogic.Start(sb, () => CultureInfo.GetCultureInfo("en"));
                WordTemplateLogic.Start(sb);
                MapLogic.Start(sb);
                PredictorLogic.Start(sb, () => new FileTypeAlgorithm(f => new PrefixPair(Starter.Configuration.Value.Folders.PredictorModelFolder)));
                PredictorLogic.RegisterAlgorithm(CNTKPredictorAlgorithm.NeuralNetwork, new CNTKNeuralNetworkPredictorAlgorithm());
                PredictorLogic.RegisterPublication(ProductPredictorPublication.MonthlySales, new PublicationSettings(typeof(OrderEntity)));
                EmployeeLogic.Start(sb);
                ProductLogic.Start(sb);
                CustomerLogic.Start(sb);
                OrderLogic.Start(sb);
                ShipperLogic.Start(sb);

                StartAtTestConfiguration(sb);

                TypeConditionLogic.Register<OrderEntity>(AtTestGroup.UserEntities, o => o.Employee == EmployeeEntity.Current);
                TypeConditionLogic.Register<EmployeeEntity>(AtTestGroup.UserEntities, e => EmployeeEntity.Current.Is(e));

                TypeConditionLogic.Register<OrderEntity>(AtTestGroup.CurrentCustomer, o => o.Customer == CustomerEntity.Current);
                TypeConditionLogic.Register<PersonEntity>(AtTestGroup.CurrentCustomer, o => o == CustomerEntity.Current);
                TypeConditionLogic.Register<CompanyEntity>(AtTestGroup.CurrentCustomer, o => o == CustomerEntity.Current);

                ProfilerLogic.Start(sb,
                    timeTracker: true,
                    heavyProfiler: true,
                    overrideSessionTimeout: true);

                if (includeDynamic)
                {
                }
                SetupCache(sb);

                Schema.Current.OnSchemaCompleted();
            }
Beispiel #21
0
        public static void Start(string connectionString)
        {
            string logDatabase = Connector.TryExtractDatabaseNameWithPostfix(ref connectionString, "_Log");

            SchemaBuilder sb = new SchemaBuilder();

            sb.Schema.Version          = typeof(Starter).Assembly.GetName().Version;
            sb.Schema.ForceCultureInfo = CultureInfo.GetCultureInfo("en-US");

            MixinDeclarations.Register <OperationLogEntity, DiffLogMixin>();
            MixinDeclarations.Register <UserEntity, UserEmployeeMixin>();

            OverrideAttributes(sb);

            SetupDisconnectedStrategies(sb);

            DynamicQueryManager dqm = new DynamicQueryManager();

            Connector.Default = new SqlConnector(connectionString, sb.Schema, dqm, SqlServerVersion.SqlServer2012);

            CacheLogic.Start(sb);

            TypeLogic.Start(sb, dqm);

            OperationLogic.Start(sb, dqm);

            MigrationLogic.Start(sb, dqm);

            CultureInfoLogic.Start(sb, dqm);
            EmbeddedFilePathLogic.Start(sb, dqm);
            SmtpConfigurationLogic.Start(sb, dqm);
            EmailLogic.Start(sb, dqm, () => Configuration.Value.Email, et => Configuration.Value.SmtpConfiguration);

            AuthLogic.Start(sb, dqm, "System", null);

            AuthLogic.StartAllModules(sb, dqm);
            ResetPasswordRequestLogic.Start(sb, dqm);
            UserTicketLogic.Start(sb, dqm);
            SessionLogLogic.Start(sb, dqm);

            ProcessLogic.Start(sb, dqm);
            PackageLogic.Start(sb, dqm, packages: true, packageOperations: true);

            MapLogic.Start(sb, dqm);
            SchedulerLogic.Start(sb, dqm);

            QueryLogic.Start(sb);
            UserQueryLogic.Start(sb, dqm);
            UserQueryLogic.RegisterUserTypeCondition(sb, SouthwindGroup.UserEntities);
            UserQueryLogic.RegisterRoleTypeCondition(sb, SouthwindGroup.RoleEntities);
            ChartLogic.Start(sb, dqm);
            UserChartLogic.RegisterUserTypeCondition(sb, SouthwindGroup.UserEntities);
            UserChartLogic.RegisterRoleTypeCondition(sb, SouthwindGroup.RoleEntities);
            DashboardLogic.Start(sb, dqm);
            DashboardLogic.RegisterUserTypeCondition(sb, SouthwindGroup.UserEntities);
            DashboardLogic.RegisterRoleTypeCondition(sb, SouthwindGroup.RoleEntities);
            ViewLogLogic.Start(sb, dqm, new HashSet <Type> {
                typeof(UserQueryEntity), typeof(UserChartEntity), typeof(DashboardEntity)
            });
            DiffLogLogic.Start(sb, dqm);

            ExceptionLogic.Start(sb, dqm);

            SMSLogic.Start(sb, dqm, null, () => Configuration.Value.Sms);
            SMSLogic.RegisterPhoneNumberProvider <PersonEntity>(p => p.Phone, p => null);
            SMSLogic.RegisterDataObjectProvider((PersonEntity p) => new { p.FirstName, p.LastName, p.Title, p.DateOfBirth });
            SMSLogic.RegisterPhoneNumberProvider <CompanyEntity>(p => p.Phone, p => null);

            NoteLogic.Start(sb, dqm, typeof(UserEntity), /*Note*/ typeof(OrderEntity));
            AlertLogic.Start(sb, dqm, typeof(UserEntity), /*Alert*/ typeof(OrderEntity));
            FileLogic.Start(sb, dqm);

            TranslationLogic.Start(sb, dqm);
            TranslatedInstanceLogic.Start(sb, dqm, () => CultureInfo.GetCultureInfo("en"));

            HelpLogic.Start(sb, dqm);
            WordTemplateLogic.Start(sb, dqm);

            EmployeeLogic.Start(sb, dqm);
            ProductLogic.Start(sb, dqm);
            CustomerLogic.Start(sb, dqm);
            OrderLogic.Start(sb, dqm);
            ShipperLogic.Start(sb, dqm);

            StartSouthwindConfiguration(sb, dqm);

            TypeConditionLogic.Register <OrderEntity>(SouthwindGroup.UserEntities, o => o.Employee.RefersTo(EmployeeEntity.Current));
            TypeConditionLogic.Register <EmployeeEntity>(SouthwindGroup.UserEntities, e => e == EmployeeEntity.Current);

            TypeConditionLogic.Register <OrderEntity>(SouthwindGroup.CurrentCustomer, o => o.Customer == CustomerEntity.Current);
            TypeConditionLogic.Register <PersonEntity>(SouthwindGroup.CurrentCustomer, o => o == CustomerEntity.Current);
            TypeConditionLogic.Register <CompanyEntity>(SouthwindGroup.CurrentCustomer, o => o == CustomerEntity.Current);

            DisconnectedLogic.Start(sb, dqm);
            DisconnectedLogic.BackupFolder        = @"D:\SouthwindTemp\Backups";
            DisconnectedLogic.BackupNetworkFolder = @"D:\SouthwindTemp\Backups";
            DisconnectedLogic.DatabaseFolder      = @"D:\SouthwindTemp\Database";

            ProfilerLogic.Start(sb, dqm,
                                timeTracker: true,
                                heavyProfiler: true,
                                overrideSessionTimeout: true);

            SetupCache(sb);

            SetSchemaNames(Schema.Current);

            if (logDatabase.HasText())
            {
                SetLogDatabase(sb.Schema, new DatabaseName(null, logDatabase));
            }

            Schema.Current.OnSchemaCompleted();
        }
Beispiel #22
0
        public static void Start(string connectionString)
        {
            using (HeavyProfiler.Log("Start"))
                using (var initial = HeavyProfiler.Log("Initial"))
                {
                    StartParameters.IgnoredDatabaseMismatches = new List <Exception>();
                    StartParameters.IgnoredCodeErrors         = new List <Exception>();

                    string?logDatabase = Connector.TryExtractDatabaseNameWithPostfix(ref connectionString, "_Log");

                    SchemaBuilder sb = new CustomSchemaBuilder {
                        LogDatabaseName = logDatabase, Tracer = initial
                    };
                    sb.Schema.Version          = typeof(Starter).Assembly.GetName().Version;
                    sb.Schema.ForceCultureInfo = CultureInfo.GetCultureInfo("en-US");

                    MixinDeclarations.Register <OperationLogEntity, DiffLogMixin>();
                    MixinDeclarations.Register <UserEntity, UserEmployeeMixin>();

                    OverrideAttributes(sb);

                    var detector = SqlServerVersionDetector.Detect(connectionString);
                    Connector.Default = new SqlConnector(connectionString, sb.Schema, detector !.Value);

                    CacheLogic.Start(sb);

                    DynamicLogicStarter.Start(sb);
                    DynamicLogic.CompileDynamicCode();

                    DynamicLogic.RegisterMixins();
                    DynamicLogic.BeforeSchema(sb);

                    TypeLogic.Start(sb);

                    OperationLogic.Start(sb);
                    ExceptionLogic.Start(sb);

                    MigrationLogic.Start(sb);

                    CultureInfoLogic.Start(sb);
                    FilePathEmbeddedLogic.Start(sb);
                    SmtpConfigurationLogic.Start(sb);
                    EmailLogic.Start(sb, () => Configuration.Value.Email, (et, target) => Configuration.Value.SmtpConfiguration);

                    AuthLogic.Start(sb, "System", null);

                    AuthLogic.StartAllModules(sb);
                    ResetPasswordRequestLogic.Start(sb);
                    UserTicketLogic.Start(sb);
                    SessionLogLogic.Start(sb);

                    ProcessLogic.Start(sb);
                    PackageLogic.Start(sb, packages: true, packageOperations: true);

                    SchedulerLogic.Start(sb);

                    QueryLogic.Start(sb);
                    UserQueryLogic.Start(sb);
                    UserQueryLogic.RegisterUserTypeCondition(sb, SouthwindGroup.UserEntities);
                    UserQueryLogic.RegisterRoleTypeCondition(sb, SouthwindGroup.RoleEntities);
                    ChartLogic.Start(sb);


                    UserChartLogic.RegisterUserTypeCondition(sb, SouthwindGroup.UserEntities);
                    UserChartLogic.RegisterRoleTypeCondition(sb, SouthwindGroup.RoleEntities);
                    DashboardLogic.Start(sb);
                    DashboardLogic.RegisterUserTypeCondition(sb, SouthwindGroup.UserEntities);
                    DashboardLogic.RegisterRoleTypeCondition(sb, SouthwindGroup.RoleEntities);
                    ViewLogLogic.Start(sb, new HashSet <Type> {
                        typeof(UserQueryEntity), typeof(UserChartEntity), typeof(DashboardEntity)
                    });
                    DiffLogLogic.Start(sb, registerAll: true);
                    ExcelLogic.Start(sb, excelReport: true);
                    ToolbarLogic.Start(sb);

                    SMSLogic.Start(sb, null, () => Configuration.Value.Sms);
                    SMSLogic.RegisterPhoneNumberProvider <PersonEntity>(p => p.Phone, p => null);
                    SMSLogic.RegisterDataObjectProvider((PersonEntity p) => new { p.FirstName, p.LastName, p.Title, p.DateOfBirth });
                    SMSLogic.RegisterPhoneNumberProvider <CompanyEntity>(p => p.Phone, p => null);

                    NoteLogic.Start(sb, typeof(UserEntity), /*Note*/ typeof(OrderEntity));
                    AlertLogic.Start(sb, typeof(UserEntity), /*Alert*/ typeof(OrderEntity));
                    FileLogic.Start(sb);

                    TranslationLogic.Start(sb, countLocalizationHits: false);
                    TranslatedInstanceLogic.Start(sb, () => CultureInfo.GetCultureInfo("en"));

                    HelpLogic.Start(sb);
                    WordTemplateLogic.Start(sb);
                    MapLogic.Start(sb);
                    PredictorLogic.Start(sb, () => new FileTypeAlgorithm(f => new PrefixPair(Starter.Configuration.Value.Folders.PredictorModelFolder)));
                    PredictorLogic.RegisterAlgorithm(CNTKPredictorAlgorithm.NeuralNetwork, new CNTKNeuralNetworkPredictorAlgorithm());
                    PredictorLogic.RegisterPublication(ProductPredictorPublication.MonthlySales, new PublicationSettings(typeof(OrderEntity)));

                    RestLogLogic.Start(sb);
                    RestApiKeyLogic.Start(sb);

                    WorkflowLogicStarter.Start(sb, () => Starter.Configuration.Value.Workflow);

                    EmployeeLogic.Start(sb);
                    ProductLogic.Start(sb);
                    CustomerLogic.Start(sb);
                    OrderLogic.Start(sb);
                    ShipperLogic.Start(sb);

                    StartSouthwindConfiguration(sb);

                    TypeConditionLogic.Register <OrderEntity>(SouthwindGroup.UserEntities, o => o.Employee == EmployeeEntity.Current);
                    TypeConditionLogic.Register <EmployeeEntity>(SouthwindGroup.UserEntities, e => EmployeeEntity.Current.Is(e));

                    TypeConditionLogic.Register <OrderEntity>(SouthwindGroup.CurrentCustomer, o => o.Customer == CustomerEntity.Current);
                    TypeConditionLogic.Register <PersonEntity>(SouthwindGroup.CurrentCustomer, o => o == CustomerEntity.Current);
                    TypeConditionLogic.Register <CompanyEntity>(SouthwindGroup.CurrentCustomer, o => o == CustomerEntity.Current);

                    ProfilerLogic.Start(sb,
                                        timeTracker: true,
                                        heavyProfiler: true,
                                        overrideSessionTimeout: true);

                    DynamicLogic.StartDynamicModules(sb);
                    DynamicLogic.RegisterExceptionIfAny();

                    SetupCache(sb);

                    Schema.Current.OnSchemaCompleted();
                }
        }