Example #1
0
        public TContent BuildAndLoad <TContent>(string sourceAssetFile, IImporter contentImporter, IProcessor contentProcessor, string fileName)
        {
            try
            {
                OutputFilename = FindNextValidAssetName(fileName ?? Path.GetFileNameWithoutExtension(sourceAssetFile), ".xnb");

                var outputDirectory = Path.GetDirectoryName(OutputFilename);
                if (!Directory.Exists(outputDirectory))
                {
                    Directory.CreateDirectory(outputDirectory);
                }

                // Create a dummy file in case a nested build uses the same name
                File.WriteAllText(OutputFilename, "");

                contentImporter = contentImporter ?? FindImporter(null, sourceAssetFile);
                if (contentImporter == null)
                {
                    throw new InvalidOperationException(string.Format("Cannot find content importer for {0}", sourceAssetFile));
                }

                contentProcessor = contentProcessor ?? FindDefaultProcessor(contentImporter);

                Trace.TraceInformation("Building {0} -> {1} with {2} and {3}",
                                       sourceAssetFile, OutputFilename,
                                       contentImporter != null ? contentImporter.GetType().Name : "<No Importer>",
                                       contentProcessor != null ? contentProcessor.GetType().Name : "<No Processor>");

                object content = contentImporter.Import(sourceAssetFile, ImporterContext);

                if (contentProcessor != null)
                {
                    content = contentProcessor.Process(content, ProcessorContext);
                }
                return((TContent)content);
            }
            catch (Exception e)
            {
                Trace.TraceError("Error importing {0} with asset name {1}", sourceAssetFile, fileName ?? "[Unspecified]");
                Trace.WriteLine(e);
                throw;
            }
        }
Example #2
0
        public TContent BuildAndLoad <TContent>(string sourceAssetFile, IImporter contentImporter, IProcessor contentProcessor, string fileName)
        {
            contentImporter = contentImporter ?? FindImporter(null, sourceAssetFile);
            if (contentImporter == null)
            {
                throw new InvalidOperationException(string.Format("Cannot find content importer for {0}", sourceAssetFile));
            }
            var content = contentImporter.Import(sourceAssetFile, ImporterContext);

            if (contentProcessor != null)
            {
                try
                {
                    outputFilenames.Push(sourceAssetFile);
                    content = contentProcessor.Process(content, ProcessorContext);
                }
                finally
                {
                    LastFilename = outputFilenames.Pop();
                }
            }
            return((TContent)content);
        }