Esempio n. 1
0
        private void AddListener(string functionName, Action <string> callback, string[][] param)
        {
            string functionFullName = GetFunctionFullName(functionName);

            ReconnectLoop().ConfigureAwait(false).GetAwaiter().GetResult();
            lock (listeners)
            {
                if (!listeners.TryGetValue(functionName, out HubListener listener))
                {
                    listeners[functionFullName] = listener = new HubListener {
                        FunctionName = functionName, FunctionFullName = functionFullName, Param = param
                    };
                }
                if (!listener.Callbacks.Contains(callback))
                {
                    listener.Callbacks.Add(callback);
                }
            }
        }
Esempio n. 2
0
        private async Task AddListener(string functionName, Func <string, Task> callback, object[][] param)
        {
            string functionFullName = GetFunctionFullName(functionName);

            // ensure connected before adding the listener
            await EnsureConnected(() =>
            {
                lock (listeners)
                {
                    if (!listeners.TryGetValue(functionName, out HubListener listener))
                    {
                        listeners[functionFullName] = listener = new HubListener {
                            FunctionName = functionName, FunctionFullName = functionFullName, Param = param
                        };
                    }
                    if (!listener.Callbacks.Contains(callback))
                    {
                        listener.Callbacks.Add(callback);
                    }
                }
            });
        }
Esempio n. 3
0
        private void AddListener(string functionName, Action <string> callback, object[][] param)
        {
            string functionFullName = GetFunctionFullName(functionName);

            // ensure connected before adding the listener
            ReconnectLoop().ContinueWith((t) =>
            {
                lock (listeners)
                {
                    if (!listeners.TryGetValue(functionName, out HubListener listener))
                    {
                        listeners[functionFullName] = listener = new HubListener {
                            FunctionName = functionName, FunctionFullName = functionFullName, Param = param
                        };
                    }
                    if (!listener.Callbacks.Contains(callback))
                    {
                        listener.Callbacks.Add(callback);
                    }
                }
            }).Sync();
        }
Esempio n. 4
0
        private void AddListener(string functionName, Action <string> callback, object[][] param)
        {
            string functionFullName = GetFunctionFullName(functionName);

            // ensure connected before adding the listener
            ReconnectLoop().ContinueWith((t) =>
            {
                lock (listeners)
                {
                    if (!listeners.TryGetValue(functionName, out HubListener listener))
                    {
                        listeners[functionFullName] = listener = new HubListener {
                            FunctionName = functionName, FunctionFullName = functionFullName, Param = param
                        };
                    }
                    if (!listener.Callbacks.Contains(callback))
                    {
                        listener.Callbacks.Add(callback);
                    }
                    Console.WriteLine($"listeners.count={listeners.Count} ++++++++++++++++");
                }
            }).ConfigureAwait(false).GetAwaiter().GetResult();
        }