本文整理匯總了C#中Orchard.Environment.Extensions.Models.FeatureDescriptor類的典型用法代碼示例。如果您正苦於以下問題:C# FeatureDescriptor類的具體用法?C# FeatureDescriptor怎麽用?C# FeatureDescriptor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FeatureDescriptor類屬於Orchard.Environment.Extensions.Models命名空間,在下文中一共展示了FeatureDescriptor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Resolve
protected override void Resolve(ILifetimeScope container) {
_compositionStrategy = container.Resolve<CompositionStrategy>();
_compositionStrategy.Logger = container.Resolve<ILogger>();
var alphaExtension = new ExtensionDescriptor {
Id = "Alpha",
Name = "Alpha",
ExtensionType = "Module"
};
var alphaFeatureDescriptor = new FeatureDescriptor {
Id = "Alpha",
Name = "Alpha",
Extension = alphaExtension
};
var betaFeatureDescriptor = new FeatureDescriptor {
Id = "Beta",
Name = "Beta",
Extension = alphaExtension,
Dependencies = new List<string> {
"Alpha"
}
};
alphaExtension.Features = new List<FeatureDescriptor> {
alphaFeatureDescriptor,
betaFeatureDescriptor
};
_availableExtensions = new[] {
alphaExtension
};
_installedFeatures = new List<Feature> {
new Feature {
Descriptor = alphaFeatureDescriptor,
ExportedTypes = new List<Type> {
typeof(AlphaDependency)
}
},
new Feature {
Descriptor = betaFeatureDescriptor,
ExportedTypes = new List<Type> {
typeof(BetaDependency)
}
}
};
_loggerMock.Setup(x => x.IsEnabled(It.IsAny<LogLevel>())).Returns(true);
_extensionManager.Setup(x => x.AvailableExtensions()).Returns(() => _availableExtensions);
_extensionManager.Setup(x => x.AvailableFeatures()).Returns(() =>
_extensionManager.Object.AvailableExtensions()
.SelectMany(ext => ext.Features)
.ToReadOnlyCollection());
_extensionManager.Setup(x => x.LoadFeatures(It.IsAny<IEnumerable<FeatureDescriptor>>())).Returns(() => _installedFeatures);
}
示例2: ProcessPlacementFile
private void ProcessPlacementFile(ShapeTableBuilder builder, FeatureDescriptor featureDescriptor, PlacementFile placementFile) {
var feature = new Feature { Descriptor = featureDescriptor };
// invert the tree into a list of leaves and the stack
var entries = DrillDownShapeLocations(placementFile.Nodes, Enumerable.Empty<PlacementMatch>());
foreach (var entry in entries) {
var shapeLocation = entry.Item1;
var matches = entry.Item2;
string shapeType;
string differentiator;
GetShapeType(shapeLocation, out shapeType, out differentiator);
Func<ShapePlacementContext, bool> predicate = ctx => true;
if (differentiator != "") {
predicate = ctx => (ctx.Differentiator ?? "") == differentiator;
}
if (matches.Any()) {
predicate = matches.SelectMany(match => match.Terms).Aggregate(predicate, BuildPredicate);
}
var placement = new PlacementInfo();
var segments = shapeLocation.Location.Split(';').Select(s => s.Trim());
foreach (var segment in segments) {
if (!segment.Contains('=')) {
placement.Location = segment;
}
else {
var index = segment.IndexOf('=');
var property = segment.Substring(0, index).ToLower();
var value = segment.Substring(index + 1);
switch (property) {
case "shape":
placement.ShapeType = value;
break;
case "alternate":
placement.Alternates = new[] { value };
break;
case "wrapper":
placement.Wrappers = new[] { value };
break;
}
}
}
builder.Describe(shapeType)
.From(feature)
.Placement(ctx => {
var hit = predicate(ctx);
// generate 'debugging' information to trace which file originated the actual location
if (hit) {
var virtualPath = featureDescriptor.Extension.Location + "/" + featureDescriptor.Extension.Id + "/Placement.info";
ctx.Source = virtualPath;
}
return hit;
}, placement);
}
}
示例3: ProcessFeatureDescriptor
private void ProcessFeatureDescriptor(ShapeTableBuilder builder, FeatureDescriptor featureDescriptor) {
var virtualPath = featureDescriptor.Extension.Location + "/" + featureDescriptor.Extension.Id + "/Placement.info";
var placementFile = _placementFileParser.Parse(virtualPath);
if (placementFile != null) {
ProcessPlacementFile(builder, featureDescriptor, placementFile);
}
}
示例4: Register
public override void Register(ContainerBuilder builder) {
var mockFeatureManager = new Mock<IFeatureManager>();
var theme1 = new FeatureDescriptor {Extension = new ExtensionDescriptor { Zones = ThemeZoneName1, ExtensionType = "Theme" }};
var theme2 = new FeatureDescriptor { Extension = new ExtensionDescriptor { Zones = ThemeZoneName2, ExtensionType = "Theme" } };
var theme3 = new FeatureDescriptor { Extension = new ExtensionDescriptor { Zones = DuplicateZoneNames, ExtensionType = "Theme" } };
var module1 = new FeatureDescriptor { Extension = new ExtensionDescriptor { Zones = "DontSeeMeBecauseIAmNotATheme", ExtensionType = "Module" } };
mockFeatureManager.Setup(x => x.GetEnabledFeatures())
.Returns(new[] { theme1, theme2, theme3, module1 });
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
builder.RegisterType<Signals>().As<ISignals>();
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
builder.RegisterInstance(new Mock<IContentDefinitionManager>().Object);
builder.RegisterInstance(new Mock<ITransactionManager>().Object);
builder.RegisterInstance(new Mock<IAuthorizer>().Object);
builder.RegisterInstance(new Mock<INotifier>().Object);
builder.RegisterInstance(mockFeatureManager.Object);
builder.RegisterType<OrchardServices>().As<IOrchardServices>();
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
builder.RegisterType<WidgetsService>().As<IWidgetsService>();
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
builder.RegisterType<StubWidgetPartHandler>().As<IContentHandler>();
builder.RegisterType<StubLayerPartHandler>().As<IContentHandler>();
builder.RegisterType<DefaultContentQuery>().As<IContentQuery>();
builder.RegisterInstance(new Mock<IPageClassBuilder>().Object);
builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
}
示例5: ProcessFeatureDescriptor
private void ProcessFeatureDescriptor(ShapeTableBuilder builder, FeatureDescriptor featureDescriptor)
{
var virtualPath = _fileSystem
.GetExtensionFileProvider(featureDescriptor.Extension, _logger)
.GetFileInfo("Placement.info");
var placementFile = _placementFileParser.Parse(virtualPath);
if (placementFile != null)
{
ProcessPlacementFile(builder, featureDescriptor, placementFile);
}
}
示例6: HasDependency
/// <summary>
/// Returns true if the item has an explicit or implicit dependency on the subject
/// </summary>
/// <param name="item"></param>
/// <param name="subject"></param>
/// <returns></returns>
internal static bool HasDependency(FeatureDescriptor item, FeatureDescriptor subject) {
if (DefaultExtensionTypes.IsTheme(item.Extension.ExtensionType)) {
if (DefaultExtensionTypes.IsModule(subject.Extension.ExtensionType)) {
// Themes implicitly depend on modules to ensure build and override ordering
return true;
}
if (DefaultExtensionTypes.IsTheme(subject.Extension.ExtensionType)) {
// Theme depends on another if it is its base theme
return item.Extension.BaseTheme == subject.Id;
}
}
// Return based on explicit dependencies
return item.Dependencies != null &&
item.Dependencies.Any(x => StringComparer.OrdinalIgnoreCase.Equals(x, subject.Id));
}
示例7: ProcessFeatureDescriptor
private void ProcessFeatureDescriptor(ShapeTableBuilder builder, FeatureDescriptor featureDescriptor)
{
var virtualPath = _fileSystem
.GetExtensionFileProvider(featureDescriptor.Extension, _logger)
.GetFileInfo("placement.json");
if (virtualPath.Exists)
{
using (var stream = virtualPath.CreateReadStream())
{
using (var reader = new StreamReader(stream))
{
using (var jtr = new JsonTextReader(reader))
{
JsonSerializer serializer = new JsonSerializer();
var placementFile = serializer.Deserialize<PlacementFile>(jtr);
ProcessPlacementFile(builder, featureDescriptor, placementFile);
}
}
}
}
}
示例8: ProcessPlacementFile
private void ProcessPlacementFile(ShapeTableBuilder builder, FeatureDescriptor featureDescriptor, PlacementFile placementFile)
{
var feature = new Feature { Descriptor = featureDescriptor };
foreach (var entry in placementFile)
{
var shapeType = entry.Key;
var matches = entry.Value;
foreach (var filter in entry.Value)
{
var placement = new PlacementInfo();
placement.Location = filter.Location;
placement.Alternates = filter.Alternates;
placement.Wrappers = filter.Wrappers;
placement.ShapeType = filter.ShapeType;
builder.Describe(shapeType)
.From(feature)
.Placement(ctx => CheckFilter(ctx, filter), placement);
}
}
}
示例9: LoadFeature
private Feature LoadFeature(FeatureDescriptor featureDescriptor)
{
var extensionDescriptor = featureDescriptor.Extension;
var featureId = featureDescriptor.Id;
var extensionId = extensionDescriptor.Id;
ExtensionEntry extensionEntry;
try {
extensionEntry = BuildEntry(extensionDescriptor);
}
catch (Exception ex) {
_logger.LogError(string.Format("Error loading extension '{0}'", extensionId), ex);
throw new OrchardException(T("Error while loading extension '{0}'.", extensionId), ex);
}
if (extensionEntry == null) {
// If the feature could not be compiled for some reason,
// return a "null" feature, i.e. a feature with no exported types.
return new Feature {
Descriptor = featureDescriptor,
ExportedTypes = Enumerable.Empty<Type>()
};
}
var extensionTypes = extensionEntry.ExportedTypes.Where(t => t.GetTypeInfo().IsClass && !t.GetTypeInfo().IsAbstract);
var featureTypes = new List<Type>();
foreach (var type in extensionTypes) {
string sourceFeature = GetSourceFeatureNameForType(type, extensionId);
if (String.Equals(sourceFeature, featureId, StringComparison.OrdinalIgnoreCase)) {
featureTypes.Add(type);
}
}
return new Feature {
Descriptor = featureDescriptor,
ExportedTypes = featureTypes
};
}
示例10: GetPriority
internal static int GetPriority(FeatureDescriptor featureDescriptor)
{
return featureDescriptor.Priority;
}
示例11: FrameworkFeature
private static Feature FrameworkFeature(FeatureDescriptor descriptor) {
return new Feature {
Descriptor = descriptor
};
}
示例12: ExtensionManagerShouldReturnEmptyFeatureIfFeatureDoesNotExist
public void ExtensionManagerShouldReturnEmptyFeatureIfFeatureDoesNotExist()
{
var featureDescriptor = new FeatureDescriptor { Id = "NoSuchFeature", Extension = new ExtensionDescriptor { Id = "NoSuchFeature" } };
var manager = new ExtensionManager(new StubExtensionLocator(), new StubLoaders[] { }, new TypeFeatureProvider(), new NullLogger<ExtensionManager>());
Feature feature = manager.LoadFeatures(new[] { featureDescriptor }).First();
Assert.Equal(featureDescriptor, feature.Descriptor);
Assert.Equal(0, feature.ExportedTypes.Count());
}
示例13: HasDependency
/// <summary>
/// Returns true if the item has an explicit or implicit dependency on the subject
/// </summary>
/// <param name="item"></param>
/// <param name="subject"></param>
/// <returns></returns>
internal static bool HasDependency(FeatureDescriptor item, FeatureDescriptor subject)
{
// Return based on explicit dependencies
return item.Dependencies != null &&
item.Dependencies.Any(x => StringComparer.OrdinalIgnoreCase.Equals(x, subject.Id));
}
示例14: ApplyChanges
public void ApplyChanges()
{
if (Logger.IsEnabled(LogLevel.Information))
{
Logger.LogInformation("Applying changes for for shell '{0}'", _settings.Name);
}
var shellState = _stateManager.GetShellStateAsync().Result;
// start with description of all declared features in order - order preserved with all merging
var orderedFeatureDescriptors = _extensionManager.AvailableFeatures();
// merge feature state into ordered list
var orderedFeatureDescriptorsAndStates = orderedFeatureDescriptors
.Select(featureDescriptor => new
{
FeatureDescriptor = featureDescriptor,
FeatureState = shellState.Features.FirstOrDefault(s => s.Name == featureDescriptor.Id),
})
.Where(entry => entry.FeatureState != null)
.ToArray();
// get loaded feature information
var loadedFeatures = _extensionManager.LoadFeatures(orderedFeatureDescriptorsAndStates.Select(entry => entry.FeatureDescriptor)).ToArray();
// merge loaded feature information into ordered list
var loadedEntries = orderedFeatureDescriptorsAndStates.Select(
entry => new
{
Feature = loadedFeatures.SingleOrDefault(f => f.Descriptor == entry.FeatureDescriptor)
?? new Feature
{
Descriptor = entry.FeatureDescriptor,
ExportedTypes = Enumerable.Empty<Type>()
},
entry.FeatureDescriptor,
entry.FeatureState,
}).ToList();
// find feature state that is beyond what's currently available from modules
var additionalState = shellState.Features.Except(loadedEntries.Select(entry => entry.FeatureState));
// create additional stub entries for the sake of firing state change events on missing features
var allEntries = loadedEntries.Concat(additionalState.Select(featureState =>
{
var featureDescriptor = new FeatureDescriptor
{
Id = featureState.Name,
Extension = new ExtensionDescriptor
{
Id = featureState.Name
}
};
return new
{
Feature = new Feature
{
Descriptor = featureDescriptor,
ExportedTypes = Enumerable.Empty<Type>(),
},
FeatureDescriptor = featureDescriptor,
FeatureState = featureState
};
})).ToArray();
// lower enabled states in reverse order
foreach (var entry in allEntries.Reverse().Where(entry => entry.FeatureState.EnableState == ShellFeatureState.State.Falling))
{
if (Logger.IsEnabled(LogLevel.Information))
{
Logger.LogInformation("Disabling feature '{0}'", entry.Feature.Descriptor.Id);
}
_eventBus.Notify<IFeatureEventHandler>(x => x.Disabling(entry.Feature));
_stateManager.UpdateEnabledState(entry.FeatureState, ShellFeatureState.State.Down);
_eventBus.Notify<IFeatureEventHandler>(x => x.Disabled(entry.Feature));
}
// lower installed states in reverse order
foreach (var entry in allEntries.Reverse().Where(entry => entry.FeatureState.InstallState == ShellFeatureState.State.Falling))
{
if (Logger.IsEnabled(LogLevel.Information))
{
Logger.LogInformation("Uninstalling feature '{0}'", entry.Feature.Descriptor.Id);
}
_eventBus.Notify<IFeatureEventHandler>(x => x.Uninstalling(entry.Feature));
_stateManager.UpdateInstalledState(entry.FeatureState, ShellFeatureState.State.Down);
_eventBus.Notify<IFeatureEventHandler>(x => x.Uninstalled(entry.Feature));
}
// raise install and enabled states in order
foreach (var entry in allEntries.Where(entry => IsRising(entry.FeatureState)))
{
if (entry.FeatureState.InstallState == ShellFeatureState.State.Rising)
{
if (Logger.IsEnabled(LogLevel.Information))
{
Logger.LogInformation("Installing feature '{0}'", entry.Feature.Descriptor.Id);
}
//.........這裏部分代碼省略.........
示例15: LoadFeature
private Feature LoadFeature(FeatureDescriptor featureDescriptor)
{
var extensionDescriptor = featureDescriptor.Extension;
var featureId = featureDescriptor.Id;
var extensionId = extensionDescriptor.Id;
ExtensionEntry extensionEntry;
try
{
extensionEntry = _cacheManager.Get(extensionId, ctx =>
{
var entry = BuildEntry(extensionDescriptor);
if (entry != null)
{
ctx.Monitor(_asyncTokenProvider.GetToken(monitor =>
{
foreach (var loader in _loaders)
{
loader.Monitor(entry.Descriptor, token => monitor(token));
}
}));
}
return entry;
});
}
catch (Exception ex)
{
Logger.Error(ex, "Error loading extension '{0}'", extensionId);
throw new CoreException(string.Format("Error while loading extension '{0}'.", extensionId), ex);
}
if (extensionEntry == null)
{
// If the feature could not be compiled for some reason,
// return a "null" feature, i.e. a feature with no exported types.
return new Feature
{
Descriptor = featureDescriptor,
ExportedTypes = Enumerable.Empty<Type>()
};
}
var extensionTypes = extensionEntry.ExportedTypes.Where(t => t.IsClass && !t.IsAbstract);
var featureTypes = new List<Type>();
foreach (var type in extensionTypes)
{
string sourceFeature = GetSourceFeatureNameForType(type, extensionId);
if (String.Equals(sourceFeature, featureId, StringComparison.OrdinalIgnoreCase))
{
featureTypes.Add(type);
}
}
return new Feature
{
Descriptor = featureDescriptor,
ExportedTypes = featureTypes
};
}