Пример #1
0
 private static IProcessor FindProcessor(string processorName)
 {
     if (string.IsNullOrEmpty(processorName))
     {
         return(null);
     }
     return(ContentProcessors.First(p => p.GetType().Name == processorName));
 }
Пример #2
0
        public TOutput Convert <TInput, TOutput>(TInput input, string processorName, OpaqueDataDictionary processorParameters)
        {
            var processor = ContentProcessors.FirstOrDefault(p => p.GetType().Name == processorName);

            if (processor == null)
            {
                throw new InvalidOperationException(string.Format("Cannot find processor {0}", processorName));
            }

            ApplyParameters(processor, processorParameters);
            return((TOutput)processor.Process(input, ProcessorContext));
        }
Пример #3
0
        public TOutput Convert <TInput, TOutput>(TInput input, string processorName, OpaqueDataDictionary processorParameters)
        {
            try
            {
                var processor = ContentProcessors.FirstOrDefault(p => p.GetType().Name == processorName);
                if (processor == null)
                {
                    throw new InvalidOperationException(string.Format("Cannot find processor {0}", processorName));
                }

                ApplyParameters(processor, processorParameters);
                processorContext = processorContext ?? new PipelineProcessorContext(this);
                return((TOutput)processor.Process(input, processorContext));
            }
            catch (Exception e)
            {
                Trace.TraceError("Error converting {0} with processor {1}", input.GetType().Name, processorName);
                Trace.WriteLine(e);
                throw new InvalidContentException("", e);
            }
        }
Пример #4
0
        private static void FindImportersProcessorAndContentWriters(Assembly assembly)
        {
            if (assembly.FullName.StartsWith("System") ||
                assembly.FullName.StartsWith("mscorlib") ||
                (assembly.FullName.StartsWith("Microsoft.") && !assembly.FullName.StartsWith("Microsoft.Xna.Framework.Content.Pipeline")))
            {
                return;
            }

            foreach (var type in assembly.GetTypes())
            {
                try
                {
                    if (typeof(IImporter).IsAssignableFrom(type) &&
                        type.GetCustomAttributes(typeof(ContentImporterAttribute), false).Any() &&
                        !ContentImporters.Any(i => i.GetType() == type))
                    {
                        ContentImporters.Add((IImporter)Activator.CreateInstance(type));
                    }
                    if (typeof(IProcessor).IsAssignableFrom(type) &&
                        type.GetCustomAttributes(typeof(ContentProcessorAttribute), false).Any() &&
                        !ContentProcessors.Any(i => i.GetType() == type))
                    {
                        ContentProcessors.Add((IProcessor)Activator.CreateInstance(type));
                    }
                    if (typeof(ContentTypeWriter).IsAssignableFrom(type) &&
                        type.GetCustomAttributes(typeof(ContentTypeWriterAttribute), false).Any() &&
                        !ContentWriters.Any(i => i.GetType() == type) && !type.IsGenericTypeDefinition)
                    {
                        ContentWriters.Add((ContentTypeWriter)Activator.CreateInstance(type));
                    }
                }
                catch (Exception e)
                {
                    Trace.TraceWarning("Error load type {0} from assembly {1}", type.AssemblyQualifiedName, assembly.FullName);
                    Trace.WriteLine(e.ToString());
                }
            }
        }