Example #1
0
        public static void Start()
        {
            if (ServiceLocator.Start != null)
            {
                return;
            }

            ServiceLocator.Start = (IServiceLocator service) =>
            {
                var profiler       = new TestProfiler();
                var host           = new TestApplicationHost(profiler);
                var localizer      = new TestLocalizer();
                var dbContext      = new SqlDbContext(profiler, host, localizer);
                var workflowEngine = new WorkflowEngine(host, dbContext);
                var renderer       = new XamlRenderer(profiler);
                var scripter       = new VueDataScripter();

                service.RegisterService <IDbContext>(dbContext);
                service.RegisterService <IWorkflowEngine>(workflowEngine);
                service.RegisterService <IApplicationHost>(host);
                service.RegisterService <IProfiler>(profiler);
                service.RegisterService <IRenderer>(renderer);
                service.RegisterService <IDataScripter>(scripter);
                _currentService = service;
            };

            ServiceLocator.GetCurrentLocator = () =>
            {
                if (_currentService == null)
                {
                    new ServiceLocator();
                }
                return(_currentService);
            };
        }
Example #2
0
        public static void StartServices(Action <StartOptions> opts)
        {
            // DI ready
            ServiceLocator.Start = (IServiceLocator locator) =>
            {
                var startOptions = new StartOptions();
                opts?.Invoke(startOptions);

                IProfiler        profiler   = startOptions.Profiler ?? new WebProfiler();
                IUserLocale      userLocale = new WebUserLocale();
                IApplicationHost host       = new WebApplicationHost(profiler, userLocale);
                ILocalizer       localizer  = new WebLocalizer(host, userLocale);

                ITokenProvider tokenProvider = startOptions.TokenProvider;
                IDbContext     dbContext     = new SqlDbContext(
                    profiler as IDataProfiler,
                    host as IDataConfiguration,
                    localizer as IDataLocalizer,
                    host as ITenantManager,
                    tokenProvider);
                IDataScripter    scripter        = new VueDataScripter(host, localizer);
                ILogger          logger          = new WebLogger(host, dbContext);
                IMessageService  emailService    = new IdentityEmailService(logger, host);
                IMessaging       messaging       = new MessageProcessor(host, dbContext, emailService, logger);
                ISmsService      smsService      = new SmsService(dbContext, logger);
                IWorkflowEngine  workflowEngine  = new WorkflowEngine(host, dbContext, messaging);
                IScriptProcessor scriptProcessor = new ScriptProcessor(scripter, host);
                IHttpService     httpService     = new HttpService();

                locator.RegisterService <IDbContext>(dbContext);
                locator.RegisterService <IProfiler>(profiler);
                locator.RegisterService <IApplicationHost>(host);
                locator.RegisterService <ILocalizer>(localizer);
                locator.RegisterService <IDataScripter>(scripter);
                locator.RegisterService <ILogger>(logger);
                locator.RegisterService <IMessageService>(emailService);
                locator.RegisterService <ISmsService>(smsService);
                locator.RegisterService <IMessaging>(messaging);
                locator.RegisterService <IWorkflowEngine>(workflowEngine);
                locator.RegisterService <IScriptProcessor>(scriptProcessor);
                locator.RegisterService <IHttpService>(httpService);
                if (tokenProvider != null)
                {
                    locator.RegisterService <ITokenProvider>(tokenProvider);
                }

                host.StartApplication(false);
                HttpContext.Current.Items.Add("ServiceLocator", locator);
            };

            ServiceLocator.GetCurrentLocator = () =>
            {
                var locator = HttpContext.Current.Items["ServiceLocator"];
                if (locator == null)
                {
                    new ServiceLocator();
                }
                return(HttpContext.Current.Items["ServiceLocator"] as IServiceLocator);
            };
        }
Example #3
0
        public void StartServices()
        {
            // DI ready
            ServiceLocator.Start = (IServiceLocator locator) =>
            {
                IProfiler        profiler  = new WebProfiler();
                IApplicationHost host      = new WebApplicationHost(profiler);
                ILocalizer       localizer = new WebLocalizer(host);
                IDbContext       dbContext = new SqlDbContext(
                    profiler as IDataProfiler,
                    host as IDataConfiguration,
                    localizer as IDataLocalizer,
                    host as ITenantManager);
                ILogger               logger               = new WebLogger(host, dbContext);
                IMessageService       emailService         = new IdentityEmailService(logger, host);
                IMessaging            messaging            = new MessageProcessor(host, dbContext, emailService, logger);
                IRenderer             renderer             = new XamlRenderer(profiler, host);
                IWorkflowEngine       workflowEngine       = new WorkflowEngine(host, dbContext, messaging);
                IDataScripter         scripter             = new VueDataScripter(host, localizer);
                ISmsService           smsService           = new SmsService(dbContext, logger);
                IExternalLoginManager externalLoginManager = new ExternalLoginManager(dbContext);
                IUserStateManager     userStateManager     = new WebUserStateManager(host, dbContext);
                IExternalDataProvider dataProvider         = new ExternalDataContext();
                IScriptProcessor      scriptProcessor      = new ScriptProcessor(scripter, host);

                locator.RegisterService <IDbContext>(dbContext);
                locator.RegisterService <IProfiler>(profiler);
                locator.RegisterService <IApplicationHost>(host);
                locator.RegisterService <IRenderer>(renderer);
                locator.RegisterService <IWorkflowEngine>(workflowEngine);
                locator.RegisterService <IMessaging>(messaging);
                locator.RegisterService <ILocalizer>(localizer);
                locator.RegisterService <IDataScripter>(scripter);
                locator.RegisterService <ILogger>(logger);
                locator.RegisterService <IMessageService>(emailService);
                locator.RegisterService <ISmsService>(smsService);
                locator.RegisterService <IExternalLoginManager>(externalLoginManager);
                locator.RegisterService <IUserStateManager>(userStateManager);
                locator.RegisterService <IExternalDataProvider>(dataProvider);
                locator.RegisterService <IScriptProcessor>(scriptProcessor);

                HttpContext.Current.Items.Add("ServiceLocator", locator);
            };

            ServiceLocator.GetCurrentLocator = () =>
            {
                if (HttpContext.Current == null)
                {
                    throw new InvalidProgramException("There is no http context");
                }
                var currentContext = HttpContext.Current;
                var locator        = currentContext.Items["ServiceLocator"];
                if (locator == null)
                {
                    new ServiceLocator();
                }
                return(HttpContext.Current.Items["ServiceLocator"] as IServiceLocator);
            };
        }
Example #4
0
        public static void StartDesktopServices()
        {
            // TODO: LOCALE
            CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("uk-UA");

            ServiceLocator.GetCurrentLocator = () =>
            {
                if (_currentService == null)
                {
                    _currentService = new ServiceLocator();
                }
                return(_currentService);
            };

            ServiceLocator.Start = (IServiceLocator service) =>
            {
                IProfiler profiler                   = new DesktopProfiler();
                DesktopApplicationHost host          = new DesktopApplicationHost(profiler);
                IUserLocale            userLocale    = new DesktopUserLocale();
                ILocalizer             localizer     = new DesktopLocalizer(host, userLocale);
                ITokenProvider         tokenProvider = new DesktopTokenProvider();
                IDbContext             dbContext     = new SqlDbContext(
                    profiler as IDataProfiler,
                    host as IDataConfiguration,
                    localizer as IDataLocalizer,
                    tenantManager: null,
                    tokenProvider: tokenProvider);                     /*host as ITenantManager*/
                IRenderer             renderer         = new XamlRenderer(profiler, host);
                IWorkflowEngine       wfEngine         = new WorkflowEngine(host, dbContext, null);
                IDataScripter         scripter         = new VueDataScripter(host, localizer);
                IUserStateManager     userStateManager = new DesktopUserStateManager(host, dbContext);
                ILicenseManager       licManager       = new DesktopLicenseManager(dbContext);
                IExternalDataProvider dataProvider     = new ExternalDataContext();
                service.RegisterService <IProfiler>(profiler);
                service.RegisterService <IApplicationHost>(host);
                service.RegisterService <IDbContext>(dbContext);
                service.RegisterService <IRenderer>(renderer);
                service.RegisterService <IWorkflowEngine>(wfEngine);
                service.RegisterService <IDataScripter>(scripter);
                service.RegisterService <ILocalizer>(localizer);
                service.RegisterService <IUserStateManager>(userStateManager);
                service.RegisterService <ISupportUserInfo>(host);
                service.RegisterService <ILicenseManager>(licManager);
                service.RegisterService <IExternalDataProvider>(dataProvider);
                service.RegisterService <ITokenProvider>(tokenProvider);
                service.RegisterService <IUserLocale>(userLocale);
                host.TenantId = 1;
            };
        }
Example #5
0
        public void ServerScriptValidate()
        {
            IDataScripter scripter = new VueDataScripter(_host, _localizer);
            var           sp       = new ScriptProcessor(scripter, _host);
            var           ssi      = new ServerScriptInfo()
            {
                DataModel = _dbContext.LoadModel(null, "a2test.[Document.Load]"),
                Template  = "document.template",
                Path      = "document/server",
                RawData   = "{Document: {Id:173}}",
                Parameter = new { Id = 123, Text = "ParamText" }
            };
            var result = sp.ValidateModel(ssi);

            Assert.IsNull(result);
        }
Example #6
0
        public static void Start()
        {
            if (ServiceLocator.Start != null)
            {
                return;
            }

            ServiceLocator.Start = (IServiceLocator service) =>
            {
                var profiler = new NullProfiler();
                var host     = new TestApplicationHost(profiler)
                {
                    HostingPath = Path.GetFullPath("../../../../Web/A2v10.Web.Site")
                };

                var localizer      = new NullLocalizer();
                var dbContext      = new SqlDbContext(profiler, host, localizer);
                var messaging      = new NullMessaging();
                var workflowEngine = new WorkflowEngine(host, dbContext, messaging);
                var renderer       = new XamlRenderer(profiler, host);
                var scripter       = new VueDataScripter(host, localizer);

                service.RegisterService <IDbContext>(dbContext);
                service.RegisterService <IWorkflowEngine>(workflowEngine);
                service.RegisterService <IApplicationHost>(host);
                service.RegisterService <IProfiler>(profiler);
                service.RegisterService <IRenderer>(renderer);
                service.RegisterService <ILocalizer>(localizer);
                service.RegisterService <IDataScripter>(scripter);
                service.RegisterService <IMessaging>(messaging);
                _currentService = service;
            };

            ServiceLocator.GetCurrentLocator = () =>
            {
                if (_currentService == null)
                {
                    new ServiceLocator();
                }
                return(_currentService);
            };
        }
Example #7
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            ServiceLocator.Start = (locator) =>
            {
                IProfiler        profiler  = new WebProfiler();
                IApplicationHost host      = new WebApplicationHost(profiler);
                ILocalizer       localizer = new WebLocalizer(host);
                IDbContext       dbContext = new SqlDbContext(
                    profiler as IDataProfiler,
                    host as IDataConfiguration,
                    localizer as IDataLocalizer,
                    host as ITenantManager);
                IDataScripter scripter = new VueDataScripter(host, localizer);
                ILogger       logger   = new WebLogger(host, dbContext);

                locator.RegisterService <IDbContext>(dbContext);
                locator.RegisterService <IProfiler>(profiler);
                locator.RegisterService <IApplicationHost>(host);
                locator.RegisterService <ILocalizer>(localizer);
                locator.RegisterService <IDataScripter>(scripter);
                locator.RegisterService <ILogger>(logger);

                HttpContext.Current.Items.Add("ServiceLocator", locator);
            };

            ServiceLocator.GetCurrentLocator = () =>
            {
                var locator = HttpContext.Current.Items["ServiceLocator"];
                if (locator == null)
                {
                    new ServiceLocator();
                }
                return(HttpContext.Current.Items["ServiceLocator"] as IServiceLocator);
            };
        }
Example #8
0
        public static void StartServices(IAppBuilder app)
        {
            // DI ready
            ServiceLocator.Start = (IServiceLocator locator) =>
            {
                IProfiler        profiler      = new WebProfiler();
                IUserLocale      userLocale    = new WebUserLocale();
                IApplicationHost host          = new WebApplicationHost(profiler, userLocale, locator);
                ILocalizer       localizer     = new WebLocalizer(host, userLocale);
                ITokenProvider   tokenProvider = new WebTokenProvider();
                IDbContext       dbContext     = new SqlDbContext(
                    profiler as IDataProfiler,
                    host as IDataConfiguration,
                    localizer as IDataLocalizer,
                    host as ITenantManager,
                    tokenProvider);
                ILogger               logger               = new WebLogger(host, dbContext);
                IMessageService       emailService         = new IdentityEmailService(logger, host);
                ISmsService           smsService           = new SmsService(dbContext, logger);
                IRenderer             renderer             = new XamlRenderer(profiler, host);
                IDataScripter         scripter             = new VueDataScripter(host, localizer);
                IExternalLoginManager externalLoginManager = new ExternalLoginManager(dbContext);
                IUserStateManager     userStateManager     = new WebUserStateManager(host, dbContext);
                IMessaging            messaging            = new MessageProcessor(host, dbContext, emailService, smsService, logger);
                IWorkflowEngine       workflowEngine       = new WorkflowEngine(host, dbContext, messaging);
                IExternalDataProvider dataProvider         = new ExternalDataContext();
                IScriptProcessor      scriptProcessor      = new ScriptProcessor(scripter, host);
                IHttpService          httpService          = new HttpService();
                IJavaScriptEngine     javaScriptEngine     = new JavaScriptEngine(dbContext, host, smsService);

                locator.RegisterService <IDbContext>(dbContext);
                locator.RegisterService <IProfiler>(profiler);
                locator.RegisterService <IApplicationHost>(host);
                locator.RegisterService <IRenderer>(renderer);
                locator.RegisterService <IWorkflowEngine>(workflowEngine);
                locator.RegisterService <IMessaging>(messaging);
                locator.RegisterService <IUserLocale>(userLocale);
                locator.RegisterService <ILocalizer>(localizer);
                locator.RegisterService <IDataScripter>(scripter);
                locator.RegisterService <ILogger>(logger);
                locator.RegisterService <IMessageService>(emailService);
                locator.RegisterService <ISmsService>(smsService);
                locator.RegisterService <IExternalLoginManager>(externalLoginManager);
                locator.RegisterService <IUserStateManager>(userStateManager);
                locator.RegisterService <IExternalDataProvider>(dataProvider);
                locator.RegisterService <IScriptProcessor>(scriptProcessor);
                locator.RegisterService <IHttpService>(httpService);
                locator.RegisterService <IJavaScriptEngine>(javaScriptEngine);
                locator.RegisterService <ITokenProvider>(tokenProvider);

                IDataProtectionProvider dataProtection = app.GetDataProtectionProvider();
                locator.RegisterService <IDataProtectionProvider>(dataProtection);

                if (HttpContext.Current != null)
                {
                    HttpContext.Current.Items.Add("ServiceLocator", locator);
                }
            };

            IServiceLocator GetOrCreateStatic()
            {
                if (_currentLocator == null)
                {
                    _currentLocator = new ServiceLocator();
                }
                return(_currentLocator);
            }

            ServiceLocator.GetCurrentLocator = () =>
            {
                if (HttpContext.Current == null)
                {
                    return(GetOrCreateStatic());
                }
                var currentContext = HttpContext.Current;
                var locator        = currentContext.Items["ServiceLocator"];
                if (locator == null)
                {
                    var loc      = new ServiceLocator(); // side effects
                    var fromHttp = HttpContext.Current.Items["ServiceLocator"] as IServiceLocator;
                    if (loc != fromHttp)
                    {
                        throw new InvalidOperationException("Invalid service locator");
                    }
                }
                return(HttpContext.Current.Items["ServiceLocator"] as IServiceLocator);
            };
        }