Beispiel #1
0
        private ITaskItem ProcessFile(ITaskItem file, XamlPreprocessor preprocessor)
        {
            var sourcePath = file.GetMetadata("FullPath");

            // properly resolve linked xaml
            var targetRelativePath = file.GetMetadata("Link");

            if (string.IsNullOrEmpty(targetRelativePath))
            {
                targetRelativePath = file.ItemSpec;
            }

            // if targetRelativePath is still absolute, use file name
            if (Path.IsPathRooted(targetRelativePath))
            {
                targetRelativePath = Path.GetFileName(targetRelativePath);
            }

            var targetPath = Path.Combine(this.OutputPath, targetRelativePath);

            TaskItem result = null;

            // process XAML
            Log.LogMessage(MessageImportance.High, "XCC > Preprocessing {0}", targetRelativePath);
            var start = DateTime.Now;

            if (preprocessor.ProcessXamlFile(sourcePath, targetPath))
            {
                // targetPath has been written, create linked item
                result = new TaskItem(targetPath);
                file.CopyMetadataTo(result);
                result.SetMetadata("Link", targetRelativePath);          // this is the trick that makes it all work (replace page with a page link pointing to \obj\debug\preprocessedxaml\*)
            }

            var duration = (DateTime.Now - start).TotalMilliseconds;

            Log.LogMessage(MessageImportance.Normal, "XCC > Preprocess completed in {0}ms, {1} has {2}changed", duration, targetRelativePath, result == null ? "not " : "");

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// When overridden in a derived class, executes the task.
        /// </summary>
        /// <returns>
        /// true if the task successfully executed; otherwise, false.
        /// </returns>
        public override bool Execute()
        {
            try {
                Log.LogMessage(MessageImportance.Normal, "XCC > DefinedSymbols: {0}", string.Join(",", this.DefinedSymbols));

                var preprocessor = new XamlPreprocessor(this.DefinedSymbols, this.RemoveIgnorableContent);

                var generatedFiles = new List<ITaskItem>();

                this.NewApplicationDefinitions = ProcessFiles(this.ApplicationDefinitions, generatedFiles, preprocessor).ToArray();
                this.NewPages = ProcessFiles(this.Pages, generatedFiles, preprocessor).ToArray();
                this.NewEmbeddedXamlResources = ProcessFiles(this.EmbeddedXamlResources, generatedFiles, preprocessor).ToArray();

                this.GeneratedFiles = generatedFiles.ToArray();

                return true;
            }
            catch (Exception e) {
                Log.LogErrorFromException(e);

                return false;
            }
        }
Beispiel #3
0
        /// <summary>
        /// When overridden in a derived class, executes the task.
        /// </summary>
        /// <returns>
        /// true if the task successfully executed; otherwise, false.
        /// </returns>
        public override bool Execute()
        {
            try {
                Log.LogMessage(MessageImportance.Normal, "XCC > DefinedSymbols: {0}", string.Join(",", this.DefinedSymbols));

                var preprocessor = new XamlPreprocessor(this.DefinedSymbols, this.RemoveIgnorableContent);

                var generatedFiles = new List <ITaskItem>();

                this.NewApplicationDefinitions = ProcessFiles(this.ApplicationDefinitions, generatedFiles, preprocessor).ToArray();
                this.NewPages = ProcessFiles(this.Pages, generatedFiles, preprocessor).ToArray();
                this.NewEmbeddedXamlResources = ProcessFiles(this.EmbeddedXamlResources, generatedFiles, preprocessor).ToArray();

                this.GeneratedFiles = generatedFiles.ToArray();

                return(true);
            }
            catch (Exception e) {
                Log.LogErrorFromException(e);

                return(false);
            }
        }
Beispiel #4
0
        private ITaskItem ProcessFile(ITaskItem file, XamlPreprocessor preprocessor)
        {
            var sourcePath = file.GetMetadata("FullPath");

            // properly resolve linked xaml
            var targetRelativePath = file.GetMetadata("Link");
            if (string.IsNullOrEmpty(targetRelativePath)) {
                targetRelativePath = file.ItemSpec;
            }

            // if targetRelativePath is still absolute, use file name
            if (Path.IsPathRooted(targetRelativePath)) {
                targetRelativePath = Path.GetFileName(targetRelativePath);
            }

            var targetPath = Path.Combine(this.OutputPath, targetRelativePath);

            TaskItem result = null;

            // process XAML
            Log.LogMessage(MessageImportance.High, "XCC > Preprocessing {0}", targetRelativePath);
            var start = DateTime.Now;
            if (preprocessor.ProcessXamlFile(sourcePath, targetPath)) {
                // targetPath has been written, create linked item
                result = new TaskItem(targetPath);
                file.CopyMetadataTo(result);
                result.SetMetadata("Link", targetRelativePath);          // this is the trick that makes it all work (replace page with a page link pointing to \obj\debug\preprocessedxaml\*)
            }

            var duration = (DateTime.Now - start).TotalMilliseconds;
            Log.LogMessage(MessageImportance.Normal, "XCC > Preprocess completed in {0}ms, {1} has {2}changed", duration, targetRelativePath, result == null ? "not " : "");

            return result;
        }
Beispiel #5
0
 private IEnumerable<ITaskItem> ProcessFiles(ITaskItem[] files, List<ITaskItem> generatedFiles, XamlPreprocessor preprocessor)
 {
     foreach (var file in files) {
         var newFile = ProcessFile(file, preprocessor);
         if (newFile != null) {
             generatedFiles.Add(newFile);
             yield return newFile;
         }
         else {
             yield return file;      // return file as-is
         }
     }
 }
Beispiel #6
0
 private IEnumerable <ITaskItem> ProcessFiles(ITaskItem[] files, List <ITaskItem> generatedFiles, XamlPreprocessor preprocessor)
 {
     foreach (var file in files)
     {
         var newFile = ProcessFile(file, preprocessor);
         if (newFile != null)
         {
             generatedFiles.Add(newFile);
             yield return(newFile);
         }
         else
         {
             yield return(file);      // return file as-is
         }
     }
 }