示例#1
0
        public static List <ServerEventUser> GetChannelSubscribers(this ServerEventsClient client)
        {
            var response = client.ServiceClient.Get(new GetEventSubscribers {
                Channels = client.Channels
            });

            return(response.Select(x => x.ToServerEventUser()).ToList());
        }
示例#2
0
        public static Task <List <ServerEventUser> > GetChannelSubscribersAsync(this ServerEventsClient client)
        {
            var responseTask = client.ServiceClient.GetAsync(new GetEventSubscribers {
                Channels = client.Channels
            });

            return(responseTask.ContinueWith(task => task.Result.ConvertAll(x => x.ToServerEventUser())));
        }
示例#3
0
 public static ServerEventsClient RegisterHandlers(this ServerEventsClient client, Dictionary <string, ServerEventCallback> handlers)
 {
     foreach (var entry in handlers)
     {
         client.Handlers[entry.Key] = entry.Value;
     }
     return(client);
 }
示例#4
0
 public static Task UnsubscribeFromChannelsAsync(this ServerEventsClient client, params string[] channels)
 {
     return(client.ServiceClient.PostAsync(new UpdateEventSubscriber {
         Id = client.ConnectionInfo.Id, UnsubscribeChannels = channels.ToArray()
     })
            .Then(x => {
         client.Update(unsubscribe: channels);
         return null;
     }));
 }
示例#5
0
        public static void UpdateSubscriber(this ServerEventsClient client, UpdateEventSubscriber request)
        {
            if (request.Id == null)
            {
                request.Id = client.ConnectionInfo.Id;
            }
            client.ServiceClient.Post(request);

            client.Update(subscribe: request.SubscribeChannels, unsubscribe: request.UnsubscribeChannels);
        }
示例#6
0
        private void CreateReceiverHandler <T>(ServerEventsClient client, ServerEventMessage msg)
        {
            var receiver = Resolver.TryResolve <T>() as IReceiver;

            if (receiver == null)
            {
                throw new ArgumentNullException("receiver", "Resolver returned null receiver");
            }

            var injectRecevier = receiver as ServerEventReceiver;

            if (injectRecevier != null)
            {
                injectRecevier.Client  = client;
                injectRecevier.Request = msg;
            }

            var target = msg.Target.Replace("-", ""); //css bg-image

            ReceiverExecContext receiverCtx;

            ReceiverExec <T> .RequestTypeExecMap.TryGetValue(target, out receiverCtx);

            if (StrictMode && receiverCtx != null && !receiverCtx.Method.EqualsIgnoreCase(target))
            {
                receiverCtx = null;
            }

            if (receiverCtx == null)
            {
                ReceiverExec <T> .MethodNameExecMap.TryGetValue(target, out receiverCtx);
            }

            if (receiverCtx == null)
            {
                receiver.NoSuchMethod(msg.Target, msg);
                return;
            }

            object requestDto;

            try
            {
                requestDto = string.IsNullOrEmpty(msg.Json)
                    ? receiverCtx.RequestType.CreateInstance()
                    : JsonSerializer.DeserializeFromString(msg.Json, receiverCtx.RequestType);
            }
            catch (Exception ex)
            {
                throw new SerializationException($"Could not deserialize into '{typeof(T).Name}' from '{msg.Json}'", ex);
            }


            receiverCtx.Exec(receiver, requestDto);
        }
示例#7
0
 public static Task UpdateSubscriberAsync(this ServerEventsClient client, UpdateEventSubscriber request)
 {
     if (request.Id == null)
     {
         request.Id = client.ConnectionInfo.Id;
     }
     return(client.ServiceClient.PostAsync(request)
            .Then(x => {
         client.Update(subscribe: request.SubscribeChannels, unsubscribe: request.UnsubscribeChannels);
         return null;
     }));
 }
示例#8
0
 public static Task <AuthenticateResponse> AuthenticateAsync(this ServerEventsClient client, Authenticate request)
 {
     return(client.ServiceClient.PostAsync(request));
 }
示例#9
0
 public static AuthenticateResponse Authenticate(this ServerEventsClient client, Authenticate request)
 {
     return(client.ServiceClient.Post(request));
 }