예제 #1
0
        static async Task DoIt()
        {
            AceQLConsole.WriteLine("Building connection with credential...");
            AceQLConnection connection = await ConnectionBuilderAsyncWithCredential().ConfigureAwait(false);;
            DocSamples      docSamples = new DocSamples(connection);

            await docSamples.DeleteCustomers().ConfigureAwait(false);;

            AceQLConsole.WriteLine("Insert customer...");
            await docSamples.InsertCustomer().ConfigureAwait(false);;

            AceQLConsole.WriteLine("display customer...");
            await docSamples.SelectCustomer().ConfigureAwait(false);;

            await docSamples.DeleteCustomers().ConfigureAwait(false);;
            await docSamples.DeleteOrderlogs().ConfigureAwait(false);;

            await docSamples.InsertCustomerAndOrderLogAsync(1, 1).ConfigureAwait(false);;

            await docSamples.DeleteOrderlogs().ConfigureAwait(false);;

            AceQLConsole.WriteLine("Insert BLOB...");
            await docSamples.InsertBlob(1, 1).ConfigureAwait(false);;

            AceQLConsole.WriteLine("Select BLOB...");
            await docSamples.SelectBlob(1, 1);

            await docSamples.DeleteOrderlogs().ConfigureAwait(false);;

            AceQLConsole.WriteLine("Insert BLOB with ProgressIndicator...");
            await docSamples.InsertBlobProgressIndicator(1, 1).ConfigureAwait(false);;

            AceQLConsole.WriteLine("Select BLOB...");
            await docSamples.SelectBlob(1, 1).ConfigureAwait(false);;
        }
예제 #2
0
        static async Task DoIt()
        {
            var netCoreVer = System.Environment.Version; // 3.0.0

            AceQLConsole.WriteLine(netCoreVer + "");

            string connectionString = ConnectionStringCurrent.Build();

            using (AceQLConnection connection = new AceQLConnection(connectionString))
            {
                connection.RequestRetry = true;
                connection.AddRequestHeader("aceqlHeader1", "myAceQLHeader1");
                connection.AddRequestHeader("aceqlHeader2", "myAceQLHeader2");

                await connection.OpenAsync();

                if (DO_LOOP)
                {
                    while (true)
                    {
                        await ExecuteExample(connection).ConfigureAwait(false);

                        Thread.Sleep(1000);
                    }
                }
                else
                {
                    await ExecuteExample(connection).ConfigureAwait(false);
                }


                await connection.CloseAsync();
            }
        }
        /// <summary>
        /// RemoteConnection Quick Start client example.
        /// Creates a Connection to a remote database and open it.
        /// </summary>
        /// <returns>The connection to the remote database</returns>
        /// <exception cref="AceQLException">If any Exception occurs.</exception>
        public static async Task <AceQLConnection> ConnectionBuilderAsync()
        {
            // Port number is the port number used to start the Web Server:
            string server   = "https://www.aceql.com:9443/aceql";
            string database = "sampledb";

            string connectionString = $"Server={server}; Database={database}";

            // (username, password) for authentication on server side.
            // No authentication will be done for our Quick Start:
            string username = "******";

            char[] password = { 'M', 'y', 'S', 'e', 'c', 'r', 'e', 't' };

            AceQLConnection connection = new AceQLConnection(connectionString)
            {
                Credential = new AceQLCredential(username, password)
            };

            // Opens the connection with the remote database.
            // On the server side, a JDBC connection is extracted from the connection
            // pool created by the server at startup. The connection will remain ours
            // during the session.
            await connection.OpenAsync();

            return(connection);
        }
        /// <summary>
        /// Does it.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <returns></returns>
        public static async Task DoIt(string[] args)
        {
            try
            {
                // Make sure connection is always closed in order to close and release
                // server connection into the pool
                using (AceQLConnection theConnection = await ConnectionBuilderAsync())
                {
                    MySqlStoredProcedureTest myRemoteConnection = new MySqlStoredProcedureTest(
                        theConnection);
                    AceQLConsole.WriteLine("Connection created....");

                    await myRemoteConnection.CallStoredProcedure().ConfigureAwait(false);

                    await theConnection.CloseAsync();

                    AceQLConsole.WriteLine("The end...");
                }

                AceQLConsole.WriteLine();
                AceQLConsole.WriteLine("Press enter to close....");
                Console.ReadLine();
            }
            catch (Exception exception)
            {
                AceQLConsole.WriteLine(exception.ToString());
                AceQLConsole.WriteLine(exception.StackTrace);
                AceQLConsole.WriteLine("Press enter to close...");
                Console.ReadLine();
            }
        }
        private async void buttonConnect_Click(object sender, EventArgs e)
        {
            if (connection != null)
            {
                PopMesssage.Show("You are already connected!", ACEQL_TEST);
                return;
            }

            SetConnectionStatusColor(CONNECTION_COLOR_YELLOW);

            Cursor.Current = Cursors.WaitCursor;
            try
            {
                //AceQLConnection.SetTraceOn(true);
                ConnectionBuilder connectionBuilder = new ConnectionBuilder(server, database, "username", "password".ToArray());
                connection = connectionBuilder.GetConnection();
                await connection.OpenAsync();
            }
            catch (Exception exeption)
            {
                Cursor.Current = Cursors.Default;
                PopMesssage.Show("Could not connect: \n" + exeption.ToString(), ACEQL_TEST);
                return;
            }
            SetConnectionStatusColor(CONNECTION_COLOR_GREEN);
            Cursor.Current = Cursors.Default;
        }
        /// <summary>
        /// RemoteConnection Quick Start client example.
        /// Creates a Connection to a remote database using a proxy.
        /// </summary>
        /// <returns>The connection to the remote database</returns>
        /// <exception cref="AceQLException">If any Exception occurs.</exception>
        public static async Task <AceQLConnection> RemoteConnectionBuilderUsingProxyAsync()
        {
            // Port number is the port number used to start the Web Server:
            string server   = "http://www.aceql.com:9090/aceql";
            string database = "sampledb";

            // (username, password) for authentication on server side.
            // No authentication will be done for our Quick Start:
            string username = "******";
            string password = "******";

            // Proxy will be detected, pass the auth info for proxy that require authentication:
            string proxyUri      = "http://localhost:8080";
            string proxyUsername = "******";
            string proxyPassword = null;

            if (await ExistsAsync("AceQLPclFolder", "password.txt"))
            {
                IFile file = await GetFileAsync("AceQLPclFolder", "password.txt");

                proxyPassword = await file.ReadAllTextAsync();
            }

            string connectionString = $"Server={server}; Database={database}; "
                                      + $"Username={username}; Password={password};"
                                      + $"ProxyUri={proxyUri};"
                                      + $"ProxyUsername={proxyUsername}; ProxyPassword={proxyPassword}";

            AceQLConnection connection = new AceQLConnection(connectionString);

            return(connection);
        }
        /// RemoteConnection Quick Start client example.
        /// Creates a Connection to a remote database using a proxy.
        /// </summary>
        /// <returns>The connection to the remote database</returns>
        /// <exception cref="AceQLException">If any Exception occurs.</exception>
        public static AceQLConnection RemoteConnectionBuilderUsingProxyAsync()
        {
            // Port number is the port number used to start the Web Server:
            string server   = "http://www.aceql.com:9090/aceql";
            string database = "sampledb";

            // (username, password) for authentication on server side.
            // No authentication will be done for our Quick Start:
            string username = "******";
            string password = "******";

            // WebProxy will be detected, pass the auth info for proxy that require authentication:
            string proxyUri      = "http://localhost:8080";
            string proxyUsername = "******";
            string proxyPassword = null;

            String   path     = AceQLConnection.GetAceQLLocalFolder() + "\\password.txt";
            FileInfo fileInfo = new FileInfo(path);

            if (fileInfo.Exists)
            {
                proxyPassword = File.ReadAllText(path);
            }

            string connectionString = $"Server={server}; Database={database}; "
                                      + $"Username={username}; Password={password};"
                                      + $"ProxyUri={proxyUri};"
                                      + $"ProxyUsername={proxyUsername}; ProxyPassword={proxyPassword}";

            AceQLConnection connection = new AceQLConnection(connectionString);

            return(connection);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="aceQLConnection">the Connection to the remote database.</param>
 /// <exception cref="ArgumentNullException">aceQLConnection is null!</exception>
 internal RemoteDatabaseMetaData(AceQLConnection aceQLConnection)
 {
     if (aceQLConnection == null)
     {
         throw new ArgumentNullException("aceQLConnection is null!");
     }
     this.aceQLHttpApi = aceQLConnection.GetAceQLHttpApi();
 }
예제 #9
0
        static async Task DoIt(string[] args)
        {
            AceQLConsole.WriteLine("Building connection with credential...");
            AceQLConnection connection = await ConnectionBuilderAsyncWithCredential().ConfigureAwait(false);

            WebDocSample webDocSamples = new WebDocSample(connection);

            await webDocSamples.DeleteCustomers().ConfigureAwait(false);

            AceQLConsole.WriteLine("Insert customer...");
            await webDocSamples.InsertCustomer().ConfigureAwait(false);

            AceQLConsole.WriteLine("display customer 1...");
            await webDocSamples.SelectCustomerOne().ConfigureAwait(false);

            AceQLConsole.WriteLine();

            AceQLConsole.WriteLine("update customer...");
            await webDocSamples.UpdateCustomer().ConfigureAwait(false);

            AceQLConsole.WriteLine();

            AceQLConsole.WriteLine("display customer...");
            await webDocSamples.SelectCustomer().ConfigureAwait(false);

            AceQLConsole.WriteLine();

            await webDocSamples.DeleteCustomers().ConfigureAwait(false);

            await webDocSamples.DeleteOrderlogs().ConfigureAwait(false);

            await webDocSamples.InsertCustomerAndOrderLogAsync(1, 1).ConfigureAwait(false);

            AceQLConsole.WriteLine();

            await webDocSamples.DeleteOrderlogs().ConfigureAwait(false);

            AceQLConsole.WriteLine();
            AceQLConsole.WriteLine("Insert BLOB...");
            await webDocSamples.InsertBlob(1, 1).ConfigureAwait(false);

            AceQLConsole.WriteLine("Select BLOB...");
            await webDocSamples.SelectBlob(1, 1).ConfigureAwait(false);

            await webDocSamples.DeleteOrderlogs();

            AceQLConsole.WriteLine();
            AceQLConsole.WriteLine("Insert BLOB with ProgressIndicator...");
            await webDocSamples.InsertBlobProgressIndicator(1, 1).ConfigureAwait(false);

            AceQLConsole.WriteLine();
            AceQLConsole.WriteLine("Select BLOB...");
            await webDocSamples.SelectBlob(1, 1).ConfigureAwait(false);

            await connection.CloseAsync();

            AceQLConsole.WriteLine("Connection closed.");
        }
예제 #10
0
        private static void UseConnection2()
        {
            string connectionString = null;

            using (AceQLConnection connection = new AceQLConnection(connectionString))
            {
                // SQL stuff...
            }
        }
예제 #11
0
        internal void AddAuthenticatedProyCredentialCache()
        {
            MyProxyInfo myProxyInfo = new MyProxyInfo(MyProxyInfo.NEOTUNNEL_SAVE_TXT);
            String      username    = myProxyInfo.ProxyUsername;
            String      password    = myProxyInfo.ProxyPassword;

            CredentialCache.DefaultNetworkCredentials.UserName = username;
            CredentialCache.DefaultNetworkCredentials.Password = password;

            AceQLConnection.SetDefaultWebProxy(WebRequest.GetSystemWebProxy());
            connectionString += $"UseCredentialCache=True;";
        }
예제 #12
0
        static async Task DoIt()
        {
            string connectionString = ConnectionStringCurrent.Build();

            // Make sure connection is always closed to close and release server connection into the pool
            using (AceQLConnection connection = new AceQLConnection(connectionString))
            {
                await ExecuteExample(connection).ConfigureAwait(false);

                await connection.CloseAsync();
            }
        }
예제 #13
0
        static async Task DoIt(string[] args)
        {
            string username = "******";
            string password = "******";

            //customer_id integer NOT NULL,
            //customer_title character(4),
            //fname character varying(32),
            //lname character varying(32) NOT NULL,
            //addressline character varying(64),
            //town character varying(32),
            //zipscode character(10) NOT NULL,
            //phone character varying(32),

            string connectionString = null;
            bool   useProxy         = false;

            if (useProxy)
            {
                string proxyUsername = "******";
                string proxyPassword = "";
                connectionString = $"Server={server}; Database={database}; ProxyUsername={proxyUsername}; ProxyPassword= {proxyPassword}";
            }
            else
            {
                connectionString = $"Server={server}; Database={database}";
            }

            AceQLCredential credential = new AceQLCredential(username, password.ToCharArray());

            // Make sure connection is always closed to close and release server connection into the pool
            using (AceQLConnection connection = new AceQLConnection(connectionString))
            {
                //connection.SetTraceOn(true);

                connection.Credential = credential;
                await ExecuteExample(connection).ConfigureAwait(false);

                await connection.CloseAsync();

                AceQLConnection connection2 = new AceQLConnection(connectionString)
                {
                    Credential = credential
                };

                await connection2.OpenAsync();

                AceQLConsole.WriteLine("connection2.GetServerVersion(): " + await connection2.GetServerVersionAsync());

                await connection2.LogoutAsync().ConfigureAwait(false);
            }
        }
예제 #14
0
        /// <summary>
        /// Get connection as an asynchronous operation.
        /// </summary>
        /// <returns>Task&lt;AceQLConnection&gt;.</returns>
        public AceQLConnection GetConnection()
        {
            // Port number is the port number used to start the Web Server:

            string connectionString = $"Server={server}; Database={database};";

            AceQLConnection connection = new AceQLConnection(connectionString)
            {
                Credential = new AceQLCredential(username, password)
            };

            return(connection);
        }
        /// <summary>
        /// RemoteConnection Quick Start client example.
        /// Creates a Connection to a remote database and open it.
        /// </summary>
        /// <returns>The connection to the remote database</returns>
        /// <exception cref="AceQLException">If any Exception occurs.</exception>
        public static async Task <AceQLConnection> ConnectionBuilderAsync()
        {
            string connectionString = ConnectionStringCurrent.Build();

            AceQLConnection theConnection = new AceQLConnection(connectionString);

            // Opens the connection with the remote database.
            // On the server side, a JDBC connection is extracted from the connection
            // pool created by the server at startup. The connection will remain ours
            // during the session.
            await theConnection.OpenAsync();

            return(theConnection);
        }
예제 #16
0
        static async Task DoIt()
        {
            var netCoreVer = System.Environment.Version; // 3.0.0

            AceQLConsole.WriteLine(netCoreVer + "");

            string connectionString = ConnectionStringCurrent.Build();

            using (AceQLConnection connection = new AceQLConnection(connectionString))
            {
                await ExecuteExample(connection).ConfigureAwait(false);

                //NOT Neccessary: await connection.CloseAsync();
            }
        }
예제 #17
0
        public static async Task UseConnection()
        {
            string          connectionString = null;
            AceQLConnection connection       = null;

            try
            {
                connection = new AceQLConnection(connectionString);
                await connection.OpenAsync();

                // SQL stuff...
            }
            finally
            {
                await connection.CloseAsync();
            }
        }
        static async Task DoIt()
        {
            string serverUrlLocalhost = "http://localhost:9090/aceql";
            string server             = serverUrlLocalhost;
            string database           = "sampledb";
            string username           = "******";
            string sessionId          = "4pdh8p2t14nd6j7dxt1owyjxef";

            string connectionString = $"Server={server}; Database={database}";

            Boolean doItWithCredential = true;

            if (!doItWithCredential)
            {
                connectionString += $"; Username={username}; SessionId={sessionId}";
                AceQLConsole.WriteLine("Using connectionString with SessionId: " + connectionString);

                // Make sure connection is always closed to close and release server connection into the pool
                using (AceQLConnection connection = new AceQLConnection(connectionString))
                {
                    await connection.OpenAsync();

                    await AceQLTest.ExecuteExample(connection).ConfigureAwait(false);

                    await connection.CloseAsync();
                }
            }
            else
            {
                AceQLConsole.WriteLine("Using AceQLCredential with SessionId: " + sessionId);
                AceQLCredential credential = new AceQLCredential(username, sessionId);

                // Make sure connection is always closed to close and release server connection into the pool
                using (AceQLConnection connection = new AceQLConnection(connectionString))
                {
                    connection.Credential = credential;
                    await connection.OpenAsync();

                    await AceQLTest.ExecuteExample(connection).ConfigureAwait(false);

                    await connection.CloseAsync();
                }
            }
        }
예제 #19
0
        /// <summary>
        /// RemoteConnection Quick Start client example.
        /// Creates a Connection to a remote database and open it.
        /// </summary>
        /// <returns>The connection to the remote database</returns>
        /// <exception cref="AceQLException">If any Exception occurs.</exception>
        public static async Task <AceQLConnection> ConnectionBuilderAsync()
        {
            // Port number is the port number used to start the Web Server:
            string server   = "http://localhost:9090/aceql";
            string database = "sampledb";

            string username = "******";
            string password = "******";

            string connectionString = $"Server={server}; Database={database}; "
                                      + $"Username={username}; Password={password}";

            AceQLConnection connection = new AceQLConnection(connectionString);

            // Opens the connection with the remote database
            await connection.OpenAsync();

            return(connection);
        }
        private async void buttonSelectBlob_ClickAsync(object sender, EventArgs e)
        {
            if (connection == null)
            {
                PopMesssage.Show("Please connect to remote database before Select!", ACEQL_TEST);
                return;
            }

            Cursor.Current = Cursors.WaitCursor;
            try
            {
                string folder = AceQLConnection.GetAceQLLocalFolder();
                String file   = folder + "\\koala_blob.jpg";

                RemoteStatement remoteStatement = new RemoteStatement(connection);

                using (Stream stream = await remoteStatement.SelectProductImageAsync(1))
                {
                    if (stream == null)
                    {
                        PopMesssage.Show("Click \"Insert\" to insert a Blob in remote database before doing the Select!", ACEQL_TEST);
                        return;
                    }

                    // Dump on koala_blob.jpg
                    using (var writeStream = File.OpenWrite(file))
                    {
                        stream.CopyTo(writeStream);
                    }
                }

                PopMesssage.Show("Blob successfully downloaded from database in file: \n"
                                 + file, ACEQL_TEST);
            }
            catch (Exception exeption)
            {
                Cursor.Current = Cursors.Default;
                PopMesssage.Show("Could not execute Insert statement: \n" + exeption.ToString(), ACEQL_TEST);
            }
            Cursor.Current = Cursors.Default;
        }
예제 #21
0
        /// <summary>
        /// Executes our example using an <see cref="AceQLConnection"/>
        /// </summary>
        /// <param name="connection"></param>
        public static async Task ExecuteExample(AceQLConnection connection)
        {
            await connection.OpenAsync();

            AceQLConsole.WriteLine("Host: " + connection.ConnectionInfo.ConnectionString);
            AceQLConsole.WriteLine("aceQLConnection.GetClientVersion(): " + AceQLConnection.GetClientVersion());
            AceQLConsole.WriteLine("aceQLConnection.GetServerVersion(): " + await connection.GetServerVersionAsync());
            AceQLConsole.WriteLine("AceQL local folder: ");
            AceQLConsole.WriteLine(AceQLConnection.GetAceQLLocalFolder());

            int maxSelect = 1;

            for (int j = 0; j < maxSelect; j++)
            {
                string       sql     = "select * from customer where customer_id > @parm1 and lname = @parm2";
                AceQLCommand command = new AceQLCommand(sql, connection);

                command.Parameters.AddWithValue("@parm2", "Name_5");
                command.Parameters.AddWithValue("@parm1", 1);

                // Our dataReader must be disposed to delete underlying downloaded files
                using (AceQLDataReader dataReader = await command.ExecuteReaderAsync())
                {
                    //await dataReader.ReadAsync(new CancellationTokenSource().Token)
                    while (dataReader.Read())
                    {
                        AceQLConsole.WriteLine();
                        AceQLConsole.WriteLine("" + DateTime.Now);
                        int i = 0;
                        AceQLConsole.WriteLine("GetValue: " + dataReader.GetValue(i++) + "\n"
                                               + "GetValue: " + dataReader.GetValue(i++) + "\n"
                                               + "GetValue: " + dataReader.GetValue(i++) + "\n"
                                               + "GetValue: " + dataReader.GetValue(i++) + "\n"
                                               + "GetValue: " + dataReader.GetValue(i++) + "\n"
                                               + "GetValue: " + dataReader.GetValue(i++) + "\n"
                                               + "GetValue: " + dataReader.GetValue(i++) + "\n"
                                               + "GetValue: " + dataReader.GetValue(i));
                    }
                }
            }
        }
        /// <summary>
        /// Does it.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <returns></returns>
        public static async Task DoIt(string[] args)
        {
            try
            {
                int customerId = 1;
                int itemId     = 1;

                // Make sure connection is always closed in order to close and release
                // server connection into the pool
                using (AceQLConnection connection = await ConnectionBuilderAsync())
                {
                    MyRemoteConnection myRemoteConnection = new MyRemoteConnection(
                        connection);

                    // Delete previous instances, so that user can recall

                    AceQLConsole.WriteLine("deleting customer...");
                    await myRemoteConnection.DeleteCustomerAsync(customerId).ConfigureAwait(false);;

                    AceQLConsole.WriteLine("deleting orderlog...");
                    await myRemoteConnection.DeleteOrderlogAsync(customerId, itemId).ConfigureAwait(false);;

                    await myRemoteConnection.InsertCustomerAndOrderLogAsync(customerId, itemId).ConfigureAwait(false);;
                    await myRemoteConnection.SelectCustomerAndOrderLogAsync(customerId).ConfigureAwait(false);;

                    await connection.CloseAsync().ConfigureAwait(false);;
                    AceQLConsole.WriteLine("The end...");
                }

                AceQLConsole.WriteLine();
                AceQLConsole.WriteLine("Press enter to close....");
                Console.ReadLine();
            }
            catch (Exception exception)
            {
                AceQLConsole.WriteLine(exception.ToString());
                AceQLConsole.WriteLine(exception.StackTrace);
                AceQLConsole.WriteLine("Press enter to close...");
                Console.ReadLine();
            }
        }
예제 #23
0
        /// <summary>
        /// RemoteConnection Quick Start client example.
        /// Creates a Connection to a remote database and open it.
        /// </summary>
        /// <returns>The connection to the remote database</returns>
        /// <exception cref="AceQLException">If any Exception occurs.</exception>
        public static async Task <AceQLConnection> ConnectionBuilderAsync()
        {
            // C# Example: connection to a remote database

            string server   = "https://www.acme.com:9443/aceql";
            string database = "sampledb";
            string username = "******";
            string password = "******";

            string connectionString = $"Server={server}; Database={database}; "
                                      + $"Username={username}; Password={password}";

            AceQLConnection connection = new AceQLConnection(connectionString);

            // Attempt to establish a connection to the remote SQL database:
            await connection.OpenAsync();

            AceQLConsole.WriteLine("Connected to database " + database + "!");

            return(connection);
        }
        private async void buttonInsertBlob_ClickAsync(object sender, EventArgs e)
        {
            if (connection == null)
            {
                PopMesssage.Show("Please connect to remote database before Insert!", ACEQL_TEST);
                return;
            }

            // Test if koala.jpg is in ACEQL_PCL_FOLDER

            String folder = AceQLConnection.GetAceQLLocalFolder();
            String file   = folder + "\\koala.jpg";

            if (!File.Exists(file))
            {
                PopMesssage.Show("Please copy a file named koala.jpg in this folder and try again: \n"
                                 + folder
                                 , ACEQL_TEST);
                return;
            }

            Cursor.Current = Cursors.WaitCursor;
            try
            {
                // Delte all before to avoid duplicates
                RemoteStatement remoteStatement = new RemoteStatement(connection);
                await remoteStatement.DeleteAllProductsAsync();

                Stream stream = File.OpenRead(file);
                await remoteStatement.InsertIntoProductAsync(1, "koala.jpg", stream);

                PopMesssage.Show("Blob inserted in database!", ACEQL_TEST);
            }
            catch (Exception exeption)
            {
                Cursor.Current = Cursors.Default;
                PopMesssage.Show("Could not execute Insert statement: \n" + exeption.ToString(), ACEQL_TEST);
            }
            Cursor.Current = Cursors.Default;
        }
예제 #25
0
        /// <summary>
        /// RemoteConnection Quick Start client example.
        /// Creates a Connection to a remote database and open it.
        /// </summary>
        /// <returns>The connection to the remote database</returns>
        /// <exception cref="AceQLException">If any Exception occurs.</exception>
        public static async Task <AceQLConnection> ConnectionBuilderAsyncWithCredential()
        {
            // Port number is the port number used to start the Web Server:
            string server   = "http://localhost:9090/aceql";
            string database = "sampledb";

            string connectionString = $"Server={server}; Database={database}";

            string username = "******";

            char[] password = GetFromUserInput();

            AceQLConnection connection = new AceQLConnection(connectionString)
            {
                Credential = new AceQLCredential(username, password)
            };

            // Opens the connection with the remote database
            await connection.OpenAsync();

            return(connection);
        }
예제 #26
0
        /// <summary>
        /// RemoteConnection Quick Start client example.
        /// Creates a Connection to a remote database and open it.
        /// </summary>
        /// <returns>The connection to the remote database</returns>
        /// <exception cref="AceQLException">If any Exception occurs.</exception>
        public static async Task <AceQLConnection> ConnectionBuilderAsyncWithCredential()
        {
            string server   = "https://www.aceql.com:9443/aceql";
            string database = "sampledb";

            string connectionString = $"Server={server}; Database={database}";
            string username         = "******";

            char[] password = { 'M', 'y', 'S', 'e', 'c', 'r', 'e', 't' };

            AceQLConnection connection = new AceQLConnection(connectionString)
            {
                Credential = new AceQLCredential(username, password)
            };

            // Opens the connection with the remote database
            await connection.OpenAsync();

            AceQLConsole.WriteLine("Successfully connected to database " + database + "!");

            return(connection);
        }
예제 #27
0
        static async Task DoIt(string[] args)
        {
#pragma warning disable CS0219 // Variable is assigned but its value is never used
            string serverUrlLocalhost = "http://localhost:9090/aceql";
#pragma warning disable CS0219 // Variable is assigned but its value is never used
            string serverUrlLocalhostTomcat = "http://localhost:8080/aceql-test/aceql";
#pragma warning restore CS0219 // Variable is assigned but its value is never used
#pragma warning disable CS0219 // Variable is assigned but its value is never used
            string serverUrlLinux = "https://www.aceql.com:9443/aceql";
#pragma warning restore CS0219 // Variable is assigned but its value is never used

            string server   = serverUrlLinux;
            string database = "sampledb";
            string username = "******";
            string password = "******";

            //customer_id integer NOT NULL,
            //customer_title character(4),
            //fname character varying(32),
            //lname character varying(32) NOT NULL,
            //addressline character varying(64),
            //town character varying(32),
            //zipcode character(10) NOT NULL,
            //phone character varying(32),

            string connectionString = $"Server={server}; Database={database}; ";
            //connectionString += $"Username={username}; Password={password}";

            AceQLCredential credential = new AceQLCredential(username, password.ToCharArray());

            // Make sure connection is always closed to close and release server connection into the pool
            using (AceQLConnection connection = new AceQLConnection(connectionString))
            {
                connection.Credential = credential;
                await ExecuteExample(connection).ConfigureAwait(false);

                await connection.CloseAsync();
            }
        }
        /// <summary>
        /// Gets the  the Default Or System proxy in use. Will return null if no Default/System proxy is in use.
        /// </summary>
        /// <returns>System.Net.IWebProxy.</returns>
        public static IWebProxy GetWebProxy()
        {
            IWebProxy webProxy = null;

            // See if end user has forced to use a System.Net.WebRequest.GetSystemWebProxy()
            if (AceQLConnection.GetDefaultWebProxy() != null)
            {
                webProxy = AceQLConnection.GetDefaultWebProxy();
            }
            else
            {
                webProxy = System.Net.WebRequest.DefaultWebProxy;
            }

            // Test the secret URL, if it is bypassed, there is no Default/System proxy set, so we will return null:
            if (webProxy.IsBypassed(new Uri(HttpClientHandlerBuilderNew.SECRET_URL)))
            {
                return(null);
            }
            else
            {
                return(webProxy);
            }
        }
예제 #29
0
        /// <summary>
        /// Executes our example using an <see cref="AceQLConnection"/>
        /// </summary>
        /// <param name="connection"></param>
        private static async Task ExecuteExample(AceQLConnection connection)
        {
            await connection.OpenAsync();

            AceQLConsole.WriteLine("host: " + connection.ConnectionString);
            AceQLConsole.WriteLine("aceQLConnection.GetClientVersion(): " + AceQLConnection.GetClientVersion());
            AceQLConsole.WriteLine("aceQLConnection.GetServerVersion(): " + await connection.GetServerVersionAsync());
            AceQLConsole.WriteLine("AceQL local folder: ");
            AceQLConsole.WriteLine(await AceQLConnection.GetAceQLLocalFolderAsync());

            RemoteDatabaseMetaData remoteDatabaseMetaData = connection.GetRemoteDatabaseMetaData();

            string userPath       = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
            string schemaFilePath = userPath + "\\db_schema.out.html";

            // Download Schema in HTML format:
            using (Stream stream = await remoteDatabaseMetaData.DbSchemaDownloadAsync())
            {
                using (var fileStream = File.Create(schemaFilePath))
                {
                    stream.CopyTo(fileStream);
                }
            }

            System.Diagnostics.Process.Start(schemaFilePath);
            AceQLConsole.WriteLine("Creating schema done.");

            JdbcDatabaseMetaData jdbcDatabaseMetaData = await remoteDatabaseMetaData.GetJdbcDatabaseMetaDataAsync();

            AceQLConsole.WriteLine("Major Version: " + jdbcDatabaseMetaData.GetJDBCMajorVersion);
            AceQLConsole.WriteLine("Minor Version: " + jdbcDatabaseMetaData.GetJDBCMinorVersion);
            AceQLConsole.WriteLine("IsReadOnly   : " + jdbcDatabaseMetaData.IsReadOnly);

            AceQLConsole.WriteLine("JdbcDatabaseMetaData: " + jdbcDatabaseMetaData.ToString().Substring(1, 200));
            AceQLConsole.WriteLine();

            AceQLConsole.WriteLine("Get the table names:");
            List <String> tableNames = await remoteDatabaseMetaData.GetTableNamesAsync();

            AceQLConsole.WriteLine("Print the column details of each table:");
            foreach (String tableName in tableNames)
            {
                Table table = await remoteDatabaseMetaData.GetTableAsync(tableName);

                AceQLConsole.WriteLine("Columns:");
                foreach (Column column in table.Columns)
                {
                    AceQLConsole.WriteLine(column.ToString());
                }
            }

            AceQLConsole.WriteLine();

            String name          = "orderlog";
            Table  tableOrderlog = await remoteDatabaseMetaData.GetTableAsync(name);

            AceQLConsole.WriteLine("table name: " + tableOrderlog.TableName);
            AceQLConsole.WriteLine("table keys: ");
            List <PrimaryKey> primakeys = tableOrderlog.PrimaryKeys;

            foreach (PrimaryKey primaryKey in primakeys)
            {
                AceQLConsole.WriteLine("==> primaryKey: " + primaryKey);
            }
            AceQLConsole.WriteLine();

            AceQLConsole.WriteLine("Full table: " + tableOrderlog);

            AceQLConsole.WriteLine();
            AceQLConsole.WriteLine("Done.");
        }
        /// <summary>
        /// Executes our example using an <see cref="AceQLConnection"/>
        /// </summary>
        /// <param name="connection"></param>
        private static async Task ExecuteExample(AceQLConnection connection)
        {
            await connection.OpenAsync();

            AceQLConsole.WriteLine("host: " + connection.ConnectionInfo.ConnectionString);
            AceQLConsole.WriteLine("aceQLConnection.GetClientVersion(): " + AceQLConnection.GetClientVersion());
            AceQLConsole.WriteLine("aceQLConnection.GetServerVersion(): " + await connection.GetServerVersionAsync());
            AceQLConsole.WriteLine("AceQL local folder: ");
            AceQLConsole.WriteLine(AceQLConnection.GetAceQLLocalFolder());

            AceQLTransaction transaction = await connection.BeginTransactionAsync();

            await transaction.CommitAsync();

            transaction.Dispose();

            string sql = "delete from customer_2";

            AceQLCommand command = new AceQLCommand
            {
                CommandText = sql,
                Connection  = connection
            };

            command.Prepare();

            await command.ExecuteNonQueryAsync();

            for (int i = 0; i < 3; i++)
            {
                sql =
                    "insert into customer_2 values (@parm1, @parm2, @parm3, @parm4, @parm5, @parm6, @parm7, @parm8, @parm9, @parm_10)";

                command = new AceQLCommand(sql, connection);

                int customer_id = i;

                command.Parameters.AddWithValue("@parm1", customer_id);
                command.Parameters.AddWithValue("@parm2", "Sir");
                command.Parameters.AddWithValue("@parm3", "André_" + customer_id);
                command.Parameters.Add(new AceQLParameter("@parm4", "Name_" + customer_id));
                command.Parameters.AddWithValue("@parm5", customer_id + ", road 66");
                command.Parameters.AddWithValue("@parm6", "Town_" + customer_id);
                command.Parameters.AddWithValue("@parm7", customer_id + "1111");
                command.Parameters.Add(new AceQLParameter("@parm8", AceQLNullType.VARCHAR)); //null value for NULL SQL insert.
                command.Parameters.AddWithValue("@parm9", customer_id + "_row_2");
                command.Parameters.AddWithValue("@parm_10", customer_id + "_row_count");

                CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
                await command.ExecuteNonQueryAsync(cancellationTokenSource.Token);
            }

            command.Dispose();

            sql     = "select * from customer_2";
            command = new AceQLCommand(sql, connection);

            // Our dataReader must be disposed to delete underlying downloaded files
            using (AceQLDataReader dataReader = await command.ExecuteReaderAsync())
            {
                while (dataReader.Read())
                {
                    AceQLConsole.WriteLine();
                    int i = 0;
                    AceQLConsole.WriteLine("GetValue: " + dataReader.GetValue(i++) + "\n"
                                           + "GetValue: " + dataReader.GetValue(i++) + "\n"
                                           + "GetValue: " + dataReader.GetValue(i++) + "\n"
                                           + "GetValue: " + dataReader.GetValue(i++) + "\n"
                                           + "GetValue: " + dataReader.GetValue(i++) + "\n"
                                           + "GetValue: " + dataReader.GetValue(i++) + "\n"
                                           + "GetValue: " + dataReader.GetValue(i++) + "\n"
                                           + "GetValue: " + dataReader.GetValue(i++) + "\n"
                                           + "GetValue: " + dataReader.GetValue(i++) + "\n"
                                           + "GetValue: " + dataReader.GetValue(i));
                }
            }

            AceQLConsole.WriteLine("Done.");
        }