public void SetLocale() { if (User.Identity.IsAuthenticated) { _userLocale.Locale = User.Identity.GetUserLocale(); return; } var rq = Request.QueryString["lang"]; var loc = WebUserLocale.Lang2Locale(rq); if (loc != null) { Response.Cookies.Add(new HttpCookie(LOCALE_COOKIE, loc)); _userLocale.Locale = loc; return; } var locale = Request.Cookies[LOCALE_COOKIE]; if (locale != null) { // CheckValue _userLocale.Locale = WebUserLocale.CheckLocale(locale.Value); return; } }
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); }; }
public void ParseFile() { var profiler = new NullProfiler(); var userLocale = new WebUserLocale(); var host = new WebApplicationHost(profiler, userLocale); host.StartApplication(false); var parser = new TSDefParser(host.ApplicationReader, "typescript"); parser.Parse("model.d.ts"); }
public static void StartServices() { // DI ready ServiceLocator.Start = (IServiceLocator locator) => { IProfiler profiler = new WebProfiler(); IUserLocale userLocale = new WebUserLocale(); IApplicationHost host = new WebApplicationHost(profiler, userLocale); 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); 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); IHttpService httpService = new HttpService(); IJavaScriptEngine javaScriptEngine = new JavaScriptEngine(dbContext, 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 <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); if (HttpContext.Current != null) { 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); }; }