Esempio n. 1
0
        public async Task Register(string query)
        {
            if (StreamHandler.queriesToUsers.ContainsKey(query))
            {
                StreamHandler.queriesToUsers[query].Add(Context.ConnectionId);
            }
            else
            {
                StreamHandler.queriesToUsers.Add(query, new List <string>()
                {
                    Context.ConnectionId
                });
            }

            var tokenSource = new CancellationTokenSource();

            CurrentTasks.TryAdd(query, new TwitterTaskData
            {
                CancelToken = tokenSource,
                Id          = query,
                Status      = "Initializing."
            });

            await Groups.Add(Context.ConnectionId, query);

            try
            {
                var task = TwitterStream.StartStream(query, tokenSource.Token);

                await task;
            }
            catch (AggregateException e) when(e.InnerException is OperationCanceledException)
            {
            }
        }
Esempio n. 2
0
        public async Task StartTwitterLive()
        {
            var tokenSource = new CancellationTokenSource();

            var taskId = string.Format("T-{0}", Guid.NewGuid());

            CurrentTasks.TryAdd(taskId, new TwitterTaskData
            {
                CancelToken = tokenSource,
                Id          = taskId,
                Status      = "Started."
            });

            await Clients.Caller.setTaskId(taskId);

            var task = TwitterStream.StartStream(tokenSource.Token);

            await task;
        }