Skip to content

Commit 6592be5

Browse files
author
Wayfarer
committed
sync weaver
1 parent ed227f6 commit 6592be5

101 files changed

Lines changed: 1025 additions & 671 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CoreBuilder/CommandFactory.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System;
1515
using System.Collections.Generic;
1616
using System.Linq;
17+
using Weaver;
1718
using Weaver.Interfaces;
1819

1920
namespace CoreBuilder
@@ -26,8 +27,11 @@ public static class CommandFactory
2627
/// <summary>
2728
/// Gets the commands.
2829
/// </summary>
29-
/// <returns>All commands.</returns>
30-
public static IReadOnlyList<ICommand> GetCommands()
30+
/// <param name="weave">The weave.</param>
31+
/// <returns>
32+
/// All commands.
33+
/// </returns>
34+
public static IReadOnlyList<ICommand> GetCommands(Weave? weave = null)
3135
{
3236
ICommand[] modules =
3337
{
@@ -37,7 +41,7 @@ public static IReadOnlyList<ICommand> GetCommands()
3741
new LicenseHeaderAnalyzer(), new UnusedClassAnalyzer(), new UnusedConstantAnalyzer(),
3842
new UnusedLocalVariableAnalyzer(), new UnusedParameterAnalyzer(), new UnusedPrivateFieldAnalyzer(),
3943
new DocCommentCoverageCommand(), new DeadReferenceAnalyzer(), new ApiExplorerCommand(),
40-
new FileLockScanner(), new SmartPingPro(), new WhoAmI(), new Tree()
44+
new FileLockScanner(), new SmartPingPro(), new WhoAmI(weave.Runtime.Variables), new Tree()
4145
};
4246

4347
return modules;
@@ -47,8 +51,11 @@ public static IReadOnlyList<ICommand> GetCommands()
4751
/// Gets the commands.
4852
/// </summary>
4953
/// <param name="userspace">The userspace.</param>
50-
/// <returns>All commands by Namespace.</returns>
51-
public static IReadOnlyList<ICommand> GetCommands(string userspace)
54+
/// <param name="weave">The weave.</param>
55+
/// <returns>
56+
/// All commands by Namespace.
57+
/// </returns>
58+
public static IReadOnlyList<ICommand> GetCommands(string userspace, Weave? weave = null)
5259
{
5360
ICommand[] modules =
5461
{
@@ -58,7 +65,7 @@ public static IReadOnlyList<ICommand> GetCommands(string userspace)
5865
new HotPathAnalyzer(), new LicenseHeaderAnalyzer(), new UnusedClassAnalyzer(),
5966
new UnusedConstantAnalyzer(), new UnusedLocalVariableAnalyzer(), new UnusedParameterAnalyzer(),
6067
new UnusedPrivateFieldAnalyzer(), new DocCommentCoverageCommand(), new DeadReferenceAnalyzer(),
61-
new ApiExplorerCommand(), new FileLockScanner(), new SmartPingPro(), new WhoAmI(), new Tree()
68+
new ApiExplorerCommand(), new FileLockScanner(), new SmartPingPro(), new WhoAmI(weave.Runtime.Variables), new Tree()
6269
};
6370

6471
// Filter by Namespace
@@ -70,7 +77,9 @@ public static IReadOnlyList<ICommand> GetCommands(string userspace)
7077
/// <summary>
7178
/// Gets the extensions.
7279
/// </summary>
73-
/// <returns>All Extensions</returns>
80+
/// <returns>
81+
/// All Extensions
82+
/// </returns>
7483
public static IReadOnlyList<ICommandExtension> GetExtensions()
7584
{
7685
ICommandExtension[] modules = { new WhoAmIExtension() };
@@ -96,4 +105,4 @@ public static IReadOnlyList<ICodeAnalyzer> GetAllAnalyzers()
96105
return modules;
97106
}
98107
}
99-
}
108+
}

CoreBuilder/CoreResources.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ internal static class CoreResources
2323
/// </summary>
2424
internal const string ResourceCsProjectExtension = "*.csproj";
2525
}
26-
}
26+
}

CoreBuilder/Development/ApiExplorerCommand.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ private static void DumpTypes(IEnumerable<BaseTypeDeclarationSyntax> types, Stri
150150
{
151151
var memberLine = member switch
152152
{
153+
ConstructorDeclarationSyntax c when IsPublic(c.Modifiers) =>
154+
$" constructor: {c.Identifier}({string.Join(", ", c.ParameterList.Parameters.Select(p => $"{p.Type} {p.Identifier}"))})",
153155
MethodDeclarationSyntax m when IsPublic(m.Modifiers) =>
154156
$" method: {m.Identifier}({string.Join(", ", m.ParameterList.Parameters.Select(p => $"{p.Type} {p.Identifier}"))})",
155157
PropertyDeclarationSyntax p when IsPublic(p.Modifiers) =>
@@ -183,7 +185,7 @@ EventDeclarationSyntax e when IsPublic(e.Modifiers) =>
183185
/// </returns>
184186
private static bool IsPublic(SyntaxTokenList modifiers)
185187
{
186-
return modifiers.Any(m => m.Text == "public");
188+
return modifiers.Any(m => m.IsKind(SyntaxKind.PublicKeyword));
187189
}
188190
}
189-
}
191+
}

CoreBuilder/Development/HeaderExtractor.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ public CommandResult TryRun(params string[] args)
168168
"no" => CommandResult.Fail("Operation cancelled by user."),
169169
_ => new CommandResult
170170
{
171-
Message = "Please answer yes/no.", RequiresConfirmation = true, Feedback = feedback
171+
Message = "Please answer yes/no.",
172+
RequiresConfirmation = true,
173+
Feedback = feedback
172174
}
173175
};
174176
});
@@ -241,4 +243,4 @@ private static string InsertHeader(string fileContent, string fileName, string p
241243
return string.Concat(header, Environment.NewLine, fileContent);
242244
}
243245
}
244-
}
246+
}

CoreBuilder/Development/ResXtract.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,4 +368,4 @@ private static void GenerateResourceFile(Dictionary<string, string> resourceMap,
368368
}
369369
}
370370
}
371-
}
371+
}

CoreBuilder/Diagnostic.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,4 @@ public override string ToString()
9898
: $"{Name}, {Severity}, {FilePath}({LineNumber}): {Message}";
9999
}
100100
}
101-
}
101+
}

CoreBuilder/Enums/DiagnosticImpact.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ public enum DiagnosticImpact
3434
Other = 3,
3535
Readability = 4
3636
}
37-
}
37+
}

CoreBuilder/Enums/DiagnosticSeverity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ public enum DiagnosticSeverity
2828
/// </summary>
2929
Error = 2
3030
}
31-
}
31+
}

CoreBuilder/Enums/LoopContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ public enum LoopContext
3333
/// </summary>
3434
Nested = 3
3535
}
36-
}
36+
}

CoreBuilder/Extensions/WhoAmIExtension.cs

Lines changed: 80 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
*/
88

99
using System;
10+
using System.Collections.Generic;
1011
using System.Linq;
1112
using System.Net.NetworkInformation;
1213
using Weaver.Interfaces;
1314
using Weaver.Messages;
15+
using Weaver.Registry;
1416

1517
namespace CoreBuilder.Extensions
1618
{
@@ -31,60 +33,112 @@ public sealed class WhoAmIExtension : ICommandExtension
3133
public string Namespace => "System";
3234

3335
/// <inheritdoc />
34-
public CommandResult Invoke(ICommand command, string[] extensionArgs, Func<string[], CommandResult> executor,
35-
string[] commandArgs)
36+
public CommandResult Invoke(ICommand command, string[] extensionArgs, Func<string[], CommandResult> executor, string[] commandArgs)
3637
{
3738
if (extensionArgs.Length == 0)
3839
{
3940
return CommandResult.Fail(
4041
"No parameter specified. Example: whoami().who(ip,hostname) or whoami().who(ip)");
4142
}
4243

44+
// 1. Cast to the concrete parent command to access its public/internal fields
45+
if (command is not WhoAmI parent)
46+
{
47+
return CommandResult.Fail("Extension 'who' is only compatible with the WhoAmI command.");
48+
}
49+
50+
// Use the registry and the key defined by the parent command
51+
var registry = parent.Variables;
52+
string storeKey = parent.LastStoreKey;
53+
4354
try
4455
{
56+
// 2. Fetch existing object from the registry to allow incremental updates
57+
// This ensures that whoami(x).who(ip).who(os) preserves the IP.
58+
var whoamiData = new Dictionary<string, VmValue>();
59+
if (registry.TryGetObject(storeKey, out var existingObj) && existingObj != null)
60+
{
61+
foreach (var kvp in existingObj)
62+
{
63+
whoamiData[kvp.Key] = kvp.Value;
64+
}
65+
}
66+
67+
// 3. Gather System Data
4568
var hostname = Environment.MachineName;
4669
var username = Environment.UserName;
4770
var domain = Environment.UserDomainName;
4871

49-
var ips = NetworkInterface
50-
.GetAllNetworkInterfaces()
72+
var ips = NetworkInterface.GetAllNetworkInterfaces()
5173
.Where(n => n.OperationalStatus == OperationalStatus.Up)
5274
.SelectMany(n => n.GetIPProperties().UnicastAddresses)
5375
.Where(a => a.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
5476
.Select(a => a.Address.ToString())
5577
.Distinct()
5678
.ToList();
5779

58-
var ipsJoined = ips.Any() ? string.Join(", ", ips) : "None";
80+
string ipsJoined = ips.Any() ? string.Join(", ", ips) : "None";
5981

60-
// Build a list of lines for requested fields
61-
var lines = extensionArgs.Select(arg => arg.ToLowerInvariant())
62-
.Select(field =>
82+
// 4. Parse requested fields and update the dictionary
83+
var lines = new List<string>();
84+
foreach (var field in extensionArgs.Select(arg => arg.ToLowerInvariant()))
85+
{
86+
switch (field)
6387
{
64-
return field switch
65-
{
66-
"hostname" => $"Hostname: {hostname}",
67-
"username" => $"Username: {username}",
68-
"domain" => $"Domain: {domain}",
69-
"ip" => $"IP: {ipsJoined}",
70-
"os" => $"OS: {Environment.OSVersion}",
71-
"64bitos" => $"64-bit OS: {Environment.Is64BitOperatingSystem}",
72-
"64bitprocess" => $"64-bit Process: {Environment.Is64BitProcess}",
73-
"processorcount" => $"Processor Count: {Environment.ProcessorCount}",
74-
"clrversion" => $"CLR Version: {Environment.Version}",
75-
_ => $"Unknown parameter: {field}"
76-
};
77-
}).ToArray();
88+
case "hostname":
89+
whoamiData["hostname"] = VmValue.FromString(hostname);
90+
lines.Add($"Hostname: {hostname}");
91+
break;
92+
case "username":
93+
whoamiData["username"] = VmValue.FromString(username);
94+
lines.Add($"Username: {username}");
95+
break;
96+
case "domain":
97+
whoamiData["domain"] = VmValue.FromString(domain);
98+
lines.Add($"Domain: {domain}");
99+
break;
100+
case "ip":
101+
whoamiData["ip"] = VmValue.FromString(ipsJoined);
102+
lines.Add($"IP: {ipsJoined}");
103+
break;
104+
case "os":
105+
whoamiData["os"] = VmValue.FromString(Environment.OSVersion.ToString());
106+
lines.Add($"OS: {Environment.OSVersion}");
107+
break;
108+
case "64bitos":
109+
whoamiData["64bitos"] = VmValue.FromBool(Environment.Is64BitOperatingSystem);
110+
lines.Add($"64-bit OS: {Environment.Is64BitOperatingSystem}");
111+
break;
112+
case "64bitprocess":
113+
whoamiData["64bitprocess"] = VmValue.FromBool(Environment.Is64BitProcess);
114+
lines.Add($"64-bit Process: {Environment.Is64BitProcess}");
115+
break;
116+
case "processorcount":
117+
whoamiData["processorcount"] = VmValue.FromInt(Environment.ProcessorCount);
118+
lines.Add($"Processor Count: {Environment.ProcessorCount}");
119+
break;
120+
case "clrversion":
121+
whoamiData["clrversion"] = VmValue.FromString(Environment.Version.ToString());
122+
lines.Add($"CLR Version: {Environment.Version}");
123+
break;
124+
default:
125+
lines.Add($"Unknown parameter: {field}");
126+
break;
127+
}
128+
}
78129

79-
// Join lines into a single message
80-
var message = string.Join(Environment.NewLine, lines);
130+
// 5. Store the updated dictionary back into the registry
131+
// Your VariableRegistry.SetObject handles the memory overwrite/reuse logic.
132+
registry.SetObject(storeKey, whoamiData);
81133

82-
return CommandResult.Ok(message: message);
134+
// 6. Return the status message
135+
string message = string.Join(Environment.NewLine, lines);
136+
return CommandResult.Ok(message, storeKey, EnumTypes.Wobject);
83137
}
84138
catch (Exception ex)
85139
{
86140
return CommandResult.Fail($"WhoExtension failed: {ex.Message}");
87141
}
88142
}
89143
}
90-
}
144+
}

0 commit comments

Comments
 (0)