Skip to content

Commit e5f55c0

Browse files
committed
🎨 (plugin) Added CLH Internal Data
1 parent ed31540 commit e5f55c0

File tree

5 files changed

+120
-7
lines changed

5 files changed

+120
-7
lines changed

src/CloudlogHelper/Services/PluginService.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ public async Task SendMessage<T>(T msg, CancellationToken token) where T: IMessa
166166
case RigData:
167167
if (!Capabilities.Contains(Capability.RigData))return ;
168168
break;
169+
case ClhInternalMessage:
170+
if (!Capabilities.Contains(Capability.ClhInternalData))return ;
171+
break;
169172
default:
170173
return ;
171174
}
@@ -180,7 +183,6 @@ public async Task SendMessage<T>(T msg, CancellationToken token) where T: IMessa
180183
}
181184
finally
182185
{
183-
184186
_cliLock.Release();
185187
}
186188
}

src/CloudlogHelper/Utils/PbMsgConverter.cs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,86 @@ private static ClearWindow MapClearWindow(WsjtxUtilsPatch.WsjtxMessages.Messages
272272
_ => ClearWindow.ClearBandActivity
273273
};
274274
}
275+
276+
/// <summary>
277+
/// Convert CloudlogHelper RecordedCallsignDetail to protobuf RecordedCallsignDetail message.
278+
/// </summary>
279+
/// <param name="detail">The C# model to convert</param>
280+
/// <returns>A protobuf RecordedCallsignDetail message</returns>
281+
public static ClhInternalMessage ToPbRecordedCallsignDetail(RecordedCallsignDetail detail)
282+
{
283+
var pbDetail = new ClhQSOUploadStatusChanged()
284+
{
285+
OriginalCountryName = detail.OriginalCountryName ?? "",
286+
CqZone = detail.CqZone,
287+
ItuZone = detail.ItuZone,
288+
Continent = detail.Continent ?? "",
289+
Latitude = detail.Latitude,
290+
Longitude = detail.Longitude,
291+
GmtOffset = detail.GmtOffset,
292+
Dxcc = detail.Dxcc ?? "",
293+
DateTimeOff = Timestamp.FromDateTime(detail.DateTimeOff),
294+
DxCall = detail.DXCall ?? "",
295+
DxGrid = detail.DXGrid ?? "",
296+
TxFrequencyInHz = detail.TXFrequencyInHz,
297+
TxFrequencyInMeters = detail.TXFrequencyInMeters ?? "",
298+
Mode = detail.Mode ?? "",
299+
ParentMode = detail.ParentMode ?? "",
300+
ReportSent = detail.ReportSent ?? "",
301+
ReportReceived = detail.ReportReceived ?? "",
302+
TxPower = detail.TXPower ?? "",
303+
Comments = detail.Comments ?? "",
304+
Name = detail.Name ?? "",
305+
DateTimeOn = Timestamp.FromDateTime(detail.DateTimeOn),
306+
OperatorCall = detail.OperatorCall ?? "",
307+
MyCall = detail.MyCall ?? "",
308+
MyGrid = detail.MyGrid ?? "",
309+
ExchangeSent = detail.ExchangeSent ?? "",
310+
ExchangeReceived = detail.ExchangeReceived ?? "",
311+
AdifPropagationMode = detail.AdifPropagationMode ?? "",
312+
ClientId = detail.ClientId ?? "",
313+
RawData = detail.RawData?.ToString() ?? "",
314+
FailReason = detail.FailReason ?? "",
315+
UploadStatus = MapUploadStatus(detail.UploadStatus),
316+
ForcedUpload = detail.ForcedUpload
317+
};
318+
319+
// Copy uploaded services map
320+
foreach (var kvp in detail.UploadedServices)
321+
{
322+
pbDetail.UploadedServices[kvp.Key] = kvp.Value;
323+
}
324+
325+
// Copy uploaded services error message map
326+
foreach (var kvp in detail.UploadedServicesErrorMessage)
327+
{
328+
pbDetail.UploadedServicesErrorMessage[kvp.Key] = kvp.Value;
329+
}
330+
331+
var tmp = new ClhInternalMessage
332+
{
333+
Timestamp = Timestamp.FromDateTime(DateTime.UtcNow),
334+
QsoUploadStatus = pbDetail
335+
};
336+
337+
return tmp;
338+
}
339+
340+
/// <summary>
341+
/// Map CloudlogHelper UploadStatus enum to protobuf UploadStatus enum.
342+
/// </summary>
343+
/// <param name="status">The upload status to convert</param>
344+
/// <returns>Converted protobuf UploadStatus</returns>
345+
private static UploadStatus MapUploadStatus(Enums.UploadStatus status)
346+
{
347+
return status switch
348+
{
349+
Enums.UploadStatus.Pending => UploadStatus.Pending,
350+
Enums.UploadStatus.Uploading => UploadStatus.Uploading,
351+
Enums.UploadStatus.Success => UploadStatus.Success,
352+
Enums.UploadStatus.Fail => UploadStatus.Fail,
353+
Enums.UploadStatus.Ignored => UploadStatus.Ignored,
354+
_ => UploadStatus.Unspecified
355+
};
356+
}
275357
}

src/CloudlogHelper/ViewModels/MainWindowViewModel.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public MainWindowViewModel(
4949
StatusLightUserControlViewModel statusLightUserControlViewModel,
5050
PolarChartWindowViewModel ignored1, // force init - DO NOT REMOVE IT!
5151
StationStatisticsChartWindowViewModel ignored2, // force init - DO NOT REMOVE IT!
52-
IPluginService _, // force init - DO NOT REMOVE IT!
5352
CommandLineOptions cmd,
5453
IWindowManagerService wm,
5554
IInAppNotificationService inAppNotificationService

src/CloudlogHelper/ViewModels/UserControls/UDPLogInfoGroupboxUserControlViewModel.cs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ public UDPLogInfoGroupboxUserControlViewModel(
195195
.DisposeWith(compositeDisposable);
196196

197197
SetupQsoRateCalculation(compositeDisposable);
198+
SetupQsoList(compositeDisposable);
198199
SetupFilteringAndSorting(compositeDisposable);
199200

200201
this.WhenAnyValue(
@@ -251,15 +252,44 @@ private void SetupQsoRateCalculation(CompositeDisposable disposables)
251252

252253
QsAvgMin = $"{rate:F2} Q's/m";
253254
}).DisposeWith(disposables);
254-
255+
}
255256

257+
private void SetupQsoList(CompositeDisposable disposables)
258+
{
256259
_allQsos.Connect()
257260
.WhenPropertyChanged(p => p.UploadStatus)
258-
.Where(x => x.Value == UploadStatus.Success)
259-
.Subscribe(x =>
261+
.Subscribe(async void (x) =>
262+
{
263+
try
264+
{
265+
await _pluginService.BroadcastMessageAsync(
266+
PbMsgConverter.ToPbRecordedCallsignDetail(x.Sender),
267+
CancellationToken.None);
268+
269+
if (x.Value == UploadStatus.Success) UploadedQsosCount += 1;
270+
}
271+
catch (Exception ex)
272+
{
273+
ClassLogger.Error(ex, "Error occurred. Ignored.");
274+
}
275+
})
276+
.DisposeWith(disposables);
277+
278+
_allQsos.Connect()
279+
.OnItemAdded(async void (x) =>
260280
{
261-
UploadedQsosCount += 1;
281+
try
282+
{
283+
await _pluginService.BroadcastMessageAsync(
284+
PbMsgConverter.ToPbRecordedCallsignDetail(x),
285+
CancellationToken.None);
286+
}
287+
catch (Exception ex)
288+
{
289+
ClassLogger.Error(ex, "Error occurred. Ignored.");
290+
}
262291
})
292+
.Subscribe()
263293
.DisposeWith(disposables);
264294
}
265295

0 commit comments

Comments
 (0)