Browse Source

Add SetSolutionPath method and refactor solution path handling

Introduced SetSolutionPath to ActivityContext for consistent solution path updates. Refactored TelemetrySolutionInfoEnricher to use the new method and improved logic for resolving .abpsln files based on possible extensions.
pull/24395/head
SALİH ÖZKARA 8 months ago
parent
commit
3cab27772c
  1. 24
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/ActivityContext.cs
  2. 40
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Providers/TelemetrySolutionInfoEnricher.cs

24
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/ActivityContext.cs

@ -65,6 +65,30 @@ public class ActivityContext
return false;
}
public void SetSolutionPath(string solutionPath)
{
if (solutionPath == SolutionPath)
{
return;
}
ExtraProperties[ActivityPropertyNames.SolutionPath] = solutionPath;
if(Current.ContainsKey(ActivityPropertyNames.SolutionPath))
{
Current[ActivityPropertyNames.SolutionPath] = solutionPath;
}
if (Current.TryGetValue(ActivityPropertyNames.AdditionalProperties, out var additionalPropertiesObj) &&
additionalPropertiesObj is Dictionary<string, object> additionalPropertiesDict)
{
if (additionalPropertiesDict.ContainsKey(ActivityPropertyNames.SolutionPath))
{
additionalPropertiesDict[ActivityPropertyNames.SolutionPath] = solutionPath;
}
}
}
public void Terminate()
{
IsTerminated = true;

40
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Providers/TelemetrySolutionInfoEnricher.cs

@ -49,7 +49,7 @@ internal sealed class TelemetrySolutionInfoEnricher : TelemetryActivityEventEnri
return Task.CompletedTask;
}
context.ExtraProperties[ActivityPropertyNames.SolutionPath] = correctSolutionPath;
context.SetSolutionPath(correctSolutionPath);
var jsonContent = File.ReadAllText(context.SolutionPath!);
using var doc = JsonDocument.Parse(jsonContent, new JsonDocumentOptions
@ -178,37 +178,27 @@ internal sealed class TelemetrySolutionInfoEnricher : TelemetryActivityEventEnri
{
return solutionPath;
}
var possibleExtensions = new[]
{
".sln",
".slnx"
};
if (solutionPath.EndsWith(".sln"))
foreach (var extension in possibleExtensions)
{
solutionPath = solutionPath.RemovePostFix(".sln") + ".abpsln";
if (File.Exists(solutionPath))
if (!solutionPath.EndsWith(extension))
{
return solutionPath;
continue;
}
}
if (solutionPath.EndsWith(".slnx"))
{
solutionPath = solutionPath.RemovePostFix(".slnx") + ".abpsln";
if (File.Exists(solutionPath))
var abpSlnPath = solutionPath.Substring(0, solutionPath.Length - extension.Length) + ".abpsln";
if (File.Exists(abpSlnPath))
{
return solutionPath;
return abpSlnPath;
}
}
var dir = Path.GetDirectoryName(solutionPath);
if (dir.IsNullOrEmpty())
{
return null;
}
var abpSolutionFiles = Directory.GetFiles(dir, "*.abpsln", SearchOption.TopDirectoryOnly);
return abpSolutionFiles.Length switch
{
1 => abpSolutionFiles[0],
_ => null
};
return null;
}
}
Loading…
Cancel
Save