Example #1
0
        public ActionResult ViewUserChart(Lite <UserChartEntity> lite, Lite <Entity> currentEntity)
        {
            UserChartEntity uc = UserChartLogic.RetrieveUserChart(lite);

            ChartRequest request = (uc.EntityType == null ? null : CurrentEntityConverter.SetCurrentEntity(currentEntity.Retrieve()))
                                   .Using(_ => uc.ToRequest());

            return(OpenChartRequest(request, uc.ToLite()));
        }
Example #2
0
    public static void Start(SchemaBuilder sb, bool googleMapsChartScripts, string[]?svgMapUrls = null)
    {
        if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
        {
            QueryLogic.Start(sb);

            PermissionAuthLogic.RegisterTypes(typeof(ChartPermission));

            ChartColorLogic.Start(sb);
            ChartScriptLogic.Start(sb, googleMapsChartScripts, svgMapUrls);
            UserChartLogic.Start(sb);
        }
    }
Example #3
0
        private static ToolBarButton UserCharButton(UrlHelper url, object queryName, string prefix, Lite <UserChartEntity> currentUserChart)
        {
            var items = new List <IMenuItem>();

            foreach (var uc in UserChartLogic.GetUserCharts(queryName).OrderBy(a => a.ToString()))
            {
                items.Add(new MenuItem(prefix, "sfUserChart" + uc.Id)
                {
                    Text     = uc.ToString(),
                    Title    = uc.ToString(),
                    Href     = RouteHelper.New().Action <ChartController>(c => c.ViewUserChart(uc, null)),
                    CssClass = (currentUserChart.Is(uc) ? " sf-userchart-selected" : "")
                });
            }

            if (items.Count > 0)
            {
                items.Add(new MenuItemSeparator());
            }

            if (Navigator.IsCreable(typeof(UserChartEntity), isSearch: null))
            {
                string uqNewText = ChartMessage.CreateNew.NiceToString();
                items.Add(new MenuItem(prefix, "qbUserChartNew")
                {
                    Title   = uqNewText,
                    Text    = uqNewText,
                    OnClick = ChartClient.Module["createUserChart"](prefix, url.Action((ChartController c) => c.CreateUserChart())),
                });
            }

            if (currentUserChart != null && currentUserChart.IsAllowedFor(TypeAllowedBasic.Modify, inUserInterface: true))
            {
                string ucEditText = ChartMessage.EditUserChart.NiceToString();
                items.Add(new MenuItem(prefix, "qbUserChartEdit")
                {
                    Title = ucEditText,
                    Text  = ucEditText,
                    Href  = Navigator.NavigateRoute(currentUserChart)
                });
            }

            string ucUserChartText = typeof(UserChartEntity).NicePluralName();

            return(new ToolBarDropDown(prefix, "tmUserCharts")
            {
                Title = ucUserChartText,
                Text = ucUserChartText,
                Items = items
            });
        }
Example #4
0
    public Data.DataTable GetDataTable(string suffix, Entity?entity)
    {
        var userChart = Database.Query <UserChartEntity>().SingleEx(a => a.Guid == Guid.Parse((suffix.TryBefore("\n") ?? suffix).Trim()));

        using (CurrentEntityConverter.SetCurrentEntity(entity))
        {
            var         chartRequest = UserChartLogic.ToChartRequest(userChart);
            ResultTable result       = ChartLogic.ExecuteChartAsync(chartRequest, CancellationToken.None).Result;
            var         tokens       = chartRequest.Columns.Select(a => a.Token).NotNull().ToList();


            return(result.ToDataTable());
        }
    }
Example #5
0
        public Data.DataTable GetDataTable(string suffix, WordTemplateLogic.WordContext context)
        {
            var userChart = Database.Query <UserChartEntity>().SingleOrDefault(a => a.Guid == Guid.Parse(suffix));

            using (CurrentEntityConverter.SetCurrentEntity(context.Entity))
            {
                var         chartRequest = UserChartLogic.ToChartRequest(userChart);
                ResultTable result       = ChartLogic.ExecuteChartAsync(chartRequest, CancellationToken.None).Result;
                var         tokens       = chartRequest.Columns.Where(a => a.Token != null).ToList();

                if (chartRequest.GroupResults && tokens.Count(a => a.IsGroupKey.Value) == 2 && tokens.Count(a => !a.IsGroupKey.Value) == 1)
                {
                    var firstKeyIndex  = tokens.FindIndex(a => a.IsGroupKey.Value);
                    var secondKeyIndex = tokens.FindIndex(firstKeyIndex + 1, a => a.IsGroupKey.Value);
                    var valueIndex     = tokens.FindIndex(a => !a.IsGroupKey.Value);
                    return(result.ToDataTablePivot(secondKeyIndex, firstKeyIndex, valueIndex));
                }
                else
                {
                    return(result.ToDataTable());
                }
            }
        }
Example #6
0
        public Data.DataTable GetDataTable(string suffix, Entity entity)
        {
            var userChart = Database.Query <UserChartEntity>().SingleEx(a => a.Guid == Guid.Parse(suffix));

            using (CurrentEntityConverter.SetCurrentEntity(entity))
            {
                var         chartRequest = UserChartLogic.ToChartRequest(userChart);
                ResultTable result       = ChartLogic.ExecuteChartAsync(chartRequest, CancellationToken.None).Result;
                var         tokens       = chartRequest.Columns.Select(a => a.Token).NotNull().ToList();

                //TODO: Too specific. Will be better if controlled by some parameters.
                if (chartRequest.HasAggregates() && tokens.Count(a => !(a.Token is AggregateToken)) == 2 && tokens.Count(a => a.Token is AggregateToken) == 1)
                {
                    var firstKeyIndex  = tokens.FindIndex(a => !(a.Token is AggregateToken));
                    var secondKeyIndex = tokens.FindIndex(firstKeyIndex + 1, a => !(a.Token is AggregateToken));
                    var valueIndex     = tokens.FindIndex(a => a.Token is AggregateToken);
                    return(result.ToDataTablePivot(secondKeyIndex, firstKeyIndex, valueIndex));
                }
                else
                {
                    return(result.ToDataTable());
                }
            }
        }
Example #7
0
        public static void Start(IApplicationBuilder app)
        {
            UserAssetServer.Start(app);

            SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod());

            CustomizeChartRequest();

            SignumServer.WebEntityJsonConverterFactory.AfterDeserilization.Register((ChartRequestModel cr) =>
            {
                if (cr.ChartScript != null)
                {
                    cr.GetChartScript().SynchronizeColumns(cr, null);
                }

                if (cr.QueryName != null)
                {
                    var qd = QueryLogic.Queries.QueryDescription(cr.QueryName);

                    if (cr.Columns != null)
                    {
                        foreach (var c in cr.Columns)
                        {
                            c.ParseData(cr, qd, SubTokensOptions.CanElement | SubTokensOptions.CanAggregate);
                        }
                    }
                }
            });

            SignumServer.WebEntityJsonConverterFactory.AfterDeserilization.Register((UserChartEntity uc) =>
            {
                if (uc.ChartScript != null)
                {
                    uc.GetChartScript().SynchronizeColumns(uc, null);
                }

                if (uc.Query != null)
                {
                    var qd = QueryLogic.Queries.QueryDescription(uc.Query.ToQueryName());
                    uc.ParseData(qd);
                }
            });

            UserChartEntity.SetConverters(
                query => QueryLogic.ToQueryName(query.Key),
                queryName => QueryLogic.GetQueryEntity(queryName));

            EntityPackTS.AddExtension += ep =>
            {
                if (ep.entity.IsNew || !ChartPermission.ViewCharting.IsAuthorized() || TypeAuthLogic.GetAllowed(typeof(UserChartEntity)).MaxDB() == TypeAllowedBasic.None)
                {
                    return;
                }

                var userCharts = UserChartLogic.GetUserChartsEntity(ep.entity.GetType());
                if (userCharts.Any())
                {
                    ep.extension.Add("userCharts", userCharts);
                }
            };
        }
Example #8
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();
                }
        }
Example #9
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
                }
        }
 public IEnumerable <Lite <UserChartEntity> > FromEntityType(string typeName)
 {
     return(UserChartLogic.GetUserChartsEntity(TypeLogic.GetType(typeName)));
 }
 public IEnumerable <Lite <UserChartEntity> > FromQuery(string queryKey)
 {
     return(UserChartLogic.GetUserCharts(QueryLogic.ToQueryName(queryKey)));
 }
Example #12
0
        public static void Start()
        {
            if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                QueryClient.Start();

                UserAssetsClient.Start();
                UserAssetsClient.RegisterExportAssertLink <UserChartEntity>();

                LinksClient.RegisterEntityLinks <UserChartEntity>((lite, ctx) => new[]
                {
                    new QuickLinkAction(ChartMessage.Preview, RouteHelper.New().Action <ChartController>(cc => cc.ViewUserChart(lite, null)))
                    {
                        IsVisible = ChartPermission.ViewCharting.IsAuthorized()
                    }
                });

                Func <SubTokensOptions, Mapping <QueryTokenEmbedded> > qtMapping = ops => ctx =>
                {
                    string tokenStr = UserAssetsHelper.GetTokenString(ctx);

                    string queryKey  = ctx.Parent.Parent.Parent.Inputs[TypeContextUtilities.Compose("Query", "Key")];
                    object queryName = QueryLogic.ToQueryName(queryKey);

                    var chart = ((UserChartEntity)ctx.Parent.Parent.Parent.UntypedValue);

                    QueryDescription qd = DynamicQueryManager.Current.QueryDescription(queryName);
                    return(new QueryTokenEmbedded(QueryUtils.Parse(tokenStr, qd, ops | (chart.GroupResults ? SubTokensOptions.CanAggregate : 0))));
                };

                Navigator.AddSettings(new List <EntitySettings>
                {
                    new EntitySettings <UserChartEntity> {
                        PartialViewName = _ => ChartClient.ViewPrefix.FormatWith("UserChart"), IsCreable = EntityWhen.Never
                    }
                });

                Navigator.EntitySettings <UserChartEntity>().MappingMain = Navigator.EntitySettings <UserChartEntity>().MappingLine =
                    new EntityMapping <UserChartEntity>(true)
                    .SetProperty(cb => cb.Columns, new ChartClient.MListCorrelatedOrDefaultMapping <ChartColumnEmbedded>(ChartClient.MappingChartColumn))
                    .SetProperty(cr => cr.Filters, new MListMapping <QueryFilterEmbedded>
                {
                    ElementMapping = new EntityMapping <QueryFilterEmbedded>(false)
                                     .CreateProperty(a => a.Operation)
                                     .CreateProperty(a => a.ValueString)
                                     .SetProperty(a => a.Token, qtMapping(SubTokensOptions.CanAnyAll | SubTokensOptions.CanElement))
                })
                    .SetProperty(cr => cr.Orders, new MListMapping <QueryOrderEmbedded>
                {
                    ElementMapping = new EntityMapping <QueryOrderEmbedded>(false)
                                     .CreateProperty(a => a.OrderType)
                                     .SetProperty(a => a.Token, qtMapping(SubTokensOptions.CanAnyAll | SubTokensOptions.CanElement))
                })
                    .SetProperty(cb => cb.Parameters, new MListDictionaryMapping <ChartParameterEmbedded, string>(p => p.Name)
                {
                    OnlyIfPossible = true
                });

                RouteTable.Routes.MapRoute(null, "UC/{webQueryName}/{lite}",
                                           new { controller = "Chart", action = "ViewUserChart" });

                UserChartEntity.SetConverters(query => QueryLogic.ToQueryName(query.Key), queryName =>
                                              QueryLogic.GetQueryEntity(queryName));

                OperationClient.AddSetting(new EntityOperationSettings <UserChartEntity>(UserChartOperation.Delete)
                {
                    Click = ctx => ChartClient.Module["deleteUserChart"](ctx.Options(), Finder.FindRoute(((UserChartEntity)ctx.Entity).Query.ToQueryName())),
                });

                LinksClient.RegisterEntityLinks <Entity>((entity, ctrl) =>
                {
                    if (!ChartPermission.ViewCharting.IsAuthorized())
                    {
                        return(null);
                    }

                    return(UserChartLogic.GetUserChartsEntity(entity.EntityType)
                           .Select(cp => new UserChartQuickLink(cp, entity)).ToArray());
                });
            }
        }
Example #13
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();
        }
Example #14
0
        public static void Start(HttpConfiguration config)
        {
            UserAssetServer.Start(config);

            SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod());

            CustomizeChartRequest();

            PropertyConverter.GetPropertyConverters(typeof(ChartScriptParameterEmbedded)).Add("enumValues", new PropertyConverter()
            {
                CustomWriteJsonProperty = ctx =>
                {
                    var csp = (ChartScriptParameterEmbedded)ctx.Entity;

                    if (csp.Type == ChartParameterType.Enum)
                    {
                        ctx.JsonWriter.WritePropertyName(ctx.LowerCaseName);
                        ctx.JsonSerializer.Serialize(ctx.JsonWriter, csp.GetEnumValues().Select(a => new { name = a.Name, typeFilter = a.TypeFilter }).ToList());
                    }
                },
                AvoidValidate          = true,
                CustomReadJsonProperty = ctx =>
                {
                    var list = ctx.JsonSerializer.Deserialize(ctx.JsonReader);
                    //Discard
                }
            });

            EntityJsonConverter.AfterDeserilization.Register((ChartRequest cr) =>
            {
                if (cr.ChartScript != null)
                {
                    cr.ChartScript.SynchronizeColumns(cr);
                }

                if (cr.QueryName != null)
                {
                    var qd = DynamicQueryManager.Current.QueryDescription(cr.QueryName);

                    if (cr.Columns != null)
                    {
                        foreach (var c in cr.Columns)
                        {
                            c.ParseData(cr, qd, SubTokensOptions.CanElement | (c.IsGroupKey == false ? SubTokensOptions.CanAggregate : 0));
                        }
                    }
                }
            });

            EntityJsonConverter.AfterDeserilization.Register((UserChartEntity uc) =>
            {
                if (uc.ChartScript != null)
                {
                    uc.ChartScript.SynchronizeColumns(uc);
                }

                if (uc.Query != null)
                {
                    var qd = DynamicQueryManager.Current.QueryDescription(uc.Query.ToQueryName());
                    uc.ParseData(qd);
                }
            });

            UserChartEntity.SetConverters(
                query => QueryLogic.ToQueryName(query.Key),
                queryName => QueryLogic.GetQueryEntity(queryName));

            EntityPackTS.AddExtension += ep =>
            {
                if (ep.entity.IsNew || !ChartPermission.ViewCharting.IsAuthorized())
                {
                    return;
                }

                var userCharts = UserChartLogic.GetUserChartsEntity(ep.entity.GetType());
                if (userCharts.Any())
                {
                    ep.Extension.Add("userCharts", userCharts);
                }
            };
        }
Example #15
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
            }
    }
Example #16
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();
            }