コード例 #1
0
        virtual public Task SendAsync(ArraySegment <byte> buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken cancellationToken)
        {
            var json = Encoding.UTF8.GetString(buffer.Array, 0, buffer.Count);

            LastPacket = JToken.Parse(json);
            LastId     = LastPacket["id"]?.Value <int>();

            if (_isFirstSend)
            {
                _isFirstSend = false;
                if (IsChat)
                {
                    JoinedChat.Set();
                    if (_isAuthenticated)
                    {
                        InjectPacket("{'type':'reply','error':null,'id':<MSGID>,'data':{'authenticated':true,'roles':[]}}"
                                     .Replace("'", "\"")
                                     .Replace("<MSGID>", LastId.ToString())
                                     );
                    }
                    else
                    {
                        InjectPacket("{'type':'reply','error':null,'id':<MSGID>,'data':null}"
                                     .Replace("'", "\"")
                                     .Replace("<MSGID>", LastId.ToString())
                                     );
                    }
                }
                else
                {
                    JoinedConstallation.Set();
                    if (_isAuthenticated)
                    {
                        InjectPacket("{'type':'reply','error':null,'id':<MSGID>,'data':{'authenticated':true,'roles':['Owner','User']}}".Replace("'", "\"").Replace("<MSGID>", LastId.ToString()));
                    }
                    else
                    {
                        InjectPacket("{'id':<MSGID>,'type':'reply','result':null,'error':null}".Replace("'", "\"").Replace("<MSGID>", LastId.ToString()));
                    }
                }
            }

            return(Task.CompletedTask);
        }
コード例 #2
0
            public Dictionary <string, string> ToDictionary()
            {
                var options = new Dictionary <string, string>();

                if (UnreadOnly)
                {
                    options.Add("unreadOnly", "true");
                }
                if (Limit.HasValue)
                {
                    options.Add("limit", Limit.ToString());
                }
                if (LastId.HasValue)
                {
                    options.Add("lastId", LastId.ToString());
                }
                if (AllUsers)
                {
                    options.Add("allUsers", "true");
                }
                return(options);
            }
コード例 #3
0
            public Dictionary <string, string> ToDictionary()
            {
                var options = new Dictionary <string, string>();

                if (!string.IsNullOrEmpty(UserId))
                {
                    options.Add("userId", UserId);
                }
                if (LastId.HasValue)
                {
                    options.Add("lastId", LastId.ToString());
                }
                if (Limit.HasValue)
                {
                    options.Add("limit", Limit.ToString());
                }
                if (SortOrder == ListSortOrder.Ascending)
                {
                    options.Add("sortOrder", "asc");
                }
                return(options);
            }