Skip to content

Commit

Permalink
start intercept
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatandrei committed Mar 16, 2024
1 parent 7aa6b10 commit 47e392b
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 36 deletions.
5 changes: 3 additions & 2 deletions src/NetPackageAnalyzer/AnalyzeMerge/AnalyzeMergeData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public AnalyzeMergeData(string folder)
folderRoot=folder;
}

public async Task GenerateNow()
public async Task<int> GenerateNow()
{
await Task.Delay(1000);

Expand All @@ -28,7 +28,7 @@ public async Task GenerateNow()
folderRoot = folderRoot.Substring(0, folder.Length - relPath.Length);
}

using (var repo = new Repository(folderRoot))
using var repo = new Repository(folderRoot) ;
{
//Commit? debugCommit = null;
Branch? mainBranch = null;
Expand Down Expand Up @@ -175,6 +175,7 @@ public async Task GenerateNow()

}
//data.Analyze();
return 1;
}
string? relFolder()
{
Expand Down
6 changes: 6 additions & 0 deletions src/NetPackageAnalyzer/NetPackageAnalyzer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetPackageAnalyzerTests", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetPackageAnalyzerObjects", "NetPackageAnalyzerObjects\NetPackageAnalyzerObjects.csproj", "{579A9B8E-FD8D-4E0E-9BF8-C3AF5BE2B682}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WhatIAmDoingData", "WhatIAmDoingData\WhatIAmDoingData.csproj", "{6AB6C867-AAFC-4A29-9440-504EF79B5DCC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -39,6 +41,10 @@ Global
{579A9B8E-FD8D-4E0E-9BF8-C3AF5BE2B682}.Debug|Any CPU.Build.0 = Debug|Any CPU
{579A9B8E-FD8D-4E0E-9BF8-C3AF5BE2B682}.Release|Any CPU.ActiveCfg = Release|Any CPU
{579A9B8E-FD8D-4E0E-9BF8-C3AF5BE2B682}.Release|Any CPU.Build.0 = Release|Any CPU
{6AB6C867-AAFC-4A29-9440-504EF79B5DCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6AB6C867-AAFC-4A29-9440-504EF79B5DCC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6AB6C867-AAFC-4A29-9440-504EF79B5DCC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6AB6C867-AAFC-4A29-9440-504EF79B5DCC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,41 @@
<Watch Include="**\*.cshtml" />
</ItemGroup>


<ItemGroup>
<None Remove="rscg.ps1" />
</ItemGroup>


<ItemGroup>
<Compile Include="..\WhatIAmDoingData\Interceptors.cs" Link="Interceptors.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="ThisAssembly.AssemblyInfo" Version="1.4.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

</ItemGroup>
<ItemGroup>
<PackageReference Include="RSCG_WhatIAmDoing" Version="8.2024.10316.2235" />
<PackageReference Include="RSCG_WhatIAmDoing_Common" Version="8.2024.10316.2235" />

</ItemGroup>
<PropertyGroup>

<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);RSCG_InterceptorTemplate</InterceptorsPreviewNamespaces>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>

</Project>
87 changes: 59 additions & 28 deletions src/NetPackageAnalyzer/NetPackageAnalyzerConsole/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@

using LibGit2Sharp;
using RSCG_WhatIAmDoing_Common;

public class Program
{
static async Task<int> Main(string[] args)
{
try
{
return await RealMain(args);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
WhatIAmDoingData.DisplayData.DisplayJustErrors();

return 1;
}
}
static async Task<int> RealMain(string[] args)
{
GlobalsForGenerating.Version = ThisAssembly.Info.Version.ToString();
WriteLine("Version:"+ThisAssembly.Info.Version.ToString());
Expand Down Expand Up @@ -48,28 +64,8 @@ static async Task<int> Main(string[] args)
// }

//});
cmdGenerate.SetHandler(async (string folder, string where, WhatToGenerate what) =>
{

WriteLine($"analyzing {folder}");
GenerateFiles? g=null;
switch(what)
{
case WhatToGenerate.Docusaurus:
g = new GenerateFilesDocusaurus(new FileSystem());
break;
default:
throw new NotImplementedException($"what={what}");
}
if (!await g.GenerateData(folder))
{
Console.WriteLine("not capable to generate data");
return;
}
await g.GenerateNow(folder, where);


}, folderToHaveSln,folderGenerate, generateData);

cmdGenerate.SetHandler(GenerateHandler, folderToHaveSln,folderGenerate, generateData);

//Command cmdAnalyzeBranch = new("analyzeBranch", "Analyze branch");

Expand All @@ -93,15 +89,50 @@ static async Task<int> Main(string[] args)
//rootCommand.Add(cmdAnalyzeBranch);
if(args.Length == 0)
{
args = ["-h"];
//args = new[] { "generateFiles",
// "--folder", @"D:\gth\PackageAnalyzer\src\NetPackageAnalyzer\",
// "--where", @"D:\gth\PackageAnalyzer\src\documentation1\",
//};
args = ["-h"];
args = new[] { "generateFiles",
"--folder", @"D:\gth\PackageAnalyzer\src\NetPackageAnalyzer\",
//"--folder",@"D:\gth\PackageAnalyzer\src\documentation1\",
"--where", @"D:\gth\PackageAnalyzer\src\documentation1\",
};

}
WriteLine("args:" + string.Join(" ",args));
await rootCommand.InvokeAsync(args);
return 0;
}
private static async Task GenerateHandler(string folder, string where, WhatToGenerate what)
{
try
{
await RealGenerateHandler(folder, where, what);
}
catch (Exception ex)
{
WriteLine("Exception!! "+ex.Message);



}
}
private static async Task RealGenerateHandler(string folder, string where, WhatToGenerate what)
{

WriteLine($"analyzing {folder}");
GenerateFiles? g = null;
switch (what)
{
case WhatToGenerate.Docusaurus:
g = new GenerateFilesDocusaurus(new FileSystem());
break;
default:
throw new NotImplementedException($"what={what}");
}
if (!await g.GenerateData(folder))
{
Console.WriteLine("not capable to generate data");
return;
}
await g.GenerateNow(folder, where);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ while($true)
dotnet clean
dotnet restore
dotnet build /p:EmitCompilerGeneratedFiles=true --disable-build-servers --force
# dotnet run
dotnet run
Read-Host -Prompt "Press Enter to continue"

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ public PackageWithVersion[] Problems()

).ToArray();
}
public abstract Task GenerateNow(string folder, string where);
public abstract Task<int> GenerateNow(string folder, string where);
public async Task<bool> GenerateData(string folder)
{
var sln = system.Directory.GetFiles(folder, "*.sln");
if (sln.Length != 1)
{
WriteLine($"Must be 1 sln in the {folder}");
//throw new ArgumentException($"Must be 1 sln in the {folder}");
return false;
}

GlobalsForGenerating.FullPathToSolution = sln[0];
NameSolution = system.Path.GetFileNameWithoutExtension(sln[0]);
GlobalsForGenerating.NameSolution = NameSolution;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
<AdditionalFiles Include="generatedJson/outdatedV1.gen.json" />
<AdditionalFiles Include="mixin/Packages.mixin" />
</ItemGroup>


<ItemGroup>
<Compile Include="..\WhatIAmDoingData\Interceptors.cs" Link="Interceptors.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ThisAssembly.AssemblyInfo" Version="1.4.0">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -23,9 +28,16 @@
<!--<PackageReference Include="rscgutils" Version="2024.1859.1955" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />-->
<PackageReference Include="rscgutils" Version="2024.2000.2000" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />

</ItemGroup>
<ItemGroup>
<PackageReference Include="RSCG_WhatIAmDoing" Version="8.2024.10316.2235" />
<PackageReference Include="RSCG_WhatIAmDoing_Common" Version="8.2024.10316.2235" />

</ItemGroup>
<PropertyGroup>

<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);RSCG_InterceptorTemplate</InterceptorsPreviewNamespaces>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class ProcessOutput
{
public bool Build(string folder)
{

ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = "dotnet.exe",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public GenerateFilesDocusaurus(IFileSystem system):base(system)

}

public override async Task GenerateNow(string folder, string where)
public override async Task<int> GenerateNow(string folder, string where)
{

var folderResults = string.IsNullOrWhiteSpace(where) ? Path.Combine(folder, "Documentation") : where;
Expand Down Expand Up @@ -133,6 +133,6 @@ public override async Task GenerateNow(string folder, string where)
//await File.WriteAllTextAsync(file, await generator.Generate_DisplayAllVersionsWithProblemsMarkdown(model));

WriteLine($"now npm i && npm run start in {where}");

return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,26 @@
<Watch Remove="Templates\SolutionRelations.cshtml" />
<Watch Remove="Templates\TestProjects.cshtml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\WhatIAmDoingData\Interceptors.cs" Link="Interceptors.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="docusaurus.zip" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NetPackageAnalyzerObjects\NetPackageAnalyzerObjects.csproj" />
</ItemGroup>



<ItemGroup>
<PackageReference Include="RSCG_WhatIAmDoing" Version="8.2024.10316.2235" />
<PackageReference Include="RSCG_WhatIAmDoing_Common" Version="8.2024.10316.2235" />

</ItemGroup>
<PropertyGroup>

<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);RSCG_InterceptorTemplate</InterceptorsPreviewNamespaces>
</PropertyGroup>

</Project>
39 changes: 39 additions & 0 deletions src/NetPackageAnalyzer/WhatIAmDoingData/Interceptors.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using NetPackageAnalyzerObjects;
using RSCG_WhatIAmDoing;
using RSCG_WhatIAmDoing_Common;
using System;
namespace WhatIAmDoingData;

[InterceptStatic("System.Console.*")] // regex
internal class InterceptorMethodStatic : InterceptorMethodStaticBase, IInterceptorMethodStatic
{
}

[InterceptInstanceClass(typeof(GenerateFiles), ".*")] //regex
[InterceptInstanceClass(typeof(ProcessOutput), ".*")] //regex
public class InterceptorMethodInstanceClass : InterceptorMethodInstanceClassBase, IInterceptorMethodInstanceClass
{

}

public class DisplayData
{
public static void DisplayJustErrors()
{
var data = CachingData.MethodsError().ToArray();
Console.WriteLine("methods:" + data.Length);
foreach (var item in data)
{
//if ((item.State & AccumulatedStateMethod.RaiseException) != AccumulatedStateMethod.RaiseException)
//{
// Console.WriteLine("not interested in " + item.typeAndMethodData.MethodName);
// continue;
//}
Console.WriteLine($"{item.typeAndMethodData.MethodName} {item.State}");
Console.WriteLine($"Method {item.typeAndMethodData.MethodName} from class {item.typeAndMethodData.TypeOfClass} Time: {item.StartedAtDate} state {item.State} ");
Console.WriteLine($" =>Arguments: {item.ArgumentsAsString()}");


}
}
}
22 changes: 22 additions & 0 deletions src/NetPackageAnalyzer/WhatIAmDoingData/WhatIAmDoingData.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="RSCG_WhatIAmDoing" Version="8.2024.10316.2235" />
<PackageReference Include="RSCG_WhatIAmDoing_Common" Version="8.2024.10316.2235" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NetPackageAnalyzerObjects\NetPackageAnalyzerObjects.csproj" />
</ItemGroup>

<PropertyGroup>

<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);RSCG_InterceptorTemplate</InterceptorsPreviewNamespaces>
</PropertyGroup>
</Project>

0 comments on commit 47e392b

Please sign in to comment.