예제 #1
0
        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();
            }
        }
예제 #2
0
 public Task UpdatePlotterAsync(long plotterId, PlotterStatus status)
 => !ActivePlotters.TryUpdate(plotterId, status, status)
         ? throw new InvalidOperationException("Cannot update inactive plotter")
         : Task.CompletedTask;
예제 #3
0
 public Task ActivatePlotterAsync(long plotterId, PlotterStatus status)
 => !ActivePlotters.TryAdd(plotterId, status)
         ? throw new InvalidOperationException("Cannot activate active plotter")
         : Task.CompletedTask;
예제 #4
0
 public async Task UpdateAsync(PlotterStatus status)
 {
     long plotterId = long.Parse(Context.UserIdentifier);
     await PlotterService.UpdatePlotterAsync(Context.ConnectionId, plotterId, status);
 }
예제 #5
0
        public Task <ActivationResult> ActivateAsync(PlotterStatus status)
        {
            long plotterId = long.Parse(Context.UserIdentifier);

            return(PlotterService.ActivatePlotterAsync(Context.ConnectionId, plotterId, status));
        }
예제 #6
0
        public void Activate(PlotterStatus status)
        {
            long plotterId = long.Parse(Context.UserIdentifier);

            PlotterService.ActivatePlotterAsync(plotterId, status);
        }
예제 #7
0
        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();
            }
        }
예제 #8
0
 public PlotterActivation(string connectionId, PlotterStatus status)
 {
     ConnectionId = connectionId;
     Status       = status;
 }
예제 #9
0
        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();
            }
        }