85 lines
3.1 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Build.Utilities;
2019-09-10 22:48:25 +02:00
namespace CapnpC.CSharp.MsBuild.Generation
{
2019-09-05 21:59:25 +02:00
public class CapnpFileCodeBehindGenerator : ICapnpcCsharpGenerator
{
2019-09-05 21:59:25 +02:00
public CapnpFileCodeBehindGenerator(TaskLoggingHelper log)
{
Log = log ?? throw new ArgumentNullException(nameof(log));
}
public TaskLoggingHelper Log { get; }
public IEnumerable<string> GenerateFilesForProject(
string projectPath,
List<string> capnpFiles,
string projectFolder,
string workingDirectory,
string additionalOptions)
{
2019-09-05 21:59:25 +02:00
using (var capnpCodeBehindGenerator = new CapnpCodeBehindGenerator())
{
2019-09-05 21:59:25 +02:00
capnpCodeBehindGenerator.InitializeProject(projectPath);
var codeBehindWriter = new CodeBehindWriter(null);
2019-09-05 21:59:25 +02:00
if (capnpFiles == null)
{
yield break;
}
2019-09-05 21:59:25 +02:00
foreach (var capnpFile in capnpFiles)
{
2019-09-10 22:48:25 +02:00
var generatorResult = capnpCodeBehindGenerator.GenerateCodeBehindFile(capnpFile);
if (!generatorResult.Success)
{
2019-09-10 22:48:25 +02:00
if (!string.IsNullOrEmpty(generatorResult.Error))
{
2019-09-10 22:48:25 +02:00
Log.LogError("{0}", generatorResult.Error);
}
2019-09-10 22:48:25 +02:00
if (generatorResult.Messages != null)
{
foreach (var message in generatorResult.Messages)
{
if (message.IsParseSuccess)
{
Log.LogError(
subcategory: null,
errorCode: null,
helpKeyword: null,
file: capnpFile,
lineNumber: message.Line,
columnNumber: message.Column,
endLineNumber: message.Line,
endColumnNumber: message.EndColumn == 0 ? message.Column : message.EndColumn,
"{0}",
message.MessageText);
}
else
{
Log.LogError("{0}", message.FullMessage);
}
}
}
continue;
}
2019-09-10 22:48:25 +02:00
var resultedFile = codeBehindWriter.WriteCodeBehindFile(generatorResult.Filename, generatorResult);
yield return FileSystemHelper.GetRelativePath(resultedFile, projectFolder);
}
}
}
}
}