コード例 #1
0
        /// <summary>
        /// 将一个外壳描述符存储到缓存中。
        /// </summary>
        /// <param name="shellName">外壳名称。</param>
        /// <param name="descriptor">外壳描述符。</param>
        public void Store(string shellName, ShellDescriptor descriptor)
        {
            if (Disabled)
                return;

            lock (SynLock)
            {
                VerifyCacheFile();
                var text = _appDataFolder.ReadFile(DescriptorCacheFileName);
                var tenantCacheUpdated = false;
                var saveWriter = new StringWriter();
                var xmlDocument = new XmlDocument();
                xmlDocument.LoadXml(text);
                XmlNode rootNode = xmlDocument.DocumentElement;
                if (rootNode != null)
                {
                    foreach (var tenantNode in rootNode.ChildNodes.Cast<XmlNode>().Where(tenantNode => string.Equals(tenantNode.Name, shellName, StringComparison.OrdinalIgnoreCase)))
                    {
                        tenantNode.InnerText = GetCacheTextForShellDescriptor(descriptor);
                        tenantCacheUpdated = true;
                        break;
                    }
                    if (!tenantCacheUpdated)
                    {
                        var newTenant = xmlDocument.CreateElement(shellName);
                        newTenant.InnerText = GetCacheTextForShellDescriptor(descriptor);
                        rootNode.AppendChild(newTenant);
                    }
                }

                xmlDocument.Save(saveWriter);
                _appDataFolder.CreateFile(DescriptorCacheFileName, saveWriter.ToString());
            }
        }
コード例 #2
0
 /// <summary>
 /// 当外壳描述符发生变更时执行。
 /// </summary>
 /// <param name="descriptor">新的外壳描述符。</param><param name="tenant">租户名称。</param>
 public void Changed(ShellDescriptor descriptor, string tenant)
 {
     lock (NeedMigratorTenants)
     {
         if (!NeedMigratorTenants.Contains(tenant))
             NeedMigratorTenants.Add(tenant);
     }
 }
コード例 #3
0
 public ShapePlacementParsingStrategy(
     IExtensionManager extensionManager,
     ShellDescriptor shellDescriptor,
     IPlacementFileParser placementFileParser)
 {
     _extensionManager = extensionManager;
     _shellDescriptor = shellDescriptor;
     _placementFileParser = placementFileParser;
 }
コード例 #4
0
        /// <summary>
        /// 获取开启的特性。
        /// </summary>
        /// <param name="extensionManager">扩展管理者。</param>
        /// <param name="descriptor">外壳描述符。</param>
        /// <returns></returns>
        public static IEnumerable<FeatureDescriptor> EnabledFeatures(this IExtensionManager extensionManager, ShellDescriptor descriptor)
        {
            extensionManager.NotNull("extensionManager");

            var features = extensionManager.AvailableFeatures();
            if (descriptor != null)
                features = features.Where(fd => descriptor.Features.Any(sf => sf.Name == fd.Id));

            return features.ToArray();
        }
コード例 #5
0
        public ReactHarvester(IExtensionManager extensionManager, IParallelCacheContext parallelCacheContext,
                              IVirtualPathProvider virtualPathProvider, ShellDescriptor shellDescriptor)
        {
            _extensionManager     = extensionManager;
            _parallelCacheContext = parallelCacheContext;
            _virtualPathProvider  = virtualPathProvider;
            _shellDescriptor      = shellDescriptor;

            Logger = NullLogger.Instance;
        }
コード例 #6
0
 /// <summary>
 /// 当外壳描述符发生变更时执行。
 /// </summary>
 /// <param name="descriptor">新的外壳描述符。</param><param name="tenant">租户名称。</param>
 public void Changed(ShellDescriptor descriptor, string tenant)
 {
     lock (NeedMigratorTenants)
     {
         if (!NeedMigratorTenants.Contains(tenant))
         {
             NeedMigratorTenants.Add(tenant);
         }
     }
 }
コード例 #7
0
        /// <summary>
        /// 当外壳描述符发生变更时执行。
        /// </summary>
        /// <param name="descriptor">新的外壳描述符。</param><param name="tenant">租户名称。</param>
        public void Changed(ShellDescriptor descriptor, string tenant)
        {
            if (!DataMigratorsBuilderExtensions.StartingExecute)
                return;

            lock (NeedMigratorTenants)
            {
                if (!NeedMigratorTenants.Contains(tenant))
                    NeedMigratorTenants.Add(tenant);
            }
        }
コード例 #8
0
        public ModularPageApplicationModelProvider(
            ITypeFeatureProvider typeFeatureProvider,
            IExtensionManager extensionManager,
            ShellDescriptor shellDescriptor)
        {
            // Available features in the current shell.
            _features = extensionManager.GetFeatures().Where(f => shellDescriptor.Features.Any(sf =>
                                                                                               sf.Id == f.Id)).Select(f => f);

            _typeFeatureProvider = typeFeatureProvider;
        }
コード例 #9
0
        public ShellBlueprint Compose(ShellSettings settings, ShellDescriptor descriptor)
        {
            Logger.Debug("Composing blueprint");

            var builtinFeatures           = BuiltinFeatures().ToList();
            var builtinFeatureDescriptors = builtinFeatures.Select(x => x.Descriptor).ToList();
            var availableFeatures         = _extensionManager.AvailableFeatures()
                                            .Concat(builtinFeatureDescriptors)
                                            .GroupBy(x => x.Id.ToLowerInvariant()) // prevent duplicates
                                            .Select(x => x.FirstOrDefault())
                                            .ToDictionary(x => x.Id, StringComparer.OrdinalIgnoreCase);
            var enabledFeatures  = _extensionManager.EnabledFeatures(descriptor).Select(x => x.Id).ToList();
            var expandedFeatures = ExpandDependencies(availableFeatures, descriptor.Features.Select(x => x.Name)).ToList();
            var autoEnabledDependencyFeatures = expandedFeatures.Except(enabledFeatures).Except(builtinFeatureDescriptors.Select(x => x.Id)).ToList();
            var featureDescriptors            = _extensionManager.EnabledFeatures(expandedFeatures.Select(x => new ShellFeature {
                Name = x
            })).ToList();
            var features = _extensionManager.LoadFeatures(featureDescriptors);

            if (descriptor.Features.Any(feature => feature.Name == "Boying.Framework"))
            {
                features = builtinFeatures.Concat(features);
            }

            var excludedTypes   = GetExcludedTypes(features);
            var modules         = BuildBlueprint(features, IsModule, BuildModule, excludedTypes);
            var dependencies    = BuildBlueprint(features, IsDependency, (t, f) => BuildDependency(t, f, descriptor), excludedTypes);
            var controllers     = BuildBlueprint(features, IsController, BuildController, excludedTypes);
            var httpControllers = BuildBlueprint(features, IsHttpController, BuildController, excludedTypes);
            var records         = BuildBlueprint(features, IsRecord, (t, f) => BuildRecord(t, f, settings), excludedTypes);

            var result = new ShellBlueprint
            {
                Settings        = settings,
                Descriptor      = descriptor,
                Dependencies    = dependencies.Concat(modules).ToArray(),
                Controllers     = controllers,
                HttpControllers = httpControllers,
                Records         = records,
            };

            Logger.Debug("Done composing blueprint.");

            if (autoEnabledDependencyFeatures.Any())
            {
                // Add any dependencies previously not enabled to the shell descriptor.
                descriptor.Features = descriptor.Features.Concat(autoEnabledDependencyFeatures.Select(x => new ShellFeature {
                    Name = x
                })).ToList();
                Logger.Information("Automatically enabled the following dependency features: {0}.", String.Join(", ", autoEnabledDependencyFeatures));
            }

            return(result);
        }
コード例 #10
0
 public ShellFeaturesManager(
     IExtensionManager extensionManager,
     ShellDescriptor shellDescriptor,
     IShellDescriptorFeaturesManager shellDescriptorFeaturesManager,
     IEnumerable <IFeatureValidationProvider> featureValidators)
 {
     _extensionManager = extensionManager;
     _shellDescriptor  = shellDescriptor;
     _shellDescriptorFeaturesManager = shellDescriptorFeaturesManager;
     _featureValidators = featureValidators;
 }
コード例 #11
0
        public ComponentViewLocationExpanderProvider(
            RazorCompilationFileProviderAccessor fileProviderAccessor,
            IExtensionManager extensionManager,
            ShellDescriptor shellDescriptor,
            IMemoryCache memoryCache)
        {
            _extensionManager = extensionManager;
            _shellDescriptor  = shellDescriptor;
            _memoryCache      = memoryCache;

            if (_initialized)
            {
                return;
            }

            lock (_synLock)
            {
                if (!_initialized)
                {
                    var modulesWithComponentViews      = new List <IExtensionInfo>();
                    var modulesWithPagesComponentViews = new List <IExtensionInfo>();

                    var orderedModules = _extensionManager.GetExtensions()
                                         .Where(e => e.Manifest.Type.Equals("module", StringComparison.OrdinalIgnoreCase))
                                         .Reverse();

                    foreach (var module in orderedModules)
                    {
                        var moduleComponentsViewFilePaths = fileProviderAccessor.FileProvider.GetViewFilePaths(
                            module.SubPath + "/Views/Shared/Components", RazorExtensions,
                            viewsFolder: null, inViewsFolder: true, inDepth: true);

                        if (moduleComponentsViewFilePaths.Any())
                        {
                            modulesWithComponentViews.Add(module);
                        }

                        var modulePagesComponentsViewFilePaths = fileProviderAccessor.FileProvider.GetViewFilePaths(
                            module.SubPath + "/Pages/Shared/Components", RazorExtensions,
                            viewsFolder: null, inViewsFolder: true, inDepth: true);

                        if (modulePagesComponentsViewFilePaths.Any())
                        {
                            modulesWithPagesComponentViews.Add(module);
                        }
                    }

                    _modulesWithComponentViews      = modulesWithComponentViews;
                    _modulesWithPagesComponentViews = modulesWithPagesComponentViews;

                    _initialized = true;
                }
            }
        }
コード例 #12
0
 public ShapePlacementParsingStrategy(
     IExtensionManager extensionManager,
     ShellDescriptor shellDescriptor,
     IPlacementFileParser placementFileParser,
     IEnumerable <IPlacementParseMatchProvider> placementParseMatchProviders)
 {
     _extensionManager             = extensionManager;
     _shellDescriptor              = shellDescriptor;
     _placementFileParser          = placementFileParser;
     _placementParseMatchProviders = placementParseMatchProviders;
 }
コード例 #13
0
        public ShellBlueprint Compose(ShellSettings settings, ShellDescriptor descriptor)
        {
            if (_logger.IsEnabled(LogLevel.Debug))
            {
                _logger.LogDebug("Composing blueprint");
            }

            var enabledFeatures = _extensionManager.EnabledFeatures(descriptor);
            var features        = _extensionManager.LoadFeatures(enabledFeatures);

            // Requiring "Orchard.Hosting" is a shortcut for adding all referenced
            // assemblies as features
            if (descriptor.Features.Any(feature => feature.Name == "Orchard.Hosting"))
            {
                features = BuiltinFeatures().Concat(features);
            }

            var excludedTypes = GetExcludedTypes(features);

            var modules      = BuildBlueprint(features, IsModule, BuildModule, excludedTypes);
            var dependencies = BuildBlueprint(features, IsDependency, (t, f) => BuildDependency(t, f, descriptor),
                                              excludedTypes);

            var uniqueDependencies = new Dictionary <Type, DependencyBlueprint>();

            foreach (var dependency in dependencies)
            {
                if (!uniqueDependencies.ContainsKey(dependency.Type))
                {
                    uniqueDependencies.Add(dependency.Type, dependency);
                }
            }

            foreach (var dependency in modules)
            {
                if (!uniqueDependencies.ContainsKey(dependency.Type))
                {
                    uniqueDependencies.Add(dependency.Type, dependency);
                }
            }

            var result = new ShellBlueprint
            {
                Settings     = settings,
                Descriptor   = descriptor,
                Dependencies = uniqueDependencies.Values
            };

            if (_logger.IsEnabled(LogLevel.Debug))
            {
                _logger.LogDebug("Done composing blueprint");
            }
            return(result);
        }
コード例 #14
0
        public async Task <ShellBlueprint> ComposeAsync(ShellSettings settings, ShellDescriptor descriptor)
        {
            V_0.u003cu003e4__this    = this;
            V_0.settings             = settings;
            V_0.descriptor           = descriptor;
            V_0.u003cu003et__builder = AsyncTaskMethodBuilder <ShellBlueprint> .Create();

            V_0.u003cu003e1__state = -1;
            V_0.u003cu003et__builder.Start <CompositionStrategy.u003cComposeAsyncu003ed__3>(ref V_0);
            return(V_0.u003cu003et__builder.get_Task());
        }
コード例 #15
0
        public Task <ShellDescriptor> GetShellDescriptorAsync()
        {
            if (_shellDescriptor == null)
            {
                _shellDescriptor = new ShellDescriptor
                {
                    Features = _shellFeatures.ToList()
                };
            }

            return(Task.FromResult(_shellDescriptor));
        }
コード例 #16
0
 public ThemeCommands(IDataMigrationManager dataMigrationManager,
                      ISiteThemeService siteThemeService,
                      IExtensionManager extensionManager,
                      ShellDescriptor shellDescriptor,
                      IThemeService themeService)
 {
     _dataMigrationManager = dataMigrationManager;
     _siteThemeService     = siteThemeService;
     _extensionManager     = extensionManager;
     _shellDescriptor      = shellDescriptor;
     _themeService         = themeService;
 }
コード例 #17
0
        private static string GetCacheTextForShellDescriptor(ShellDescriptor descriptor)
        {
            var sb = new StringBuilder();

            sb.Append(descriptor.SerialNumber + "|");
            foreach (var feature in descriptor.Features)
            {
                sb.Append(feature.Name + ";");
            }

            return(sb.ToString());
        }
コード例 #18
0
 public ThemeController(
     IWorkContextAccessor workContextAccessor,
     ShellSettings shellSettings,
     IExtensionManager extensionManager,
     SiteSettings siteSettings, ShellDescriptor shellDescriptor)
     : base(workContextAccessor)
 {
     this.shellSettings    = shellSettings;
     this.extensionManager = extensionManager;
     this.siteSettings     = siteSettings;
     this.shellDescriptor  = shellDescriptor;
 }
コード例 #19
0
        public Task <ShellDescriptor> GetShellDescriptorAsync()
        {
            if (_shellDescriptor == null)
            {
                _shellDescriptor = new ShellDescriptor
                {
                    Features = _shellSettings.Features.Select(x => new ShellFeature(x)).ToList()
                };
            }

            return(Task.FromResult(_shellDescriptor));
        }
コード例 #20
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);
        }
コード例 #21
0
        string IProcessingEngine.AddTask(ShellSettings shellSettings, ShellDescriptor shellDescriptor, string messageName, Dictionary <string, object> parameters)
        {
            _addedTasks.Add(new ProcessingEngineTask
            {
                ShellSettings   = shellSettings,
                ShellDescriptor = shellDescriptor,
                MessageName     = messageName,
                Parameters      = parameters
            });

            // As in DefaultProcessingEngine.
            return(Guid.NewGuid().ToString("n"));
        }
コード例 #22
0
 public ShapePlacementParsingStrategy(
     IExtensionManager extensionManager,
     ShellDescriptor shellDescriptor,
     IPlacementFileParser placementFileParser,
     IEnumerable <IPlacementPredicateProvider> predicateBuilders,
     IPlacementAlterationProvider alterationBuilder)
 {
     _extensionManager    = extensionManager;
     _shellDescriptor     = shellDescriptor;
     _placementFileParser = placementFileParser;
     _predicateBuilders   = predicateBuilders;
     _alterationBuilder   = alterationBuilder;
 }
コード例 #23
0
 public OpenIdValidationService(
     ShellDescriptor shellDescriptor,
     ShellSettings shellSettings,
     IShellHost shellHost,
     ISiteService siteService,
     IStringLocalizer <OpenIdValidationService> stringLocalizer)
 {
     _shellDescriptor = shellDescriptor;
     _shellSettings   = shellSettings;
     _shellHost       = shellHost;
     _siteService     = siteService;
     S = stringLocalizer;
 }
コード例 #24
0
        public void UpdateShellDescriptor(int priorSerialNumber, IEnumerable <ShellFeature> enabledFeatures, IEnumerable <ShellParameter> parameters)
        {
            var shellDescriptorRecord = GetShellDescriptor();
            var serialNumber          = shellDescriptorRecord == null ? 0 : shellDescriptorRecord.SerialNumber;

            if (priorSerialNumber != serialNumber)
            {
                throw new InvalidOperationException(T("Invalid serial number for shell descriptor").ToString());
            }

            _logger.LogInformation("Updating shell descriptor for shell '{0}'...", _shellSettings.Name);

            if (shellDescriptorRecord == null)
            {
                shellDescriptorRecord = new ShellDescriptor {
                    SerialNumber = 1
                };
                _session.Save(shellDescriptorRecord);
            }
            else
            {
                shellDescriptorRecord.SerialNumber++;
            }

            shellDescriptorRecord.Features.Clear();
            foreach (var feature in enabledFeatures)
            {
                shellDescriptorRecord.Features.Add(new ShellFeature {
                    Name = feature.Name
                });
            }
            _logger.LogDebug("Enabled features for shell '{0}' set: {1}.", _shellSettings.Name, string.Join(", ", enabledFeatures.Select(feature => feature.Name)));


            shellDescriptorRecord.Parameters.Clear();
            foreach (var parameter in parameters)
            {
                shellDescriptorRecord.Parameters.Add(new ShellParameter
                {
                    Component = parameter.Component,
                    Name      = parameter.Name,
                    Value     = parameter.Value
                });
            }
            _logger.LogDebug("Parameters for shell '{0}' set: {1}.", _shellSettings.Name, string.Join(", ", parameters.Select(parameter => parameter.Name + "-" + parameter.Value)));

            _logger.LogInformation("Shell descriptor updated for shell '{0}'.", _shellSettings.Name);

            //_eventNotifier.Notify<IShellDescriptorManagerEventHandler>(
            //    e => e.Changed(GetShellDescriptorFromRecord(shellDescriptorRecord), _shellSettings.Name));
        }
コード例 #25
0
 public AdminController(
     IOrchardServices orchardServices,
     ISettingsService settingsService,
     IExtensionManager extensionManager,
     ShellDescriptor shellDescriptor,
     IEnumerable <IThemeSelectionRule> rules)
 {
     Services          = orchardServices;
     _settingsService  = settingsService;
     _extensionManager = extensionManager;
     _shellDescriptor  = shellDescriptor;
     _rules            = rules;
     T = NullLocalizer.Instance;
 }
コード例 #26
0
        private static ShellDescriptor GetShellDecriptorForCacheText(string p)
        {
            var fields          = p.Trim().Split(new[] { "|" }, StringSplitOptions.None);
            var shellDescriptor = new ShellDescriptor {
                SerialNumber = Convert.ToInt32(fields[0])
            };
            var features = fields[1].Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries);

            shellDescriptor.Features = features.Select(feature => new ShellFeature {
                Name = feature
            }).ToList();

            return(shellDescriptor);
        }
コード例 #27
0
        public void StoreCanBeCalledMoreThanOnceOnTheSameName()
        {
            var service    = _container.Resolve <IShellDescriptorCache>();
            var descriptor = new ShellDescriptor {
                SerialNumber = 6655321
            };

            service.Store("Hello", descriptor);
            service.Store("Hello", descriptor);
            var result = service.Fetch("Hello");

            Assert.NotNull(result);
            Assert.Equal(result.SerialNumber, 6655321);
        }
コード例 #28
0
        public Task <ShellDescriptor> GetShellDescriptorAsync()
        {
            if (_shellDescriptor == null)
            {
                _shellDescriptor = new ShellDescriptor
                {
                    Features = _extensionManager.GetFeatures().Select(x => new ShellFeature {
                        Id = x.Id
                    }).ToList()
                };
            }

            return(Task.FromResult(_shellDescriptor));
        }
コード例 #29
0
        public AdminController(
            IEnumerable <Orchard.Modules.Events.IExtensionDisplayEventHandler> extensionDisplayEventHandlers,
            IOrchardServices services,
            IModuleService moduleService,
            IDataMigrationManager dataMigrationManager,
            IReportsCoordinator reportsCoordinator,
            IExtensionManager extensionManager,
            IFeatureManager featureManager,
            IRecipeHarvester recipeHarvester,
            IRecipeManager recipeManager,
            ShellDescriptor shellDescriptor,
            ShellSettings shellSettings,
            IShapeFactory shapeFactory,
            IPackageService packageService,
            IMimeTypeProvider mimeTypeProvider,
            ISiteThemeService siteThemeService,
            IThemeService themeService)
        {
            Services = services;
            _extensionDisplayEventHandler = extensionDisplayEventHandlers.FirstOrDefault();
            _moduleService        = moduleService;
            _dataMigrationManager = dataMigrationManager;
            _reportsCoordinator   = reportsCoordinator;
            _extensionManager     = extensionManager;
            _featureManager       = featureManager;
            _recipeHarvester      = recipeHarvester;
            _recipeManager        = recipeManager;
            _shellDescriptor      = shellDescriptor;
            _shellSettings        = shellSettings;
            Shape             = shapeFactory;
            _packageService   = packageService;
            _mimeTypeProvider = mimeTypeProvider;

            _siteThemeService = siteThemeService;
            _themeService     = themeService;

            T      = NullLocalizer.Instance;
            Logger = NullLogger.Instance;

            _tempPackageStoragePath = new Lazy <string>(() =>
            {
                var path = HostingEnvironment.MapPath("~/App_Data/Packages");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                return(path);
            });
        }
コード例 #30
0
        public void NormalExecutionReturnsExpectedObjects()
        {
            var settings = new ShellSettings {
                Name = ShellSettings.DefaultName
            };
            var descriptor = new ShellDescriptor {
                SerialNumber = 6655321
            };
            var blueprint          = new ShellBlueprint();
            var shellLifetimeScope = _container.BeginLifetimeScope("shell");
            var httpContext        = new StubHttpContext();

            _container.Mock <IShellDescriptorCache>()
            .Setup(x => x.Fetch(ShellSettings.DefaultName))
            .Returns(descriptor);

            _container.Mock <ICompositionStrategy>()
            .Setup(x => x.Compose(settings, descriptor))
            .Returns(blueprint);

            _container.Mock <IShellContainerFactory>()
            .Setup(x => x.CreateContainer(settings, blueprint))
            .Returns(shellLifetimeScope);

            _container.Mock <IShellDescriptorManager>()
            .Setup(x => x.GetShellDescriptor())
            .Returns(descriptor);

            _container.Mock <IWorkContextEvents>()
            .Setup(x => x.Started());

            _container.Mock <IHttpContextAccessor>()
            .Setup(x => x.Current())
            .Returns(httpContext);

            _container.Mock <IHttpContextAccessor>()
            .Setup(x => x.CreateContext(It.IsAny <ILifetimeScope>()))
            .Returns(httpContext);

            var factory = _container.Resolve <IShellContextFactory>();

            var context = factory.CreateShellContext(settings);

            Assert.That(context.Settings, Is.SameAs(settings));
            Assert.That(context.Descriptor, Is.SameAs(descriptor));
            Assert.That(context.Blueprint, Is.SameAs(blueprint));
            Assert.That(context.LifetimeScope, Is.SameAs(shellLifetimeScope));
            Assert.That(context.Shell, Is.SameAs(shellLifetimeScope.Resolve <IOrchardShell>()));
        }
コード例 #31
0
        public Task <ShellDescriptor> GetShellDescriptorAsync()
        {
            if (_shellDescriptor == null)
            {
                var features = _alwaysEnabledFeatures.Concat(_shellSettings.Features
                                                             .Select(id => new ShellFeature(id))).Distinct().ToList();

                _shellDescriptor = new ShellDescriptor
                {
                    Features = features
                };
            }

            return(Task.FromResult(_shellDescriptor));
        }
コード例 #32
0
        /// <summary>
        /// 当外壳描述符发生变更时执行。
        /// </summary>
        /// <param name="descriptor">新的外壳描述符。</param><param name="tenant">租户名称。</param>
        public void Changed(ShellDescriptor descriptor, string tenant)
        {
            if (!DataMigratorsBuilderExtensions.StartingExecute)
            {
                return;
            }

            lock (NeedMigratorTenants)
            {
                if (!NeedMigratorTenants.Contains(tenant))
                {
                    NeedMigratorTenants.Add(tenant);
                }
            }
        }
コード例 #33
0
        public ThemeAwareViewEngine(
            WorkContext workContext,
            IEnumerable<IViewEngineProvider> viewEngineProviders,
            IConfiguredEnginesCache configuredEnginesCache,
            IExtensionManager extensionManager,
            ShellDescriptor shellDescriptor)
        {
            _workContext = workContext;
            _viewEngineProviders = viewEngineProviders;
            _configuredEnginesCache = configuredEnginesCache;
            _extensionManager = extensionManager;
            _shellDescriptor = shellDescriptor;

            Logger = NullLogger.Instance;
        }
コード例 #34
0
        public ThemeAwareViewEngine(
            WorkContext workContext,
            IEnumerable <IViewEngineProvider> viewEngineProviders,
            IConfiguredEnginesCache configuredEnginesCache,
            IExtensionManager extensionManager,
            ShellDescriptor shellDescriptor)
        {
            _workContext            = workContext;
            _viewEngineProviders    = viewEngineProviders;
            _configuredEnginesCache = configuredEnginesCache;
            _extensionManager       = extensionManager;
            _shellDescriptor        = shellDescriptor;

            Logger = NullLogger.Instance;
        }
コード例 #35
0
        /// <summary>
        /// 更新外壳描述符。
        /// </summary>
        /// <param name="serialNumber">序列号。</param>
        /// <param name="enabledFeatures">需要开启的特性。</param>
        public void UpdateShellDescriptor(int serialNumber, IEnumerable <ShellFeature> enabledFeatures)
        {
            var descriptor = new ShellDescriptor
            {
                SerialNumber = serialNumber,
                Features     = enabledFeatures
            };

            _shellDescriptorCache.Store(_settings.Name, descriptor);

            foreach (var handler in _events)
            {
                handler.Changed(descriptor, _settings.Name);
            }
        }
        public ModularApplicationModelProvider(
            ITypeFeatureProvider typeFeatureProvider,
            IHostingEnvironment hostingEnvironment,
            IExtensionManager extensionManager,
            ShellDescriptor shellDescriptor,
            ShellSettings shellSettings)
        {
            _typeFeatureProvider = typeFeatureProvider;
            _hostingEnvironment  = hostingEnvironment;

            _enabledFeatureIds = extensionManager.GetFeatures().Where(f => shellDescriptor
                                                                      .Features.Any(sf => sf.Id == f.Id)).Select(f => f.Id).ToArray();

            _shellSettings = shellSettings;
        }
コード例 #37
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>()
            };
        }
コード例 #38
0
 public ShapeTemplateBindingStrategy(
     IEnumerable<IShapeTemplateHarvester> harvesters,
     ShellDescriptor shellDescriptor,
     IExtensionManager extensionManager,
     ICacheManager cacheManager,
     IVirtualPathMonitor virtualPathMonitor,
     IVirtualPathProvider virtualPathProvider,
     IEnumerable<IShapeTemplateViewEngine> shapeTemplateViewEngines,
     IParallelCacheContext parallelCacheContext,
     Work<ILayoutAwareViewEngine> viewEngine,
     IWorkContextAccessor workContextAccessor)
 {
     _harvesters = harvesters;
     _shellDescriptor = shellDescriptor;
     _extensionManager = extensionManager;
     _cacheManager = cacheManager;
     _virtualPathMonitor = virtualPathMonitor;
     _virtualPathProvider = virtualPathProvider;
     _shapeTemplateViewEngines = shapeTemplateViewEngines;
     _parallelCacheContext = parallelCacheContext;
     _viewEngine = viewEngine;
     _workContextAccessor = workContextAccessor;
     Logger = NullLogger.Instance;
 }
コード例 #39
0
 protected StaticFileBindingStrategy(IExtensionManager extensionManager, ShellDescriptor shellDescriptor, IVirtualPathProvider virtualPathProvider)
 {
     _extensionManager = extensionManager;
     _shellDescriptor = shellDescriptor;
     _virtualPathProvider = virtualPathProvider;
 }
コード例 #40
0
 public static IEnumerable<FeatureDescriptor> EnabledFeatures(this IExtensionManager extensionManager, ShellDescriptor descriptor) {
     return extensionManager.AvailableFeatures().Where(fd => descriptor.Features.Any(sf => sf.Name == fd.Id));
 }
コード例 #41
0
ファイル: DefaultHost.cs プロジェクト: l1183479157/RabbitHub
        /// <summary>
        /// 当外壳描述符发生变更时执行。
        /// </summary>
        /// <param name="descriptor">新的外壳描述符。</param>
        /// <param name="tenant">租户名称。</param>
        void IShellDescriptorManagerEventHandler.Changed(ShellDescriptor descriptor, string tenant)
        {
            if (_shellContexts == null)
            {
                return;
            }

            Logger.Debug("外壳发生了变化: " + tenant);

            var context = _shellContexts.FirstOrDefault(x => x.Settings.Name == tenant);

            if (context == null)
            {
                return;
            }

            //如果租户没有在运行则跳过
            if (context.Settings.State != TenantState.Running)
            {
                return;
            }

            //如果租户已标识为需要重启则跳过。
            if (_tenantsToRestart.GetState().Any(x => x.Name == tenant))
            {
                return;
            }

            Logger.Debug("标识租户: {0} 需要重启", tenant);
            _tenantsToRestart.GetState().Add(context.Settings);
        }
コード例 #42
0
        private static ShellDescriptor GetShellDecriptorForCacheText(string p)
        {
            var fields = p.Trim().Split(new[] { "|" }, StringSplitOptions.None);
            var shellDescriptor = new ShellDescriptor { SerialNumber = Convert.ToInt32(fields[0]) };
            var features = fields[1].Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            shellDescriptor.Features = features.Select(feature => new ShellFeature { Name = feature }).ToList();

            return shellDescriptor;
        }
コード例 #43
0
        private static string GetCacheTextForShellDescriptor(ShellDescriptor descriptor)
        {
            var sb = new StringBuilder();
            sb.Append(descriptor.SerialNumber + "|");
            foreach (var feature in descriptor.Features)
            {
                sb.Append(feature.Name + ";");
            }

            return sb.ToString();
        }
コード例 #44
0
 public StylesheetBindingStrategy(IExtensionManager extensionManager, ShellDescriptor shellDescriptor, IVirtualPathProvider virtualPathProvider)
     : base(extensionManager, shellDescriptor, virtualPathProvider)
 {
 }
コード例 #45
0
ファイル: SetupService.cs プロジェクト: jp311/Brochard
        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;
        }
コード例 #46
0
 /// <summary>
 /// 更新外壳描述符。
 /// </summary>
 /// <param name="serialNumber">序列号。</param>
 /// <param name="enabledFeatures">需要开启的特性。</param>
 public void UpdateShellDescriptor(int serialNumber, IEnumerable<ShellFeature> enabledFeatures)
 {
     if (enabledFeatures == null)
         DeleteShellDescriptor();
     else
     {
         var features = enabledFeatures.Distinct(new ShellFeatureEqualityComparer()).ToArray();
         var descriptor = new ShellDescriptor
         {
             SerialNumber = serialNumber,
             Features = features
         };
         List.Add(new ShellDescriptorEntry
         {
             Features = features,
             SerialNumber = descriptor.SerialNumber,
             ShellName = _settings.Name
         });
         List.Save();
         foreach (var handler in _events)
             handler.Changed(descriptor, _settings.Name);
     }
 }