Exemplo n.º 1
1
        private static string BuildErrorMessage(EmitResult result, ViewLocationResult viewLocationResult, string sourceCode)
        {
            var failures = result.Diagnostics
                .Where(diagnostic => diagnostic.IsWarningAsError || diagnostic.Severity == DiagnosticSeverity.Error)
                .ToArray();

            var fullTemplateName = viewLocationResult.Location + "/" + viewLocationResult.Name + "." + viewLocationResult.Extension;
            var templateLines = GetViewBodyLines(viewLocationResult);
            var compilationSource = GetCompilationSource(sourceCode);
            var errorMessages = BuildErrorMessages(failures, templateLines, compilationSource);

            var lineNumber = 1;

            var errorDetails = string.Format(
                "Error compiling template: <strong>{0}</strong><br/><br/>Errors:<br/>{1}<br/><br/>Details:<br/>{2}<br/><br/>Compilation Source:<br/><pre><code>{3}</code></pre>",
                fullTemplateName,
                errorMessages,
                templateLines.Aggregate((s1, s2) => s1 + "<br/>" + s2),
                compilationSource.Aggregate((s1, s2) => s1 + "<br/>Line " + lineNumber++ + ":\t" + s2));

            return errorDetails;
        }
Exemplo n.º 2
0
 private void VerifyCompilationResults(EmitResult compilationResult)
 {
     if (compilationResult.Success)
     {
         return;
     }
     var errorsString = string.Join(
         Environment.NewLine,
         compilationResult.Diagnostics
             .Where(diagnostic => diagnostic.IsWarningAsError ||
                                  diagnostic.Severity == DiagnosticSeverity.Error)
             .Select(diagnostic => $"{diagnostic.Id}: {diagnostic.GetMessage(CultureInfo.CurrentUICulture)}"));
     throw new PluginCompilationException(errorsString);
 }
Exemplo n.º 3
0
 public CompilationDifference(
     ImmutableArray<byte> metadata, 
     ImmutableArray<byte> il, 
     Stream pdbStream, 
     EmitBaseline nextGeneration,
     CompilationTestData testData,
     EmitResult result)
 {
     this.MetadataBlob = metadata;
     this.ILBlob = il;
     this.Pdb = pdbStream;
     this.NextGeneration = nextGeneration;
     this.TestData = testData;
     this.Result = result;
 }
Exemplo n.º 4
0
        static void Check(EmitResult result)
        {
            if (result.Success)
                return;

            var errors = result.Diagnostics
                .WhereAsArray(x => x.Severity == DiagnosticSeverity.Error);

            if (errors.Any())
                throw new NakeException("Compilation failed!\r\n\r\n" +
                    string.Join("\r\n", errors.Select(x => x.ToString())));
        }
Exemplo n.º 5
0
		public CompileResult(EmitResult emitResult, string pathToAssembly)
		{
			EmitResult = emitResult;
			PathToAssembly = pathToAssembly;
		}
Exemplo n.º 6
0
 public CompilationException(EmitResult compileResult) : base(CreateMessage(compileResult))
 {
 }
Exemplo n.º 7
0
 private static string CreateMessage(EmitResult compileResult)
 {
     return "Compile failed" + string.Join(Environment.NewLine, compileResult.Diagnostics);
 }
Exemplo n.º 8
0
 private void ProcessResult(EmitResult result)
 {
     foreach (var diagnostic in result.Diagnostics)
     {
         if (!diagnostic.Location.IsInSource)
         {
             throw new NotSupportedException("Only support source file locations.");
         }
         var itemType = GetItemType(diagnostic.Severity);
         var description = diagnostic.GetMessage();
         var lineSpan = diagnostic.Location.GetLineSpan();
         _errorList.AddItem(itemType, description,
             lineSpan.Path,
             lineSpan.StartLinePosition.Line,
             lineSpan.StartLinePosition.Character,
             () =>
             {
                 var openDocumentResult = new OpenDocumentResult(lineSpan.Path);
                 IoC.BuildUp(openDocumentResult);
                 openDocumentResult.Execute(null);
             });
     }
 }
Exemplo n.º 9
0
 public EmitCompilerResults(EmitResult result, string assemblyFile, Predicate<CompilerMessage> messageFilter)
 {
     _result = result;
     _assemblyFile = assemblyFile;
     _messageFilter = messageFilter;
 }
Exemplo n.º 10
0
        /// <summary>
        /// Emits compiled assembly to temporary file
        /// </summary>
        /// <param name="compilation"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public AssemblyWrapper EmitCompiledAssembly(Compilation compilation, out EmitResult result, string filename)
        {
            var fi = new FileInfo(filename);
            if (fi.Directory != null) fi.Directory.Create();
            using (var fs = new FileStream(fi.FullName, FileMode.Create))
            {
                result = compilation.Emit(fs);
                if (!result.Success)
                    return null;


            }
            var assembly = LoadByFullFilename(fi.FullName);
            return assembly;


            //            using (var memoryStream = new MemoryStream())
            //            {
            //                result = compilation.Emit(memoryStream);
            //                if (!result.Success)
            //                    return null;
            //
            //                memoryStream.Flush();
            //                // var g = memoryStream.GetBuffer();
            //                var binaryData = memoryStream.ToArray();
            //                var assembly = _appDomain.Load(binaryData);
            //                return assembly;
            //            }

        }