Skip to content

Instantly share code, notes, and snippets.

@pregress
Created November 26, 2013 12:37
Show Gist options
  • Save pregress/7657656 to your computer and use it in GitHub Desktop.
Save pregress/7657656 to your computer and use it in GitHub Desktop.
ParseResharperCLI CodeActivity
[BuildActivity(HostEnvironmentOption.All)]
public sealed class ParseResharperCLI : CodeActivity
{
// Define an activity input argument of type string
public InArgument<string> PathToXml { get; set; }
public OutArgument<string[]> Warnings { get; set; }
public OutArgument<string[]> Errors { get; set; }
// If your activity returns a value, derive from CodeActivity<TResult>
// and return the value from the Execute method.
protected override void Execute(CodeActivityContext context)
{
var document = XDocument.Load(context.GetValue(PathToXml), LoadOptions.None);
var issueTypes = document.Descendants("IssueType")
.Select(x => new
{
Id = x.Attribute("Id").Value,
Severity = x.Attribute("Severity").Value
})
.ToList();
var issues = document.Descendants("Issue")
.Select(x => new Issue
{
File = x.Attribute("File").Value,
Message = x.Attribute("Message").Value,
Severity = issueTypes.First(t => t.Id == x.Attribute("TypeId").Value).Severity,
Line = x.Attribute("Line") != null ? x.Attribute("Line").Value : null,
})
.ToList();
var warnings = issues
.Where(i => i.Severity != "ERROR")
.Select(i => i.ToString())
.ToArray();
var errors = issues
.Where(i => i.Severity == "ERROR")
.Select(i => i.ToString())
.ToArray();
context.SetValue<string[]>(this.Errors, errors);
context.SetValue<string[]>(this.Warnings, warnings);
}
}
public class Issue
{
public string File { get; set; }
public string Message { get; set; }
public string Severity { get; set; }
public string Line { get; set; }
public override string ToString()
{
return string.Format("{0} File: {1} Line: {2} Message: {3} ", Severity, File, Line, Message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment