Skip to content

Commit 0f8bce8

Browse files
authored
Fix dotnet warnings and suggestions (#1951)
* Fix dotnet warnings and suggestions * Suppress another warning
1 parent 1cdd440 commit 0f8bce8

File tree

7 files changed

+47
-65
lines changed

7 files changed

+47
-65
lines changed

backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ internal void CompleteExemplars(WritingSystems writingSystems)
140140
{
141141
if (entry.CitationForm is not null)
142142
LcmHelpers.ContributeExemplars(entry.CitationForm, wsExemplarsByHandle);
143-
if (entry.LexemeFormOA is {Form: not null })
143+
if (entry.LexemeFormOA is { Form: not null })
144144
LcmHelpers.ContributeExemplars(entry.LexemeFormOA.Form, wsExemplarsByHandle);
145145
}
146146

@@ -294,7 +294,7 @@ public IAsyncEnumerable<PartOfSpeech> GetPartsOfSpeech()
294294
? FromLcmPartOfSpeech(partOfSpeech) : null);
295295
}
296296

297-
public async Task<PartOfSpeech> CreatePartOfSpeech(PartOfSpeech partOfSpeech)
297+
public Task<PartOfSpeech> CreatePartOfSpeech(PartOfSpeech partOfSpeech)
298298
{
299299
IPartOfSpeech? lcmPartOfSpeech = null;
300300
if (partOfSpeech.Id == default) partOfSpeech.Id = Guid.NewGuid();
@@ -307,7 +307,8 @@ public async Task<PartOfSpeech> CreatePartOfSpeech(PartOfSpeech partOfSpeech)
307307
.Create(partOfSpeech.Id, Cache.LangProject.PartsOfSpeechOA);
308308
UpdateLcmMultiString(lcmPartOfSpeech.Name, partOfSpeech.Name);
309309
});
310-
return FromLcmPartOfSpeech(lcmPartOfSpeech ?? throw new InvalidOperationException("Part of speech was not created"));
310+
return Task.FromResult(FromLcmPartOfSpeech(
311+
lcmPartOfSpeech ?? throw new InvalidOperationException("Part of speech was not created")));
311312
}
312313

313314
public Task<PartOfSpeech> UpdatePartOfSpeech(Guid id, UpdateObjectInput<PartOfSpeech> update)
@@ -351,19 +352,20 @@ public async Task<Publication> CreatePublication(Publication pub)
351352
UpdateLcmMultiString(lcmPublication.Name, pub.Name);
352353
}
353354
);
354-
return await Task.FromResult(FromLcmPossibility(lcmPublication ?? throw new InvalidOperationException("Failed to create publication")));
355+
return await Task.FromResult(FromLcmPossibility(
356+
lcmPublication ?? throw new InvalidOperationException("Failed to create publication")));
355357
}
356358

357-
private Publication FromLcmPossibility(ICmPossibility lcmPossibility)
359+
private Publication FromLcmPossibility(ICmPossibility lcmPossibility)
358360
{
359-
var possibility = new Publication
360-
{
361-
Id = lcmPossibility.Guid,
362-
Name = FromLcmMultiString(lcmPossibility.Name)
363-
};
361+
var possibility = new Publication
362+
{
363+
Id = lcmPossibility.Guid,
364+
Name = FromLcmMultiString(lcmPossibility.Name)
365+
};
364366

365-
return possibility;
366-
}
367+
return possibility;
368+
}
367369

368370
public Task<Publication> UpdatePublication(Guid id, UpdateObjectInput<Publication> update)
369371
{
@@ -496,7 +498,7 @@ private ComplexFormType ToComplexFormType(ILexEntryType t)
496498
return new ComplexFormType() { Id = t.Guid, Name = FromLcmMultiString(t.Name) };
497499
}
498500

499-
public async Task<ComplexFormType> CreateComplexFormType(ComplexFormType complexFormType)
501+
public Task<ComplexFormType> CreateComplexFormType(ComplexFormType complexFormType)
500502
{
501503
if (complexFormType.Id == default) complexFormType.Id = Guid.NewGuid();
502504
UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW("Create complex form type",
@@ -510,7 +512,7 @@ public async Task<ComplexFormType> CreateComplexFormType(ComplexFormType complex
510512
ComplexFormTypes.PossibilitiesOS.Add(lexComplexFormType);
511513
UpdateLcmMultiString(lexComplexFormType.Name, complexFormType.Name);
512514
});
513-
return ToComplexFormType(ComplexFormTypesFlattened.Single(c => c.Guid == complexFormType.Id));
515+
return Task.FromResult(ToComplexFormType(ComplexFormTypesFlattened.Single(c => c.Guid == complexFormType.Id)));
514516
}
515517

516518
public Task<ComplexFormType> UpdateComplexFormType(Guid id, UpdateObjectInput<ComplexFormType> update)
@@ -657,9 +659,9 @@ private Entry FromLexEntry(ILexEntry entry)
657659
CitationForm = FromLcmMultiString(entry.CitationForm),
658660
LiteralMeaning = FromLcmMultiString(entry.LiteralMeaning),
659661
MorphType = LcmHelpers.FromLcmMorphType(entry.PrimaryMorphType), // TODO: Decide what to do about entries with *mixed* morph types
660-
Senses = entry.AllSenses.Select(FromLexSense).ToList(),
662+
Senses = [.. entry.AllSenses.Select(FromLexSense)],
661663
ComplexFormTypes = ToComplexFormTypes(entry),
662-
Components = ToComplexFormComponents(entry).ToList(),
664+
Components = [.. ToComplexFormComponents(entry)],
663665
ComplexForms = [
664666
..entry.ComplexFormEntries.Select(complexEntry => ToEntryReference(entry, complexEntry)),
665667
..entry.AllSenses.SelectMany(sense => sense.ComplexFormEntries.Select(complexEntry => ToSenseReference(sense, complexEntry)))
@@ -747,7 +749,7 @@ private ComplexFormComponent ToSenseReference(ILexSense componentSense, ILexEntr
747749

748750
private static int Order(ICmObject component, ILexEntry complexEntry)
749751
{
750-
int order = 0;
752+
var order = 0;
751753
foreach (var entryRef in complexEntry.ComplexFormEntryRefs)
752754
{
753755
var foundIndex = entryRef.ComponentLexemesRS.IndexOf(component);
@@ -768,16 +770,16 @@ private static int Order(ICmObject component, ILexEntry complexEntry)
768770
private Sense FromLexSense(ILexSense sense)
769771
{
770772
var pos = sense.MorphoSyntaxAnalysisRA?.GetPartOfSpeech();
771-
var s = new Sense
773+
var s = new Sense
772774
{
773775
Id = sense.Guid,
774776
EntryId = sense.Entry.Guid,
775777
Gloss = FromLcmMultiString(sense.Gloss),
776778
Definition = FromLcmMultiString(sense.Definition),
777779
PartOfSpeech = pos is null ? null : FromLcmPartOfSpeech(pos),
778780
PartOfSpeechId = pos?.Guid,
779-
SemanticDomains = sense.SemanticDomainsRC.Select(FromLcmSemanticDomain).ToList(),
780-
ExampleSentences = sense.ExamplesOS.Select(sentence => FromLexExampleSentence(sense.Guid, sentence)).ToList()
781+
SemanticDomains = [.. sense.SemanticDomainsRC.Select(FromLcmSemanticDomain)],
782+
ExampleSentences = [.. sense.ExamplesOS.Select(sentence => FromLexExampleSentence(sense.Guid, sentence))]
781783
};
782784
return s;
783785
}
@@ -791,13 +793,13 @@ private ExampleSentence FromLexExampleSentence(Guid senseGuid, ILexExampleSenten
791793
SenseId = senseGuid,
792794
Sentence = FromLcmMultiString(sentence.Example),
793795
Reference = ToRichString(sentence.Reference),
794-
Translation = translation is null ? new() : FromLcmMultiString(translation),
796+
Translation = translation is null ? [] : FromLcmMultiString(translation),
795797
};
796798
}
797799

798800
private MultiString FromLcmMultiString(ITsMultiString? multiString)
799801
{
800-
if (multiString is null) return new MultiString();
802+
if (multiString is null) return [];
801803
var result = new MultiString(multiString.StringCount);
802804
for (var i = 0; i < multiString.StringCount; i++)
803805
{
@@ -852,7 +854,7 @@ private string ToMediaUri(string tsString)
852854
internal string FromMediaUri(string mediaUriString)
853855
{
854856
//path includes `AudioVisual` currently
855-
MediaUri mediaUri = new MediaUri(mediaUriString);
857+
var mediaUri = new MediaUri(mediaUriString);
856858
var path = mediaAdapter.PathFromMediaUri(mediaUri, Cache);
857859
if (path is null) throw new NotFoundException($"Unable to find file {mediaUri.FileId}.", nameof(MediaFile));
858860
return Path.GetRelativePath(Path.Join(Cache.LangProject.LinkedFilesRootDir, AudioVisualFolder), path);
@@ -1175,11 +1177,8 @@ internal void RemoveComplexFormComponent(ILexEntry lexEntry, ComplexFormComponen
11751177
internal void AddComplexFormType(ILexEntry lexEntry, Guid complexFormTypeId)
11761178
{
11771179
//do the same thing as LCM, use the first when adding if there's more than one
1178-
ILexEntryRef? entryRef = lexEntry.ComplexFormEntryRefs.FirstOrDefault();
1179-
if (entryRef is null)
1180-
{
1181-
entryRef = AddComplexFormLexEntryRef(lexEntry);
1182-
}
1180+
var entryRef = lexEntry.ComplexFormEntryRefs.FirstOrDefault()
1181+
?? AddComplexFormLexEntryRef(lexEntry);
11831182

11841183
var lexEntryType = ComplexFormTypesFlattened.Single(c => c.Guid == complexFormTypeId);
11851184
entryRef.ComplexEntryTypesRS.Add(lexEntryType);
@@ -1429,7 +1428,7 @@ private void ApplySenseToLexSense(Sense sense, ILexSense lexSense)
14291428
return Task.FromResult(lcmSense is null ? null : FromLexSense(lcmSense));
14301429
}
14311430

1432-
public async Task<Sense> CreateSense(Guid entryId, Sense sense, BetweenPosition? between = null)
1431+
public Task<Sense> CreateSense(Guid entryId, Sense sense, BetweenPosition? between = null)
14331432
{
14341433
if (sense.Id == default) sense.Id = Guid.NewGuid();
14351434
if (!EntriesRepository.TryGetObject(entryId, out var lexEntry))
@@ -1438,7 +1437,7 @@ public async Task<Sense> CreateSense(Guid entryId, Sense sense, BetweenPosition?
14381437
"Remove sense",
14391438
Cache.ServiceLocator.ActionHandler,
14401439
() => CreateSense(lexEntry, sense, between));
1441-
return FromLexSense(SenseRepository.GetObject(sense.Id));
1440+
return Task.FromResult(FromLexSense(SenseRepository.GetObject(sense.Id)));
14421441
}
14431442

14441443
public Task<Sense> UpdateSense(Guid entryId, Guid senseId, UpdateObjectInput<Sense> update)
@@ -1574,7 +1573,7 @@ public ICmTranslation CreateExampleSentenceTranslation(ILexExampleSentence paren
15741573
return CmTranslationFactory.Create(parent, freeTranslationType);
15751574
}
15761575

1577-
public async Task<ExampleSentence> CreateExampleSentence(Guid entryId, Guid senseId, ExampleSentence exampleSentence, BetweenPosition? between = null)
1576+
public Task<ExampleSentence> CreateExampleSentence(Guid entryId, Guid senseId, ExampleSentence exampleSentence, BetweenPosition? between = null)
15781577
{
15791578
if (exampleSentence.Id == default) exampleSentence.Id = Guid.NewGuid();
15801579
if (!SenseRepository.TryGetObject(senseId, out var lexSense))
@@ -1583,7 +1582,8 @@ public async Task<ExampleSentence> CreateExampleSentence(Guid entryId, Guid sens
15831582
"Remove example sentence",
15841583
Cache.ServiceLocator.ActionHandler,
15851584
() => CreateExampleSentence(lexSense, exampleSentence, between));
1586-
return FromLexExampleSentence(senseId, ExampleSentenceRepository.GetObject(exampleSentence.Id));
1585+
return Task.FromResult(
1586+
FromLexExampleSentence(senseId, ExampleSentenceRepository.GetObject(exampleSentence.Id)));
15871587
}
15881588

15891589
public Task<ExampleSentence> UpdateExampleSentence(Guid entryId,
@@ -1672,7 +1672,7 @@ public Task<ReadFileResponse> GetFileStream(MediaUri mediaUri)
16721672
if (mediaUri == MediaUri.NotFound) return Task.FromResult(new ReadFileResponse(ReadFileResult.NotFound));
16731673
var pathFromMediaUri = mediaAdapter.PathFromMediaUri(mediaUri, Cache);
16741674
if (pathFromMediaUri is not {Length: > 0}) return Task.FromResult(new ReadFileResponse(ReadFileResult.NotFound));
1675-
string fullPath = Path.Combine(Cache.LangProject.LinkedFilesRootDir, pathFromMediaUri);
1675+
var fullPath = Path.Combine(Cache.LangProject.LinkedFilesRootDir, pathFromMediaUri);
16761676
if (!File.Exists(fullPath)) return Task.FromResult(new ReadFileResponse(ReadFileResult.NotFound));
16771677
return Task.FromResult(new ReadFileResponse(File.OpenRead(fullPath), Path.GetFileName(fullPath)));
16781678
}

backend/FwLite/FwDataMiniLcmBridge/LcmUtils/LcmThreadedProgress.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ namespace FwDataMiniLcmBridge.LcmUtils;
55

66
public class LcmThreadedProgress : IThreadedProgress
77
{
8-
private SingleThreadedSynchronizeInvoke _synchronizeInvoke = new();
8+
private readonly SingleThreadedSynchronizeInvoke _synchronizeInvoke = new();
99

10+
#pragma warning disable CS0067
1011
public event CancelEventHandler? Canceling; // this is part of the interface
12+
#pragma warning restore CS0067
1113

1214
public void Step(int amount)
1315
{
@@ -20,10 +22,7 @@ public void Step(int amount)
2022
public int Minimum { get; set; }
2123
public int Maximum { get; set; }
2224

23-
public ISynchronizeInvoke SynchronizeInvoke
24-
{
25-
get { return _synchronizeInvoke; }
26-
}
25+
public ISynchronizeInvoke SynchronizeInvoke => _synchronizeInvoke;
2726

2827
public bool IsIndeterminate { get; set; }
2928
public bool AllowCancel { get; set; }
@@ -40,13 +39,7 @@ public object RunTask(bool fDisplayUi,
4039
return backgroundTask(this, parameters);
4140
}
4241

43-
public bool Canceled
44-
{
45-
get { return false; }
46-
}
42+
public bool Canceled => false;
4743

48-
public bool IsCanceling
49-
{
50-
get { return false; }
51-
}
44+
public bool IsCanceling => false;
5245
}

backend/FwLite/FwLiteMaui/MainPage.xaml.Windows.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,17 @@ private partial void BlazorWebViewInitialized(object? sender, BlazorWebViewIniti
2727
CoreWebView2PermissionKind.OtherSensors,
2828
CoreWebView2PermissionKind.WindowManagement,
2929
];
30-
#pragma warning disable VSTHRD110
30+
#pragma warning disable VSTHRD110, CS4014
3131
foreach (var permission in permissions)
3232
{
33-
//either of these ip addresses may be used, so just do both
3433
e.WebView.CoreWebView2.Profile.SetPermissionStateAsync(permission,
3534
"https://0.0.0.1",
3635
CoreWebView2PermissionState.Allow);
3736
e.WebView.CoreWebView2.Profile.SetPermissionStateAsync(permission,
3837
"https://0.0.0.0",
3938
CoreWebView2PermissionState.Allow);
4039
}
41-
#pragma warning restore VSTHRD110
40+
#pragma warning restore VSTHRD110, CS4014
4241
e.WebView.CoreWebView2.Settings.IsGeneralAutofillEnabled = false;
4342
}
4443
}

backend/FwLite/FwLiteProjectSync/Import/ResumableImportApi.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async Task<Publication> IMiniLcmWriteApi.CreatePublication(Publication publicati
6666
{
6767
return await HasCreated(publication, _api.GetPublications(), () => _api.CreatePublication(publication));
6868
}
69-
async Task<WritingSystem> IMiniLcmWriteApi.CreateWritingSystem(WritingSystem writingSystem, BetweenPosition<WritingSystemId?>? between = null)
69+
async Task<WritingSystem> IMiniLcmWriteApi.CreateWritingSystem(WritingSystem writingSystem, BetweenPosition<WritingSystemId?>? between)
7070
{
7171
return await HasCreated(writingSystem, AsyncWs(), () => _api.CreateWritingSystem(writingSystem, between), ws => ws.Type + ws.WsId.Code);
7272
}

backend/FwLite/FwLiteShared/Services/ProjectServicesProvider.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ public class ProjectServicesProvider(
1717
CrdtProjectsService crdtProjectsService,
1818
IServiceProvider serviceProvider,
1919
LexboxProjectService lexboxProjectService,
20-
IEnumerable<IProjectProvider> projectProviders,
21-
ILogger<ProjectServicesProvider> logger
20+
IEnumerable<IProjectProvider> projectProviders
2221
): IAsyncDisposable
2322
{
2423
private IProjectProvider? FwDataProjectProvider =>
@@ -153,14 +152,8 @@ public ProjectScope(AsyncServiceScope serviceScope,
153152
{
154153
logger.LogInformation("Disposing project scope {ProjectName}", projectName);
155154
projectServicesProvider._projectScopes.TryRemove(this, out _);
156-
if (HistoryService is not null)
157-
{
158-
HistoryService.Dispose();
159-
}
160-
if (SyncService is not null)
161-
{
162-
SyncService.Dispose();
163-
}
155+
HistoryService?.Dispose();
156+
SyncService?.Dispose();
164157

165158
MiniLcm.Value.Dispose();
166159
MiniLcm.Dispose();

backend/LexBoxApi/Controllers/SyncController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public async Task<ActionResult<SyncJobResult>> AwaitSyncFinished(Guid projectId)
4646
{
4747
return await fwHeadlessClient.AwaitStatus(projectId, HttpContext.RequestAborted);
4848
}
49-
catch (OperationCanceledException e)
49+
catch (OperationCanceledException)
5050
{
5151
return Ok(new SyncJobResult(SyncJobStatusEnum.TimedOutAwaitingSyncStatus, "Timed out awaiting sync status"));
5252
}

backend/Testing/FwHeadless/MediaFileServiceTests.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
using Chorus.VcsDrivers.Mercurial;
2-
using FwDataMiniLcmBridge;
32
using FwDataMiniLcmBridge.Tests.Fixtures;
43
using FwHeadless;
54
using FwHeadless.Media;
65
using FwHeadless.Services;
7-
using LexCore.Entities;
86
using LexData;
97
using Microsoft.EntityFrameworkCore;
108
using Microsoft.Extensions.DependencyInjection;
119
using Microsoft.Extensions.Options;
12-
using MiniLcm;
1310
using MiniLcm.Media;
1411
using SIL.LCModel;
1512
using SIL.Progress;
@@ -240,7 +237,7 @@ public async Task SaveMediaFile_ThrowsWhenTheFileIsTooBig()
240237
{
241238
while (memoryStream.Length < _fwHeadlessConfig.MaxUploadFileSizeBytes)
242239
{
243-
stream.Write(Guid.NewGuid().ToString("N"));
240+
await stream.WriteAsync(Guid.NewGuid().ToString("N"));
244241
}
245242
}
246243
memoryStream.Position = 0;

0 commit comments

Comments
 (0)