Esempio n. 1
0
        private SlackSocketClient CreateClient(string authToken, IWebProxy proxySettings = null)
        {
            SlackSocketClient client;

            LoginResponse loginResponse = null;

            using (var syncClient = new InSync($"{nameof(SlackClient.Connect)} - Connected callback"))
                using (var syncClientSocket = new InSync($"{nameof(SlackClient.Connect)} - SocketConnected callback"))
                    using (var syncClientSocketHello = new InSync($"{nameof(SlackClient.Connect)} - SocketConnected hello callback"))
                    {
                        client          = new SlackSocketClient(authToken, proxySettings);
                        client.OnHello += () => syncClientSocketHello.Proceed();
                        client.Connect(x =>
                        {
                            loginResponse = x;

                            Console.WriteLine($"Connected {x.ok}");
                            syncClient.Proceed();
                            if (!x.ok)
                            {
                                // If connect fails, socket connect callback is not called
                                syncClientSocket.Proceed();
                                syncClientSocketHello.Proceed();
                            }
                        }, () =>
                        {
                            Console.WriteLine("Socket Connected");
                            syncClientSocket.Proceed();
                        });
                    }

            loginResponse.AssertOk();

            return(client);
        }
        private SlackSocketClient CreateClient(string authToken, IWebProxy proxySettings = null, bool maintainPresenceChanges = false, Action <SlackSocketClient, PresenceChange> presenceChanged = null)
        {
            SlackSocketClient client;

            LoginResponse loginResponse = null;

            using (var syncClient = new InSync($"{nameof(SlackClient.Connect)} - Connected callback"))
                using (var syncClientSocket = new InSync($"{nameof(SlackClient.Connect)} - SocketConnected callback"))
                    using (var syncClientSocketHello = new InSync($"{nameof(SlackClient.Connect)} - SocketConnected hello callback"))
                    {
                        client = new SlackSocketClient(authToken, proxySettings, maintainPresenceChanges);

                        void OnPresenceChanged(PresenceChange x)
                        {
                            presenceChanged?.Invoke(client, x);
                        }

                        client.OnPresenceChanged += OnPresenceChanged;
                        client.OnHello           += () => syncClientSocketHello.Proceed();
                        client.Connect(x =>
                        {
                            loginResponse = x;

                            Console.WriteLine($"Connected {x.ok}");
                            syncClient.Proceed();
                            if (!x.ok)
                            {
                                // If connect fails, socket connect callback is not called
                                syncClientSocket.Proceed();
                                syncClientSocketHello.Proceed();
                            }
                        }, () =>
                        {
                            Console.WriteLine("Socket Connected");
                            syncClientSocket.Proceed();
                        });
                    }

            loginResponse.AssertOk();

            return(client);
        }