public void BuildContent(PipelineBuildEvent pipelineEvent, PipelineBuildEvent cachedEvent, string eventFilepath) { if (!File.Exists(pipelineEvent.SourceFile)) throw new PipelineException("The source file does not exist!"); Logger.PushFile(pipelineEvent.SourceFile); var rebuild = pipelineEvent.NeedsRebuild(cachedEvent); if (!rebuild) { // While this asset doesn't need to be rebuilt the dependent assets might. foreach (var asset in cachedEvent.BuildAsset) { string assetEventFilepath; var assetCachedEvent = LoadBuildEvent(asset, out assetEventFilepath); // If we cannot find the cached event for the dependancy // then we have to trigger a rebuild of the parent content. if (assetCachedEvent == null) { rebuild = true; break; } var depEvent = new PipelineBuildEvent { SourceFile = assetCachedEvent.SourceFile, DestFile = assetCachedEvent.DestFile, Importer = assetCachedEvent.Importer, Processor = assetCachedEvent.Processor, Parameters = assetCachedEvent.Parameters, }; // Give the asset a chance to rebuild. BuildContent(depEvent, assetCachedEvent, assetEventFilepath); } } // Do we need to rebuild? if (rebuild) { Logger.LogMessage("{0}", pipelineEvent.SourceFile); // Make sure we can find the importer and processor. var importer = CreateImporter(pipelineEvent.Importer); if (importer == null) throw new PipelineException("Failed to create importer '{0}'", pipelineEvent.Importer); var processor = CreateProcessor(pipelineEvent.Processor, pipelineEvent.Parameters); if (processor == null) throw new PipelineException("Failed to create processor '{0}'", pipelineEvent.Processor); // Try importing the content. object importedObject; try { var importContext = new PipelineImporterContext(this); importedObject = importer.Import(pipelineEvent.SourceFile, importContext); } catch (PipelineException) { throw; } catch (Exception inner) { throw new PipelineException(string.Format("Importer '{0}' had unexpected failure!", pipelineEvent.Importer), inner); } // Make sure the input type is valid. if (!processor.InputType.IsAssignableFrom(importedObject.GetType())) { throw new PipelineException( string.Format("The type '{0}' cannot be processed by {1} as a {2}!", importedObject.GetType().FullName, pipelineEvent.Processor, processor.InputType.FullName)); } // Process the imported object. object processedObject; try { var processContext = new PipelineProcessorContext(this, pipelineEvent); processedObject = processor.Process(importedObject, processContext); } catch (PipelineException) { throw; } catch (Exception inner) { throw new PipelineException(string.Format("Processor '{0}' had unexpected failure!", pipelineEvent.Processor), inner); } // Write the content to disk. WriteXnb(processedObject, pipelineEvent); // Store the new event into the intermediate folder. pipelineEvent.Save(eventFilepath); } else { Logger.LogMessage("Skipping {0}", pipelineEvent.SourceFile); } Logger.PopFile(); }
public void BuildContent(PipelineBuildEvent pipelineEvent, PipelineBuildEvent cachedEvent, string eventFilepath) { if (!File.Exists(pipelineEvent.SourceFile)) { throw new PipelineException("The source file does not exist!"); } Logger.PushFile(pipelineEvent.SourceFile); var rebuild = pipelineEvent.NeedsRebuild(cachedEvent); if (!rebuild) { // While this asset doesn't need to be rebuilt the dependent assets might. foreach (var asset in cachedEvent.BuildAsset) { string assetEventFilepath; var assetCachedEvent = LoadBuildEvent(asset, out assetEventFilepath); // If we cannot find the cached event for the dependancy // then we have to trigger a rebuild of the parent content. if (assetCachedEvent == null) { rebuild = true; break; } var depEvent = new PipelineBuildEvent { SourceFile = assetCachedEvent.SourceFile, DestFile = assetCachedEvent.DestFile, Importer = assetCachedEvent.Importer, Processor = assetCachedEvent.Processor, Parameters = assetCachedEvent.Parameters, }; // Give the asset a chance to rebuild. BuildContent(depEvent, assetCachedEvent, assetEventFilepath); } } // Do we need to rebuild? if (rebuild) { Logger.LogMessage("{0}", pipelineEvent.SourceFile); // Make sure we can find the importer and processor. var importer = CreateImporter(pipelineEvent.Importer); if (importer == null) { throw new PipelineException("Failed to create importer '{0}'", pipelineEvent.Importer); } var processor = CreateProcessor(pipelineEvent.Processor, pipelineEvent.Parameters); if (processor == null) { throw new PipelineException("Failed to create processor '{0}'", pipelineEvent.Processor); } // Try importing the content. object importedObject; try { var importContext = new PipelineImporterContext(this); importedObject = importer.Import(pipelineEvent.SourceFile, importContext); } catch (PipelineException) { throw; } catch (Exception inner) { throw new PipelineException(string.Format("Importer '{0}' had unexpected failure!", pipelineEvent.Importer), inner); } // Make sure the input type is valid. if (!processor.InputType.IsAssignableFrom(importedObject.GetType())) { throw new PipelineException( string.Format("The type '{0}' cannot be processed by {1} as a {2}!", importedObject.GetType().FullName, pipelineEvent.Processor, processor.InputType.FullName)); } // Process the imported object. object processedObject; try { var processContext = new PipelineProcessorContext(this, pipelineEvent); processedObject = processor.Process(importedObject, processContext); } catch (PipelineException) { throw; } catch (Exception inner) { throw new PipelineException(string.Format("Processor '{0}' had unexpected failure!", pipelineEvent.Processor), inner); } // Write the content to disk. WriteXnb(processedObject, pipelineEvent); // Store the new event into the intermediate folder. pipelineEvent.Save(eventFilepath); } else { Logger.LogMessage("Skipping {0}", pipelineEvent.SourceFile); } Logger.PopFile(); }
public object ProcessContent(PipelineBuildEvent pipelineEvent) { if (!File.Exists(pipelineEvent.SourceFile)) { throw new PipelineException("The source file '{0}' does not exist!", pipelineEvent.SourceFile); } // Store the last write time of the source file // so we can detect if it has been changed. pipelineEvent.SourceTime = File.GetLastWriteTime(pipelineEvent.SourceFile); // Make sure we can find the importer and processor. var importer = CreateImporter(pipelineEvent.Importer); if (importer == null) { throw new PipelineException("Failed to create importer '{0}'", pipelineEvent.Importer); } // Try importing the content. object importedObject; if (RethrowExceptions) { try { var importContext = new PipelineImporterContext(this); importedObject = importer.Import(pipelineEvent.SourceFile, importContext); } catch (PipelineException) { throw; } catch (Exception inner) { throw new PipelineException(string.Format("Importer '{0}' had unexpected failure!", pipelineEvent.Importer), inner); } } else { var importContext = new PipelineImporterContext(this); importedObject = importer.Import(pipelineEvent.SourceFile, importContext); } // The pipelineEvent.Processor can be null or empty. In this case the // asset should be imported but not processed. if (string.IsNullOrEmpty(pipelineEvent.Processor)) { return(importedObject); } var processor = CreateProcessor(pipelineEvent.Processor, pipelineEvent.Parameters); if (processor == null) { throw new PipelineException("Failed to create processor '{0}'", pipelineEvent.Processor); } // Make sure the input type is valid. if (!processor.InputType.IsAssignableFrom(importedObject.GetType())) { throw new PipelineException( string.Format("The type '{0}' cannot be processed by {1} as a {2}!", importedObject.GetType().FullName, pipelineEvent.Processor, processor.InputType.FullName)); } // Process the imported object. object processedObject; if (RethrowExceptions) { try { var processContext = new PipelineProcessorContext(this, pipelineEvent); processedObject = processor.Process(importedObject, processContext); } catch (PipelineException) { throw; } catch (InvalidContentException) { throw; } catch (Exception inner) { throw new PipelineException(string.Format("Processor '{0}' had unexpected failure!", pipelineEvent.Processor), inner); } } else { var processContext = new PipelineProcessorContext(this, pipelineEvent); processedObject = processor.Process(importedObject, processContext); } return(processedObject); }