Example #1
0
        private async Task StartTaskIfLoggedOn(IConnectionTask task, string code)
        {
            try
            {
                string userId = userServices.GetCurrentUserId();

                var connection = new Connection(Context.ConnectionId, task, Clients.Caller, userId);
                connections[Context.ConnectionId] = connection;

                Task queueProcess = connection.ProcessQueueAsync();

                if (userId == null)
                {
                    connection.PostToQueue((QueueItemType.ConsoleOut, "Can't run code because you are not logged in"));
                    connection.PostToQueue((QueueItemType.Complete, null));
                }
                else
                {
                    await RunTaskAsync(connection, code);
                }

                await queueProcess;
            }
            catch (Exception e)
            {
                await LogErrorAsync(e, code);

                throw new HubException("An error occured when running your code", e);
            }
        }
            public Connection(string connectionId, IConnectionTask connectionTask, ICodeRunnerHubClient caller, string userId)
            {
                this.connectionId   = connectionId;
                this.connectionTask = connectionTask;
                this.caller         = caller;
                this.userId         = userId;

                connectionQueue = new BufferBlock <(QueueItemType type, string message)>();
                consoleOut      = new ConnectionConsoleOut(this);
            }
 public StartConnectionDirective(IConnectionTask input, string token)
 {
     this.Uri   = input.ConnectionUri;
     this.Input = input;
     this.Token = token;
 }
 public static StartConnectionDirective ToConnectionDirective(this IConnectionTask task, string token = null)
 {
     return(new StartConnectionDirective(task, token));
 }