Beispiel #1
0
 /// <summary>
 /// 关闭连接
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void mumCloseLink_Click(object sender, EventArgs e)
 {
     try
     {
         if (m_Client != null && m_Client.IsConnected())
         {
             m_Client.Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #2
0
        private void Connect()
        {
            if (client != null)
            {
                return;
            }

            clientLock.Wait();

            try
            {
                if (client == null)
                {
                    client = new AsyncClient(config.ClientPolicy, config.Hosts);

                    try
                    {
                        RegisterUDF();
                    }
                    catch (Exception)
                    {
                        client.Close();
                        client = null;
                        throw;
                    }
                }
            }
            finally
            {
                clientLock.Release();
            }
        }
Beispiel #3
0
 public void Dispose()
 {
     if (client != null)
     {
         client.Close();
         client = null;
     }
 }
Beispiel #4
0
 private void btnStop_Click(object sender, EventArgs e)
 {
     try
     {
         _Client.Close();
         _Client.Dispose();
         _Client = null;
     }
     catch { }
     SetControlEnabled(btnStart, true);
     SetControlEnabled(btnStop, false);
 }
Beispiel #5
0
        public void Close()
        {
            if (client != null)
            {
                client.Close();
                client = null;
            }

            if (asyncClient != null)
            {
                asyncClient.Close();
                asyncClient = null;
            }
        }
Beispiel #6
0
 /// <summary>釋放 TcpMaster 所使用的資源。 </summary>
 /// <param name="disposing">是否完全釋放</param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _OnDisposing = true;
         if (_Client != null)
         {
             try
             {
                 _Client.Close();
                 _Client.Dispose();
             }
             finally
             {
                 _Client = null;
             }
         }
         this.IsDisposed = true;
     }
 }
Beispiel #7
0
        public override void RunExample(Arguments args)
        {
            AsyncClientPolicy policy = new AsyncClientPolicy();

            policy.user               = args.user;
            policy.password           = args.password;
            policy.asyncMaxCommands   = args.commandMax;
            policy.failIfNotConnected = true;

            AsyncClient client = new AsyncClient(policy, args.host, args.port);

            try
            {
                args.SetServerSpecific(client);
                RunExample(client, args);
            }
            finally
            {
                client.Close();
            }
        }
Beispiel #8
0
 private void DisconnectButton_Click(object sender, EventArgs e)
 {
     try
     {
         if (client != null)
         {
             if (client.Client != null)
             {
                 if (client.Client.Connected)
                 {
                     connected = false;
                     client.Close();
                     ChatTextBox.Text += "Connection Closed.\n";
                 }
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #9
0
 private async Task Close(CancellationToken cancellationToken)
 {
     _client.Close();
 }
Beispiel #10
0
        static async Task Main(string[] args)
        {
            var host = Host();

            var client = new AsyncClient(host.Item1, host.Item2);

            var key1 = new Key("test", "myset1", "mykey1");
            var key2 = new Key("test", "myset2", "mykey2");
            var key3 = new Key("test", "myset3", "mykey3");

            var bin1 = new Bin("name", "John");
            var bin2 = new Bin("age", 25);
            var bin3 = new Bin("hello", "world");
            var bin4 = new Bin("first", "first");
            var bin5 = new Bin("first", "last");

            // Synchronous methods
            client.Put(null, key1, bin1, bin2);
            client.Add(null, key1, bin3);
            client.Prepend(null, key1, bin4);
            client.Append(null, key1, bin5);

            _ = client.Get(null, key1);
            _ = client.Exists(null, key1);
            _ = client.Get(null, new[] { key1, key2, key3 });
            _ = client.Exists(null, new[] { key1, key2, key3 });

            client.CreateIndex(null, "test", "myset1", indexName: "age", binName: "age", IndexType.NUMERIC).Wait();

            var statement = new Statement
            {
                Namespace = "test",
                SetName   = "myset1",
                BinNames  = new[] { "name", "age" },
                Filter    = Filter.Range("age", 20, 30)
            };

            var result = client.Query(new QueryPolicy(), statement);

            while (result.Next())
            {
                ;                   // Force the query to execute
            }
            client.Delete(null, key1);

            // Asynchronous methods
            await client.Put(null, CancellationToken.None, key1, bin1, bin2);

            await client.Add(null, CancellationToken.None, key1, bin3);

            await client.Prepend(null, CancellationToken.None, key1, bin4);

            await client.Append(null, CancellationToken.None, key1, bin5);

            _ = await client.Get(null, CancellationToken.None, key1);

            _ = await client.Exists(null, CancellationToken.None, key1);

            _ = await client.Get(null, CancellationToken.None, new[] { key1, key2, key3 });

            _ = await client.Exists(null, CancellationToken.None, new[] { key1, key2, key3 });

            await client.Delete(null, CancellationToken.None, key1);

            client.DropIndex(null, "test", "myset1", indexName: "age").Wait();

            client.Close();
        }