Exemplo n.º 1
0
            public async Task GetNotifications_ProcessAsync(int seqid, TProtocol iprot, TProtocol oprot, CancellationToken cancellationToken)
            {
                var args = new GetNotificationsArgs();
                await args.ReadAsync(iprot, cancellationToken);

                await iprot.ReadMessageEndAsync(cancellationToken);

                var result = new GetNotificationsResult();

                try
                {
                    result.Success = await _iAsync.GetNotificationsAsync(cancellationToken);

                    await oprot.WriteMessageBeginAsync(new TMessage("GetNotifications", TMessageType.Reply, seqid), cancellationToken);

                    await result.WriteAsync(oprot, cancellationToken);
                }
                catch (TTransportException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine("Error occurred in processor:");
                    Console.Error.WriteLine(ex.ToString());
                    var x = new TApplicationException(TApplicationException.ExceptionType.InternalError, " Internal error.");
                    await oprot.WriteMessageBeginAsync(new TMessage("GetNotifications", TMessageType.Exception, seqid), cancellationToken);

                    await x.WriteAsync(oprot, cancellationToken);
                }
                await oprot.WriteMessageEndAsync(cancellationToken);

                await oprot.Transport.FlushAsync(cancellationToken);
            }
Exemplo n.º 2
0
            public async Task <string> GetNotificationsAsync(CancellationToken cancellationToken)
            {
                await OutputProtocol.WriteMessageBeginAsync(new TMessage("GetNotifications", TMessageType.Call, SeqId), cancellationToken);

                var args = new GetNotificationsArgs();

                await args.WriteAsync(OutputProtocol, cancellationToken);

                await OutputProtocol.WriteMessageEndAsync(cancellationToken);

                await OutputProtocol.Transport.FlushAsync(cancellationToken);

                var msg = await InputProtocol.ReadMessageBeginAsync(cancellationToken);

                if (msg.Type == TMessageType.Exception)
                {
                    var x = await TApplicationException.ReadAsync(InputProtocol, cancellationToken);

                    await InputProtocol.ReadMessageEndAsync(cancellationToken);

                    throw x;
                }

                var result = new GetNotificationsResult();
                await result.ReadAsync(InputProtocol, cancellationToken);

                await InputProtocol.ReadMessageEndAsync(cancellationToken);

                if (result.__isset.success)
                {
                    return(result.Success);
                }
                throw new TApplicationException(TApplicationException.ExceptionType.MissingResult, "GetNotifications failed: unknown result");
            }
Exemplo n.º 3
0
        public async Task GetNotifications(GetNotificationsArgs args)
        {
            if ((args.ChatUserID + "") != Context.UserIdentifier)
            {
                throw new ArgumentException(nameof(args.ChatUserID));
            }

            var chatUser = await ChatContext.Users
                           .FirstOrDefaultAsync(u => u.Id == args.ChatUserID);

            if (chatUser == null)
            {
                throw new ArgumentException(nameof(args.ChatUserID));
            }

            await Clients.Caller.SendAsync(
                "ReceiveNotifications",
                await ChatContext.Notification
                .Where(n => n.ChatUserID == chatUser.Id)
                .Select(n => new ReceiveNotificationArgs(n))
                .ToListAsync()
                );
        }