Compare commits

...

6 Commits

4 changed files with 72 additions and 43 deletions

View File

@ -1 +1 @@
1.2.0.0 1.2.1.2

View File

@ -8,8 +8,8 @@
<SignAssembly>True</SignAssembly> <SignAssembly>True</SignAssembly>
<StartupObject>BreCalClient.App</StartupObject> <StartupObject>BreCalClient.App</StartupObject>
<AssemblyOriginatorKeyFile>..\..\misc\brecal.snk</AssemblyOriginatorKeyFile> <AssemblyOriginatorKeyFile>..\..\misc\brecal.snk</AssemblyOriginatorKeyFile>
<AssemblyVersion>1.2.0.10</AssemblyVersion> <AssemblyVersion>1.2.1.2</AssemblyVersion>
<FileVersion>1.2.0.0</FileVersion> <FileVersion>1.2.1.2</FileVersion>
<Title>Bremen calling client</Title> <Title>Bremen calling client</Title>
<Description>A Windows WPF client for the Bremen calling API.</Description> <Description>A Windows WPF client for the Bremen calling API.</Description>
<ApplicationIcon>containership.ico</ApplicationIcon> <ApplicationIcon>containership.ico</ApplicationIcon>

View File

@ -38,7 +38,8 @@ namespace BreCalClient
#region Fields #region Fields
private static int _uiUpdateRunning = 0; //private static int _uiUpdateRunning = 0;
private static SemaphoreSlim uiLock = new SemaphoreSlim(1);
private Credentials? _credentials; private Credentials? _credentials;
@ -97,9 +98,10 @@ namespace BreCalClient
var jitterer = new Random(); var jitterer = new Random();
var retryPolicy = var retryPolicy =
Policy.Handle<HttpRequestException>() // Policy.Handle<HttpRequestException>()
.OrResult<RestSharp.RestResponse>(resp => resp.StatusCode == HttpStatusCode.Unauthorized) Policy.HandleResult<RestSharp.RestResponse>(resp => resp.StatusCode == HttpStatusCode.Unauthorized)
.WaitAndRetryAsync(3, //.OrResult<RestSharp.RestResponse>
.WaitAndRetryAsync(1,
retryAttempt => retryAttempt =>
{ {
var calculatedDelayInMilliseconds = Math.Pow(2, retryAttempt) * 1000; var calculatedDelayInMilliseconds = Math.Pow(2, retryAttempt) * 1000;
@ -114,6 +116,7 @@ namespace BreCalClient
Trace.WriteLine("token refreshed"); Trace.WriteLine("token refreshed");
}); });
RetryConfiguration.AsyncRetryPolicy = retryPolicy; RetryConfiguration.AsyncRetryPolicy = retryPolicy;
this.generalProgressStatus.Maximum = PROGRESS_STEPS; this.generalProgressStatus.Maximum = PROGRESS_STEPS;
} }
@ -235,7 +238,7 @@ namespace BreCalClient
NewWithModel(null); NewWithModel(null);
} }
private void NewWithModel(ShipcallControlModel? model) private async void NewWithModel(ShipcallControlModel? model)
{ {
EditShipcallControl esc = new() EditShipcallControl esc = new()
{ {
@ -250,7 +253,9 @@ namespace BreCalClient
// create UI & save new dialog model // create UI & save new dialog model
if (esc.ShipcallModel.Shipcall != null) if (esc.ShipcallModel.Shipcall != null)
{ {
await uiLock.WaitAsync();
this.UpdateUI(); this.UpdateUI();
uiLock.Release();
esc.ShipcallModel.Shipcall?.Participants.Clear(); esc.ShipcallModel.Shipcall?.Participants.Clear();
foreach (ParticipantAssignment pa in esc.ShipcallModel.AssignedParticipants.Values) foreach (ParticipantAssignment pa in esc.ShipcallModel.AssignedParticipants.Values)
@ -344,10 +349,12 @@ namespace BreCalClient
this.FilterShipcalls(); this.FilterShipcalls();
} }
private void SearchFilterControl_SearchFilterChanged() private async void SearchFilterControl_SearchFilterChanged()
{ {
this.FilterShipcalls(); this.FilterShipcalls();
await uiLock.WaitAsync();
this.UpdateUI(); this.UpdateUI();
uiLock.Release();
} }
private void checkboxShowCancelledCalls_Checked(object sender, RoutedEventArgs e) private void checkboxShowCancelledCalls_Checked(object sender, RoutedEventArgs e)
@ -356,11 +363,13 @@ namespace BreCalClient
this.SearchFilterControl_SearchFilterChanged(); this.SearchFilterControl_SearchFilterChanged();
} }
private void comboBoxSortOrder_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) private async void comboBoxSortOrder_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{ {
_sortOrder = (Extensions.SortOrder) this.comboBoxSortOrder.SelectedIndex; _sortOrder = (Extensions.SortOrder) this.comboBoxSortOrder.SelectedIndex;
this.FilterShipcalls(); this.FilterShipcalls();
await uiLock.WaitAsync();
this.UpdateUI(); this.UpdateUI();
uiLock.Release();
} }
private void buttonHistory_Click(object sender, RoutedEventArgs e) private void buttonHistory_Click(object sender, RoutedEventArgs e)
@ -445,6 +454,7 @@ namespace BreCalClient
{ {
labelGeneralStatus.Text = $"Connection {ConnectionStatus.SUCCESSFUL}"; labelGeneralStatus.Text = $"Connection {ConnectionStatus.SUCCESSFUL}";
labelLatestUpdate.Text = $"Last update: {DateTime.Now.ToLongTimeString()}"; labelLatestUpdate.Text = $"Last update: {DateTime.Now.ToLongTimeString()}";
labelStatusBar.Text = "";
generalProgressStatus.Value = 0; generalProgressStatus.Value = 0;
})); }));
} }
@ -462,49 +472,68 @@ namespace BreCalClient
} }
} }
if (shipcalls != null) try
{ {
foreach (Shipcall shipcall in shipcalls)
{
// load times for each shipcall
List<Times> currentTimes = await _timesApi.TimesGetAsync(shipcall.Id);
if(!_allShipcallsDict.ContainsKey(shipcall.Id)) if (shipcalls != null)
{
foreach (Shipcall shipcall in shipcalls)
{ {
// add entry // load times for each shipcall
ShipcallControlModel scm = new() List<Times> currentTimes = await _timesApi.TimesGetAsync(shipcall.Id);
if (!_allShipcallsDict.ContainsKey(shipcall.Id))
{ {
Shipcall = shipcall, // add entry
Times = currentTimes ShipcallControlModel scm = new()
}; {
this.AddShipcall(scm); Shipcall = shipcall,
Times = currentTimes
};
this.AddShipcall(scm);
}
else
{
// update entry
_allShipcallsDict[shipcall.Id].Shipcall = shipcall;
_allShipcallsDict[shipcall.Id].Times = currentTimes;
UpdateShipcall(_allShipcallsDict[shipcall.Id]);
}
} }
else
List<int> existingIds = new(this._allShipcallsDict.Keys);
foreach (int existingId in existingIds)
{ {
// update entry if (shipcalls.Find(s => s.Id == existingId) == null) // the model is no longer in the search result
_allShipcallsDict[shipcall.Id].Shipcall = shipcall; {
_allShipcallsDict[shipcall.Id].Times = currentTimes; this.RemoveShipcall(existingId);
UpdateShipcall(_allShipcallsDict[shipcall.Id]); }
} }
this.FilterShipcalls();
await uiLock.WaitAsync();
this.UpdateUI();
} }
}
List<int> existingIds = new(this._allShipcallsDict.Keys); catch(Exception ex)
{
foreach (int existingId in existingIds) _log.Error(ex);
{ }
if (shipcalls.Find(s => s.Id == existingId) == null) // the model is no longer in the search result finally
{ {
this.RemoveShipcall(existingId); uiLock.Release();
}
}
this.FilterShipcalls();
this.UpdateUI();
} }
try try
{ {
double interval = (double) SHIPCALL_UPDATE_INTERVAL_SECONDS / PROGRESS_STEPS; double interval = (double) SHIPCALL_UPDATE_INTERVAL_SECONDS / PROGRESS_STEPS;
//if (Interlocked.CompareExchange(ref _uiUpdateRunning, 1, 0) == 1) // do not restart progress unless UI update has completed
// await Task.Delay(TimeSpan.FromSeconds(interval));
System.Diagnostics.Trace.WriteLine("restarting refresh countdown");
for (int i = 0; i < PROGRESS_STEPS; i++) for (int i = 0; i < PROGRESS_STEPS; i++)
{ {
await Task.Delay(TimeSpan.FromSeconds(interval), _tokenSource.Token); await Task.Delay(TimeSpan.FromSeconds(interval), _tokenSource.Token);
@ -762,7 +791,7 @@ namespace BreCalClient
this.Dispatcher.Invoke(new Action(() => this.Dispatcher.Invoke(new Action(() =>
{ {
if (Interlocked.CompareExchange(ref _uiUpdateRunning, 1, 0) == 1) return; //if (Interlocked.CompareExchange(ref _uiUpdateRunning, 1, 0) == 1) return;
try try
{ {
@ -782,7 +811,7 @@ namespace BreCalClient
} }
finally finally
{ {
_uiUpdateRunning = 0; // _uiUpdateRunning = 0;
} }
Mouse.OverrideCursor = null; Mouse.OverrideCursor = null;

View File

@ -5,7 +5,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<ApplicationRevision>10</ApplicationRevision> <ApplicationRevision>10</ApplicationRevision>
<ApplicationVersion>1.2.0.10</ApplicationVersion> <ApplicationVersion>1.2.1.2</ApplicationVersion>
<BootstrapperEnabled>False</BootstrapperEnabled> <BootstrapperEnabled>False</BootstrapperEnabled>
<Configuration>Release</Configuration> <Configuration>Release</Configuration>
<CreateWebPageOnPublish>True</CreateWebPageOnPublish> <CreateWebPageOnPublish>True</CreateWebPageOnPublish>