Example #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());
        }
        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())));
        }
 public static ServerEventsClient RegisterHandlers(this ServerEventsClient client, Dictionary <string, ServerEventCallback> handlers)
 {
     foreach (var entry in handlers)
     {
         client.Handlers[entry.Key] = entry.Value;
     }
     return(client);
 }
Example #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;
     }));
 }
Example #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);
        }
Example #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);
        }
Example #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;
     }));
 }
Example #8
0
 public static Task <AuthenticateResponse> AuthenticateAsync(this ServerEventsClient client, Authenticate request)
 {
     return(client.ServiceClient.PostAsync(request));
 }
Example #9
0
 public static AuthenticateResponse Authenticate(this ServerEventsClient client, Authenticate request)
 {
     return(client.ServiceClient.Post(request));
 }