Esempio n. 1
0
 public StylizeConfiguration(
     IDictionary<string, IOptionApplier> exclusionMatchers,
     IOptionApplier globalOptions,
     IDictionary<string, IOptionApplier> rules,
     string repositoryName)
 {
     this.ExclusionMatchers = new Dictionary<string, IOptionApplier>(exclusionMatchers);
     this.GlobalOptions = globalOptions;
     this.Rules = new Dictionary<string, IOptionApplier>(rules);
     this.RepositoryName = repositoryName;
 }
Esempio n. 2
0
        public StylizeEngine(IConfigurationParser configurationParser)
        {
            if (configurationParser == null) { throw new ArgumentNullException(nameof(configurationParser)); }

            Log.WriteVerbose("Initializing MEF");
            var catalog = new AggregateCatalog(
                new AssemblyCatalog(Assembly.GetExecutingAssembly().Location));
            string currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            foreach (string exportAssemblyName in configurationParser.ExportAssemblyNames)
            {
                string exportAssemblyPath = Path.IsPathRooted(exportAssemblyName)
                    ? exportAssemblyName
                    : Path.Combine(currentDirectory, exportAssemblyName);
                catalog.Catalogs.Add(new AssemblyCatalog(exportAssemblyPath));
            }

            this.container = new CompositionContainer(catalog);
            IReadOnlyList<IOption> supportedOptions = this.container.GetExportedValues<IOption>(
                ExportStylizeOptionAttribute.OptionContractName).ToList();

            Log.WriteVerbose("Parsing configuration");
            StylizeConfiguration configuration = configurationParser.ParseConfiguration(supportedOptions);
            this.globalOptions = configuration.GlobalOptions;

            Log.WriteVerbose("Loading exports");
            if (!String.IsNullOrEmpty(configuration.RepositoryName))
            {
                this.repository = this.container.GetExportedValue<ISourceRepository>(configuration.RepositoryName);
                this.container.ComposeExportedValue(ExportSourceRepositoryAttribute.CurrentName, this.repository);
            }

            this.exclusionMatchers = this.container.GetExports<IDocumentMatcher, INamedMetadata>(
                configuration.ExclusionMatchers);

            IReadOnlyList<Export<IStyleRule, StyleRuleMetadata>> rules =
                this.container.GetExports<IStyleRule, StyleRuleMetadata>(configuration.Rules);
            this.languageRuleMap = OrderAndMapRules(rules);

            Log.WriteVerbose("Engine initialized");
        }