91 lines
3.3 KiB
C#

#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
#endregion
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.Framework.Content.Pipeline.Tasks
{
public class ProcessorManager
{
private Dictionary<string, IContentProcessor> processors = new Dictionary<string, IContentProcessor>();
public ProcessorManager()
{
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
#if LINUX
//Apparently these Assemblies are bad juju, so lets blacklist them as we don't need to check them anyway
if (assembly.FullName == "MonoDevelop.Core, Version=2.6.0.0, Culture=neutral, PublicKeyToken=null" || assembly.FullName == "pango-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f"
|| assembly.FullName == "Mono.TextEditor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" || assembly.FullName == "MonoDevelop.Ide, Version=2.6.0.0, Culture=neutral, PublicKeyToken=null")
return;
Console.WriteLine("ProcessorManager: Checking " + assembly.FullName);
#endif
try
{
foreach (Type type in assembly.GetTypes())
{
ContentProcessorAttribute[] value = (ContentProcessorAttribute[]) type.GetCustomAttributes(typeof(ContentProcessorAttribute), true);
if (value.Length > 0 && !processors.ContainsKey(type.Name))
{
processors[type.Name] = (IContentProcessor)Activator.CreateInstance(type);
}
}
}
catch(Exception ex)
{
Console.WriteLine(assembly.FullName);
}
}
}
public IContentProcessor GetInstance(string processorName)
{
IContentProcessor processor;
if (!this.processors.TryGetValue(processorName, out processor))
{
throw new Exception(String.Format("can't find processor {0}", processorName));
}
return processor;
}
public String GetProcessorForType(Type type)
{
foreach (KeyValuePair<string, IContentProcessor> processorDescription in processors)
{
if (Type.Equals(processorDescription.Value.InputType, type))
{
return processorDescription.Key;
}
}
return string.Empty;
}
public string GetProcessorForImporter(IContentImporter contentImporter)
{
return GetProcessorForType(contentImporter.OutputType);
}
public IEnumerable<KeyValuePair<string, IContentProcessor>> AvailableProcessors
{
get
{
foreach (KeyValuePair<string, IContentProcessor> kvp in processors)
{
yield return kvp;
}
}
}
}
}