static PipelineTypes() { AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; MissingImporter = new ImporterTypeDescription() { DisplayName = "Invalid / Missing Importer", }; MissingProcessor = new ProcessorTypeDescription() { DisplayName = "Invalid / Missing Processor", Properties = new ProcessorTypeDescription.ProcessorPropertyCollection(Array.Empty <ProcessorTypeDescription.Property>()), }; NullImporter = new ImporterTypeDescription() { DisplayName = "", }; NullProcessor = new ProcessorTypeDescription() { DisplayName = "", Properties = new ProcessorTypeDescription.ProcessorPropertyCollection(Array.Empty <ProcessorTypeDescription.Property>()), }; _watchers = new List <FileSystemWatcher>(); }
public void ResolveTypes() { if (BuildAction == BuildAction.Copy) { // Copy items do not have importers or processors. _importer = PipelineTypes.NullImporter; _processor = PipelineTypes.NullProcessor; } else { _importer = PipelineTypes.FindImporter(ImporterName, System.IO.Path.GetExtension(OriginalPath)); if (_importer != null && (string.IsNullOrEmpty(ImporterName) || ImporterName != _importer.TypeName)) ImporterName = _importer.TypeName; if (_importer == null) _importer = PipelineTypes.MissingImporter; _processor = PipelineTypes.FindProcessor(ProcessorName, _importer); if (_processor != null && (string.IsNullOrEmpty(ProcessorName) || ProcessorName != _processor.TypeName)) ProcessorName = _processor.TypeName; if (_processor == null) _processor = PipelineTypes.MissingProcessor; // ProcessorParams get deserialized as strings // this code converts them to object(s) of their actual type // so that the correct editor appears within the property grid. foreach (var p in _processor.Properties) { if (!ProcessorParams.ContainsKey(p.Name)) { ProcessorParams[p.Name] = p.DefaultValue; } else { var src = ProcessorParams[p.Name]; if (src != null) { var srcType = src.GetType(); var converter = PipelineTypes.FindConverter(p.Type); // Should we throw an exception here? // This property will actually not be editable in the property grid // since we do not have a type converter for it. if (converter.CanConvertFrom(srcType)) { var dst = converter.ConvertFrom(null, CultureInfo.InvariantCulture, src); ProcessorParams[p.Name] = dst; } } } } } }
public static void Load(PipelineProject project) { Unload(); var assemblyPaths = new List <string>(); var projectRoot = project.Location; foreach (var i in project.References) { var path = Path.Combine(projectRoot, i); if (string.IsNullOrEmpty(path)) { throw new ArgumentException("assemblyFilePath cannot be null!"); } if (!Path.IsPathRooted(path)) { throw new ArgumentException("assemblyFilePath must be absolute!"); } // Make sure we're not adding the same assembly twice. path = PathHelper.Normalize(path); if (!assemblyPaths.Contains(path)) { assemblyPaths.Add(path); } } ResolveAssemblies(assemblyPaths); var importerDescriptions = new ImporterTypeDescription[_importers.Count]; var cur = 0; foreach (var item in _importers) { // Find the abstract base class ContentImporter<T>. var baseType = item.Type.BaseType; while (!baseType.IsAbstract) { baseType = baseType.BaseType; } var outputType = baseType.GetGenericArguments()[0]; var name = item.Attribute.DisplayName; if (string.IsNullOrEmpty(name)) { name = item.GetType().Name; } var desc = new ImporterTypeDescription() { TypeName = item.Type.Name, DisplayName = name, DefaultProcessor = item.Attribute.DefaultProcessor, FileExtensions = item.Attribute.FileExtensions, OutputType = outputType, }; importerDescriptions[cur] = desc; cur++; } Importers = importerDescriptions; ImportersStandardValuesCollection = new TypeConverter.StandardValuesCollection(Importers); var processorDescriptions = new ProcessorTypeDescription[_processors.Count]; const BindingFlags bindings = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static; cur = 0; foreach (var item in _processors) { var obj = Activator.CreateInstance(item.Type); var typeProperties = item.Type.GetProperties(bindings); var properties = new List <ProcessorTypeDescription.Property>(); foreach (var i in typeProperties) { var attrs = i.GetCustomAttributes(true); var name = i.Name; var browsable = true; var defvalue = i.GetValue(obj, null); foreach (var a in attrs) { if (a is BrowsableAttribute) { browsable = (a as BrowsableAttribute).Browsable; } else if (a is DisplayNameAttribute) { name = (a as DisplayNameAttribute).DisplayName; } } var p = new ProcessorTypeDescription.Property() { Name = i.Name, DisplayName = name, Type = i.PropertyType, DefaultValue = defvalue, Browsable = browsable }; properties.Add(p); } var inputType = (obj as IContentProcessor).InputType; var desc = new ProcessorTypeDescription() { TypeName = item.Type.Name, DisplayName = item.Attribute.DisplayName, Properties = new ProcessorTypeDescription.ProcessorPropertyCollection(properties), InputType = inputType, }; if (string.IsNullOrEmpty(desc.DisplayName)) { desc.DisplayName = desc.TypeName; } processorDescriptions[cur] = desc; cur++; } Processors = processorDescriptions; ProcessorsStandardValuesCollection = new TypeConverter.StandardValuesCollection(Processors); }