Skip to content

Commit f6082e4

Browse files
committed
Refactor packet hash logic to ObjectTranslator class
Moved GetPacketHash method from AbstractBootstrap to a new ObjectTranslator class for better separation of concerns. Updated usages in GeneralClientBootstrap and GeneralUpdateBootstrap to use ObjectTranslator. Updated project files to include ObjectTranslator.
1 parent b1fdbdb commit f6082e4

File tree

7 files changed

+16
-9
lines changed

7 files changed

+16
-9
lines changed

src/c#/GeneralUpdate.Bowl/GeneralUpdate.Bowl.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
<Compile Include="..\GeneralUpdate.Common\Shared\Object\Enum\ReportType.cs" Link="Common\ReportType.cs" />
7979
<Compile Include="..\GeneralUpdate.Common\Shared\Object\GlobalConfigInfo.cs" Link="Common\GlobalConfigInfo.cs" />
8080
<Compile Include="..\GeneralUpdate.Common\Shared\Object\GlobalConfigInfoOSS.cs" Link="Common\GlobalConfigInfoOSS.cs" />
81+
<Compile Include="..\GeneralUpdate.Common\Shared\Object\ObjectTranslator.cs" Link="Common\ObjectTranslator.cs" />
8182
<Compile Include="..\GeneralUpdate.Common\Shared\Object\Packet.cs" Link="Common\Packet.cs" />
8283
<Compile Include="..\GeneralUpdate.Common\Shared\Object\ProcessInfo.cs" Link="Common\ProcessInfo.cs" />
8384
<Compile Include="..\GeneralUpdate.Common\Shared\Object\VersionInfo.cs" Link="Common\VersionInfo.cs" />

src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,21 +419,21 @@ private GeneralClientBootstrap AddListener<TArgs>(Action<object, TArgs> callback
419419

420420
private void OnMultiDownloadStatistics(object sender, MultiDownloadStatisticsEventArgs e)
421421
{
422-
var message = GetPacketHash(e.Version);
422+
var message = ObjectTranslator.GetPacketHash(e.Version);
423423
GeneralTracer.Info($"Multi download statistics, {message}[BytesReceived]:{e.BytesReceived} [ProgressPercentage]:{e.ProgressPercentage} [Remaining]:{e.Remaining} [TotalBytesToReceive]:{e.TotalBytesToReceive} [Speed]:{e.Speed}");
424424
EventManager.Instance.Dispatch(sender, e);
425425
}
426426

427427
private void OnMultiDownloadCompleted(object sender, MultiDownloadCompletedEventArgs e)
428428
{
429-
var message = GetPacketHash(e.Version);
429+
var message = ObjectTranslator.GetPacketHash(e.Version);
430430
GeneralTracer.Info($"Multi download completed, {message}[IsComplated]:{e.IsComplated}.");
431431
EventManager.Instance.Dispatch(sender, e);
432432
}
433433

434434
private void OnMultiDownloadError(object sender, MultiDownloadErrorEventArgs e)
435435
{
436-
var message = GetPacketHash(e.Version);
436+
var message = ObjectTranslator.GetPacketHash(e.Version);
437437
GeneralTracer.Error($"Multi download error {message}.", e.Exception);
438438
EventManager.Instance.Dispatch(sender, e);
439439
}

src/c#/GeneralUpdate.ClientCore/GeneralUpdate.ClientCore.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<Compile Include="..\GeneralUpdate.Common\Shared\Object\Enum\ReportType.cs" Link="Common\ReportType.cs" />
6969
<Compile Include="..\GeneralUpdate.Common\Shared\Object\GlobalConfigInfo.cs" Link="Common\GlobalConfigInfo.cs" />
7070
<Compile Include="..\GeneralUpdate.Common\Shared\Object\GlobalConfigInfoOSS.cs" Link="Common\GlobalConfigInfoOSS.cs" />
71+
<Compile Include="..\GeneralUpdate.Common\Shared\Object\ObjectTranslator.cs" Link="Common\ObjectTranslator.cs" />
7172
<Compile Include="..\GeneralUpdate.Common\Shared\Object\Packet.cs" Link="Common\Packet.cs" />
7273
<Compile Include="..\GeneralUpdate.Common\Shared\Object\ProcessInfo.cs" Link="Common\ProcessInfo.cs" />
7374
<Compile Include="..\GeneralUpdate.Common\Shared\Object\VersionInfo.cs" Link="Common\VersionInfo.cs" />

src/c#/GeneralUpdate.Common/Internal/Bootstrap/AbstractBootstrap.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,5 @@ public TBootstrap Option<T>(UpdateOption<T> option, T value)
6262
return default;
6363
}
6464
}
65-
66-
protected string GetPacketHash(object version) =>
67-
!GeneralTracer.IsTracingEnabled() ? string.Empty : $"[PacketHash]:{(version as VersionInfo).Hash} ";
6865
}
6966
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace GeneralUpdate.Common.Shared.Object;
2+
3+
public sealed class ObjectTranslator
4+
{
5+
public static string GetPacketHash(object version) =>
6+
!GeneralTracer.IsTracingEnabled() ? string.Empty : $"[PacketHash]:{(version as VersionInfo).Hash} ";
7+
}

src/c#/GeneralUpdate.Core/GeneralUpdate.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<Compile Include="..\GeneralUpdate.Common\Shared\Object\Enum\ReportType.cs" Link="Common\ReportType.cs" />
7272
<Compile Include="..\GeneralUpdate.Common\Shared\Object\GlobalConfigInfo.cs" Link="Common\GlobalConfigInfo.cs" />
7373
<Compile Include="..\GeneralUpdate.Common\Shared\Object\GlobalConfigInfoOSS.cs" Link="Common\GlobalConfigInfoOSS.cs" />
74+
<Compile Include="..\GeneralUpdate.Common\Shared\Object\ObjectTranslator.cs" Link="Common\ObjectTranslator.cs" />
7475
<Compile Include="..\GeneralUpdate.Common\Shared\Object\Packet.cs" Link="Common\Packet.cs" />
7576
<Compile Include="..\GeneralUpdate.Common\Shared\Object\ProcessInfo.cs" Link="Common\ProcessInfo.cs" />
7677
<Compile Include="..\GeneralUpdate.Common\Shared\Object\VersionInfo.cs" Link="Common\VersionInfo.cs" />

src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,21 @@ private GeneralUpdateBootstrap AddListener<TArgs>(Action<object, TArgs> callback
133133

134134
private void OnMultiDownloadStatistics(object sender, MultiDownloadStatisticsEventArgs e)
135135
{
136-
var message = GetPacketHash(e.Version);
136+
var message = ObjectTranslator.GetPacketHash(e.Version);
137137
GeneralTracer.Info($"Multi download statistics, {message}[BytesReceived]:{e.BytesReceived} [ProgressPercentage]:{e.ProgressPercentage} [Remaining]:{e.Remaining} [TotalBytesToReceive]:{e.TotalBytesToReceive} [Speed]:{e.Speed}");
138138
EventManager.Instance.Dispatch(sender, e);
139139
}
140140

141141
private void OnMultiDownloadCompleted(object sender, MultiDownloadCompletedEventArgs e)
142142
{
143-
var message = GetPacketHash(e.Version);
143+
var message = ObjectTranslator.GetPacketHash(e.Version);
144144
GeneralTracer.Info($"Multi download completed, {message}[IsComplated]:{e.IsComplated}.");
145145
EventManager.Instance.Dispatch(sender, e);
146146
}
147147

148148
private void OnMultiDownloadError(object sender, MultiDownloadErrorEventArgs e)
149149
{
150-
var message = GetPacketHash(e.Version);
150+
var message = ObjectTranslator.GetPacketHash(e.Version);
151151
GeneralTracer.Error($"Multi download error {message}.", e.Exception);
152152
EventManager.Instance.Dispatch(sender, e);
153153
}

0 commit comments

Comments
 (0)