From 016694c77061c593348b709351db4c08fb00795d Mon Sep 17 00:00:00 2001 From: Glatzemann Date: Mon, 27 Aug 2012 05:33:46 +0000 Subject: [PATCH] added custom parameters to ContentPipeline BuildItem --- .../ANX.Framework.Content.Pipeline.csproj | 2 +- .../NamedValueDictionary.cs | 55 +++++++++++-------- .../OpaqueDataDictionary.cs | 20 ++++--- .../Tasks/BuildContent.cs | 14 ++--- .../Tasks/BuildItem.cs | 22 +++++++- .../Tasks/BuildRequest.cs | 23 -------- Tools/ContentBuilder/Program.cs | 9 ++- 7 files changed, 75 insertions(+), 70 deletions(-) delete mode 100644 ANX.Framework.Content.Pipeline/Tasks/BuildRequest.cs diff --git a/ANX.Framework.Content.Pipeline/ANX.Framework.Content.Pipeline.csproj b/ANX.Framework.Content.Pipeline/ANX.Framework.Content.Pipeline.csproj index 2b030833..631d2ea2 100644 --- a/ANX.Framework.Content.Pipeline/ANX.Framework.Content.Pipeline.csproj +++ b/ANX.Framework.Content.Pipeline/ANX.Framework.Content.Pipeline.csproj @@ -172,7 +172,7 @@ - + diff --git a/ANX.Framework.Content.Pipeline/NamedValueDictionary.cs b/ANX.Framework.Content.Pipeline/NamedValueDictionary.cs index 22c98a12..1bb1a286 100644 --- a/ANX.Framework.Content.Pipeline/NamedValueDictionary.cs +++ b/ANX.Framework.Content.Pipeline/NamedValueDictionary.cs @@ -15,26 +15,30 @@ namespace ANX.Framework.Content.Pipeline { public class NamedValueDictionary : IDictionary, ICollection>, IEnumerable>, IEnumerable { + private Dictionary keyValues = new Dictionary(); + public NamedValueDictionary() { - throw new NotImplementedException(); + // nothing to do } public int Count { - get; - private set; + get + { + return this.keyValues.Count; + } } public T this[string key] { get { - throw new NotImplementedException(); + return this.keyValues[key]; } set { - throw new NotImplementedException(); + this.keyValues[key] = value; } } @@ -42,7 +46,7 @@ namespace ANX.Framework.Content.Pipeline { get { - throw new NotImplementedException(); + return this.keyValues.Keys; } } @@ -50,7 +54,7 @@ namespace ANX.Framework.Content.Pipeline { get { - throw new NotImplementedException(); + return this.keyValues.Values; } } @@ -58,88 +62,91 @@ namespace ANX.Framework.Content.Pipeline { get { - throw new NotImplementedException(); + return typeof(T); } } public void Add(string key, T value) { - throw new NotImplementedException(); + this.keyValues.Add(key, value); } public void Clear() { - throw new NotImplementedException(); + this.keyValues.Clear(); } public bool ContainsKey(string key) { - throw new NotImplementedException(); + return this.keyValues.ContainsKey(key); } public IEnumerator> GetEnumerator() { - throw new NotImplementedException(); + return this.keyValues.GetEnumerator(); } public bool Remove(string key) { - throw new NotImplementedException(); + return this.keyValues.Remove(key); } public bool TryGetValue(string key, out T value) { - throw new NotImplementedException(); + return this.keyValues.TryGetValue(key, out value); } protected virtual void AddItem(string key, T value) { - throw new NotImplementedException(); + this.keyValues.Add(key, value); } protected virtual void ClearItems() { - throw new NotImplementedException(); + this.keyValues.Clear(); } protected virtual bool RemoveItem(string key) { - throw new NotImplementedException(); + return this.keyValues.Remove(key); } protected virtual void SetItem(string key, T value) { - throw new NotImplementedException(); + this.keyValues[key] = value; } bool ICollection>.IsReadOnly { - get { throw new NotImplementedException(); } + get + { + return false; + } } void ICollection>.Add(KeyValuePair item) { - throw new NotImplementedException(); + this.keyValues.Add(item.Key, item.Value); } bool ICollection>.Contains(KeyValuePair item) { - throw new NotImplementedException(); + return this.keyValues.ContainsKey(item.Key); } void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) { - throw new NotImplementedException(); + ((ICollection>)this.keyValues).CopyTo(array, arrayIndex); } IEnumerator IEnumerable.GetEnumerator() { - throw new NotImplementedException(); + return this.keyValues.GetEnumerator(); } bool ICollection>.Remove(KeyValuePair item) { - throw new NotImplementedException(); + return this.keyValues.Remove(item.Key); } } } diff --git a/ANX.Framework.Content.Pipeline/OpaqueDataDictionary.cs b/ANX.Framework.Content.Pipeline/OpaqueDataDictionary.cs index 34ef419b..4bdf95ef 100644 --- a/ANX.Framework.Content.Pipeline/OpaqueDataDictionary.cs +++ b/ANX.Framework.Content.Pipeline/OpaqueDataDictionary.cs @@ -16,19 +16,21 @@ namespace ANX.Framework.Content.Pipeline { public OpaqueDataDictionary() { - throw new NotImplementedException(); - } - - public string GetContentAsXml() - { - throw new NotImplementedException(); + // nothing to do } public T GetValue(string key, T defaultValue) { - throw new NotImplementedException(); + object retValue = null; + if (base.TryGetValue(key, out retValue)) + { + if (retValue is T) + { + return (T)retValue; + } + } + + return defaultValue; } - - } } diff --git a/ANX.Framework.Content.Pipeline/Tasks/BuildContent.cs b/ANX.Framework.Content.Pipeline/Tasks/BuildContent.cs index 49517d2b..57f92957 100644 --- a/ANX.Framework.Content.Pipeline/Tasks/BuildContent.cs +++ b/ANX.Framework.Content.Pipeline/Tasks/BuildContent.cs @@ -104,9 +104,9 @@ namespace ANX.Framework.Content.Pipeline.Tasks { var importedObject = ImportAsset(buildItem); - if (String.IsNullOrEmpty(buildItem.BuildRequest.ProcessorName)) + if (String.IsNullOrEmpty(buildItem.ProcessorName)) { - buildItem.BuildRequest.ProcessorName = ProcessorManager.GetProcessorForType(importedObject.GetType()); + buildItem.ProcessorName = ProcessorManager.GetProcessorForType(importedObject.GetType()); } var buildedItem = Process(buildItem, importedObject); @@ -117,21 +117,21 @@ namespace ANX.Framework.Content.Pipeline.Tasks private object ImportAsset(BuildItem item) { - IContentImporter instance = this.ImporterManager.GetInstance(item.BuildRequest.ImporterName); + IContentImporter instance = this.ImporterManager.GetInstance(item.ImporterName); ContentImporterContext context = new AnxContentImporterContext(this, item, BuildLogger); BuildLogger.LogMessage("building {0} of type {1}", new object[] { - item.BuildRequest.SourceFilename, + item.SourceFilename, instance.GetType() }); - return instance.Import(item.BuildRequest.SourceFilename, context); + return instance.Import(item.SourceFilename, context); } private object Process(BuildItem item, object importedObject) { - if (String.IsNullOrEmpty(item.BuildRequest.ProcessorName) == false) + if (String.IsNullOrEmpty(item.ProcessorName) == false) { - IContentProcessor instance = this.ProcessorManager.GetInstance(item.BuildRequest.ProcessorName); + IContentProcessor instance = this.ProcessorManager.GetInstance(item.ProcessorName); ContentProcessorContext context = new AnxContentProcessorContext(item, BuildLogger, TargetPlatform, TargetProfile, ""); context.OutputDirectory = OutputDirectory; context.OutputFilename = item.OutputFilename; diff --git a/ANX.Framework.Content.Pipeline/Tasks/BuildItem.cs b/ANX.Framework.Content.Pipeline/Tasks/BuildItem.cs index 513f5c5e..a3f945de 100644 --- a/ANX.Framework.Content.Pipeline/Tasks/BuildItem.cs +++ b/ANX.Framework.Content.Pipeline/Tasks/BuildItem.cs @@ -14,7 +14,27 @@ namespace ANX.Framework.Content.Pipeline.Tasks { public class BuildItem { - public BuildRequest BuildRequest + public readonly OpaqueDataDictionary ProcessorParameters = new OpaqueDataDictionary(); + + public String SourceFilename + { + get; + set; + } + + public String AssetName + { + get; + set; + } + + public string ImporterName + { + get; + set; + } + + public string ProcessorName { get; set; diff --git a/ANX.Framework.Content.Pipeline/Tasks/BuildRequest.cs b/ANX.Framework.Content.Pipeline/Tasks/BuildRequest.cs deleted file mode 100644 index 2a941967..00000000 --- a/ANX.Framework.Content.Pipeline/Tasks/BuildRequest.cs +++ /dev/null @@ -1,23 +0,0 @@ -#region Using Statements -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -#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 BuildRequest - { - public String SourceFilename; - public String AssetName; - public string ImporterName; - public string ProcessorName; - - } -} diff --git a/Tools/ContentBuilder/Program.cs b/Tools/ContentBuilder/Program.cs index 3077801a..04887c59 100644 --- a/Tools/ContentBuilder/Program.cs +++ b/Tools/ContentBuilder/Program.cs @@ -30,12 +30,11 @@ namespace ContentBuilder if (!arg.StartsWith("/") && !arg.StartsWith("-")) { BuildItem buildItem = new BuildItem(); - buildItem.BuildRequest = new BuildRequest(); - buildItem.BuildRequest.ImporterName = ImporterManager.GuessImporterByFileExtension(arg); + buildItem.ImporterName = ImporterManager.GuessImporterByFileExtension(arg); //TODO: set configured processor name - buildItem.BuildRequest.SourceFilename = arg; - buildItem.BuildRequest.AssetName = System.IO.Path.GetFileNameWithoutExtension(arg); - buildItem.OutputFilename = String.Format("{0}.xnb", buildItem.BuildRequest.AssetName); + buildItem.SourceFilename = arg; + buildItem.AssetName = System.IO.Path.GetFileNameWithoutExtension(arg); + buildItem.OutputFilename = String.Format("{0}.xnb", buildItem.AssetName); itemsToBuild.Add(buildItem); }