Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -294,7 +294,7 @@ public IAsyncEnumerable<PartOfSpeech> GetPartsOfSpeech()
? FromLcmPartOfSpeech(partOfSpeech) : null);
}

public async Task<PartOfSpeech> CreatePartOfSpeech(PartOfSpeech partOfSpeech)
public Task<PartOfSpeech> CreatePartOfSpeech(PartOfSpeech partOfSpeech)
{
IPartOfSpeech? lcmPartOfSpeech = null;
if (partOfSpeech.Id == default) partOfSpeech.Id = Guid.NewGuid();
Expand All @@ -307,7 +307,8 @@ public async Task<PartOfSpeech> 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<PartOfSpeech> UpdatePartOfSpeech(Guid id, UpdateObjectInput<PartOfSpeech> update)
Expand Down Expand Up @@ -351,19 +352,20 @@ public async Task<Publication> 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<Publication> UpdatePublication(Guid id, UpdateObjectInput<Publication> update)
{
Expand Down Expand Up @@ -496,7 +498,7 @@ private ComplexFormType ToComplexFormType(ILexEntryType t)
return new ComplexFormType() { Id = t.Guid, Name = FromLcmMultiString(t.Name) };
}

public async Task<ComplexFormType> CreateComplexFormType(ComplexFormType complexFormType)
public Task<ComplexFormType> CreateComplexFormType(ComplexFormType complexFormType)
{
if (complexFormType.Id == default) complexFormType.Id = Guid.NewGuid();
UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW("Create complex form type",
Expand All @@ -510,7 +512,7 @@ public async Task<ComplexFormType> 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<ComplexFormType> UpdateComplexFormType(Guid id, UpdateObjectInput<ComplexFormType> update)
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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);
Expand All @@ -768,16 +770,16 @@ 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,
Gloss = FromLcmMultiString(sense.Gloss),
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;
}
Expand All @@ -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++)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1425,7 +1424,7 @@ private void ApplySenseToLexSense(Sense sense, ILexSense lexSense)
return Task.FromResult(lcmSense is null ? null : FromLexSense(lcmSense));
}

public async Task<Sense> CreateSense(Guid entryId, Sense sense, BetweenPosition? between = null)
public Task<Sense> CreateSense(Guid entryId, Sense sense, BetweenPosition? between = null)
{
if (sense.Id == default) sense.Id = Guid.NewGuid();
if (!EntriesRepository.TryGetObject(entryId, out var lexEntry))
Expand All @@ -1434,7 +1433,7 @@ public async Task<Sense> 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<Sense> UpdateSense(Guid entryId, Guid senseId, UpdateObjectInput<Sense> update)
Expand Down Expand Up @@ -1570,7 +1569,7 @@ public ICmTranslation CreateExampleSentenceTranslation(ILexExampleSentence paren
return CmTranslationFactory.Create(parent, freeTranslationType);
}

public async Task<ExampleSentence> CreateExampleSentence(Guid entryId, Guid senseId, ExampleSentence exampleSentence, BetweenPosition? between = null)
public Task<ExampleSentence> 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))
Expand All @@ -1579,7 +1578,8 @@ public async Task<ExampleSentence> 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<ExampleSentence> UpdateExampleSentence(Guid entryId,
Expand Down Expand Up @@ -1668,7 +1668,7 @@ public Task<ReadFileResponse> 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)));
}
Expand Down
19 changes: 6 additions & 13 deletions backend/FwLite/FwDataMiniLcmBridge/LcmUtils/LcmThreadedProgress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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; }
Expand All @@ -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;
}
5 changes: 2 additions & 3 deletions backend/FwLite/FwLiteMaui/MainPage.xaml.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,17 @@ 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);
e.WebView.CoreWebView2.Profile.SetPermissionStateAsync(permission,
"https://0.0.0.0",
CoreWebView2PermissionState.Allow);
}
#pragma warning restore VSTHRD110
#pragma warning restore VSTHRD110, CS4014
e.WebView.CoreWebView2.Settings.IsGeneralAutofillEnabled = false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async Task<Publication> IMiniLcmWriteApi.CreatePublication(Publication publicati
{
return await HasCreated(publication, _api.GetPublications(), () => _api.CreatePublication(publication));
}
async Task<WritingSystem> IMiniLcmWriteApi.CreateWritingSystem(WritingSystem writingSystem, BetweenPosition<WritingSystemId?>? between = null)
async Task<WritingSystem> IMiniLcmWriteApi.CreateWritingSystem(WritingSystem writingSystem, BetweenPosition<WritingSystemId?>? between)
{
return await HasCreated(writingSystem, AsyncWs(), () => _api.CreateWritingSystem(writingSystem, between), ws => ws.Type + ws.WsId.Code);
}
Expand Down
13 changes: 3 additions & 10 deletions backend/FwLite/FwLiteShared/Services/ProjectServicesProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public class ProjectServicesProvider(
CrdtProjectsService crdtProjectsService,
IServiceProvider serviceProvider,
LexboxProjectService lexboxProjectService,
IEnumerable<IProjectProvider> projectProviders,
ILogger<ProjectServicesProvider> logger
IEnumerable<IProjectProvider> projectProviders
): IAsyncDisposable
{
private IProjectProvider? FwDataProjectProvider =>
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion backend/LexBoxApi/Controllers/SyncController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task<ActionResult<SyncJobResult>> 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"));
}
Expand Down
5 changes: 1 addition & 4 deletions backend/Testing/FwHeadless/MediaFileServiceTests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading