Beispiel #1
0
 public Client(string sessionId,Guid userId, IClientProxy clientProxy, Language language)
 {
     this._SessionId = sessionId;
     this._UserId = userId;
     this._ClientProxy = clientProxy;
     this._Language = language;
     this._MessageRelayEngine = new RelayEngine<Message>(this.SendMessage, this.HandlEngineException);
 }
        private void AddClientToRegisteredClients(IClientProxy client)
        {
            lock (monitor)
            {
                // The 'dead' code on the next line is the correct implementation
                //clients = new List<IClientProxy>(clients) { client };

                clients.Add(client);
            }
        }
        private void RemoveClientFromRegisteredClients(IClientProxy client)
        {
            lock (monitor)
            {
                var clientList = new List<IClientProxy>(clients);
                clientList.Remove(client);
                clients = clientList;

                // using the code below :
                // clients.Remove(client);
                // instead of the implementation below will result in a bug
            }
        }
 public Client AddClient(string oldSessionId, string sessionId, Guid userId, IClientProxy clientProxy, Language language)
 {
     Client client;
     if (!string.IsNullOrEmpty(oldSessionId) && this._Clients.TryGetValue(oldSessionId, out client))
     {
         client.Replace(sessionId, clientProxy);
         this._Clients.Remove(oldSessionId);
     }
     else
     {
         client = new Client(sessionId, userId, clientProxy, language);
     }
     this._Clients.Add(client.SessionId, client);
     return client;
 }
Beispiel #5
0
 public virtual void Invoke(IClientProxy hubClient) => hubClient.Invoke(MethodName); // It makes sense to implement this as an extension method for IClientProxy
 public static T Build(IClientProxy proxy)
 {
     return(_builder.Value(proxy));
 }
Beispiel #7
0
 public MathService(IClientProxy proxy)
 {
     _proxy = proxy;
 }
Beispiel #8
0
 public static async Task notifyOnlineUser(List <UserActivity> activity)
 {
     var          context = GlobalHost.ConnectionManager.GetHubContext <chatHub>();
     IClientProxy proxy   = context.Clients.All;
     await proxy.Invoke("notifyOnlineUser", activity);
 }
Beispiel #9
0
 public StockTickerCallback(IClientProxy proxy)
 {
     _proxy = proxy;
 }
 public static T AsStrongHub <T>(this IClientProxy source)
 {
     return((T)Generator.CreateInterfaceProxyWithoutTarget(typeof(T), new StrongClientProxy(source)));
 }
 /// <summary>
 /// 通用消息发送
 /// </summary>
 /// <param name="message">SenparcWebSocket 标准化信息</param>
 /// <returns></returns>
 public virtual async Task SendAsync(string message, IClientProxy clientProxy, CancellationToken cancellationToken)
 {
     await clientProxy.SendAsync(ClientFunctionName, message);
 }
 /// <summary>
 /// Invokes a method on the connection(s) represented by the <see cref="IClientProxy"/> instance.
 /// Does not wait for a response from the receiver.
 /// </summary>
 /// <param name="clientProxy">The <see cref="IClientProxy"/></param>
 /// <param name="method">name of the method to invoke</param>
 /// <returns>A task that represents when the data has been sent to the client.</returns>
 public static Task SendAsync(this IClientProxy clientProxy, string method)
 {
     return(clientProxy.SendCoreAsync(method, Array.Empty <object>()));
 }
 /// <summary>
 /// Invokes a method on the connection(s) represented by the <see cref="IClientProxy"/> instance.
 /// Does not wait for a response from the receiver.
 /// </summary>
 /// <param name="clientProxy">The <see cref="IClientProxy"/></param>
 /// <param name="method">name of the method to invoke</param>
 /// <param name="arg1">The first argument</param>
 /// <returns>A task that represents when the data has been sent to the client.</returns>
 public static Task SendAsync(this IClientProxy clientProxy, string method, object arg1)
 {
     return(clientProxy.SendCoreAsync(method, new[] { arg1 }));
 }
Beispiel #14
0
 public ChangesConnection(string id, IClientProxy clientProxy, string ip)
 {
     Client = clientProxy;
     Id     = id;
     Ip     = ip;
 }
Beispiel #15
0
 public GrpcHostedService(IClientProxy <IService> client, IService service) //DI client here.
 {
     _client  = client;
     _service = service;
 }
 public static Task SendAsync(this IClientProxy clientProxy, string method, object?arg1, object?arg2, object?arg3, object?arg4, CancellationToken cancellationToken = default)
 {
     return(clientProxy.SendCoreAsync(method, new[] { arg1, arg2, arg3, arg4 }, cancellationToken));
 }
 public static Task SendAsync(this IClientProxy clientProxy, string method, CancellationToken cancellationToken = default)
 {
     return(clientProxy.SendCoreAsync(method, Array.Empty <object>(), cancellationToken));
 }
        public static IRequestProgressObservable <IEnumerable <TItem>, TResponse> RequestProgress <TResponse, TItem>(this IClientProxy requestRouter, IPartialItemsRequest <TResponse, TItem> @params, Func <IEnumerable <TItem>, TResponse> factory, CancellationToken cancellationToken = default)
            where TResponse : IEnumerable <TItem>
        {
            var resultToken = new ProgressToken(Guid.NewGuid().ToString());

            @params.PartialResultToken = resultToken;

            return(requestRouter.ProgressManager.MonitorUntil(@params, factory, cancellationToken));
        }
Beispiel #19
0
 public void Transfer(IClientProxy clientProxy, string connectionId)
 {
     Client       = clientProxy ?? throw new ArgumentNullException(nameof(clientProxy));
     ConnectionId = connectionId ?? throw new ArgumentNullException(nameof(connectionId));
     Connected    = true;
 }
 /// <summary>
 /// Invokes a method on the connection(s) represented by the <see cref="IClientProxy"/> instance.
 /// Does not wait for a response from the receiver.
 /// </summary>
 /// <param name="clientProxy">The <see cref="IClientProxy"/></param>
 /// <param name="method">name of the method to invoke</param>
 /// <param name="arg1">The first argument</param>
 /// <param name="arg2">The second argument</param>
 /// <param name="arg3">The third argument</param>
 /// <param name="arg4">The fourth argument</param>
 /// <param name="arg5">The fifth argument</param>
 /// <returns>A task that represents when the data has been sent to the client.</returns>
 public static Task SendAsync(this IClientProxy clientProxy, string method, object arg1, object arg2, object arg3, object arg4, object arg5)
 {
     return(clientProxy.SendCoreAsync(method, new[] { arg1, arg2, arg3, arg4, arg5 }));
 }
 public static ClientProxyGroup And(this IClientProxy proxy1, IClientProxy proxy2)
 {
     return(new ClientProxyGroup(proxy1, proxy2));
 }
 public override void Arrange()
 {
     client    = MockRepository.GenerateMock <IClientProxy>();
     sleepTime = new IntGenerator(0, 10).GetRandomValue();
 }
 public StrongClientProxy(IClientProxy source)
 {
     Source = source;
 }
Beispiel #24
0
 private async Task SendUserListUpdate(IClientProxy to, Room room, bool callTo)
 {
     await to.SendAsync(callTo? "callToUserList" : "updateUserList", room.Name, room.Users);
 }
Beispiel #25
0
 private async Task Notify(IClientProxy target, string message) => await target.SendAsync("Message", message);
 public static Task SendNoticeAsync <T>(this IClientProxy clientProxy, T data)
     where T : class
 {
     return(clientProxy.SendAsync(typeof(T).Name, data));
 }
Beispiel #27
0
 public static async Task notifyUserStatus(string connectionID, string status)
 {
     var          context = GlobalHost.ConnectionManager.GetHubContext <chatHub>();
     IClientProxy proxy   = context.Clients.All;
     await proxy.Invoke("notifyUserStatus", connectionID, status);
 }
 public override void Arrange()
 {
     client = MockRepository.GenerateMock<IClientProxy>();
     sleepTime = new IntGenerator(0, 10).GetRandomValue();
 }
 public StrongClientProxy(IClientProxy source)
 {
     Source = source;
 }
Beispiel #30
0
 public DefaultRpcInvokerReflection(IClientProxy clientProxy)
 {
     this._proxy       = clientProxy;
     this._proxyCreate = clientProxy.GetType().GetMethod("Create");
 }
Beispiel #31
0
        public void DynamicInvoke(string method)
        {
            IClientProxy proxy = Caller;

            proxy.Invoke(method);
        }
Beispiel #32
0
 private static Task NotifyClientError(IClientProxy client, string error) => client.SendAsync("JS.Error", error);
Beispiel #33
0
 public void StartHandling(HubCallerContext context, IClientProxy caller)
 => _ = HandleAsync(context, caller);
Beispiel #34
0
 public virtual void Add(string connectionId, IClientProxy handler)
 {
     clients.TryAdd(connectionId, handler);
 }
 public Spec ClientIsRemovedFromCollection(IClientProxy input, Null output)
 {
     return new Spec(
         () => Ensure.False(GetBroadcastersClients().Contains(input)));
 }
        private async Task HandleAsync(HubCallerContext context, IClientProxy caller)
        {
            string connectionDetails;

            try
            {
                connectionDetails = $"{context.ConnectionId}, {context.UserIdentifier}, {context.User.Identity?.Name}";
            }
            catch (Exception exception)
            {
                connectionDetails = "Failed to get details";
                _logger.LogError(exception, "Failed to get connection details.");
            }

            try
            {
                using var localCts    = new CancellationTokenSource();
                using var combinedCts = CancellationTokenSource.CreateLinkedTokenSource(
                          _cts.Token, localCts.Token);

                var notificator = new Notificator();
                var connection  = new SignalRMessageSender(caller)
                                  .WithNotificator(notificator)
                                  .WithJson(_jsonConnectionFactory)
                                  .WithReceiveAcknowledgement();

                var task = _connectionHandler
                           .HandleAsync(connection, combinedCts.Token)
                           .HandleCancellationAsync(exception =>
                {
                    _logger.LogDebug(exception, $"Cancellation request received for client: {connectionDetails}");
                })
                           .HandleExceptionAsync <Exception>(exception =>
                {
                    _logger.LogError(exception, $"Error happened while handling SignalR connection: {connectionDetails}");
                });

                var resource = new SignalRConnectionResource(
                    notificator,
                    async() =>
                {
                    localCts.Cancel();
                    await task.ConfigureAwait(false);
                });

                _notificators.TryAdd(context.ConnectionId, resource);

                _connectionProcessors.Add(task);
                _connectionProcessors.RemoveAll(t => t.IsCompleted);

                await task.ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, $"Error happened when creating SignalR connection: {connectionDetails}");
            }
            finally
            {
                _notificators.TryRemove(context.ConnectionId, out _);
            }
        }
Beispiel #37
0
 public void Replace(string sessionId, IClientProxy clientProxy)
 {
     this._SessionId = sessionId;
     this._ClientProxy = clientProxy;
     this._MessageRelayEngine.Resume();
 }
Beispiel #38
0
 public CircuitClientProxy(IClientProxy clientProxy, string connectionId)
 {
     Transfer(clientProxy, connectionId);
 }