public async Task UpdatePlotterAsync(string connectionId, long plotterId, PlotterStatus status) { await ActivePlottersLock.WaitAsync(); try { if (!ActivePlotters.TryGetValue(plotterId, out var oldValue)) { throw new InvalidOperationException("Cannot update inactive plotter"); } if (oldValue.ConnectionId != connectionId) { throw new InvalidOperationException("Cannot update active plotter from different connection"); } oldValue.Status = status; ActivePlotters[plotterId] = oldValue; Logger.LogInformation($"Updated plotter [{plotterId}]"); } finally { ActivePlottersLock.Release(); } }
public Task UpdatePlotterAsync(long plotterId, PlotterStatus status) => !ActivePlotters.TryUpdate(plotterId, status, status) ? throw new InvalidOperationException("Cannot update inactive plotter") : Task.CompletedTask;
public Task ActivatePlotterAsync(long plotterId, PlotterStatus status) => !ActivePlotters.TryAdd(plotterId, status) ? throw new InvalidOperationException("Cannot activate active plotter") : Task.CompletedTask;
public async Task UpdateAsync(PlotterStatus status) { long plotterId = long.Parse(Context.UserIdentifier); await PlotterService.UpdatePlotterAsync(Context.ConnectionId, plotterId, status); }
public Task <ActivationResult> ActivateAsync(PlotterStatus status) { long plotterId = long.Parse(Context.UserIdentifier); return(PlotterService.ActivatePlotterAsync(Context.ConnectionId, plotterId, status)); }
public void Activate(PlotterStatus status) { long plotterId = long.Parse(Context.UserIdentifier); PlotterService.ActivatePlotterAsync(plotterId, status); }
public async Task <ActivationResult> ActivatePlotterAsync(string connectionId, long plotterId, PlotterStatus status) { await ActivePlottersLock.WaitAsync(); try { var activation = new PlotterActivation(connectionId, status); if (!ActivePlotters.TryAdd(plotterId, activation)) { return(ActivationResult.FromFailed("There already is a active connection from this plotter!")); } Logger.LogInformation($"Activated plotter [{plotterId}]"); long userId = await UserService.GetOwnerIdFromPlotterId(plotterId); return(ActivationResult.FromSuccess(userId)); } catch (Exception ex) { Logger.LogCritical(ex, "There was an exception while activating a plotter!"); return(ActivationResult.FromFailed("An unknown error occurred!")); } finally { ActivePlottersLock.Release(); } }
public PlotterActivation(string connectionId, PlotterStatus status) { ConnectionId = connectionId; Status = status; }
public async Task <PlotterUpdateResult> UpdatePlotterAsync(string connectionId, long plotterId, PlotterStatus status) { await PlotterLock.WaitAsync(); try { if (!ActivePlotters.TryGetValue(plotterId, out var oldValue)) { throw new InvalidOperationException("Cannot update inactive plotter"); } if (oldValue.ConnectionId != connectionId) { throw new InvalidOperationException("Cannot update active plotter from different connection"); } oldValue.Status = status; ActivePlotters[plotterId] = oldValue; Logger.LogInformation($"Updated plotter [{plotterId}]"); return(PlotterUpdateResult.FromSuccess()); } catch (Exception ex) { Logger.LogCritical(ex, "There was an excpetion while updating a plotter!"); return(PlotterUpdateResult.FromError()); } finally { PlotterLock.Release(); } }