Ejemplo n.º 1
0
        void IShellSettingsManager.SaveSettings(ShellSettings shellSettings)
        {
            Argument.ThrowIfNull(shellSettings, nameof(shellSettings));
            Argument.ThrowIfNullOrWhiteSpace(shellSettings.Name,
                nameof(shellSettings.Name),
                "The Name property of the supplied ShellSettings object is null or empty; the settings cannot be saved.");

            if (_logger.IsEnabled(LogLevel.Information))
            {
                _logger.LogInformation("Saving ShellSettings for tenant '{0}'", shellSettings.Name);
            }
            var tenantPath = _appDataFolder.MapPath(
                _appDataFolder.Combine(
                    _optionsAccessor.Value.Location, 
                    shellSettings.Name, 
                    string.Format(SettingsFileNameFormat, "txt")));

            var configurationProvider = 
                new YamlConfigurationProvider(tenantPath, false);

            foreach (var key in shellSettings.Keys)
            {
                if (!string.IsNullOrEmpty(shellSettings[key]))
                {
                    configurationProvider.Set(key, shellSettings[key]);
                }
            }

            configurationProvider.Commit();

            if (_logger.IsEnabled(LogLevel.Information))
            {
                _logger.LogInformation("Saved ShellSettings for tenant '{0}'", shellSettings.Name);
            }
        }
Ejemplo n.º 2
0
        public void Add(ShellSettings settings)
        {
            _lock.EnterWriteLock();
            try
            {
                // _single is set when there is only a single tenant
                if (_single != null)
                {
                    _single = null;
                }
                else
                {
                    _single = settings;
                }

                if(ShellHelper.DefaultShellName == settings.Name)
                {
                    _default = settings;
                }

                var hostAndPrefix = GetHostAndPrefix(settings);
                _shellsByHostAndPrefix.Add(hostAndPrefix, settings);
            }
            finally
            {
                _lock.ExitWriteLock();
            }
        }
Ejemplo n.º 3
0
        public AdminController(
            IContentDefinitionDisplayManager contentDefinitionDisplayManager,
            IContentDefinitionService contentDefinitionService,
            IContentDefinitionManager contentDefinitionManager,
            ShellSettings settings,
            IAuthorizationService authorizationService,
            ISession session,
            ILogger<AdminController> logger,
            IHtmlLocalizer<AdminMenu> htmlLocalizer,
            IStringLocalizer<AdminMenu> stringLocalizer,
            INotifier notifier
            )
        {
            _notifier = notifier;
            _contentDefinitionDisplayManager = contentDefinitionDisplayManager;
            _session = session;
            _authorizationService = authorizationService;
            _contentDefinitionService = contentDefinitionService;
            _contentDefinitionManager = contentDefinitionManager;
            _settings = settings;

            Logger = logger;
            T = htmlLocalizer;
            S = stringLocalizer;
        }
Ejemplo n.º 4
0
        IEnumerable<ShellSettings> IShellSettingsManager.LoadSettings()
        {
            var shellSettings = new List<ShellSettings>();

            foreach (var tenant in _appDataFolder.ListDirectories("Sites")) {
                _logger.LogInformation("ShellSettings found in '{0}', attempting to load.", tenant.Name);

                var configurationContainer =
                    new ConfigurationBuilder()
                        .AddJsonFile(_appDataFolder.Combine(tenant.PhysicalPath, string.Format(SettingsFileNameFormat, "json")),
                            true)
                        .AddXmlFile(_appDataFolder.Combine(tenant.PhysicalPath, string.Format(SettingsFileNameFormat, "xml")),
                            true)
                        .AddYamlFile(_appDataFolder.Combine(tenant.PhysicalPath, string.Format(SettingsFileNameFormat, "txt")),
                            false);

                var config = configurationContainer.Build();

                var shellSetting = new ShellSettings(config);
                shellSettings.Add(shellSetting);

                _logger.LogInformation("Loaded ShellSettings for tenant '{0}'", shellSetting.Name);
            }

            return shellSettings;
        }
Ejemplo n.º 5
0
 public RoutePublisher(
     IRouteBuilder routeBuilder,
     ShellSettings shellSettings)
 {
     _routeBuilder = routeBuilder;
     _shellSettings = shellSettings;
 }
Ejemplo n.º 6
0
        public SetupController(ISetupService setupService,
            ShellSettings shellSettings)
        {
            _setupService = setupService;
            _shellSettings = shellSettings;

            T = NullLocalizer.Instance;
        }
Ejemplo n.º 7
0
 public TenantRoute(
     ShellSettings shellSettings,
     IEnumerable<IRouter> routes,
     RequestDelegate pipeline)
 {
     _routes = routes;
     _shellSettings = shellSettings;
     _pipeline = pipeline;
 }
Ejemplo n.º 8
0
 public DbContextFactoryHolder(
     ShellSettings shellSettings,
     IEnumerable<IDataServicesProvider> dataServicesProviders,
     IAppDataFolder appDataFolder)
 {
     _shellSettings = shellSettings;
     _dataServicesProviders = dataServicesProviders;
     _appDataFolder = appDataFolder;
 }
Ejemplo n.º 9
0
 public ShellContext GetOrCreateShellContext(ShellSettings settings)
 {
     return _shellContexts.GetOrAdd(settings.Name, tenant =>
     {
         var shellContext = CreateShellContext(settings);
         ActivateShell(shellContext);
         return shellContext;
     });
 }
Ejemplo n.º 10
0
 public AutomaticDataMigrations(
     IServiceProvider serviceProvider,
     ShellSettings shellSettings,
     ILogger<AutomaticDataMigrations> logger)
 {
     _serviceProvider = serviceProvider;
     _shellSettings = shellSettings;
     _logger = logger;
 }
Ejemplo n.º 11
0
        public async Task Invoke(HttpContext httpContext, ShellSettings shellSettings) {
            _orchardShellHost.BeginRequest(shellSettings);

            httpContext.Response.Headers.Append("X-Generator", "Orchard");

            await _next.Invoke(httpContext);

            _orchardShellHost.EndRequest(shellSettings);
        }
Ejemplo n.º 12
0
 public TenantRoute(
     ShellSettings shellSettings,
     IRouter target,
     RequestDelegate pipeline)
 {
     _target = target;
     _shellSettings = shellSettings;
     _pipeline = pipeline;
 }
Ejemplo n.º 13
0
        public ShellSettings(ShellSettings settings)
        {
            RootConfiguration = new ConfigurationRoot(new[] { new InternalConfigurationProvider() });

            Name = settings.Name;
            RequestUrlHost = settings.RequestUrlHost;
            RequestUrlPrefix = settings.RequestUrlPrefix;
            State = settings.State;
        }
Ejemplo n.º 14
0
        // Build the middleware pipeline for the current tenant
        public RequestDelegate BuildTenantPipeline(ShellSettings shellSettings, IServiceProvider serviceProvider)
        {
            var startups = serviceProvider.GetServices<IStartup>();
            var inlineConstraintResolver = serviceProvider.GetService<IInlineConstraintResolver>();

            IApplicationBuilder appBuilder = new ApplicationBuilder(serviceProvider);

            string routePrefix = "";
            if (!string.IsNullOrWhiteSpace(shellSettings.RequestUrlPrefix))
            {
                routePrefix = shellSettings.RequestUrlPrefix + "/";
            }

            var routeBuilder = new RouteBuilder(appBuilder)
            {
                DefaultHandler = serviceProvider.GetRequiredService<MvcRouteHandler>()
            };

            var prefixedRouteBuilder = new PrefixedRouteBuilder(routePrefix, routeBuilder, inlineConstraintResolver);

            // Register one top level TenantRoute per tenant. Each instance contains all the routes
            // for this tenant.

            // In the case of several tenants, they will all be checked by ShellSettings. To optimize
            // the TenantRoute resolution we can create a single Router type that would index the
            // TenantRoute object by their ShellSetting. This way there would just be one lookup.
            // And the ShellSettings test in TenantRoute would also be useless.

            foreach (var startup in startups)
            {
                startup.Configure(appBuilder, prefixedRouteBuilder, serviceProvider);
            }


            // The default route is added to each tenant as a template route, with a prefix
            prefixedRouteBuilder.Routes.Add(new Route(
                prefixedRouteBuilder.DefaultHandler,
                "Default",
                "{area:exists}/{controller}/{action}/{id?}",
                null,
                null,
                null,
                inlineConstraintResolver)
            );

            // Add home page route
            routeBuilder.Routes.Add(new HomePageRoute(shellSettings.RequestUrlPrefix, routeBuilder, inlineConstraintResolver));

            var router = prefixedRouteBuilder.Build();

            appBuilder.UseRouter(router);

            var pipeline = appBuilder.Build();

            return pipeline;
        }
Ejemplo n.º 15
0
        public SetupController(
            ISetupService setupService,
            ShellSettings shellSettings,
            IStringLocalizer<SetupController> t)
        {
            _setupService = setupService;
            _shellSettings = shellSettings;

            T = t;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Creates a shell context based on shell settings
        /// </summary>
        public ShellContext CreateShellContext(ShellSettings settings)
        {
            if (settings.State == TenantState.Uninitialized) {
                _logger.LogDebug("Creating shell context for tenant {0} setup", settings.Name);
                return _shellContextFactory.CreateSetupContext(settings);
            }

            _logger.LogDebug("Creating shell context for tenant {0}", settings.Name);
            return _shellContextFactory.CreateShellContext(settings);
        }
Ejemplo n.º 17
0
        public void UpdateShellSettings(ShellSettings settings)
        {
            ShellContext context;

            _shellSettingsManager.SaveSettings(settings);
            _runningShellTable.Update(settings);
            _shellContexts.TryRemove(settings.Name, out context);
            context = CreateShellContext(settings);
            ActivateShell(context);
        }
Ejemplo n.º 18
0
 public ShellStateCoordinator(
     ShellSettings settings,
     IShellStateManager stateManager,
     IDeferredTaskEngine deferredTaskEngine,
     ILogger<ShellStateCoordinator> logger)
 {
     _deferredTaskEngine = deferredTaskEngine;
     _settings = settings;
     _stateManager = stateManager;
     Logger = logger;
 }
Ejemplo n.º 19
0
 public AutomaticDataMigrations(
     IDataMigrationManager dataMigrationManager,
     IFeatureManager featureManager,
     ShellSettings shellSettings,
     ILoggerFactory loggerFactory)
 {
     _dataMigrationManager = dataMigrationManager;
     _featureManager = featureManager;
     _shellSettings = shellSettings;
     _logger = loggerFactory.CreateLogger<AutomaticDataMigrations>();
 }
Ejemplo n.º 20
0
 public AutomaticDataMigrations(
     IDataMigrationManager dataMigrationManager,
     IFeatureManager featureManager,
     ShellSettings shellSettings,
     ILogger<AutomaticDataMigrations> logger)
 {
     _dataMigrationManager = dataMigrationManager;
     _featureManager = featureManager;
     _shellSettings = shellSettings;
     _logger = logger;
 }
Ejemplo n.º 21
0
        public void UpdateShellSettings(ShellSettings settings)
        {
            ShellContext context;

            _shellSettingsManager.SaveSettings(settings);
            _runningShellTable.Remove(settings);
            if (_shellContexts.TryRemove(settings.Name, out context))
            {
                context.Dispose();
            }
            GetOrCreateShellContext(settings);
        }
Ejemplo n.º 22
0
        public ShellSettings(ShellSettings settings)
        {
            RootConfiguration = new ConfigurationRoot(new[] { new InternalConfigurationProvider() });

            Name = settings.Name;
            RequestUrlHost = settings.RequestUrlHost;
            RequestUrlPrefix = settings.RequestUrlPrefix;
            State = settings.State;
            DatabaseProvider = settings.DatabaseProvider;
            ConnectionString = settings.ConnectionString;
            TablePrefix = settings.TablePrefix;
        }
Ejemplo n.º 23
0
 public void Remove(ShellSettings settings)
 {
     _lock.EnterWriteLock();
     try
     {
         _shellsByHostAndPrefix.Remove(GetHostAndPrefix(settings));
     }
     finally
     {
         _lock.ExitWriteLock();
     }
 }
Ejemplo n.º 24
0
        public ShellSettings(ShellSettings settings)
        {
            _values = new Dictionary<string, string>(settings._values, StringComparer.OrdinalIgnoreCase);

            Name = settings.Name;
            RequestUrlHost = settings.RequestUrlHost;
            RequestUrlPrefix = settings.RequestUrlPrefix;
            State = settings.State;
            DatabaseProvider = settings.DatabaseProvider;
            ConnectionString = settings.ConnectionString;
            TablePrefix = settings.TablePrefix;
            State = settings.State;
        }
Ejemplo n.º 25
0
 public void Update(ShellSettings settings)
 {
     _lock.EnterWriteLock();
     try
     {
         var hostAndPrefix = GetHostAndPrefix(settings);
         _shellsByHostAndPrefix.Remove(hostAndPrefix);
         _shellsByHostAndPrefix.Add(hostAndPrefix, settings);
     }
     finally
     {
         _lock.ExitWriteLock();
     }
 }
Ejemplo n.º 26
0
 public NavigationManager(
     IEnumerable<INavigationProvider> navigationProviders,
     ILogger<NavigationManager> logger,
     ShellSettings shellSettings,
     IUrlHelperFactory urlHelperFactory
     //IAuthorizationService authorizationService ,
     )
 {
     _navigationProviders = navigationProviders;
     _logger = logger;
     _shellSettings = shellSettings;
     _urlHelperFactory = urlHelperFactory;
     //_authorizationService = authorizationService;
 }
Ejemplo n.º 27
0
 public OrchardShell(
     IEnumerable<IRouteProvider> routeProviders,
     IRoutePublisher routePublisher,
     IEnumerable<IMiddlewareProvider> middlewareProviders,
     ShellSettings shellSettings,
     IServiceProvider serviceProvider
     )
 {
     _routeProviders = routeProviders;
     _routePublisher = routePublisher;
     _middlewareProviders = middlewareProviders;
     _shellSettings = shellSettings;
     _serviceProvider = serviceProvider;
 }
Ejemplo n.º 28
0
 public ShellStateUpdater(
     ShellSettings settings,
     IShellStateManager stateManager,
     IExtensionManager extensionManager,
     IEventBus eventBus,
     IDeferredTaskEngine deferredTaskEngine,
     ILogger<ShellStateCoordinator> logger)
 {
     _deferredTaskEngine = deferredTaskEngine;
     _settings = settings;
     _stateManager = stateManager;
     _extensionManager = extensionManager;
     _eventBus = eventBus;
     Logger = logger;
 }
Ejemplo n.º 29
0
        public void Add(ShellSettings settings)
        {
            _lock.EnterWriteLock();
            try {
                _shells = _shells
                    .Where(s => s.Name != settings.Name)
                    .Concat(new[] { settings })
                    .ToArray();

                Organize();
            }
            finally {
                _lock.ExitWriteLock();
            }
        }
Ejemplo n.º 30
0
        public string Setup(SetupContext context)
        {
            string executionId = Guid.NewGuid().ToString();

            // The vanilla Orchard distibution has the following features enabled.
            string[] hardcoded = {
                // Framework
                "Orchard.Hosting",
                // Core
                "Settings",
                // Test Modules
                "Orchard.Demo", "Orchard.Test1"
                };

            context.EnabledFeatures = hardcoded.Union(context.EnabledFeatures ?? Enumerable.Empty<string>()).Distinct().ToList();

            var shellSettings = new ShellSettings();
            shellSettings.Name = context.SiteName;

            //if (shellSettings.DataProviders.Any()) {
            //    DataProvider provider = new DataProvider();
                //shellSettings.DataProvider = context.DatabaseProvider;
                //shellSettings.DataConnectionString = context.DatabaseConnectionString;
                //shellSettings.DataTablePrefix = context.DatabaseTablePrefix;
            //}

            // TODO: Add Encryption Settings in

            var shellDescriptor = new ShellDescriptor {
                Features = context.EnabledFeatures.Select(name => new ShellFeature { Name = name })
            };

            // creating a standalone environment.
            // in theory this environment can be used to resolve any normal components by interface, and those
            // components will exist entirely in isolation - no crossover between the safemode container currently in effect

            // must mark state as Running - otherwise standalone enviro is created "for setup"
            shellSettings.State = TenantState.Running;

            // TODO: Remove and mirror Orchard Setup
            shellSettings.RequestUrlHost = _httpContextAccessor.HttpContext.Request.Host.Value;
            shellSettings.RequestUrlPrefix = string.Empty;
            //shellSettings.DataProvider = "InMemory";

            _shellSettingsManager.SaveSettings(shellSettings);

            return executionId;
        }
Ejemplo n.º 31
0
 public ShellSettings(ShellSettings settings)
 {
     _values = new Dictionary <string, string>(settings._values, StringComparer.OrdinalIgnoreCase);
     State   = settings.State;
 }
Ejemplo n.º 32
0
 public void SaveSettings(ShellSettings shellSettings)
 {
 }
Ejemplo n.º 33
0
 private string GetHostAndPrefix(ShellSettings shellSettings)
 {
     return(shellSettings.RequestUrlHost + "/" + shellSettings.RequestUrlPrefix);
 }
Ejemplo n.º 34
0
 public void UpdateShellSettings(ShellSettings settings)
 {
     _shellSettingsManager.SaveSettings(settings);
     ReloadShellContext(settings);
 }