private void SaveProfile() { if (HasPassword) { if (!string.IsNullOrEmpty(NewPassword)) { if (NewPassword == RetypedNewPassword) { if (_user.Password == OldPassword) { _user.Password = NewPassword; } } } } else { _user.Password = string.Empty; } SaveAvatar(); using (IWorkContextScope scope = _serviceLocator.GetInstance <IWorkEnvironment>().GetWorkContextScope()) { IUserService userService = _serviceLocator.GetInstance <IUserService>(); userService.Update(_user); } MessageBox.Show("保存成功"); }
/// <summary> /// Gets all themes for the specified tenant. /// </summary> /// <param name="tenant">The name of the tenant.</param> /// <returns>An array of objects representing themes from the specified tenant.</returns> public OrchardTheme[] GetThemes(string tenant) { using (IWorkContextScope workContext = this.CreateWorkContextScope(tenant)) { var dataMigrationManager = workContext.Resolve <IDataMigrationManager>(); IEnumerable <string> featuresThatNeedUpdate = dataMigrationManager.GetFeaturesThatNeedUpdate(); var extensionManager = workContext.Resolve <IExtensionManager>(); OrchardFeature[] tenantFeatures = this.GetFeatures(tenant); var services = workContext.Resolve <IOrchardServices>(); string currentThemeId = services.WorkContext.CurrentSite.As <ThemeSiteSettingsPart>().CurrentThemeName; return(extensionManager.AvailableExtensions() .Where(d => DefaultExtensionTypes.IsTheme(d.ExtensionType)) .Where(d => d.Tags != null && d.Tags.Split(',').Any( t => t.Trim().Equals("hidden", StringComparison.OrdinalIgnoreCase)) == false) .Select( d => new OrchardTheme { Module = MapDescriptorToOrchardModule(d), Enabled = tenantFeatures.Any(f => f.Id == d.Id && f.Enabled), Activated = d.Id == currentThemeId, NeedsUpdate = featuresThatNeedUpdate.Contains(d.Id), TenantName = tenant }) .ToArray()); } }
public ISession For(Type entityType) { Logger.Debug("Acquiring session for {0}", entityType); IWorkContextScope currentScope = _workEnvironment.GetWorkContextScope(); object session = null; if (!currentScope.Items.TryGetValue(ContextKey, out session)) { currentScope.Disposing += WorkUnitScope_Disposing; var sessionFactory = _sessionFactoryHolder.GetSessionFactory(); ITransactionManager txManager = ServiceLocator.Current.GetInstance <ITransactionManager>(); txManager.Demand(); currentScope.Items.Add(TransactionKey, txManager); Logger.Debug("Openning database session"); session = sessionFactory.OpenSession(); currentScope.Items.Add(ContextKey, session); } return(session as ISession); }
private void ProcessLogOn() { if (_lockLogOn) { return; } _lockLogOn = true; User savedUser = null; bool isLogOnOk = false; using (IWorkContextScope scope = _workEnvironment.GetWorkContextScope()) { if ((isLogOnOk = _userService.LogOn(UserName, Password))) { savedUser = _userService.GetUser(UserName); } } if (isLogOnOk) { GoBack(savedUser); } else { HasError = true; ErrorMessage = _userService.ErrorString; } _lockLogOn = false; }
private void CreateNewUser() { User savedUser = null; IsRegisterFailed = false; ErrorMessage = string.Empty; using (IWorkContextScope scope = _workEnvironment.GetWorkContextScope()) { savedUser = _userService.GetUser(UserName); if (savedUser == null) { savedUser = _userService.Register(_user); _sessionManager.Add(savedUser); } else { IsRegisterFailed = true; ErrorMessage = _userService.ErrorString; } } if (!IsRegisterFailed) { GoBack(savedUser); } }
private void CreateTenantData(SetupContext context, IWorkContextScope environment) { // create superuser var membershipService = environment.Resolve <IMembershipService>(); var user = membershipService.CreateUser(new CreateUserParams(context.AdminUsername, context.AdminPassword, String.Empty, true)); // set superuser as current user for request (it will be set as the owner of all content items) var authenticationService = environment.Resolve <IAuthenticationService>(); authenticationService.SetAuthenticatedUserForRequest(user); // set site name and settings var siteService = environment.Resolve <ISiteService>(); var siteSettings = (SiteSettings)siteService.GetSiteSettings(); siteSettings.SiteSalt = Guid.NewGuid().ToString("N"); siteSettings.SiteName = context.SiteName; siteSettings.SuperUser = context.AdminUsername; var settingService = environment.Resolve <ISettingService>(); settingService.SaveSetting(siteSettings); // null check: temporary fix for running setup in command line if (HttpContext.Current != null) { authenticationService.SignIn(user, true); } }
public void TestWhat() { using (IWorkContextScope scope = _container.Resolve <IWorkEnvironment>().GetWorkContextScope()) { IDataMigrationManager migrationManager = _container.Resolve <IDataMigrationManager>(); migrationManager.Migrate(); } }
public void LoadDietPlanData() { using (IWorkContextScope scope = _workEnviroment.GetWorkContextScope()) { foreach (var dietPlan in _dataSource.DietPlans) { _foodService.DietPlanProvider.Create(dietPlan); } } }
public void LoadNutritionalElementData() { using (IWorkContextScope scope = _workEnviroment.GetWorkContextScope()) { foreach (var nutrionalElement in _dataSource.NutritionalElements) { _foodService.NutritionElementProvider.Create(nutrionalElement); } } }
public void LoadFoodData() { using (IWorkContextScope scope = _workEnviroment.GetWorkContextScope()) { foreach (var food in _dataSource.Foods) { _foodService.FoodProvider.Create(food); } } }
public void LoadCategoryData() { using (IWorkContextScope scope = _workEnviroment.GetWorkContextScope()) { foreach (var category in _dataSource.Categories) { _foodService.CategoryProvider.Create(category); } } }
public CoeveryInstanceContext(IWorkContextAccessor workContextAccessor) { _workContext = workContextAccessor.GetContext(); if (_workContext == null) { _workContextScope = workContextAccessor.CreateWorkContextScope(); _workContext = _workContextScope.WorkContext; } }
public RabbitInstanceContext(IWorkContextAccessor workContextAccessor) { _workContext = workContextAccessor.GetContext(); if (_workContext != null) { return; } _workContextScope = workContextAccessor.CreateWorkContextScope(); _workContext = _workContextScope.WorkContext; }
private void WorkUnitScope_Disposing(object sender, EventArgs e) { IWorkContextScope scope = (IWorkContextScope)sender; ITransactionManager txManager = scope.Items[TransactionKey] as ITransactionManager; txManager.Dispose(); ISession session = scope.Items[ContextKey] as ISession; session.Close(); }
private IEnumerable <string> GetTenantDatabaseTableNames(IWorkContextScope environment) { var sessionFactoryHolder = environment.Resolve <ISessionFactoryHolder>(); var configuration = sessionFactoryHolder.GetConfiguration(); var result = from mapping in configuration.ClassMappings select mapping.Table.Name; return(result.ToArray()); }
public override ServiceHostBase CreateServiceHost(string constructorString, Uri[] baseAddresses) { IComponentRegistration registration; if (constructorString == null) { throw new ArgumentNullException("constructorString"); } if (constructorString == string.Empty) { throw new ArgumentOutOfRangeException("constructorString"); } if (HostContainer == null) { throw new InvalidOperationException(); } // Create work context IRunningShellTable runningShellTable = HostContainer.Resolve <IRunningShellTable>(); ShellSettings shellSettings = runningShellTable.Match(baseAddresses.First().Host, baseAddresses.First().LocalPath); IBoyingHost BoyingHost = HostContainer.Resolve <IBoyingHost>(); ShellContext shellContext = BoyingHost.GetShellContext(shellSettings); IWorkContextAccessor workContextAccessor = shellContext.LifetimeScope.Resolve <IWorkContextAccessor>(); WorkContext workContext = workContextAccessor.GetContext(); if (workContext == null) { using (IWorkContextScope workContextScope = workContextAccessor.CreateWorkContextScope()) { ILifetimeScope lifetimeScope = workContextScope.Resolve <ILifetimeScope>(); registration = GetRegistration(lifetimeScope, constructorString); } } else { ILifetimeScope lifetimeScope = workContext.Resolve <ILifetimeScope>(); registration = GetRegistration(lifetimeScope, constructorString); } if (registration == null) { throw new InvalidOperationException(); } if (!registration.Activator.LimitType.IsClass) { throw new InvalidOperationException(); } return(CreateServiceHost(workContextAccessor, registration, registration.Activator.LimitType, baseAddresses)); }
private string CreateTenantData(SetupContext context, IWorkContextScope environment) { // Create site owner. var membershipService = environment.Resolve <IMembershipService>(); var user = membershipService.CreateUser( new CreateUserParams(context.AdminUsername, context.AdminPassword, String.Empty, String.Empty, String.Empty, true)); // Set site owner as current user for request (it will be set as the owner of all content items). var authenticationService = environment.Resolve <IAuthenticationService>(); authenticationService.SetAuthenticatedUserForRequest(user); // Set site name and settings. var siteService = environment.Resolve <ISiteService>(); var siteSettings = siteService.GetSiteSettings().As <SiteSettingsPart>(); siteSettings.SiteSalt = Guid.NewGuid().ToString("N"); siteSettings.SiteName = context.SiteName; siteSettings.SuperUser = context.AdminUsername; siteSettings.SiteCulture = "en-US"; // Add default culture. var cultureManager = environment.Resolve <ICultureManager>(); cultureManager.AddCulture("en-US"); var recipeManager = environment.Resolve <IRecipeManager>(); var recipe = context.Recipe; var executionId = recipeManager.Execute(recipe); // Once the recipe has finished executing, we need to update the shell state to "Running", so add a recipe step that does exactly that. var recipeStepQueue = environment.Resolve <IRecipeStepQueue>(); var recipeStepResultRecordRepository = environment.Resolve <IRepository <RecipeStepResultRecord> >(); var activateShellStep = new RecipeStep(Guid.NewGuid().ToString("N"), recipe.Name, "ActivateShell", new XElement("ActivateShell")); recipeStepQueue.Enqueue(executionId, activateShellStep); recipeStepResultRecordRepository.Create(new RecipeStepResultRecord { ExecutionId = executionId, RecipeName = recipe.Name, StepId = activateShellStep.Id, StepName = activateShellStep.Name }); // Null check: temporary fix for running setup in command line. if (HttpContext.Current != null) { authenticationService.SignIn(user, true); } return(executionId); }
private void DropTenantDatabaseTables(IWorkContextScope environment) { var tableNames = GetTenantDatabaseTableNames(environment); var schemaBuilder = new SchemaBuilder(environment.Resolve <IDataMigrationInterpreter>()); foreach (var tableName in tableNames) { try { schemaBuilder.DropTable(schemaBuilder.RemoveDataTablePrefix(tableName)); } catch (Exception ex) { Logger.Warning(ex, "Failed to drop table '{0}'.", tableName); } } }
public void Execute(IWorkContextScope scope) { int maxTries; int messagesPerBatch; var smtpSettings = scope.Resolve <SmtpSettings>(); if (string.IsNullOrEmpty(smtpSettings.Host)) { maxTries = smtpSettings.MaxTries; messagesPerBatch = smtpSettings.MessagesPerBatch; } else { maxTries = 3; messagesPerBatch = 500; } var messageService = scope.Resolve <IMessageService>(); var queuedEmails = messageService.GetQueuedEmails(maxTries, true, false, messagesPerBatch); if (queuedEmails.Count == 0) { return; } var emailSender = scope.Resolve <IEmailSender>(); foreach (var queuedEmail in queuedEmails) { try { var mailMessage = queuedEmail.GetMailMessage(); emailSender.Send(mailMessage); queuedEmail.SentOnUtc = DateTime.UtcNow; } catch (Exception exc) { Logger.Error(string.Format("Error sending e-mail. {0}", exc.Message), exc); } finally { queuedEmail.SentTries = queuedEmail.SentTries + 1; messageService.Update(queuedEmail); } } }
public void Execute(IWorkContextScope scope) { var logger = scope.WorkContext.ResolveWithParameters <ILogger>(new TypedParameter(typeof(Type), typeof(BackupDatabasesTask))); logger.Info("Starting execute Backup Databases Task."); var backupStorageProvider = scope.Resolve <IBackupStorageProvider>(); if (backupStorageProvider == null) { logger.Error("Does not have any backup storage provider in system."); return; } var shellSettingsManager = scope.Resolve <IShellSettingsManager>(); var shellContextFactory = scope.Resolve <IShellContextFactory>(); var allSettings = shellSettingsManager.LoadSettings().ToArray(); var folder = "Backup_" + DateTime.Now.ToString("yyyyMMdd_HHmmss"); foreach (var shellSettings in allSettings) { try { var shellContext = shellContextFactory.CreateShellContext(shellSettings); var workContextScope = shellContext.LifetimeScope.CreateWorkContextScope(); var backupProvider = workContextScope.Resolve <IBackupProvider>(); if (backupProvider == null) { logger.Error("Does not have any backup provider in system."); continue; } string fileName; var stream = backupProvider.Backup(out fileName); if (stream == null) { continue; } backupStorageProvider.Store(stream, folder, fileName, scope); } catch (Exception ex) { logger.InfoFormat(ex, "Cannot backup database for {0} tenant.", shellSettings.Name); } } }
private string CreateTenantData(SetupContext context, IWorkContextScope environment) { // create superuser var membershipService = environment.Resolve <IMembershipService>(); var user = membershipService.CreateUser(new CreateUserParams(context.AdminUsername, context.AdminPassword, String.Empty, String.Empty, String.Empty, true)); // set superuser as current user for request (it will be set as the owner of all content items) var authenticationService = environment.Resolve <IAuthenticationService>(); authenticationService.SetAuthenticatedUserForRequest(user); // set site name and settings var siteService = environment.Resolve <ISiteService>(); var siteSettings = siteService.GetSiteSettings().As <SiteSettingsPart>(); siteSettings.SiteSalt = Guid.NewGuid().ToString("N"); siteSettings.SiteName = context.SiteName; siteSettings.SuperUser = context.AdminUsername; siteSettings.SiteCulture = "en-US"; // add default culture var cultureManager = environment.Resolve <ICultureManager>(); cultureManager.AddCulture("en-US"); var recipeManager = environment.Resolve <IRecipeManager>(); var recipe = Recipes().FirstOrDefault(r => r.Name.Equals(context.Recipe, StringComparison.OrdinalIgnoreCase)); if (recipe == null) { throw new OrchardException(T("The recipe '{0}' could not be found.", context.Recipe)); } var executionId = recipeManager.Execute(recipe); // null check: temporary fix for running setup in command line if (HttpContext.Current != null) { authenticationService.SignIn(user, true); } return(executionId); }
private string CreateTenantData(SetupContext context, IWorkContextScope environment) { // Create superuser. var membershipService = environment.Resolve <IMembershipService>(); var user = membershipService.CreateUser( new CreateUserParams( context.AdminUsername, context.AdminPassword, email: String.Empty, passwordQuestion: String.Empty, passwordAnswer: String.Empty, isApproved: true)); // Set superuser as current user for request (it will be set as the owner of all content items). var authenticationService = environment.Resolve <IAuthenticationService>(); authenticationService.SetAuthenticatedUserForRequest(user); // Set site name and settings. var siteService = environment.Resolve <ISiteService>(); var siteSettings = siteService.GetSiteSettings().As <SiteSettingsPart>(); siteSettings.SiteSalt = Guid.NewGuid().ToString("N"); siteSettings.SiteName = context.SiteName; siteSettings.SuperUser = context.AdminUsername; siteSettings.SiteCulture = "en-US"; // Add default culture. var cultureManager = environment.Resolve <ICultureManager>(); cultureManager.AddCulture("en-US"); // Execute recipe var recipeParser = environment.Resolve <IRecipeParser>(); var recipe = recipeParser.ParseRecipe(context.RecipeDocument); var recipeManager = environment.Resolve <IRecipeManager>(); var executionId = recipeManager.Execute(recipe); // Null check: temporary fix for running setup in command line. if (HttpContext.Current != null) { authenticationService.SignIn(user, true); } return(executionId); }
private string CreateTenantData(SetupContext context, IWorkContextScope environment) { string executionId = null; // create superuser var membershipService = environment.Resolve <IMembershipService>(); var user = membershipService.CreateUser(new CreateUserParams(context.AdminUsername, context.AdminPassword, String.Empty, String.Empty, String.Empty, true)); // set superuser as current user for request (it will be set as the owner of all content items) var authenticationService = environment.Resolve <IAuthenticationService>(); authenticationService.SetAuthenticatedUserForRequest(user); // set site name and settings var siteService = environment.Resolve <ISiteService>(); var siteSettings = siteService.GetSiteSettings().As <SiteSettingsPart>(); siteSettings.Record.SiteSalt = Guid.NewGuid().ToString("N"); siteSettings.Record.SiteName = context.SiteName; siteSettings.Record.SuperUser = context.AdminUsername; siteSettings.Record.SiteCulture = "en-US"; // set site theme var themeService = environment.Resolve <ISiteThemeService>(); themeService.SetSiteTheme("TheThemeMachine"); // add default culture var cultureManager = environment.Resolve <ICultureManager>(); cultureManager.AddCulture("en-US"); var recipeManager = environment.Resolve <IRecipeManager>(); executionId = recipeManager.Execute(Recipes().Where(r => r.Name == context.Recipe).FirstOrDefault()); //null check: temporary fix for running setup in command line if (HttpContext.Current != null) { authenticationService.SignIn(user, true); } return(executionId); }
/// <summary> /// Enables the specified theme for a tenant. /// </summary> /// <param name="tenant">The name of the tenant for which the theme will be enabled.</param> /// <param name="id">The identifier of the theme to enable.</param> public void EnableTheme(string tenant, string id) { using (IWorkContextScope workContext = this.CreateWorkContextScope(tenant)) { var extensionManager = workContext.Resolve <IExtensionManager>(); ExtensionDescriptor theme = extensionManager.AvailableExtensions().FirstOrDefault(x => x.Id == id); if (theme == null) { throw new ArgumentException("Could not find theme '" + id + "'.", "id"); } var featureManager = workContext.Resolve <IFeatureManager>(); if (featureManager.GetEnabledFeatures().All(sf => sf.Id != theme.Id)) { var themeService = workContext.Resolve <IThemeService>(); themeService.EnableThemeFeatures(theme.Id); } var siteThemeService = workContext.Resolve <ISiteThemeService>(); siteThemeService.SetSiteTheme(theme.Id); } }
private IEnumerable <string> GetTenantDatabaseTableNames(IWorkContextScope environment) { var shellSettings = environment.Resolve <ShellSettings>(); var sqlStatementProviders = environment.Resolve <IEnumerable <ISqlStatementProvider> >(); var transactionManager = environment.Resolve <ITransactionManager>(); var session = transactionManager.GetSession(); var tenants = GetTenants().Where(x => x.Name != shellSettings.Name); string command = null; IEnumerable <string> result = null; foreach (var sqlStatementProvider in sqlStatementProviders) { if (!String.Equals(sqlStatementProvider.DataProvider, shellSettings.DataProvider)) { continue; } command = sqlStatementProvider.GetStatement("table_names") ?? command; } if (command != null) { var tableNames = session.CreateSQLQuery(command).List <string>(); if (string.IsNullOrWhiteSpace(shellSettings.DataTablePrefix)) { // If current tenant doesn't has table prefix, then exclude all tables which have prefixes for other tenants result = tableNames.Where(table => !tenants.Any(tenant => table.StartsWith(tenant.DataTablePrefix + "_"))); } else { // If current tenant has table prefix, then filter tables which have the right prefix result = tableNames.Where(table => table.StartsWith(shellSettings.DataTablePrefix + "_")); } } return((result ?? Enumerable.Empty <string>()).OrderBy(x => x).ToList()); }
public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData) { scope = workContextAccessor.CreateWorkContextScope(new HttpContextWrapper(context)); var shellSettings = scope.Resolve <ShellSettings>(); if (shellSettings.State == TenantState.Offline) { var appDataFolder = scope.Resolve <IAppDataFolder>(); var path = appDataFolder.Combine("Sites", shellSettings.Name, "App_Offline.htm"); if (appDataFolder.FileExists(path)) { context.Response.WriteFile(appDataFolder.GetVirtualPath(path)); } else { if (appDataFolder.FileExists("App_Offline.htm")) { context.Response.WriteFile(appDataFolder.GetVirtualPath("App_Offline.htm")); } else { context.Response.Write("Sorry, our site is undergoing routine maintenance. Please check back with us soon."); } } var asyncResult = new OfflineAsyncResult(); return(asyncResult); } try { return(httpAsyncHandler.BeginProcessRequest(context, cb, extraData)); } catch { scope.Dispose(); throw; } }
private void ExecuteResetEventHandlers(IWorkContextScope environment) { var handler = environment.Resolve <ITenantResetEventHandler>(); handler.Resetting(); }
private void ExecuteResetEventHandlers(IWorkContextScope environment) { var handler = environment.Resolve<ITenantResetEventHandler>(); handler.Resetting(); }
public void Execute(IWorkContextScope scope) { }
public StandaloneEnvironmentWorkContextScopeWrapper(IWorkContextScope workContextScope, ShellContext shellContext) { _workContextScope = workContextScope; _shellContext = shellContext; }
private string CreateTenantData(SetupContext context, IWorkContextScope environment) { // Create site owner. var membershipService = environment.Resolve<IMembershipService>(); var user = membershipService.CreateUser( new CreateUserParams(context.AdminUsername, context.AdminPassword, String.Empty, String.Empty, String.Empty, true)); // Set site owner as current user for request (it will be set as the owner of all content items). var authenticationService = environment.Resolve<IAuthenticationService>(); authenticationService.SetAuthenticatedUserForRequest(user); // Set site name and settings. var siteService = environment.Resolve<ISiteService>(); var siteSettings = siteService.GetSiteSettings().As<SiteSettingsPart>(); siteSettings.SiteSalt = Guid.NewGuid().ToString("N"); siteSettings.SiteName = context.SiteName; siteSettings.SuperUser = context.AdminUsername; siteSettings.SiteCulture = "en-US"; // Add default culture. var cultureManager = environment.Resolve<ICultureManager>(); cultureManager.AddCulture("en-US"); var recipeManager = environment.Resolve<IRecipeManager>(); var recipe = context.Recipe; var executionId = recipeManager.Execute(recipe); // Once the recipe has finished executing, we need to update the shell state to "Running", so add a recipe step that does exactly that. var recipeStepQueue = environment.Resolve<IRecipeStepQueue>(); var recipeStepResultRecordRepository = environment.Resolve<IRepository<RecipeStepResultRecord>>(); var activateShellStep = new RecipeStep(Guid.NewGuid().ToString("N"), recipe.Name, "ActivateShell", new XElement("ActivateShell")); recipeStepQueue.Enqueue(executionId, activateShellStep); recipeStepResultRecordRepository.Create(new RecipeStepResultRecord { ExecutionId = executionId, RecipeName = recipe.Name, StepId = activateShellStep.Id, StepName = activateShellStep.Name }); // Null check: temporary fix for running setup in command line. if (HttpContext.Current != null) { authenticationService.SignIn(user, true); } return executionId; }
private void DropTenantDatabaseTables(IWorkContextScope environment) { var tableNames = GetTenantDatabaseTableNames(environment); var schemaBuilder = new SchemaBuilder(environment.Resolve<IDataMigrationInterpreter>()); foreach (var tableName in tableNames) { try { schemaBuilder.DropTable(schemaBuilder.RemoveDataTablePrefix(tableName)); } catch (Exception ex) { Logger.Warning(ex, "Failed to drop table '{0}'.", tableName); } } }
private string CreateTenantData(SetupContext context, IWorkContextScope environment) { // create superuser var membershipService = environment.Resolve<IMembershipService>(); var user = membershipService.CreateUser(new CreateUserParams(context.AdminUsername, context.AdminPassword, String.Empty, String.Empty, String.Empty, true)); // set superuser as current user for request (it will be set as the owner of all content items) var authenticationService = environment.Resolve<IAuthenticationService>(); authenticationService.SetAuthenticatedUserForRequest(user); // set site name and settings var siteService = environment.Resolve<ISiteService>(); var siteSettings = siteService.GetSiteSettings().As<SiteSettingsPart>(); siteSettings.Record.SiteSalt = Guid.NewGuid().ToString("N"); siteSettings.Record.SiteName = context.SiteName; siteSettings.Record.SuperUser = context.AdminUsername; siteSettings.Record.SiteCulture = "en-US"; // add default culture var cultureManager = environment.Resolve<ICultureManager>(); cultureManager.AddCulture("en-US"); var recipeManager = environment.Resolve<IRecipeManager>(); string executionId = recipeManager.Execute(Recipes().FirstOrDefault(r => r.Name.Equals(context.Recipe, StringComparison.OrdinalIgnoreCase))); // null check: temporary fix for running setup in command line if (HttpContext.Current != null) { authenticationService.SignIn(user, true); } return executionId; }
private void CreateTenantData(SetupContext context, IWorkContextScope environment) { // create superuser var membershipService = environment.Resolve<IMembershipService>(); var user = membershipService.CreateUser(new CreateUserParams(context.AdminUsername, context.AdminPassword, String.Empty, true)); // set superuser as current user for request (it will be set as the owner of all content items) var authenticationService = environment.Resolve<IAuthenticationService>(); authenticationService.SetAuthenticatedUserForRequest(user); // set site name and settings var siteService = environment.Resolve<ISiteService>(); var siteSettings = (SiteSettings)siteService.GetSiteSettings(); siteSettings.SiteSalt = Guid.NewGuid().ToString("N"); siteSettings.SiteName = context.SiteName; siteSettings.SuperUser = context.AdminUsername; var settingService = environment.Resolve<ISettingService>(); settingService.SaveSetting(siteSettings); // null check: temporary fix for running setup in command line if (HttpContext.Current != null) { authenticationService.SignIn(user, true); } }
private IEnumerable<string> GetTenantDatabaseTableNames(IWorkContextScope environment) { var sessionFactoryHolder = environment.Resolve<ISessionFactoryHolder>(); var configuration = sessionFactoryHolder.GetConfiguration(); var result = from mapping in configuration.ClassMappings select mapping.Table.Name; return result.ToArray(); }
private string CreateTenantData(SetupContext context, IWorkContextScope environment) { // set site name and settings var siteService = environment.Resolve<ISiteService>(); var siteSettings = siteService.GetSiteSettings().As<SiteSettingsPart>(); siteSettings.SiteSalt = Guid.NewGuid().ToString("N"); siteSettings.SiteName = context.SiteName; siteSettings.SuperUser = context.AdminUsername; siteSettings.SiteCulture = "en-US"; // add default culture var cultureManager = environment.Resolve<ICultureManager>(); cultureManager.AddCulture("en-US"); var recipeManager = environment.Resolve<IRecipeManager>(); string executionId = recipeManager.Execute(Recipes().FirstOrDefault(r => r.Name.Equals(context.Recipe, StringComparison.OrdinalIgnoreCase))); return executionId; }