Skip to content

Commit

Permalink
intercept
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatandrei committed Apr 3, 2024
1 parent 47e392b commit ef7c5e2
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 54 deletions.
4 changes: 2 additions & 2 deletions src/NetPackageAnalyzer/AnalyzeMerge/AnalyzeMerge.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="LibGit2Sharp" Version="0.27.2" />
<PackageReference Include="RazorBlade" Version="0.4.3" PrivateAssets="all" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
<PackageReference Include="LibGit2Sharp" Version="0.30.0" />
<PackageReference Include="RazorBlade" Version="0.5.0" PrivateAssets="all" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />

</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
</PropertyGroup>
<ItemGroup>
<None Include="..\..\..\README.md" Link="README.md" Pack="true" PackagePath="\" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<None Include="..\..\..\docs\ico.png" Pack="true" PackagePath="\" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AnalyzeMerge\AnalyzeMerge.csproj" />
<ProjectReference Include="..\NetPackageAnalyzerWork\NetPackageAnalyzerDocusaurus.csproj" />
<ProjectReference Include="..\WhatIAmDoingData\WhatIAmDoingData.csproj" />
</ItemGroup>
<PropertyGroup>
<Version>8.2024.315.1900</Version>
Expand Down Expand Up @@ -60,15 +61,15 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="ThisAssembly.AssemblyInfo" Version="1.4.0">
<PackageReference Include="ThisAssembly.AssemblyInfo" Version="1.4.3">
<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" />
<PackageReference Include="RSCG_WhatIAmDoing" Version="8.2024.10402.810" />
<PackageReference Include="RSCG_WhatIAmDoing_Common" Version="8.2024.10402.810" />

</ItemGroup>
<PropertyGroup>
Expand Down
31 changes: 28 additions & 3 deletions src/NetPackageAnalyzer/NetPackageAnalyzerConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ static async Task<int> Main(string[] args)
return 1;
}
}
static Option<bool> verbose = new ("--verbose", "Show verbose output");
static async Task<int> RealMain(string[] args)
{
GlobalsForGenerating.Version = ThisAssembly.Info.Version.ToString();
WriteLine("Version:"+ThisAssembly.Info.Version.ToString());
RootCommand rootCommand = new();
Command cmdGenerate = new("generateFiles", "Generate files for documentation");
cmdGenerate.AddAlias("gf");

rootCommand.AddGlobalOption(verbose);

var folderToHaveSln = new Option<string>
(name: "--folder",
Expand Down Expand Up @@ -65,7 +66,11 @@ static async Task<int> RealMain(string[] args)

//});

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

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

Expand Down Expand Up @@ -94,17 +99,37 @@ static async Task<int> RealMain(string[] args)
"--folder", @"D:\gth\PackageAnalyzer\src\NetPackageAnalyzer\",
//"--folder",@"D:\gth\PackageAnalyzer\src\documentation1\",
"--where", @"D:\gth\PackageAnalyzer\src\documentation1\",
"--verbose","true"
};

}
WriteLine("args:" + string.Join(" ",args));
await rootCommand.InvokeAsync(args);
return 0;
}
private static async Task GenerateHandler(string folder, string where, WhatToGenerate what)
private static async Task GenerateHandler(string folder, string where, WhatToGenerate what,bool verbose)
{
try
{
if (verbose)
{
CachingData.OnMethodCalled += (id, acc, method) =>
{
// WriteLine($"{id} {acc} ");

WriteLine($"({id}){acc} at {method.StartedAtDate}");
Console.WriteLine($" => Method {method.typeAndMethodData.MethodName} from class {method.typeAndMethodData.TypeOfClass} ");
Console.WriteLine($" => Arguments: {method.ArgumentsAsString()}");
if((acc & AccumulatedStateMethod.HasFinishedWithResult) == AccumulatedStateMethod.HasFinishedWithResult)
{
Console.WriteLine($" => result: {method.Result}");
}
if ((acc & AccumulatedStateMethod.RaiseException) == AccumulatedStateMethod.RaiseException)
{
Console.WriteLine($" => exception: {method.Exception.Message}");
}
};
}
await RealGenerateHandler(folder, where, what);
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
<Compile Include="..\WhatIAmDoingData\Interceptors.cs" Link="Interceptors.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ThisAssembly.AssemblyInfo" Version="1.4.0">
<PackageReference Include="ThisAssembly.AssemblyInfo" Version="1.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="TestableIO.System.IO.Abstractions.Wrappers" Version="20.0.15" />
<PackageReference Include="Morris.Moxy" Version="1.5.0" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<PackageReference Include="TestableIO.System.IO.Abstractions.Wrappers" Version="21.0.2" />
<PackageReference Include="Morris.Moxy" Version="1.8.0" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<!--<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" />
<PackageReference Include="RSCG_WhatIAmDoing" Version="8.2024.10402.810" />
<PackageReference Include="RSCG_WhatIAmDoing_Common" Version="8.2024.10402.810" />

</ItemGroup>
<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

<ItemGroup>
<PackageReference Include="MSTest" Version="3.2.2" />
<PackageReference Include="coverlet.collector" Version="6.0.1">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.2.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.2.2" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="20.0.15" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="21.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public override async Task<int> GenerateNow(string folder, string where)
if(!Directory.Exists(folderResults))
Directory.CreateDirectory(folderResults);
var zip = Path.Combine(folderResults, "docusaurus.zip");
Console.WriteLine("generate docusaurus at" + zip);
Console.WriteLine("generate docusaurus at " + zip);
await File.WriteAllBytesAsync(zip, MyResource.GetDocusaurusZip().ToArray());
ZipFile.ExtractToDirectory(zip, folderResults,true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="RazorBlade" Version="0.4.3" PrivateAssets="all" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
<PackageReference Include="ThisAssembly.AssemblyInfo" Version="1.4.0">
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="RazorBlade" Version="0.5.0" PrivateAssets="all" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
<PackageReference Include="ThisAssembly.AssemblyInfo" Version="1.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down Expand Up @@ -99,8 +99,8 @@
</ItemGroup>

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

</ItemGroup>
<PropertyGroup>
Expand Down
24 changes: 24 additions & 0 deletions src/NetPackageAnalyzer/WhatIAmDoingData/DisplayData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using RSCG_WhatIAmDoing_Common;
namespace WhatIAmDoingData;

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()}");


}
}
}
37 changes: 8 additions & 29 deletions src/NetPackageAnalyzer/WhatIAmDoingData/Interceptors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,15 @@
using System;
namespace WhatIAmDoingData;

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

[InterceptInstanceClass(typeof(GenerateFiles), ".*")] //regex
[InterceptInstanceClass(typeof(ProcessOutput), ".*")] //regex
public class InterceptorMethodInstanceClass : InterceptorMethodInstanceClassBase, IInterceptorMethodInstanceClass
//[InterceptInstanceClass(typeof(GenerateFiles), ".*")] //regex
//[InterceptInstanceClass(typeof(ProcessOutput), ".*")] //regex
[InterceptInstanceClass("NetPackageAnalyzerObjects.*",".*")]
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()}");


}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="RSCG_WhatIAmDoing" Version="8.2024.10316.2235" />
<PackageReference Include="RSCG_WhatIAmDoing_Common" Version="8.2024.10316.2235" />
<PackageReference Include="RSCG_WhatIAmDoing" Version="8.2024.10402.810" />
<PackageReference Include="RSCG_WhatIAmDoing_Common" Version="8.2024.10402.810" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NetPackageAnalyzerObjects\NetPackageAnalyzerObjects.csproj" />
Expand Down

0 comments on commit ef7c5e2

Please sign in to comment.