Esempio n. 1
0
        public ShellSettings(ShellSettings settings) {
            _values = new Dictionary<string, string>(settings._values, StringComparer.OrdinalIgnoreCase);

            Name = settings.Name;
            RequestUrlPrefix = settings.RequestUrlPrefix;
            State = settings.State;
        }
Esempio n. 2
0
 public RoutePublisher(
     IRouteBuilder routeBuilder,
     ShellSettings shellSettings)
 {
     _routeBuilder = routeBuilder;
     _shellSettings = shellSettings;
 }
Esempio n. 3
0
        public SetupController(ISetupService setupService,
            ShellSettings shellSettings)
        {
            _setupService = setupService;
            _shellSettings = shellSettings;

            T = NullLocalizer.Instance;
        }
 public DbContextFactoryHolder(
     ShellSettings shellSettings,
     IDataServicesProviderFactory dataServicesProviderFactory,
     IAppDataFolder appDataFolder)
 {
     _shellSettings = shellSettings;
     _dataServicesProviderFactory = dataServicesProviderFactory;
     _appDataFolder = appDataFolder;
 }
Esempio n. 5
0
        /// <summary>
        /// Creates a shell context based on shell settings
        /// </summary>
        public ShellContext CreateShellContext(ShellSettings settings)
        {
            if (settings.State == TenantState.Uninitialized) {
                Logger.Debug("Creating shell context for tenant {0} setup", settings.Name);
                return _shellContextFactory.CreateSetupContext(settings);
            }

            Logger.Debug("Creating shell context for tenant {0}", settings.Name);
            return _shellContextFactory.CreateShellContext(settings);
        }
Esempio n. 6
0
        public IServiceProvider CreateContainer(ShellSettings settings, ShellBlueprint blueprint)
        {
            ServiceCollection serviceCollection = new ServiceCollection();

            serviceCollection.AddScoped<IOrchardShell, DefaultOrchardShell>();
            serviceCollection.AddScoped<IRouteBuilder, DefaultShellRouteBuilder>();
            serviceCollection.AddInstance(settings);
            serviceCollection.AddInstance(blueprint.Descriptor);
            serviceCollection.AddInstance(blueprint);

            foreach (var dependency in blueprint.Dependencies
                .Where(t => typeof (IModule).IsAssignableFrom(t.Type))) {

                Logger.Debug("IModule Type: {0}", dependency.Type);

                // TODO: Rewrite to get rid of reflection.
                var instance = (IModule) Activator.CreateInstance(dependency.Type);
                instance.Configure(serviceCollection);
            }

            var p = _serviceProvider.GetService<IOrchardLibraryManager>();
            serviceCollection.AddInstance<IAssemblyProvider>(new DefaultAssemblyProviderTest(p, _serviceProvider, _serviceProvider.GetService<IAssemblyLoaderContainer>()));

            foreach (var dependency in blueprint.Dependencies
                .Where(t => !typeof(IModule).IsAssignableFrom(t.Type)))
            {
                foreach (var interfaceType in dependency.Type.GetInterfaces()
                    .Where(itf => typeof(IDependency).IsAssignableFrom(itf)))
                {
                    Logger.Debug("Type: {0}, Interface Type: {1}", dependency.Type, interfaceType);

                    if (typeof(ISingletonDependency).IsAssignableFrom(interfaceType))
                    {
                        serviceCollection.AddSingleton(interfaceType, dependency.Type);
                    }
                    else if (typeof(IUnitOfWorkDependency).IsAssignableFrom(interfaceType))
                    {
                        serviceCollection.AddScoped(interfaceType, dependency.Type);
                    }
                    else if (typeof(ITransientDependency).IsAssignableFrom(interfaceType))
                    {
                        serviceCollection.AddTransient(interfaceType, dependency.Type);
                    }
                    else
                    {
                        serviceCollection.AddScoped(interfaceType, dependency.Type);
                    }
                }
            }

            serviceCollection.AddLogging();

            return new WrappingServiceProvider(_serviceProvider, serviceCollection);
        }
Esempio n. 7
0
        public ShellSettings(ShellSettings settings)
        {
            _values = new Dictionary<string, string>(settings._values, StringComparer.OrdinalIgnoreCase);

            Name = settings.Name;
            DataProvider = settings.DataProvider;
            DataConnectionString = settings.DataConnectionString;
            DataTablePrefix = settings.DataTablePrefix;
            RequestUrlHost = settings.RequestUrlHost;
            RequestUrlPrefix = settings.RequestUrlPrefix;
            State = settings.State;
        }
Esempio n. 8
0
 public DefaultOrchardShell(
     IEnumerable<IRouteProvider> routeProviders,
     IRoutePublisher routePublisher,
     IEnumerable<IMiddlewareProvider> middlewareProviders,
     ShellSettings shellSettings,
     IServiceProvider serviceProvider) {
     _routeProviders = routeProviders;
     _routePublisher = routePublisher;
     _middlewareProviders = middlewareProviders;
     _shellSettings = shellSettings;
     _serviceProvider = serviceProvider;
 }
Esempio n. 9
0
        IEnumerable<ShellSettings> IShellSettingsManager.LoadSettings() {
            var filePaths = _appDataFolder
                .ListDirectories("Sites")
                .SelectMany(path => _appDataFolder.ListFiles(path))
                .Where(path => {
                    var filePathName = Path.GetFileName(path);

                    return _settingFileNameExtensions.Any(p =>
                        string.Equals(filePathName, string.Format(_settingsFileNameFormat, p), StringComparison.OrdinalIgnoreCase)
                    );
                });

            List<ShellSettings> shellSettings = new List<ShellSettings>();

            foreach (var filePath in filePaths) {
                IConfigurationSourceContainer configurationContainer = null;

                var extension = Path.GetExtension(filePath);

                switch (extension) {
                    case ".json":
                        configurationContainer = new Microsoft.Framework.ConfigurationModel.Configuration()
                            .AddJsonFile(filePath);
                        break;
                    case ".xml":
                        configurationContainer = new Microsoft.Framework.ConfigurationModel.Configuration()
                            .AddXmlFile(filePath);
                        break;
                    case ".ini":
                        configurationContainer = new Microsoft.Framework.ConfigurationModel.Configuration()
                            .AddIniFile(filePath);
                        break;
                    case ".txt":
                        configurationContainer = new Microsoft.Framework.ConfigurationModel.Configuration()
                            .Add(new DefaultFileConfigurationSource(_appDataFolder, filePath));
                        break;
                }

                if (configurationContainer != null) {
                    var shellSetting = new ShellSettings {
                        Name = configurationContainer.Get<string>("Name"),
                        RequestUrlPrefix = configurationContainer.Get<string>("RequestUrlPrefix")
                    };

                    TenantState state;
                    shellSetting.State = Enum.TryParse(configurationContainer.Get<string>("State"), true, out state) ? state : TenantState.Uninitialized;

                    shellSettings.Add(shellSetting);
                }
            }

            return shellSettings;
        }
        public IServiceProvider CreateContainer(ShellSettings settings, ShellBlueprint blueprint) {
            ServiceCollection serviceCollection = new ServiceCollection();

            serviceCollection.AddScoped<IOrchardShell, DefaultOrchardShell>();
            serviceCollection.AddScoped<IRouteBuilder, DefaultShellRouteBuilder>();
            serviceCollection.AddInstance(settings);
            serviceCollection.AddInstance(blueprint.Descriptor);
            serviceCollection.AddInstance(blueprint);

            serviceCollection.AddMvc();

            serviceCollection.Configure<RazorViewEngineOptions>(options => {
                var expander = new ModuleViewLocationExpander();
                options.ViewLocationExpanders.Add(expander);
            });

            var p = _serviceProvider.GetService<IOrchardLibraryManager>();
            serviceCollection.AddInstance<IAssemblyProvider>(new DefaultAssemblyProviderTest(p, _serviceProvider, _serviceProvider.GetService<IAssemblyLoaderContainer>()));

            foreach (var dependency in blueprint.Dependencies) {
                foreach (var interfaceType in dependency.Type.GetInterfaces()
                    .Where(itf => typeof(IDependency).IsAssignableFrom(itf))) {
                    Logger.Debug("Type: {0}, Interface Type: {1}", dependency.Type, interfaceType);

                    if (typeof(ISingletonDependency).IsAssignableFrom(interfaceType)) {
                        serviceCollection.AddSingleton(interfaceType, dependency.Type);
                    }
                    else if (typeof(IUnitOfWorkDependency).IsAssignableFrom(interfaceType)) {
                        serviceCollection.AddScoped(interfaceType, dependency.Type);
                    }
                    else if (typeof (ITransientDependency).IsAssignableFrom(interfaceType)) {
                        serviceCollection.AddTransient(interfaceType, dependency.Type);
                    }
                    else {
                        serviceCollection.AddScoped(interfaceType, dependency.Type);
                    }
                }
            }

            //foreach (var item in blueprint.Controllers) {
            //    var serviceKeyName = (item.AreaName + "/" + item.ControllerName).ToLowerInvariant();
            //    var serviceKeyType = item.Type;
            //    serviceCollection.AddScoped(serviceKeyType);

            //}

            return BuildFallbackServiceProvider(
                            serviceCollection,
                            _serviceProvider);
        }
Esempio n. 11
0
 public DefaultContentManager(
     IContentDefinitionManager contentDefinitionManager,
     IContentManagerSession contentManagerSession,
     IEnumerable<IContentHandler> handlers,
     IContentItemStore contentItemStore,
     IContentStorageManager contentStorageManager,
     ShellSettings shellSettings)
 {
     _contentDefinitionManager = contentDefinitionManager;
     _contentManagerSession = contentManagerSession;
     _shellSettings = shellSettings;
     _handlers = handlers;
     _contentItemStore = contentItemStore;
     _contentStorageManager = contentStorageManager;
 }
Esempio n. 12
0
        public string Setup(SetupContext context)
        {
            string executionId = Guid.NewGuid().ToString();

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

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

            var shellSettings = new ShellSettings(_shellSettings);

            if (string.IsNullOrEmpty(shellSettings.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.DataProvider = "InMemory";

            _shellSettingsManager.SaveSettings(shellSettings);

            return executionId;
        }
Esempio n. 13
0
 public SetupService(
     ShellSettings shellSettings,
     IOrchardHost orchardHost,
     IShellSettingsManager shellSettingsManager,
     IShellContainerFactory shellContainerFactory,
     ICompositionStrategy compositionStrategy,
     IExtensionManager extensionManager,
     IHttpContextAccessor httpContextAccessor)
 {
     _shellSettings = shellSettings;
     _orchardHost = orchardHost;
     _shellSettingsManager = shellSettingsManager;
     _shellContainerFactory = shellContainerFactory;
     _compositionStrategy = compositionStrategy;
     _extensionManager = extensionManager;
     _httpContextAccessor = httpContextAccessor;
     T = NullLocalizer.Instance;
 }
Esempio n. 14
0
        IEnumerable<ShellSettings> IShellSettingsManager.LoadSettings()
        {
            var tenantPaths = _appDataFolder
                .ListDirectories("Sites")
                .Select(path => _appDataFolder.MapPath(path));

            var shellSettings = new List<ShellSettings>();

            foreach (var tenantPath in tenantPaths) {
                Logger.Information("ShellSettings found in '{0}', attempting to load.", tenantPath);

                var configurationContainer =
                    new ConfigurationBuilder()
                        .AddJsonFile(_appDataFolder.Combine(tenantPath, string.Format(_settingsFileNameFormat, "json")),
                            true)
                        .AddXmlFile(_appDataFolder.Combine(tenantPath, string.Format(_settingsFileNameFormat, "xml")),
                            true)
                        .Add(
                            new DefaultFileConfigurationSource(
                                _appDataFolder.Combine(tenantPath, string.Format(_settingsFileNameFormat, "txt")), false));

                var config = configurationContainer.Build();

                var shellSetting = new ShellSettings {
                    Name = config.Get("Name"),
                    DataConnectionString = config.Get("DataConnectionString"),
                    DataProvider = config.Get("DataProvider"),
                    DataTablePrefix = config.Get("DataTablePrefix"),
                    RequestUrlHost = config.Get("RequestUrlHost"),
                    RequestUrlPrefix = config.Get("RequestUrlPrefix")
                };

                TenantState state;
                shellSetting.State = Enum.TryParse(config.Get("State"), true, out state)
                    ? state
                    : TenantState.Uninitialized;

                shellSettings.Add(shellSetting);

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

            return shellSettings;
        }
Esempio n. 15
0
        ShellContext IShellContextFactory.CreateShellContext(
            ShellSettings settings) {
            Console.WriteLine("Creating shell context for tenant {0}", settings.Name);

            var blueprint = _compositionStrategy.Compose(settings, MinimumShellDescriptor());
            var provider = _shellContainerFactory.CreateContainer(settings, blueprint);

            try {
                return new ShellContext {
                    Settings = settings,
                    Blueprint = blueprint,
                    LifetimeScope = provider,
                    Shell = provider.GetService<IOrchardShell>()
                };
            }
            catch (Exception ex) {
                Logger.Error(ex.ToString());
                throw;
            }
        }
Esempio n. 16
0
        ShellContext IShellContextFactory.CreateSetupContext(ShellSettings settings)
        {
            Logger.Debug("No shell settings available. Creating shell context for setup");

            var descriptor = new ShellDescriptor {
                SerialNumber = -1,
                Features = new[] {
                    new ShellFeature { Name = "OrchardVNext.Setup" },
                },
            };

            var blueprint = _compositionStrategy.Compose(settings, descriptor);
            var provider = _shellContainerFactory.CreateContainer(settings, blueprint);

            return new ShellContext {
                Settings = settings,
                Blueprint = blueprint,
                LifetimeScope = provider,
                Shell = provider.GetService<IOrchardShell>()
            };
        }
Esempio n. 17
0
        public Class(ShellSettings shellSettings,ILogger logger)
        {
            _shellSettings = shellSettings;	     
	        _logger = logger;
        }
Esempio n. 18
0
        void IShellSettingsManager.SaveSettings(ShellSettings shellSettings)
        {
            if (shellSettings == null)
                throw new ArgumentNullException(nameof(shellSettings));
            if (string.IsNullOrWhiteSpace(shellSettings.Name))
                throw new ArgumentException(
                    "The Name property of the supplied ShellSettings object is null or empty; the settings cannot be saved.",
                    nameof(shellSettings.Name));

            Logger.Information("Saving ShellSettings for tenant '{0}'", shellSettings.Name);

            var tenantPath = _appDataFolder.MapPath(_appDataFolder.Combine("Sites", shellSettings.Name));

            var configurationSource = new DefaultFileConfigurationSource(
                _appDataFolder.Combine(tenantPath, string.Format(_settingsFileNameFormat, "txt")), false);

            foreach (var key in shellSettings.Keys) {
                configurationSource.Set(key, (shellSettings[key] ?? string.Empty).ToString());
            }

            configurationSource.Commit();

            Logger.Information("Saved ShellSettings for tenant '{0}'", shellSettings.Name);
        }
 void IOrchardShellHost.BeginRequest(ShellSettings settings) {
     Logger.Debug("Begin Request for tenant {0}", settings.Name);
 }
        IEnumerable <ShellSettings> IShellSettingsManager.LoadSettings()
        {
            var filePaths = _appDataFolder
                            .ListDirectories("Sites")
                            .SelectMany(path => _appDataFolder.ListFiles(path))
                            .Where(path => {
                var filePathName = Path.GetFileName(path);

                return(_settingFileNameExtensions.Any(p =>
                                                      string.Equals(filePathName, string.Format(_settingsFileNameFormat, p), StringComparison.OrdinalIgnoreCase)
                                                      ));
            });

            List <ShellSettings> shellSettings = new List <ShellSettings>();

            foreach (var filePath in filePaths)
            {
                IConfigurationSourceRoot configurationContainer = null;

                var extension = Path.GetExtension(filePath);

                switch (extension)
                {
                case ".json":
                    configurationContainer = new Microsoft.Framework.ConfigurationModel.Configuration()
                                             .AddJsonFile(filePath);
                    break;

                case ".xml":
                    configurationContainer = new Microsoft.Framework.ConfigurationModel.Configuration()
                                             .AddXmlFile(filePath);
                    break;

                case ".ini":
                    configurationContainer = new Microsoft.Framework.ConfigurationModel.Configuration()
                                             .AddIniFile(filePath);
                    break;

                case ".txt":
                    configurationContainer = new Microsoft.Framework.ConfigurationModel.Configuration()
                                             .Add(new DefaultFileConfigurationSource(_appDataFolder, filePath));
                    break;
                }

                if (configurationContainer != null)
                {
                    var shellSetting = new ShellSettings {
                        Name = configurationContainer.Get <string>("Name"),
                        DataConnectionString = configurationContainer.Get <string>("DataConnectionString"),
                        DataProvider         = configurationContainer.Get <string>("DataProvider"),
                        DataTablePrefix      = configurationContainer.Get <string>("DataTablePrefix"),
                        RequestUrlHost       = configurationContainer.Get <string>("RequestUrlHost"),
                        RequestUrlPrefix     = configurationContainer.Get <string>("RequestUrlPrefix")
                    };

                    TenantState state;
                    shellSetting.State = Enum.TryParse(configurationContainer.Get <string>("State"), true, out state) ? state : TenantState.Uninitialized;

                    shellSettings.Add(shellSetting);
                }
            }

            return(shellSettings);
        }
Esempio n. 21
0
 public Class(ShellSettings shellSettings)
 {
     _shellSettings = shellSettings;
 }
Esempio n. 22
0
 public Routes(ShellSettings shellSettings) {
     _shellSettings = shellSettings;
 }