public override bool Execute() { bool hasErrors = false; try { var contentFiles = new List <ITaskItem>(); foreach (ITaskItem item in Files) { OdItem odItem = new OdItem { Name = item.ItemSpec, InputFilename = item.GetMetadata("Filename"), InputExtension = item.GetMetadata("Extension"), LinkName = item.GetMetadata("Link", item.ItemSpec), }; odItem.OutputExtension = FindExtension(odItem.InputExtension); odItem.OutputLink = Path.ChangeExtension(odItem.LinkName, odItem.OutputExtension); odItem.OutputFilePath = Path.Combine(ProjectDirectory.ItemSpec, IntermediateDirectory.ItemSpec, odItem.OutputLink); odItem.InputFilePath = Path.Combine(ProjectDirectory.ItemSpec, odItem.Name); if (!ProcessItem(odItem)) { hasErrors = true; } var returnedItem = odItem.ToTaskItem(); contentFiles.Add(returnedItem); } ContentFiles = contentFiles.ToArray(); } catch (Exception ex) { Log.LogError("Unexpected exception: {0}", ex); hasErrors = true; } return(!hasErrors); }
protected override bool ProcessItem(OdItem odItem) { var hasErrors = false; var inputFilePath = odItem.InputFilePath; var outputFilePath = odItem.OutputFilePath; try { var dependencyFilePath = Path.Combine(Path.Combine(ProjectDirectory.ItemSpec, IntermediateDirectory.ItemSpec), FileDependencyList.GetDependencyFileNameFromSourcePath(odItem.LinkName)); CreateDirectoryIfNotExists(dependencyFilePath); Log.LogMessage(MessageImportance.Low, "Check Toolkit file to compile {0} with dependency file {1}", inputFilePath, dependencyFilePath); if (FileDependencyList.CheckForChanges(dependencyFilePath) || !File.Exists(outputFilePath)) { Log.LogMessage(MessageImportance.Low, "Starting compilation of {0}", inputFilePath); if (!ProcessFile(inputFilePath, outputFilePath, dependencyFilePath, odItem)) { hasErrors = false; } else { Log.LogMessage(MessageImportance.High, "Compilation successful of {0} to {1}", inputFilePath, outputFilePath); } } } catch (Exception ex) { Log.LogError("Cannot process file '{0}' : {1}", inputFilePath, ex.Message); hasErrors = true; } return(!hasErrors); }
protected override bool ProcessFile(string inputFilePath, string outputFilePath, string dependencyFilePath, OdItem item) { ModelOperation op = ModelOperation.None; if (ModelOperations != null) op = ModelOperations.Aggregate(ModelOperation.None, (current, t) => current | (ModelOperation) Enum.Parse(typeof (ModelOperation), t.ItemSpec)); var compilerOptions = new ModelCompilerOptions() { DependencyFile = dependencyFilePath, Quality = Debug ? ModelRealTimeQuality.Low : ModelRealTimeQuality.Maximum, ExcludeElements = ExcludeElements != null ? ExcludeElements.Select(element => element.ItemSpec).ToArray() : new string[0], ModelOperations = op }; var result = ModelCompiler.CompileAndSave(inputFilePath, outputFilePath, compilerOptions); return result.HasErrors; }
protected abstract bool ProcessFile(string inputFilePath, string outputFilePath, string dependencyFilePath, OdItem item);
protected virtual bool ProcessItem(OdItem odItem) { return(true); }