Ejemplo n.º 1
0
 internal FeatureDescriptor GetFeatureDescriptor()
 {
     var descriptor = new FeatureDescriptor();
     FeatureDescriptor savedDescriptor = Thread.GetData(Thread.GetNamedDataSlot(FeatureNameSlotName)) as FeatureDescriptor ?? new FeatureDescriptor();
     descriptor.Name = FeatureName ?? savedDescriptor.Name ?? "Application";
     descriptor.Group = FeatureGroup ?? savedDescriptor.Group ?? FeatureStatistics.GlobalGroupName;
     return descriptor;
 }
Ejemplo n.º 2
0
        public void GetAggregateFeatureTest()
        {
            string ID     = "testid";
            Origin origin = new Origin();
            Signer signer = new Signer();

            Signature signature = new Signature(ID, origin, signer);

            FeatureDescriptor featureDescriptor = FeatureDescriptor.Get <String>("Desc");

            signature[featureDescriptor] = "desc";

            FeatureDescriptor featureDescriptor2 = FeatureDescriptor.Get <String>("Desc2");

            signature[featureDescriptor2] = "desc2";

            List <FeatureDescriptor> fs = new List <FeatureDescriptor>();

            fs.Add(featureDescriptor);
            fs.Add(featureDescriptor2);

            //    Assert.AreEqual(signature.GetAggregateFeature, featureDescriptor);
        }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        public void Transform(Signature signature)
        {
            if (OutputImage == null)
            {
                OutputImage = FeatureDescriptor <Image <Rgba32> > .Get(Input.Name + "Image");//TODO: <T> template-es Register()
            }

            bool[,] b = signature.GetFeature(Input);
            int w = b.GetLength(0);
            int h = b.GetLength(1);

            //itt pl lehetne Dilate meg ilyesmi

            Image <Rgba32> img = new Image <Rgba32>(w, h);

            for (int x = 0; x < w; x++)
            {
                for (int y = 0; y < h; y++)
                {
                    img[x, h - 1 - y] = b[x, y] ? ForegroundColor : BackgroundColor;
                }
                Progress = (int)(x / (double)w * 95);
            }

            signature.SetFeature(OutputImage, img);

            if (WriteToFile)
            {
                string signerString = (signature.Signer != null) ? signature.Signer.ID : "Null";
                string filename     = $"{signature.ID ?? "Null"}_{Input.Name}.png";
                img.SaveAsPng(File.Create(filename));
                this.LogInformation($"Image saved: {filename}");
            }

            Progress = 100;
            this.LogInformation($"Image generation from binary raster done.");
        }
Ejemplo n.º 4
0
 private static int GetPriority(FeatureDescriptor featureDescriptor)
 {
     return(featureDescriptor.Priority);
 }
        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);
            }
        }
Ejemplo n.º 6
0
 public PrepareForThinning()
 {
     this.Output(FeatureDescriptor <bool[, ]> .Descriptor("Prepared"));
 }
 private bool FeatureIsEnabled(FeatureDescriptor fd)
 {
     return((DefaultExtensionTypes.IsTheme(fd.Extension.ExtensionType) && (fd.Id == "TheAdmin" || fd.Id == "SafeMode")) ||
            _shellDescriptor.Features.Any(sf => sf.Name == fd.Id));
 }
 private bool FeatureIsTheme(FeatureDescriptor fd)
 {
     return(DefaultExtensionTypes.IsTheme(fd.Extension.ExtensionType));
 }
Ejemplo n.º 9
0
        void IShellStateManagerEventHandler.ApplyChanges()
        {
            Logger.Information("Applying changes for for shell '{0}'", _settings.Name);

            var shellState = _stateManager.GetShellState();

            // 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))
            {
                Logger.Information("Disabling feature '{0}'", entry.Feature.Descriptor.Id);
                _featureEvents.Disabling(entry.Feature);
                _stateManager.UpdateEnabledState(entry.FeatureState, ShellFeatureState.State.Down);
                _featureEvents.Disabled(entry.Feature);
            }

            // lower installed states in reverse order
            foreach (var entry in allEntries.Reverse().Where(entry => entry.FeatureState.InstallState == ShellFeatureState.State.Falling))
            {
                Logger.Information("Uninstalling feature '{0}'", entry.Feature.Descriptor.Id);
                _featureEvents.Uninstalling(entry.Feature);
                _stateManager.UpdateInstalledState(entry.FeatureState, ShellFeatureState.State.Down);
                _featureEvents.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)
                {
                    Logger.Information("Installing feature '{0}'", entry.Feature.Descriptor.Id);
                    _featureEvents.Installing(entry.Feature);
                    _stateManager.UpdateInstalledState(entry.FeatureState, ShellFeatureState.State.Up);
                    _featureEvents.Installed(entry.Feature);
                }
                if (entry.FeatureState.EnableState == ShellFeatureState.State.Rising)
                {
                    Logger.Information("Enabling feature '{0}'", entry.Feature.Descriptor.Id);
                    _featureEvents.Enabling(entry.Feature);
                    _stateManager.UpdateEnabledState(entry.FeatureState, ShellFeatureState.State.Up);
                    _featureEvents.Enabled(entry.Feature);
                }
            }

            // re-fire if any event handlers initiated additional state changes
            FireApplyChangesIfNeeded();
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AddVector"/> class with a vector feature.
 /// Don't forget to add as many Inputs as the vector's dimension.
 /// </summary>
 /// <param name="vectorFeature">A collection-type feature where each element represents a dimension of the vector.</param>
 public AddVector(FeatureDescriptor <List <double> > vectorFeature)
 {
     this.vectorFeature = vectorFeature;
 }
Ejemplo n.º 11
0
 /// <summary> Initializes a new instance of the <see cref="TangentExtraction"/> class. </summary>
 public TangentExtraction()
 {
     this.Output(FeatureDescriptor <List <double> > .Descriptor("Tangent"));
 }
Ejemplo n.º 12
0
 /// <summary> Initializes a new instance of the <see cref="CentroidExtraction"/> class. </summary>
 public CentroidExtraction()
 {
     //this.Input(Features.X, Features.X);
     InputFeatures = new List <FeatureDescriptor>();
     this.Output(FeatureDescriptor <List <double> > .Descriptor("Centroid"));
 }
 public static bool Equals(FeatureDescriptor x, FeatureDescriptor y)
 {
     return(x == null && y == null || (x != null && y != null) && (x.Name ?? string.Empty) == (y.Name ?? string.Empty));
 }
 public static int GetHashCode(FeatureDescriptor obj)
 {
     return(obj.Name.GetHashCode());
 }
        private static IEnumerable <FeatureDescriptor> GetFeaturesForExtension(IDictionary <string, string> manifest, ExtensionDescriptorEntry entry)
        {
            var featureDescriptors = new List <FeatureDescriptor>();

            var descriptor = entry.Descriptor;
            //默认特性
            var defaultFeature = new FeatureDescriptor
            {
                Id       = entry.Id,
                Name     = GetValue(manifest, FeatureNameSection) ?? descriptor.Name,
                Priority = GetValue(manifest, PrioritySection) != null?int.Parse(GetValue(manifest, PrioritySection)) : 0,
                               Description  = GetValue(manifest, FeatureDescriptionSection) ?? GetValue(manifest, DescriptionSection) ?? string.Empty,
                               Dependencies = ParseFeatureDependenciesEntry(GetValue(manifest, DependenciesSection)),
                               Extension    = entry,
                               Category     = GetValue(manifest, CategorySection)
            };

            featureDescriptors.Add(defaultFeature);

            //剩余特性
            var featuresText = GetValue(manifest, FeaturesSection);

            if (string.IsNullOrWhiteSpace(featuresText))
            {
                return(featureDescriptors);
            }
            FeatureDescriptor featureDescriptor = null;

            using (var reader = new StringReader(featuresText))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (IsFeatureDeclaration(line))
                    {
                        if (featureDescriptor != null)
                        {
                            if (!featureDescriptor.Equals(defaultFeature))
                            {
                                featureDescriptors.Add(featureDescriptor);
                            }
                        }

                        var featureDeclaration  = line.Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                        var featureDescriptorId = featureDeclaration[0].Trim();
                        if (string.Equals(featureDescriptorId, entry.Id, StringComparison.OrdinalIgnoreCase))
                        {
                            featureDescriptor      = defaultFeature;
                            featureDescriptor.Name = descriptor.Name;
                        }
                        else
                        {
                            featureDescriptor = new FeatureDescriptor
                            {
                                Id        = featureDescriptorId,
                                Extension = entry
                            };
                        }
                    }
                    else if (IsFeatureFieldDeclaration(line))
                    {
                        if (featureDescriptor != null)
                        {
                            var featureField       = line.Split(new[] { ":" }, 2, StringSplitOptions.None);
                            var featureFieldLength = featureField.Length;
                            if (featureFieldLength != 2)
                            {
                                continue;
                            }
                            for (var i = 0; i < featureFieldLength; i++)
                            {
                                featureField[i] = featureField[i].Trim();
                            }

                            switch (featureField[0].ToLowerInvariant())
                            {
                            case NameSection:
                                featureDescriptor.Name = featureField[1];
                                break;

                            case DescriptionSection:
                                featureDescriptor.Description = featureField[1];
                                break;

                            case CategorySection:
                                featureDescriptor.Category = featureField[1];
                                break;

                            case PrioritySection:
                                featureDescriptor.Priority = int.Parse(featureField[1]);
                                break;

                            case DependenciesSection:
                                featureDescriptor.Dependencies = ParseFeatureDependenciesEntry(featureField[1]);
                                break;
                            }
                        }
                        else
                        {
                            var message = string.Format("行 {0} 在清单文件中被忽略,来自扩展 {1}", line, entry.Id);
                            throw new ArgumentException(message);
                        }
                    }
                    else
                    {
                        var message = string.Format("行 {0} 在清单文件中被忽略,来自扩展 {1}", line, entry.Id);
                        throw new ArgumentException(message);
                    }
                }

                if (featureDescriptor != null && !featureDescriptor.Equals(defaultFeature))
                {
                    featureDescriptors.Add(featureDescriptor);
                }
            }

            return(featureDescriptors);
        }
Ejemplo n.º 16
0
        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, monitor);
                            }
                        }));
                    }
                    return(entry);
                });
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat(ex, "Error loading extension '{0}'", extensionId);
                throw new CMSException(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.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
            });
        }
Ejemplo n.º 17
0
 /// <summary>
 /// 初始化一个新的特性描述符过滤器上下文。
 /// </summary>
 /// <param name="feature">特性描述符。</param>
 public FeatureDescriptorFilterContext(FeatureDescriptor feature)
 {
     Feature = feature;
     Valid   = true;
 }
Ejemplo n.º 18
0
        private static IEnumerable <FeatureDescriptor> GetFeaturesForExtension(IDictionary <string, string> manifest, ExtensionDescriptor extensionDescriptor)
        {
            var featureDescriptors = new List <FeatureDescriptor>();

            // Default feature
            FeatureDescriptor defaultFeature = new FeatureDescriptor {
                Id       = extensionDescriptor.Id,
                Name     = GetValue(manifest, FeatureNameSection) ?? extensionDescriptor.Name,
                Priority = GetValue(manifest, PrioritySection) != null?int.Parse(GetValue(manifest, PrioritySection)) : 0,
                               Description  = GetValue(manifest, FeatureDescriptionSection) ?? GetValue(manifest, DescriptionSection) ?? string.Empty,
                               Dependencies = ParseFeatureDependenciesEntry(GetValue(manifest, DependenciesSection)),
                               Extension    = extensionDescriptor,
                               Category     = GetValue(manifest, CategorySection)
            };

            featureDescriptors.Add(defaultFeature);

            // Remaining features
            string featuresText = GetValue(manifest, FeaturesSection);

            if (featuresText != null)
            {
                FeatureDescriptor featureDescriptor = null;
                using (StringReader reader = new StringReader(featuresText)) {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        if (IsFeatureDeclaration(line))
                        {
                            if (featureDescriptor != null)
                            {
                                if (!featureDescriptor.Equals(defaultFeature))
                                {
                                    featureDescriptors.Add(featureDescriptor);
                                }

                                featureDescriptor = null;
                            }

                            string[] featureDeclaration  = line.Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                            string   featureDescriptorId = featureDeclaration[0].Trim();
                            if (String.Equals(featureDescriptorId, extensionDescriptor.Id, StringComparison.OrdinalIgnoreCase))
                            {
                                featureDescriptor      = defaultFeature;
                                featureDescriptor.Name = extensionDescriptor.Name;
                            }
                            else
                            {
                                featureDescriptor = new FeatureDescriptor {
                                    Id        = featureDescriptorId,
                                    Extension = extensionDescriptor
                                };
                            }
                        }
                        else if (IsFeatureFieldDeclaration(line))
                        {
                            if (featureDescriptor != null)
                            {
                                string[] featureField       = line.Split(new[] { ":" }, 2, StringSplitOptions.None);
                                int      featureFieldLength = featureField.Length;
                                if (featureFieldLength != 2)
                                {
                                    continue;
                                }
                                for (int i = 0; i < featureFieldLength; i++)
                                {
                                    featureField[i] = featureField[i].Trim();
                                }

                                switch (featureField[0].ToLowerInvariant())
                                {
                                case NameSection:
                                    featureDescriptor.Name = featureField[1];
                                    break;

                                case DescriptionSection:
                                    featureDescriptor.Description = featureField[1];
                                    break;

                                case CategorySection:
                                    featureDescriptor.Category = featureField[1];
                                    break;

                                case PrioritySection:
                                    featureDescriptor.Priority = int.Parse(featureField[1]);
                                    break;

                                case DependenciesSection:
                                    featureDescriptor.Dependencies = ParseFeatureDependenciesEntry(featureField[1]);
                                    break;
                                }
                            }
                            else
                            {
                                string message = string.Format("The line {0} in manifest for extension {1} was ignored", line, extensionDescriptor.Id);
                                throw new ArgumentException(message);
                            }
                        }
                        else
                        {
                            string message = string.Format("The line {0} in manifest for extension {1} was ignored", line, extensionDescriptor.Id);
                            throw new ArgumentException(message);
                        }
                    }

                    if (featureDescriptor != null && !featureDescriptor.Equals(defaultFeature))
                    {
                        featureDescriptors.Add(featureDescriptor);
                    }
                }
            }

            return(featureDescriptors);
        }
Ejemplo n.º 19
0
 /// <inheritdoc/>
 public void Add(FeatureDescriptor <List <double> > newitem)
 {
     InputFeatures.Add(newitem);
 }
Ejemplo n.º 20
0
        private Feature LoadFeature(FeatureDescriptor featureDescriptor)
        {
            lock (_features)
            {
                if (_logger.IsEnabled(LogLevel.Information))
                {
                    _logger.LogInformation("Loading feature {0}", featureDescriptor.Name);
                }

                if (_features.ContainsKey(featureDescriptor.Id))
                {
                    if (_logger.IsEnabled(LogLevel.Debug))
                    {
                        _logger.LogDebug("Feature {0} loaded from cache", featureDescriptor.Name);
                    }

                    return(_features[featureDescriptor.Id]);
                }

                var extensionDescriptor = featureDescriptor.Extension;
                var featureId           = featureDescriptor.Id;
                var extensionId         = extensionDescriptor.Id;

                var extensionEntry = LoadExtension(extensionDescriptor);

                Feature feature;
                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.
                    feature = new Feature
                    {
                        Descriptor    = featureDescriptor,
                        ExportedTypes = Enumerable.Empty <Type>()
                    };

                    _features.Add(featureDescriptor.Id, feature);
                    return(feature);
                }

                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);
                    }
                }

                feature = new Feature
                {
                    Descriptor    = featureDescriptor,
                    ExportedTypes = featureTypes
                };

                foreach (var type in feature.ExportedTypes)
                {
                    _typeFeatureProvider.TryAdd(type, feature);
                }


                _features.Add(featureDescriptor.Id, feature);
                return(feature);
            }
        }
Ejemplo n.º 21
0
        public void Discover(ShapeTableBuilder builder)
        {
            Logger.Information("Start discovering shapes");

            // Getting enabled themes
            var harvesterInfos         = _harvesters.Select(harvester => new { harvester, subPaths = harvester.SubPaths() });
            var availableFeatures      = _featureManager.GetEnabledFeatures();
            var activeThemes           = availableFeatures.Where(FeatureIsTheme);
            var activeThemesExtensions = Once(activeThemes);

            // Getting folders in Alternates folder (The folder name should be the name of one Theme)
            var appDataPath           = @"~/App_Data/Sites";
            var tenantName            = _shellSettings.Name;
            var alternatesFolderName  = "Alternates";
            var alternateFolderPath   = Path.Combine(appDataPath, tenantName, alternatesFolderName).Replace(Path.DirectorySeparatorChar, '/');
            var alternateThemeFolders = _virtualPathProvider.ListDirectories(alternateFolderPath).Select(Path.GetDirectoryName).ToReadOnlyCollection();
            // Cycling folders
            var hits = _parallelCacheContext.RunInParallel(alternateThemeFolders, folderFullPath => {
                Logger.Information("Start discovering candidate views filenames");
                var pathContexts = harvesterInfos.SelectMany(harvesterInfo => harvesterInfo.subPaths.Select(subPath => {
                    //check if the folder name match with an enabled theme
                    //otherwise it returns a null object
                    var extensionDescriptor = activeThemesExtensions.SingleOrDefault(x => x.Id.Equals(new DirectoryInfo(folderFullPath).Name, System.StringComparison.OrdinalIgnoreCase));
                    if (extensionDescriptor != null)
                    {
                        var basePath    = Path.Combine(appDataPath, tenantName, alternatesFolderName, extensionDescriptor.Id).Replace(Path.DirectorySeparatorChar, '/');
                        var monitorPath = Path.Combine(appDataPath, tenantName, alternatesFolderName).Replace(Path.DirectorySeparatorChar, '/');
                        var virtualPath = Path.Combine(basePath, subPath).Replace(Path.DirectorySeparatorChar, '/');
                        IList <string> fileNames;
                        if (!_virtualPathProvider.DirectoryExists(virtualPath))
                        {
                            fileNames = new List <string>();
                        }
                        else
                        {
                            fileNames = _cacheManager.Get(virtualPath, true, ctx => {
                                if (!DisableMonitoring)
                                {
                                    Logger.Debug("Monitoring virtual path \"{0}\"", virtualPath);
                                    ctx.Monitor(_virtualPathMonitor.WhenPathChanges(virtualPath));
                                }

                                return(_virtualPathProvider.ListFiles(virtualPath).Select(Path.GetFileName).ToReadOnlyCollection());
                            });
                        }
                        return(new { harvesterInfo.harvester, basePath, subPath, virtualPath, fileNames, extensionDescriptor });
                    }
                    return(null);
                }))
                                   .Where(context => context != null) //remove null objects cause the inspected folder belongs to a disabled theme
                                   .ToList();

                Logger.Information("Done discovering candidate views filenames");
                var fileContexts = pathContexts.SelectMany(pathContext => _shapeTemplateViewEngines.SelectMany(ve => {
                    var fileNames = ve.DetectTemplateFileNames(pathContext.fileNames);
                    return(fileNames.Select(
                               fileName => new {
                        fileName = Path.GetFileNameWithoutExtension(fileName),
                        fileVirtualPath = Path.Combine(pathContext.virtualPath, fileName).Replace(Path.DirectorySeparatorChar, '/'),
                        pathContext
                    }));
                }));

                var shapeContexts = fileContexts.SelectMany(fileContext => {
                    var extensionDescriptor = fileContext.pathContext.extensionDescriptor;
                    var harvestShapeInfo    = new HarvestShapeInfo {
                        SubPath             = fileContext.pathContext.subPath,
                        FileName            = fileContext.fileName,
                        TemplateVirtualPath = fileContext.fileVirtualPath,
                    };
                    var harvestShapeHits = fileContext.pathContext.harvester.HarvestShape(harvestShapeInfo);
                    return(harvestShapeHits.Select(harvestShapeHit => new { harvestShapeInfo, harvestShapeHit, fileContext, extensionDescriptor }));
                });

                return(shapeContexts.Select(shapeContext => new { shapeContext }).ToList());
            }).SelectMany(hits2 => hits2);

            foreach (var iter in hits)
            {
                // templates are always associated with the namesake feature of module or theme
                var hit = iter;
                var featureDescriptors = iter.shapeContext.extensionDescriptor.Features.Where(fd => fd.Id == hit.shapeContext.extensionDescriptor.Id);
                foreach (var featureDescriptor in featureDescriptors)
                {
                    Logger.Debug("Binding {0} as shape [{1}] for feature {2}",
                                 hit.shapeContext.harvestShapeInfo.TemplateVirtualPath,
                                 iter.shapeContext.harvestShapeHit.ShapeType,
                                 featureDescriptor.Id);
                    // set priority higher than theme
                    var newfeatureDescriptor = new FeatureDescriptor {
                        Id              = featureDescriptor.Id,
                        Category        = featureDescriptor.Category,
                        Description     = featureDescriptor.Description,
                        Extension       = featureDescriptor.Extension,
                        LifecycleStatus = featureDescriptor.LifecycleStatus,
                        Name            = featureDescriptor.Name,
                        Priority        = featureDescriptor.Priority + 100,
                    };
                    builder.Describe(iter.shapeContext.harvestShapeHit.ShapeType)
                    .From(new Feature {
                        Descriptor = newfeatureDescriptor
                    })
                    .BoundAs(
                        hit.shapeContext.harvestShapeInfo.TemplateVirtualPath,
                        shapeDescriptor => displayContext => Render(shapeDescriptor, displayContext, hit.shapeContext.harvestShapeInfo, hit.shapeContext.harvestShapeHit));
                }
            }
            Logger.Information("Done discovering shapes");
        }
Ejemplo n.º 22
0
 internal static int GetPriority(FeatureDescriptor featureDescriptor)
 {
     return(featureDescriptor.Priority);
 }
 static Feature Feature(FeatureDescriptor descriptor)
 {
     return(new Feature {
         Descriptor = descriptor
     });
 }
Ejemplo n.º 24
0
        private IEnumerable <string> ExpandDependenciesInternal(IDictionary <string, FeatureDescriptor> availableFeatures, IEnumerable <string> features, FeatureDescriptor dependentFeatureDescriptor = null)
        {
            foreach (var shellFeature in features)
            {
                if (!availableFeatures.ContainsKey(shellFeature))
                {
                    // If the feature comes from a list of feature dependencies it indicates a bug, so throw an exception.
                    if (dependentFeatureDescriptor != null)
                    {
                        throw new SystemException(
                                  T("The feature '{0}' was listed as a dependency of '{1}' of extension '{2}', but this feature could not be found. Please update your manifest file or install the module providing the missing feature.",
                                    shellFeature,
                                    dependentFeatureDescriptor.Name,
                                    dependentFeatureDescriptor.Extension.Name));
                    }

                    // If the feature comes from the shell descriptor it means the feature is simply orphaned, so don't throw an exception.
                    Logger.Warning("Identified '{0}' as an orphaned feature state record in Settings_ShellFeatureRecord.", shellFeature);
                    continue;
                }

                var feature = availableFeatures[shellFeature];

                foreach (var childDependency in ExpandDependenciesInternal(availableFeatures, feature.Dependencies, dependentFeatureDescriptor: feature))
                {
                    yield return(childDependency);
                }

                foreach (var dependency in feature.Dependencies)
                {
                    yield return(dependency);
                }

                yield return(shellFeature);
            }
        }
Ejemplo n.º 25
0
 /// <inheritdoc/>
 public void Add(FeatureDescriptor newItem)
 {
     InputFeatures.Add(newItem);
 }
 public bool HasDependency(FeatureDescriptor item, FeatureDescriptor subject)
 {
     return(_availableFeautures.Any(x => x.Id == item.Id));
 }
Ejemplo n.º 27
0
 private static Feature FrameworkFeature(FeatureDescriptor descriptor)
 {
     return(new Feature {
         Descriptor = descriptor
     });
 }
 private bool FeatureIsEnabled(FeatureDescriptor fd)
 {
     return(_shellDescriptor.Features.Any(sf => sf.Name == fd.Id));
 }
Ejemplo n.º 29
0
 private static bool HasDependency(FeatureDescriptor item, FeatureDescriptor subject)
 {
     return(item.Dependencies != null &&
            item.Dependencies.Any(x => StringComparer.OrdinalIgnoreCase.Equals(x, subject.Id)));
 }
Ejemplo n.º 30
0
 /// <summary>
 ///   Performs a conversion from <see cref="T:double[]" />
 ///   to <see cref="Accord.Imaging.FeatureDescriptor"/>.
 /// </summary>
 ///
 public static FeatureDescriptor FromGeneric(FeatureDescriptor <double[]> value)
 {
     return(new FeatureDescriptor(value.Descriptor));
 }
        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);
        }