Skip to content

Commit 81d4a26

Browse files
author
LoneWandererProductions
committed
sync back some stuff
1 parent f7b0a8f commit 81d4a26

13 files changed

Lines changed: 454 additions & 41 deletions

File tree

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/*
22
* COPYRIGHT: See COPYING in the top level directory
33
* PROJECT: CoreBuilder
4-
* FILE: AnalyzerFactory.cs
4+
* FILE: CommandFactory.cs
55
* PURPOSE: Return all available code analyzers.
66
* PROGRAMMER: Peter Geinitz (Wayfarer)
77
*/
88

9+
using CoreBuilder.Development;
910
using CoreBuilder.FileManager;
1011
using CoreBuilder.Interface;
1112
using CoreBuilder.Rules;
@@ -19,7 +20,7 @@ namespace CoreBuilder
1920
/// <summary>
2021
/// Simple factory to return all available code analyzers and commands.
2122
/// </summary>
22-
public static class AnalyzerFactory
23+
public static class CommandFactory
2324
{
2425
/// <summary>
2526
/// Gets the commands.
@@ -50,20 +51,28 @@ public static IReadOnlyList<ICommand> GetCommands()
5051
new DeadReferenceAnalyzer(),
5152
new ApiExplorerCommand(),
5253
new FileLockScanner(),
53-
new SmartPingPro()
54+
new SmartPingPro(),
55+
new WhoAmI(),
56+
new Tree()
5457
};
5558

5659
return modules;
5760
}
5861

5962
/// <summary>
60-
/// Gets all analyzers.
63+
/// Gets the commands.
6164
/// </summary>
62-
/// <returns>All Code Analyzers</returns>
63-
public static IReadOnlyList<ICodeAnalyzer> GetAllAnalyzers()
65+
/// <param name="userspace">The userspace.</param>
66+
/// <returns>All commands by Namespace.</returns>
67+
public static IReadOnlyList<ICommand> GetCommands(string userspace)
6468
{
65-
ICodeAnalyzer[] modules =
69+
ICommand[] modules =
6670
{
71+
new DirectorySizeAnalyzer(),
72+
new DirectorySizeAnalyzer(),
73+
new LogTailCommand(),
74+
new HeaderExtractor(),
75+
new ResXtract(),
6776
new AllocationAnalyzer(),
6877
new DisposableAnalyzer(),
6978
new DoubleNewlineAnalyzer(),
@@ -77,32 +86,45 @@ public static IReadOnlyList<ICodeAnalyzer> GetAllAnalyzers()
7786
new UnusedParameterAnalyzer(),
7887
new UnusedPrivateFieldAnalyzer(),
7988
new DocCommentCoverageCommand(),
80-
new DeadReferenceAnalyzer()
89+
new DeadReferenceAnalyzer(),
90+
new ApiExplorerCommand(),
91+
new FileLockScanner(),
92+
new SmartPingPro(),
93+
new WhoAmI(),
94+
new Tree()
8195
};
8296

83-
return modules;
97+
// Filter by Namespace
98+
return modules
99+
.Where(m => string.Equals(m.Namespace, userspace, StringComparison.OrdinalIgnoreCase))
100+
.ToList();
84101
}
85102

86103
/// <summary>
87-
/// Gets the commands.
104+
/// Gets all analyzers.
88105
/// </summary>
89-
/// <param name="userspace">The userspace.</param>
90-
/// <returns>All commands by Namespace.</returns>
91-
public static IReadOnlyList<ICommand> GetCommands(string userspace)
106+
/// <returns>All Code Analyzers</returns>
107+
public static IReadOnlyList<ICodeAnalyzer> GetAllAnalyzers()
92108
{
93-
ICommand[] modules =
109+
ICodeAnalyzer[] modules =
94110
{
95-
new DirectorySizeAnalyzer(),
96-
new FileLockScanner(),
97-
new SmartPingPro(),
98-
new DirectorySizeAnalyzer(),
99-
new LogTailCommand()
111+
new AllocationAnalyzer(),
112+
new DisposableAnalyzer(),
113+
new DoubleNewlineAnalyzer(),
114+
new DuplicateStringLiteralAnalyzer(),
115+
new EventHandlerAnalyzer(),
116+
new HotPathAnalyzer(),
117+
new LicenseHeaderAnalyzer(),
118+
new UnusedClassAnalyzer(),
119+
new UnusedConstantAnalyzer(),
120+
new UnusedLocalVariableAnalyzer(),
121+
new UnusedParameterAnalyzer(),
122+
new UnusedPrivateFieldAnalyzer(),
123+
new DocCommentCoverageCommand(),
124+
new DeadReferenceAnalyzer()
100125
};
101126

102-
// Filter by Namespace
103-
return modules
104-
.Where(m => string.Equals(m.Namespace, userspace, StringComparison.OrdinalIgnoreCase))
105-
.ToList();
127+
return modules;
106128
}
107129
}
108130
}

CoreBuilder/ApiExplorerCommand.cs renamed to CoreBuilder/Development/ApiExplorerCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* COPYRIGHT: See COPYING in the top level directory
3-
* PROJECT: CoreBuilder
3+
* PROJECT: CoreBuilder.Development
44
* FILE: ApiExplorerCommand.cs
55
* PURPOSE: Command to list namespaces, classes, and members in a source directory.
66
* PROGRAMMER: Peter Geinitz (Wayfarer)
@@ -19,7 +19,7 @@
1919
using Weaver.Interfaces;
2020
using Weaver.Messages;
2121

22-
namespace CoreBuilder
22+
namespace CoreBuilder.Development
2323
{
2424
/// <inheritdoc />
2525
/// <summary>

CoreBuilder/HeaderExtractor.cs renamed to CoreBuilder/Development/HeaderExtractor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* COPYRIGHT: See COPYING in the top level directory
3-
* PROJECT: CoreBuilder
3+
* PROJECT: CoreBuilder.Development
44
* FILE: HeaderExtractor.cs
55
* PURPOSE: Inserts or detects license headers in C# source files.
66
* PROGRAMMER: Peter Geinitz (Wayfarer)
@@ -19,7 +19,7 @@
1919
using Weaver.Interfaces;
2020
using Weaver.Messages;
2121

22-
namespace CoreBuilder;
22+
namespace CoreBuilder.Development;
2323

2424
/// <inheritdoc />
2525
/// <summary>
@@ -128,7 +128,7 @@ public CommandResult Execute(params string[] args)
128128
return CommandResult.Fail("Missing argument: directory path.");
129129

130130
var directoryPath = args[0];
131-
var includeSubdirs = args.Length <= 1 || (args.Length > 1 && bool.TryParse(args[1], out var result) && result);
131+
var includeSubdirs = args.Length <= 1 || args.Length > 1 && bool.TryParse(args[1], out var result) && result;
132132

133133
var resultMessage = ProcessFiles(directoryPath, includeSubdirs);
134134
return CommandResult.Ok(resultMessage);
@@ -148,7 +148,7 @@ public CommandResult InvokeExtension(string extensionName, params string[] args)
148148
return CommandResult.Fail("Missing argument: directory path.");
149149

150150
var directoryPath = args[0];
151-
var includeSubDirs = args.Length <= 1 || (args.Length > 1 && bool.TryParse(args[1], out var result) && result);
151+
var includeSubDirs = args.Length <= 1 || args.Length > 1 && bool.TryParse(args[1], out var result) && result;
152152

153153
var previewList = DetectFilesNeedingHeaders(directoryPath, includeSubDirs);
154154
if (string.IsNullOrWhiteSpace(previewList) || previewList.StartsWith("All files"))
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* COPYRIGHT: See COPYING in the top level directory
3-
* PROJECT: CoreBuilder
3+
* PROJECT: CoreBuilder.Development
44
* FILE: CoreBuilder/ResXtract.cs
55
* PURPOSE: String Resource extractor.
66
* PROGRAMMER: Peter Geinitz (Wayfarer)
@@ -22,7 +22,7 @@
2222
using Weaver.Messages;
2323

2424

25-
namespace CoreBuilder;
25+
namespace CoreBuilder.Development;
2626

2727
/// <inheritdoc />
2828
/// <summary>

CoreBuilder/FileManager/Tree.cs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* COPYRIGHT: See COPYING in the top level directory
3+
* PROJECT: CoreBuilder.FileManager
4+
* FILE: Tree.cs
5+
* PURPOSE: Command to display directory structure in tree-like format.
6+
* PROGRAMMER: Peter Geinitz (Wayfarer)
7+
*/
8+
9+
// ReSharper disable UnusedType.Global
10+
11+
using System;
12+
using System.IO;
13+
using System.Text;
14+
using Weaver;
15+
using Weaver.Interfaces;
16+
using Weaver.Messages;
17+
18+
namespace CoreBuilder.FileManager
19+
{
20+
/// <inheritdoc />
21+
/// <summary>
22+
/// Displays a directory structure in a tree-like visual representation.
23+
/// </summary>
24+
public sealed class Tree : ICommand
25+
{
26+
/// <inheritdoc />
27+
public string Name => "Tree";
28+
29+
/// <inheritdoc />
30+
public string Description => "Displays folder structure visually from a given path.";
31+
32+
/// <inheritdoc />
33+
public string Namespace => "FileSystem";
34+
35+
/// <inheritdoc />
36+
public int ParameterCount => 1;
37+
38+
/// <inheritdoc />
39+
public CommandSignature Signature => new(Namespace, Name, ParameterCount);
40+
41+
/// <inheritdoc />
42+
public CommandResult Execute(params string[] args)
43+
{
44+
if (args.Length < 1)
45+
return CommandResult.Fail("Usage: Tree [path]");
46+
47+
var path = args[0];
48+
49+
if (!Directory.Exists(path))
50+
return CommandResult.Fail($"Path does not exist: {path}");
51+
52+
var sb = new StringBuilder();
53+
sb.AppendLine(path);
54+
55+
try
56+
{
57+
BuildTree(path, sb, "", true);
58+
return CommandResult.Ok(sb.ToString(), EnumTypes.Wstring);
59+
}
60+
catch (Exception ex)
61+
{
62+
return CommandResult.Fail($"Tree failed: {ex.Message}");
63+
}
64+
}
65+
66+
/// <summary>
67+
/// Recursively builds the directory structure.
68+
/// </summary>
69+
private void BuildTree(string path, StringBuilder sb, string indent, bool last)
70+
{
71+
var prefix = last ? "└── " : "├── ";
72+
sb.AppendLine($"{indent}{prefix}{Path.GetFileName(path)}");
73+
74+
indent += last ? " " : "│ ";
75+
76+
var dirs = Directory.GetDirectories(path);
77+
var files = Directory.GetFiles(path);
78+
79+
for (var i = 0; i < files.Length; i++)
80+
{
81+
var isLast = i == files.Length - 1 && dirs.Length == 0;
82+
sb.AppendLine($"{indent}{(isLast ? "└── " : "├── ")}{Path.GetFileName(files[i])}");
83+
}
84+
85+
for (var d = 0; d < dirs.Length; d++)
86+
{
87+
var isLastDir = d == dirs.Length - 1;
88+
BuildTree(dirs[d], sb, indent, isLastDir);
89+
}
90+
}
91+
92+
/// <inheritdoc />
93+
public CommandResult InvokeExtension(string extensionName, params string[] args)
94+
=> CommandResult.Fail($"'{Name}' has no extensions.");
95+
}
96+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* COPYRIGHT: See COPYING in the top level directory
3+
* PROJECT: CoreBuilder.Helper
4+
* FILE: ConsoleEventOutput.cs
5+
* PURPOSE: Sample console side channel for event output.
6+
* PROGRAMMER: Peter Geinitz (Wayfarer)
7+
*/
8+
9+
using System;
10+
using CoreBuilder.Interface;
11+
12+
namespace CoreBuilder.Helper
13+
{
14+
/// <inheritdoc />
15+
/// <summary>
16+
/// Console side channel for event output.
17+
/// </summary>
18+
/// <seealso cref="CoreBuilder.Interface.IEventOutput" />
19+
public sealed class ConsoleEventOutput : IEventOutput
20+
{
21+
/// <inheritdoc />
22+
public void Write(string message) => Console.WriteLine(message);
23+
}
24+
25+
}

CoreBuilder/WhoAmI.cs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* COPYRIGHT: See COPYING in the top level directory
3+
* PROJECT: CoreBuilder
4+
* FILE: WhoAmI.cs
5+
* PURPOSE: Command to display local machine and network identity.
6+
* PROGRAMMER: Peter Geinitz (Wayfarer)
7+
*/
8+
9+
// ReSharper disable UnusedType.Global
10+
11+
using System;
12+
using System.Linq;
13+
using System.Net.NetworkInformation;
14+
using Weaver;
15+
using Weaver.Interfaces;
16+
using Weaver.Messages;
17+
18+
namespace CoreBuilder
19+
{
20+
/// <inheritdoc />
21+
/// <summary>
22+
/// Displays local machine identity (hostname, user, IP addresses).
23+
/// </summary>
24+
public sealed class WhoAmI : ICommand
25+
{
26+
/// <inheritdoc />
27+
public string Name => "WhoAmI";
28+
29+
/// <inheritdoc />
30+
public string Description => "Displays hostname, user and IP information.";
31+
32+
/// <inheritdoc />
33+
public string Namespace => "System";
34+
35+
/// <inheritdoc />
36+
public int ParameterCount => 0;
37+
38+
/// <inheritdoc />
39+
public CommandSignature Signature => new(Namespace, Name, ParameterCount);
40+
41+
/// <inheritdoc />
42+
public CommandResult Execute(params string[] args)
43+
{
44+
try
45+
{
46+
var hostname = Environment.MachineName;
47+
var username = Environment.UserName;
48+
var domain = Environment.UserDomainName;
49+
50+
var ips = NetworkInterface
51+
.GetAllNetworkInterfaces()
52+
.Where(n => n.OperationalStatus == OperationalStatus.Up)
53+
.SelectMany(n => n.GetIPProperties().UnicastAddresses)
54+
.Where(a => a.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
55+
.Select(a => a.Address.ToString())
56+
.Distinct()
57+
.ToList();
58+
59+
var info =
60+
$"WhoAmI System Report\n" +
61+
$"------------------------\n" +
62+
$"Hostname: {hostname}\n" +
63+
$"Username: {username}\n" +
64+
$"Domain: {domain}\n" +
65+
$"IPv4 Addresses: {(ips.Any() ? string.Join(", ", ips) : "None")}\n" +
66+
$"OS: {Environment.OSVersion}\n" +
67+
$"64-bit OS: {Environment.Is64BitOperatingSystem}\n" +
68+
$"64-bit Process: {Environment.Is64BitProcess}\n" +
69+
$"Processor Count: {Environment.ProcessorCount}\n" +
70+
$"CLR Version: {Environment.Version}";
71+
72+
return CommandResult.Ok(info, EnumTypes.Wstring);
73+
}
74+
catch (Exception ex)
75+
{
76+
return CommandResult.Fail($"WhoAmI failed: {ex.Message}");
77+
}
78+
}
79+
80+
/// <inheritdoc />
81+
public CommandResult InvokeExtension(string extensionName, params string[] args)
82+
=> CommandResult.Fail($"'{Name}' has no extensions.");
83+
}
84+
}

0 commit comments

Comments
 (0)