コード例 #1
0
        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();
        }
コード例 #2
0
        private void BuildContent(PipelineBuildEvent pipelineEvent, PipelineBuildEvent cachedEvent, string eventFilepath)
        {
            if (!File.Exists(pipelineEvent.SourceFile))
            {
                Logger.LogMessage("{0}", pipelineEvent.SourceFile);
                throw new PipelineException("The source file '{0}' does not exist!", pipelineEvent.SourceFile);
            }

            Logger.PushFile(pipelineEvent.SourceFile);

            // Keep track of all build events. (Required to resolve automatic names "AssetName_n".)
            TrackPipelineBuildEvent(pipelineEvent);

            var rebuild = pipelineEvent.NeedsRebuild(this, cachedEvent);

            if (rebuild)
            {
                Logger.LogMessage("{0}", pipelineEvent.SourceFile);
            }
            else
            {
                Logger.LogMessage("Skipping {0}", pipelineEvent.SourceFile);
            }

            Logger.Indent();
            try
            {
                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)
                {
                    // Import and process the content.
                    var processedObject = ProcessContent(pipelineEvent);

                    // Write the content to disk.
                    WriteXnb(processedObject, pipelineEvent);

                    // Store the timestamp of the DLLs containing the importer and processor.
                    pipelineEvent.ImporterTime  = GetImporterAssemblyTimestamp(pipelineEvent.Importer);
                    pipelineEvent.ProcessorTime = GetProcessorAssemblyTimestamp(pipelineEvent.Processor);

                    // Store the new event into the intermediate folder.
                    pipelineEvent.Save(eventFilepath);
                }
            }
            finally
            {
                Logger.Unindent();
                Logger.PopFile();
            }
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        public void BuildContent(PipelineBuildEvent pipelineEvent, PipelineBuildEvent cachedEvent, string eventFilepath)
        {
            if (!File.Exists(pipelineEvent.SourceFile))
            {
                throw new PipelineException("The source file '{0}' does not exist!", pipelineEvent.SourceFile);
            }

            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);

                // Import and process the content.
                var processedObject = ProcessContent(pipelineEvent);

                // 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();
        }