Ejemplo n.º 1
0
        private IMessage PerformQuery(IMessage request)
        {
            ISpace ts = this.repository.GetSpace(request.Target);

            if (ts != null)
            {
                QueryRequest getReq = (QueryRequest)request;
                ITuple       tuple  = ts.Query(new Pattern(getReq.Template));
                return(new QueryResponse(request.Source, request.Session, request.Target, tuple?.Fields ?? null, StatusCode.OK, StatusMessage.OK));
            }
            return(new QueryResponse(request.Source, request.Session, request.Target, null, StatusCode.NOT_FOUND, StatusMessage.NOT_FOUND));
        }
Ejemplo n.º 2
0
        private void Stream()
        {
            var collector = new TupleCollector(space);

            space.Query("start");
            space.Get("lobby_lock");

            Console.WriteLine("Starting game data streaming");
            while (true)
            {
                collector.Collect();
            }
        }
Ejemplo n.º 3
0
        public Task<bool> ChatReader(ISpace chatSpace, CancellationTokenSource cancelTokenSource, ObservableCollection<string> dataSource)
        {
            while (!cancelTokenSource.Token.IsCancellationRequested)
            {
                ITuple received = null;

                received = Task.Run(() =>
                {
                    try
                    {
                        return chatSpace.Query(K + 1, typeof(string), typeof(string), typeof(string));
                    }
                    catch (SocketException ex)
                    {
                        Console.WriteLine(ex.Message);
                        return null;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                    return null;
                }, cancelTokenSource.Token).Result;

                if (received == null)
                {
                    cancelTokenSource.Cancel();
                    return Task.FromResult(false);
                }

                K = (int)received[0];
                var receivedName = (string)received[2];
                var message = (string)received[3];
                var finalMsg = FormatMessage(receivedName, message);
                Application.Current.Dispatcher.Invoke(() =>
                {
                    dataSource.Add(finalMsg);
                });
            }
            return Task.FromResult(true);
        }
 private void CheckForFinish()
 {
     // Id (2nd element) is unused here
     space.Query("winner", typeof(int));
     callback();
 }