Пример #1
0
        /// <summary>
        /// Opens a WebSocket connection and waits for the SocketOpened event to be called.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="milliseconds">The timeout, in milliseconds.</param>
        /// <returns>An awaitable task.</returns>
        public static async Task <bool> OpenAsync(this EtpClient client, int?milliseconds = null)
        {
            var task = new Task <bool>(() => client.IsOpen);

            client.SocketOpened += (s, e) => task.Start();
            client.Open();

            return(await task.WaitAsync(milliseconds));
        }
Пример #2
0
        private void Connect2Server_Button_Click(object sender, RoutedEventArgs e)
        {
            Client = new EtpClient(ServerUri_TextBox.Text, AppName_TextBox.Text, Version_TextBox.Text);
            Client.Register <IDiscoveryCustomer, DiscoveryCustomerHandler>();
            Client.Output = LogClientOutput;
            Client.Open();

            //System.Windows.MessageBox.Show(Proto_ListBox.SelectedIndex.ToString());
            //foreach (var item in Proto_ListBox.SelectedItems)
            //{
            //    System.Windows.MessageBox.Show(item.ToString());
            //}
        }
Пример #3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Client = new EtpClient(ServerUrl, "MyPDS", "1.0.0.0");
            Client.Register <IDiscoveryCustomer, DiscoveryCustomerHandler>();

            RegisterEventHandlers(Client.Handler <IDiscoveryCustomer>(),
                                  x => x.OnGetResourcesResponse += OnGetResourcesResponse);

            Client.Output = LogClientOutput;
            Client.Open();


            //System.Windows.MessageBox.Show(Client.IsOpen.ToString());
        }
Пример #4
0
        private async Task <bool> CanConnect(Connection connection, IDictionary <string, string> headers)
        {
            try
            {
                var applicationName    = GetType().Assembly.FullName;
                var applicationVersion = GetType().GetAssemblyVersion();

                connection.UpdateEtpSettings(headers);
                connection.SetServerCertificateValidation();

                using (var client = new EtpClient(connection.Uri, applicationName, applicationVersion, headers))
                {
                    client.Register <IChannelStreamingConsumer, ChannelStreamingConsumerHandler>();
                    client.Register <IDiscoveryCustomer, DiscoveryCustomerHandler>();
                    client.Register <IStoreCustomer, StoreCustomerHandler>();

                    var count = 0;
                    client.Open();

                    while (string.IsNullOrWhiteSpace(client.SessionId) && count < 10)
                    {
                        await Task.Delay(1000);

                        count++;
                    }

                    var result = !string.IsNullOrWhiteSpace(client.SessionId);
                    _log.DebugFormat("ETP connection test {0}", result ? "passed" : "failed");

                    return(result);
                }
            }
            catch (Exception ex)
            {
                _log.Error("ETP connection test failed", ex);
                return(false);
            }
        }