Ejemplo n.º 1
0
        private void ParseOutput(CompileResult result, string projectDir, Process process)
        {
            while (!process.StandardOutput.EndOfStream)
            {
                var line = process.StandardOutput.ReadLine();

                if (line == null)
                {
                    continue;
                }

                var bamlPrefix  = "_o|";
                var errorSuffix = "|_e";

                Debug.WriteLine(line);

                if (line.StartsWith(bamlPrefix))
                {
                    var generatedBamlAbsoluteFilename = line.Substring(bamlPrefix.Length);
                    result.GeneratedBamlFiles.Add(generatedBamlAbsoluteFilename);
                }
                else if (line.EndsWith(errorSuffix))
                {
                    var split = line.Split(new[] { '|' }, 4);

                    if (split.Length < 4)
                    {
                        continue;
                    }

                    var filenameAndPosition = split[0];
                    var match  = Regex.Match(filenameAndPosition, @"\((\d+),(\d+),(\d+),(\d+)\)");
                    var groups = match.Groups;

                    if (match.Success && groups.Count == 5)
                    {
                        try {
                            var row    = int.Parse(groups[1].Value);
                            var column = int.Parse(groups[2].Value);
                            //var endRow = int.Parse(groups[3].Value);
                            //var endColumn = int.Parse(groups[4].Value);
                            var filenameWithoutPosition = filenameAndPosition.Substring(0, filenameAndPosition.IndexOf('('));
                            var filename = Regex.Replace(filenameWithoutPosition, @"\.i\.xaml$", ".ammy");
                            //var filename = Path.ChangeExtension(filenameWithoutPosition, ".ammy");
                            var message = split[2];

                            var positionMatch = Regex.Match(message, @"Line \d+ Position \d+");
                            if (positionMatch.Success)
                            {
                                message = message.Substring(0, positionMatch.Index);
                            }

                            var outputFileSuffix = result.AmmyProject.Platform.OutputFileSuffix;
                            var file             = result.Files.FirstOrDefault(f => f.FullName
                                                                               .ToAbsolutePath(projectDir)
                                                                               .ChangeExtension(outputFileSuffix + ".xaml")
                                                                               .SamePathAs(filename));

                            if (file != null)
                            {
                                var topWithNode = ((Start)file.Ast).Top as TopWithNode;
                                if (topWithNode == null || topWithNode.IsXamlEvaluated == false)
                                {
                                    continue;
                                }

                                var xamlElement = FindXamlElement(topWithNode.Xaml, row, column);
                                if (xamlElement != null)
                                {
                                    // Some errors are resolved after fuul initial compilation
                                    // Don't want to stop MSBuild because of baml errors
                                    var msgType = _isMsBuildCompilation
                                        ? CompilerMessageType.Warning
                                        : CompilerMessageType.Error;
                                    var msg = new CompilerMessage(msgType, Guid.Empty, xamlElement.OriginalLocation, message, 0, new List <CompilerMessage>());

                                    var errorFile = msg.Location.Source?.File as AmmyFile <Top>;
                                    if (errorFile != null)
                                    {
                                        errorFile.BamlCompilerMessages.Add(msg);
                                    }
                                    else
                                    {
                                        file.BamlCompilerMessages.Add(msg);
                                    }
                                }
                            }
                        } catch (Exception e) {
                            Debug.WriteLine("Failed parsing '_e:' line: " + line + Environment.NewLine + e);
                        }
                    }
                }
            }

            var err = process.StandardError.ReadToEnd();
            //Debug.WriteLine(err);
        }
Ejemplo n.º 2
0
        public void GenerateXamlFiles(CompileResult compileResult, bool generateMetaFile)
        {
            var fileOutputWriter = new FileOutputWriter(compileResult);

            fileOutputWriter.WriteFiles(generateMetaFile);
        }