Commit 3ddf30fe authored by Nathan Bean's avatar Nathan Bean
Browse files

Added a WindowsService project to handle building student apps

parent 3df1a40a
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using System.Collections.Immutable;
using System.Linq;
using System.Resources;
namespace KSU.CS.Pendant.CodeAnalyzers.DesignAnalyzers
{
/// <summary>
/// A Code analyzer that checks for properties that reference themselves, i.e.:
/// <code>
/// public string Foo {
/// get { return Foo; }
/// set { Foo = value; }
/// }
/// </code>
/// This kind of self-reference creates and infinite recursion when the set or get method is invoked at runtime,
/// causing a StackOverflow
/// </summary>
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class PropertySelfReferenceAnalyzer : DiagnosticAnalyzer
{
internal static DiagnosticDescriptor Rule01;
internal static string MsgGetSelfReference;
internal static string MsgSetSelfReference;
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get { return ImmutableArray.Create(Rule01); } }
/// <summary>
/// Initializes the PropertySelfReferenceAnalyzer
/// </summary>
/// <param name="context">The analysis context</param>
public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.PropertyDeclaration);
}
/// <summary>
/// Analyzes a PropertyDeclarationSyntax Node for self-reference errors
/// </summary>
/// <param name="context">The context of the PropertyDeclarationSyntax Node</param>
private static void AnalyzeNode(SyntaxNodeAnalysisContext context)
{
// The context Node should be a PropertyDeclarationSyntax
var propertyDeclaration = (PropertyDeclarationSyntax)context.Node;
// Grab and evaluate any accessor declarations that go with this property
var accessorDeclarations = context.Node.DescendantNodes().OfType<AccessorDeclarationSyntax>();
foreach(var dec in accessorDeclarations)
{
// Check for a get self-reference
if (dec.IsKind(SyntaxKind.GetAccessorDeclaration))
{
// Get the accessor block (if any)
var getBlock = dec.DescendantNodes()
.OfType<BlockSyntax>();
if (!getBlock.Any()) break;
// Get any self-references
var getSelfReference = getBlock.First().DescendantNodes()
.OfType<IdentifierNameSyntax>()
.Where(id => id.Identifier.ValueText == propertyDeclaration.Identifier.ValueText);
if (!getSelfReference.Any()) break;
// Create the diagnostic
var primaryLocation = propertyDeclaration.Identifier.GetLocation();
var additionalLocations = from sr in getSelfReference select sr.Identifier.GetLocation();
var diagnostic = Diagnostic.Create(
Rule01,
primaryLocation,
additionalLocations,
MsgSetSelfReference
);
context.ReportDiagnostic(diagnostic);
}
// Check for a set self-reference
if (dec.IsKind(SyntaxKind.SetAccessorDeclaration))
{
// Get the accessor block (if any)
var setBlock = dec.DescendantNodes()
.OfType<BlockSyntax>();
if (!setBlock.Any()) break;
// Get any self-references
var getSelfReference = setBlock.First().DescendantNodes()
.OfType<IdentifierNameSyntax>()
.Where(id => id.Identifier.ValueText == propertyDeclaration.Identifier.ValueText);
if (!getSelfReference.Any()) break;
// Create the diagnostic
var primaryLocation = propertyDeclaration.Identifier.GetLocation();
var additionalLocations = from sr in getSelfReference select sr.Identifier.GetLocation();
var diagnostic = Diagnostic.Create(
Rule01,
primaryLocation,
additionalLocations,
MsgSetSelfReference
);
context.ReportDiagnostic(diagnostic);
}
}
}
/// <summary>
/// Constructs a new PropertySelfReferenceAnalyzer.
/// </summary>
public PropertySelfReferenceAnalyzer()
{
ResourceManager rm = new ResourceManager("CodeAnalyzers.Resources", typeof(PropertySelfReferenceAnalyzer).Assembly);
Rule01 = new DiagnosticDescriptor("PSR0001", rm.GetString("PSR-Title"), rm.GetString("PSR-MessageFormat"), rm.GetString("PSR-Category"), DiagnosticSeverity.Error, true);
MsgGetSelfReference = rm.GetString("PSR-MSG-Getter");
MsgGetSelfReference = rm.GetString("PSR-MSG-Setter");
}
}
}
\ No newline at end of file
This diff is collapsed.
......@@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProgramVerifier", "Verifier
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeAnalyzers", "CodeAnalyzers\CodeAnalyzers\CodeAnalyzers.csproj", "{65E28062-2B9A-4BB5-B546-449C4CB915E0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsService", "WindowsService\WindowsService.csproj", "{1E5A0004-1529-451B-847E-78DB0E17DA72}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -33,6 +35,10 @@ Global
{65E28062-2B9A-4BB5-B546-449C4CB915E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{65E28062-2B9A-4BB5-B546-449C4CB915E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{65E28062-2B9A-4BB5-B546-449C4CB915E0}.Release|Any CPU.Build.0 = Release|Any CPU
{1E5A0004-1529-451B-847E-78DB0E17DA72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1E5A0004-1529-451B-847E-78DB0E17DA72}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E5A0004-1529-451B-847E-78DB0E17DA72}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E5A0004-1529-451B-847E-78DB0E17DA72}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
......@@ -79,8 +79,8 @@ namespace KSU.CS.Pendant.Server
{
app.UseHttpsRedirection();
//app.UseDeveloperExceptionPage();
app.UseExceptionHandler("/Error");
app.UseDeveloperExceptionPage();
//app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
//app.UseHsts();
}
......
using System;
using LibGit2Sharp;
namespace WindowsService
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Repository.Clone("git@github.com:ksu-cis/webhook-test-zombiepaladin.git", "C:/workDir/test");
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LibGit2Sharp-SSH" Version="1.0.22" />
</ItemGroup>
</Project>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment