diff --git a/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs b/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs index f7e359044b..7db434984c 100644 --- a/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs +++ b/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs @@ -140,7 +140,7 @@ internal void CompleteExemplars(WritingSystems writingSystems) { if (entry.CitationForm is not null) LcmHelpers.ContributeExemplars(entry.CitationForm, wsExemplarsByHandle); - if (entry.LexemeFormOA is {Form: not null }) + if (entry.LexemeFormOA is { Form: not null }) LcmHelpers.ContributeExemplars(entry.LexemeFormOA.Form, wsExemplarsByHandle); } @@ -294,7 +294,7 @@ public IAsyncEnumerable GetPartsOfSpeech() ? FromLcmPartOfSpeech(partOfSpeech) : null); } - public async Task CreatePartOfSpeech(PartOfSpeech partOfSpeech) + public Task CreatePartOfSpeech(PartOfSpeech partOfSpeech) { IPartOfSpeech? lcmPartOfSpeech = null; if (partOfSpeech.Id == default) partOfSpeech.Id = Guid.NewGuid(); @@ -307,7 +307,8 @@ public async Task CreatePartOfSpeech(PartOfSpeech partOfSpeech) .Create(partOfSpeech.Id, Cache.LangProject.PartsOfSpeechOA); UpdateLcmMultiString(lcmPartOfSpeech.Name, partOfSpeech.Name); }); - return FromLcmPartOfSpeech(lcmPartOfSpeech ?? throw new InvalidOperationException("Part of speech was not created")); + return Task.FromResult(FromLcmPartOfSpeech( + lcmPartOfSpeech ?? throw new InvalidOperationException("Part of speech was not created"))); } public Task UpdatePartOfSpeech(Guid id, UpdateObjectInput update) @@ -351,19 +352,20 @@ public async Task CreatePublication(Publication pub) UpdateLcmMultiString(lcmPublication.Name, pub.Name); } ); - return await Task.FromResult(FromLcmPossibility(lcmPublication ?? throw new InvalidOperationException("Failed to create publication"))); + return await Task.FromResult(FromLcmPossibility( + lcmPublication ?? throw new InvalidOperationException("Failed to create publication"))); } - private Publication FromLcmPossibility(ICmPossibility lcmPossibility) + private Publication FromLcmPossibility(ICmPossibility lcmPossibility) { - var possibility = new Publication - { - Id = lcmPossibility.Guid, - Name = FromLcmMultiString(lcmPossibility.Name) - }; + var possibility = new Publication + { + Id = lcmPossibility.Guid, + Name = FromLcmMultiString(lcmPossibility.Name) + }; - return possibility; - } + return possibility; + } public Task UpdatePublication(Guid id, UpdateObjectInput update) { @@ -496,7 +498,7 @@ private ComplexFormType ToComplexFormType(ILexEntryType t) return new ComplexFormType() { Id = t.Guid, Name = FromLcmMultiString(t.Name) }; } - public async Task CreateComplexFormType(ComplexFormType complexFormType) + public Task CreateComplexFormType(ComplexFormType complexFormType) { if (complexFormType.Id == default) complexFormType.Id = Guid.NewGuid(); UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW("Create complex form type", @@ -510,7 +512,7 @@ public async Task CreateComplexFormType(ComplexFormType complex ComplexFormTypes.PossibilitiesOS.Add(lexComplexFormType); UpdateLcmMultiString(lexComplexFormType.Name, complexFormType.Name); }); - return ToComplexFormType(ComplexFormTypesFlattened.Single(c => c.Guid == complexFormType.Id)); + return Task.FromResult(ToComplexFormType(ComplexFormTypesFlattened.Single(c => c.Guid == complexFormType.Id))); } public Task UpdateComplexFormType(Guid id, UpdateObjectInput update) @@ -657,9 +659,9 @@ private Entry FromLexEntry(ILexEntry entry) CitationForm = FromLcmMultiString(entry.CitationForm), LiteralMeaning = FromLcmMultiString(entry.LiteralMeaning), MorphType = LcmHelpers.FromLcmMorphType(entry.PrimaryMorphType), // TODO: Decide what to do about entries with *mixed* morph types - Senses = entry.AllSenses.Select(FromLexSense).ToList(), + Senses = [.. entry.AllSenses.Select(FromLexSense)], ComplexFormTypes = ToComplexFormTypes(entry), - Components = ToComplexFormComponents(entry).ToList(), + Components = [.. ToComplexFormComponents(entry)], ComplexForms = [ ..entry.ComplexFormEntries.Select(complexEntry => ToEntryReference(entry, complexEntry)), ..entry.AllSenses.SelectMany(sense => sense.ComplexFormEntries.Select(complexEntry => ToSenseReference(sense, complexEntry))) @@ -747,7 +749,7 @@ private ComplexFormComponent ToSenseReference(ILexSense componentSense, ILexEntr private static int Order(ICmObject component, ILexEntry complexEntry) { - int order = 0; + var order = 0; foreach (var entryRef in complexEntry.ComplexFormEntryRefs) { var foundIndex = entryRef.ComponentLexemesRS.IndexOf(component); @@ -768,7 +770,7 @@ private static int Order(ICmObject component, ILexEntry complexEntry) private Sense FromLexSense(ILexSense sense) { var pos = sense.MorphoSyntaxAnalysisRA?.GetPartOfSpeech(); - var s = new Sense + var s = new Sense { Id = sense.Guid, EntryId = sense.Entry.Guid, @@ -776,8 +778,8 @@ private Sense FromLexSense(ILexSense sense) Definition = FromLcmMultiString(sense.Definition), PartOfSpeech = pos is null ? null : FromLcmPartOfSpeech(pos), PartOfSpeechId = pos?.Guid, - SemanticDomains = sense.SemanticDomainsRC.Select(FromLcmSemanticDomain).ToList(), - ExampleSentences = sense.ExamplesOS.Select(sentence => FromLexExampleSentence(sense.Guid, sentence)).ToList() + SemanticDomains = [.. sense.SemanticDomainsRC.Select(FromLcmSemanticDomain)], + ExampleSentences = [.. sense.ExamplesOS.Select(sentence => FromLexExampleSentence(sense.Guid, sentence))] }; return s; } @@ -791,13 +793,13 @@ private ExampleSentence FromLexExampleSentence(Guid senseGuid, ILexExampleSenten SenseId = senseGuid, Sentence = FromLcmMultiString(sentence.Example), Reference = ToRichString(sentence.Reference), - Translation = translation is null ? new() : FromLcmMultiString(translation), + Translation = translation is null ? [] : FromLcmMultiString(translation), }; } private MultiString FromLcmMultiString(ITsMultiString? multiString) { - if (multiString is null) return new MultiString(); + if (multiString is null) return []; var result = new MultiString(multiString.StringCount); for (var i = 0; i < multiString.StringCount; i++) { @@ -852,7 +854,7 @@ private string ToMediaUri(string tsString) internal string FromMediaUri(string mediaUriString) { //path includes `AudioVisual` currently - MediaUri mediaUri = new MediaUri(mediaUriString); + var mediaUri = new MediaUri(mediaUriString); var path = mediaAdapter.PathFromMediaUri(mediaUri, Cache); if (path is null) throw new NotFoundException($"Unable to find file {mediaUri.FileId}.", nameof(MediaFile)); return Path.GetRelativePath(Path.Join(Cache.LangProject.LinkedFilesRootDir, AudioVisualFolder), path); @@ -1171,11 +1173,8 @@ internal void RemoveComplexFormComponent(ILexEntry lexEntry, ComplexFormComponen internal void AddComplexFormType(ILexEntry lexEntry, Guid complexFormTypeId) { //do the same thing as LCM, use the first when adding if there's more than one - ILexEntryRef? entryRef = lexEntry.ComplexFormEntryRefs.FirstOrDefault(); - if (entryRef is null) - { - entryRef = AddComplexFormLexEntryRef(lexEntry); - } + var entryRef = lexEntry.ComplexFormEntryRefs.FirstOrDefault() + ?? AddComplexFormLexEntryRef(lexEntry); var lexEntryType = ComplexFormTypesFlattened.Single(c => c.Guid == complexFormTypeId); entryRef.ComplexEntryTypesRS.Add(lexEntryType); @@ -1425,7 +1424,7 @@ private void ApplySenseToLexSense(Sense sense, ILexSense lexSense) return Task.FromResult(lcmSense is null ? null : FromLexSense(lcmSense)); } - public async Task CreateSense(Guid entryId, Sense sense, BetweenPosition? between = null) + public Task CreateSense(Guid entryId, Sense sense, BetweenPosition? between = null) { if (sense.Id == default) sense.Id = Guid.NewGuid(); if (!EntriesRepository.TryGetObject(entryId, out var lexEntry)) @@ -1434,7 +1433,7 @@ public async Task CreateSense(Guid entryId, Sense sense, BetweenPosition? "Remove sense", Cache.ServiceLocator.ActionHandler, () => CreateSense(lexEntry, sense, between)); - return FromLexSense(SenseRepository.GetObject(sense.Id)); + return Task.FromResult(FromLexSense(SenseRepository.GetObject(sense.Id))); } public Task UpdateSense(Guid entryId, Guid senseId, UpdateObjectInput update) @@ -1570,7 +1569,7 @@ public ICmTranslation CreateExampleSentenceTranslation(ILexExampleSentence paren return CmTranslationFactory.Create(parent, freeTranslationType); } - public async Task CreateExampleSentence(Guid entryId, Guid senseId, ExampleSentence exampleSentence, BetweenPosition? between = null) + public Task CreateExampleSentence(Guid entryId, Guid senseId, ExampleSentence exampleSentence, BetweenPosition? between = null) { if (exampleSentence.Id == default) exampleSentence.Id = Guid.NewGuid(); if (!SenseRepository.TryGetObject(senseId, out var lexSense)) @@ -1579,7 +1578,8 @@ public async Task CreateExampleSentence(Guid entryId, Guid sens "Remove example sentence", Cache.ServiceLocator.ActionHandler, () => CreateExampleSentence(lexSense, exampleSentence, between)); - return FromLexExampleSentence(senseId, ExampleSentenceRepository.GetObject(exampleSentence.Id)); + return Task.FromResult( + FromLexExampleSentence(senseId, ExampleSentenceRepository.GetObject(exampleSentence.Id))); } public Task UpdateExampleSentence(Guid entryId, @@ -1668,7 +1668,7 @@ public Task GetFileStream(MediaUri mediaUri) if (mediaUri == MediaUri.NotFound) return Task.FromResult(new ReadFileResponse(ReadFileResult.NotFound)); var pathFromMediaUri = mediaAdapter.PathFromMediaUri(mediaUri, Cache); if (pathFromMediaUri is not {Length: > 0}) return Task.FromResult(new ReadFileResponse(ReadFileResult.NotFound)); - string fullPath = Path.Combine(Cache.LangProject.LinkedFilesRootDir, pathFromMediaUri); + var fullPath = Path.Combine(Cache.LangProject.LinkedFilesRootDir, pathFromMediaUri); if (!File.Exists(fullPath)) return Task.FromResult(new ReadFileResponse(ReadFileResult.NotFound)); return Task.FromResult(new ReadFileResponse(File.OpenRead(fullPath), Path.GetFileName(fullPath))); } diff --git a/backend/FwLite/FwDataMiniLcmBridge/LcmUtils/LcmThreadedProgress.cs b/backend/FwLite/FwDataMiniLcmBridge/LcmUtils/LcmThreadedProgress.cs index f8c9471e17..79d42f4698 100644 --- a/backend/FwLite/FwDataMiniLcmBridge/LcmUtils/LcmThreadedProgress.cs +++ b/backend/FwLite/FwDataMiniLcmBridge/LcmUtils/LcmThreadedProgress.cs @@ -5,9 +5,11 @@ namespace FwDataMiniLcmBridge.LcmUtils; public class LcmThreadedProgress : IThreadedProgress { - private SingleThreadedSynchronizeInvoke _synchronizeInvoke = new(); + private readonly SingleThreadedSynchronizeInvoke _synchronizeInvoke = new(); +#pragma warning disable CS0067 public event CancelEventHandler? Canceling; // this is part of the interface +#pragma warning restore CS0067 public void Step(int amount) { @@ -20,10 +22,7 @@ public void Step(int amount) public int Minimum { get; set; } public int Maximum { get; set; } - public ISynchronizeInvoke SynchronizeInvoke - { - get { return _synchronizeInvoke; } - } + public ISynchronizeInvoke SynchronizeInvoke => _synchronizeInvoke; public bool IsIndeterminate { get; set; } public bool AllowCancel { get; set; } @@ -40,13 +39,7 @@ public object RunTask(bool fDisplayUi, return backgroundTask(this, parameters); } - public bool Canceled - { - get { return false; } - } + public bool Canceled => false; - public bool IsCanceling - { - get { return false; } - } + public bool IsCanceling => false; } diff --git a/backend/FwLite/FwLiteMaui/MainPage.xaml.Windows.cs b/backend/FwLite/FwLiteMaui/MainPage.xaml.Windows.cs index 1da7091901..69eeca2419 100644 --- a/backend/FwLite/FwLiteMaui/MainPage.xaml.Windows.cs +++ b/backend/FwLite/FwLiteMaui/MainPage.xaml.Windows.cs @@ -27,10 +27,9 @@ private partial void BlazorWebViewInitialized(object? sender, BlazorWebViewIniti CoreWebView2PermissionKind.OtherSensors, CoreWebView2PermissionKind.WindowManagement, ]; -#pragma warning disable VSTHRD110 +#pragma warning disable VSTHRD110, CS4014 foreach (var permission in permissions) { - //either of these ip addresses may be used, so just do both e.WebView.CoreWebView2.Profile.SetPermissionStateAsync(permission, "https://0.0.0.1", CoreWebView2PermissionState.Allow); @@ -38,7 +37,7 @@ private partial void BlazorWebViewInitialized(object? sender, BlazorWebViewIniti "https://0.0.0.0", CoreWebView2PermissionState.Allow); } -#pragma warning restore VSTHRD110 +#pragma warning restore VSTHRD110, CS4014 e.WebView.CoreWebView2.Settings.IsGeneralAutofillEnabled = false; } } diff --git a/backend/FwLite/FwLiteProjectSync/Import/ResumableImportApi.cs b/backend/FwLite/FwLiteProjectSync/Import/ResumableImportApi.cs index 59a2c396e5..7aaacebd9b 100644 --- a/backend/FwLite/FwLiteProjectSync/Import/ResumableImportApi.cs +++ b/backend/FwLite/FwLiteProjectSync/Import/ResumableImportApi.cs @@ -66,7 +66,7 @@ async Task IMiniLcmWriteApi.CreatePublication(Publication publicati { return await HasCreated(publication, _api.GetPublications(), () => _api.CreatePublication(publication)); } - async Task IMiniLcmWriteApi.CreateWritingSystem(WritingSystem writingSystem, BetweenPosition? between = null) + async Task IMiniLcmWriteApi.CreateWritingSystem(WritingSystem writingSystem, BetweenPosition? between) { return await HasCreated(writingSystem, AsyncWs(), () => _api.CreateWritingSystem(writingSystem, between), ws => ws.Type + ws.WsId.Code); } diff --git a/backend/FwLite/FwLiteShared/Services/ProjectServicesProvider.cs b/backend/FwLite/FwLiteShared/Services/ProjectServicesProvider.cs index 71b6ee85f2..f1622f2320 100644 --- a/backend/FwLite/FwLiteShared/Services/ProjectServicesProvider.cs +++ b/backend/FwLite/FwLiteShared/Services/ProjectServicesProvider.cs @@ -17,8 +17,7 @@ public class ProjectServicesProvider( CrdtProjectsService crdtProjectsService, IServiceProvider serviceProvider, LexboxProjectService lexboxProjectService, - IEnumerable projectProviders, - ILogger logger + IEnumerable projectProviders ): IAsyncDisposable { private IProjectProvider? FwDataProjectProvider => @@ -153,14 +152,8 @@ public ProjectScope(AsyncServiceScope serviceScope, { logger.LogInformation("Disposing project scope {ProjectName}", projectName); projectServicesProvider._projectScopes.TryRemove(this, out _); - if (HistoryService is not null) - { - HistoryService.Dispose(); - } - if (SyncService is not null) - { - SyncService.Dispose(); - } + HistoryService?.Dispose(); + SyncService?.Dispose(); MiniLcm.Value.Dispose(); MiniLcm.Dispose(); diff --git a/backend/LexBoxApi/Controllers/SyncController.cs b/backend/LexBoxApi/Controllers/SyncController.cs index 1c95a65392..9ce818358a 100644 --- a/backend/LexBoxApi/Controllers/SyncController.cs +++ b/backend/LexBoxApi/Controllers/SyncController.cs @@ -46,7 +46,7 @@ public async Task> AwaitSyncFinished(Guid projectId) { return await fwHeadlessClient.AwaitStatus(projectId, HttpContext.RequestAborted); } - catch (OperationCanceledException e) + catch (OperationCanceledException) { return Ok(new SyncJobResult(SyncJobStatusEnum.TimedOutAwaitingSyncStatus, "Timed out awaiting sync status")); } diff --git a/backend/Testing/FwHeadless/MediaFileServiceTests.cs b/backend/Testing/FwHeadless/MediaFileServiceTests.cs index 372cb5a83c..f3f8c9197e 100644 --- a/backend/Testing/FwHeadless/MediaFileServiceTests.cs +++ b/backend/Testing/FwHeadless/MediaFileServiceTests.cs @@ -1,15 +1,12 @@ using Chorus.VcsDrivers.Mercurial; -using FwDataMiniLcmBridge; using FwDataMiniLcmBridge.Tests.Fixtures; using FwHeadless; using FwHeadless.Media; using FwHeadless.Services; -using LexCore.Entities; using LexData; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; -using MiniLcm; using MiniLcm.Media; using SIL.LCModel; using SIL.Progress; @@ -240,7 +237,7 @@ public async Task SaveMediaFile_ThrowsWhenTheFileIsTooBig() { while (memoryStream.Length < _fwHeadlessConfig.MaxUploadFileSizeBytes) { - stream.Write(Guid.NewGuid().ToString("N")); + await stream.WriteAsync(Guid.NewGuid().ToString("N")); } } memoryStream.Position = 0;