Example #1
0
        public void Build()
        {
            if (Project == null)
            {
                return;
            }
            currentBuild = BuildStep.Build;
            BuildStatusChanged?.BeginInvoke(this, BuildStep.Build, null, null);

            buildingThread = new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
            {
                FailedBuilds = 0;

                IsBuilding       = true;
                string outputDir = getOutputDir();
                CreateFolderIfNeeded(outputDir);
                PipelineHelper.PreBuilt(Project);
                using (engenious.Content.Pipeline.ContentImporterContext importerContext = new engenious.Content.Pipeline.ContentImporterContext())
                    using (engenious.Content.Pipeline.ContentProcessorContext processorContext = new engenious.Content.Pipeline.ContentProcessorContext())
                    {
                        importerContext.BuildMessage  += RaiseBuildMessage;
                        processorContext.BuildMessage += RaiseBuildMessage;

                        buildDir(Project, importerContext, processorContext);
                    }
                //System.Threading.Thread.Sleep(8000);
                cache.Save(getCacheFile());
                IsBuilding = false;

                BuildStatusChanged?.BeginInvoke(this, BuildStep.Build | BuildStep.Finished, null, null);
            }));
            buildingThread.Start();
        }
Example #2
0
 private void buildDir(ContentFolder folder, engenious.Content.Pipeline.ContentImporterContext importerContext, engenious.Content.Pipeline.ContentProcessorContext processorContext)
 {
     foreach (var item in folder.Contents)
     {
         if (item is ContentFile)
         {
             buildFile(item as ContentFile, importerContext, processorContext);
         }
         else if (item is ContentFolder)
         {
             buildDir(item as ContentFolder, importerContext, processorContext);
         }
     }
 }
Example #3
0
        private void buildFile(ContentFile contentFile, engenious.Content.Pipeline.ContentImporterContext importerContext, engenious.Content.Pipeline.ContentProcessorContext processorContext)
        {
            string importDir  = System.IO.Path.GetDirectoryName(Project.File);
            string importFile = System.IO.Path.Combine(importDir, contentFile.getPath());
            string destFile   = getDestinationFileAbsolute(contentFile);
            string outputPath = getOutputDir();

            CreateFolderIfNeeded(destFile);
            if (!cache.NeedsRebuild(importDir, outputPath, contentFile.getPath()))
            {
                //importerContext.RaiseBuildMessage(contentFile.getPath()," skipped(cached)",engenious.Content.Pipeline.BuildMessageEventArgs.BuildMessageType.Information);
                //ItemProgress?.BeginInvoke(this, new ItemProgressEventArgs(BuildStep.Build, contentFile), null, null);
                return;
            }
            BuildInfo cacheInfo = new BuildInfo(importDir, contentFile.getPath(), getDestinationFile(contentFile));
            var       importer  = contentFile.Importer;

            if (importer == null)
            {
                return;
            }

            object importerOutput = importer.Import(importFile, importerContext);

            if (importerOutput == null)
            {
                return;
            }

            cacheInfo.Dependencies.AddRange(importerContext.Dependencies);
            cache.AddDependencies(importDir, importerContext.Dependencies);

            engenious.Content.Pipeline.IContentProcessor processor = contentFile.Processor;
            if (processor == null)
            {
                return;
            }

            object processedData = processor.Process(importerOutput, importFile, processorContext);

            if (processedData == null)
            {
                return;
            }
            cacheInfo.Dependencies.AddRange(processorContext.Dependencies);
            cache.AddDependencies(importDir, processorContext.Dependencies);

            engenious.Content.Serialization.IContentTypeWriter typeWriter = engenious.Content.Serialization.SerializationManager.Instance.GetWriter(processedData.GetType());
            engenious.Content.ContentFile outputFileWriter = new engenious.Content.ContentFile(typeWriter.RuntimeReaderName);

            BinaryFormatter formatter = new BinaryFormatter();

            using (FileStream fs = new FileStream(destFile, FileMode.Create, FileAccess.Write))
            {
                formatter.Serialize(fs, outputFileWriter);
                engenious.Content.Serialization.ContentWriter writer = new engenious.Content.Serialization.ContentWriter(fs);
                writer.WriteObject(processedData, typeWriter);
            }
            cacheInfo.BuildDone(outputPath);
            cache.AddBuildInfo(cacheInfo);
            builtFiles[contentFile.getPath()] = contentFile;
            ItemProgress?.BeginInvoke(this, new ItemProgressEventArgs(BuildStep.Build, contentFile), null, null);
        }