/// <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();
            }
        }
Пример #2
0
        /// <summary>
        /// Executes a POST with parameters and returns a Stream
        /// </summary>
        /// <param name="theUrl">The Url.</param>
        /// <param name="parameters">The request parameters.</param>
        /// <returns>Stream.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// action is null!
        /// or
        /// postParameters is null!
        /// </exception>
        public async Task <Stream> CallWithPostAsync(Uri theUrl, Dictionary <string, string> parameters)
        {
            if (theUrl == null)
            {
                throw new ArgumentNullException("urlWithaction is null!");
            }


            if (parameters == null)
            {
                throw new ArgumentNullException("postParameters is null!");
            }

            HttpClient httpClient = new HttpClient();

            MultipartFormDataContent formData = new MultipartFormDataContent();

            // This is the postdata
            var postData = new List <KeyValuePair <string, string> >();

            foreach (var param in parameters)
            {
                postData.Add(new KeyValuePair <string, string>(param.Key, param.Value));
            }

            HttpContent content = new FormUrlEncodedContent(postData);

            HttpResponseMessage response = null;

            response = await httpClient.PostAsync(theUrl, content);

            this.httpStatusCode = response.StatusCode;
            AceQLConsole.WriteLine("this.httpStatusCode: " + this.httpStatusCode);
            return(await response.Content.ReadAsStreamAsync().ConfigureAwait(false));
        }
Пример #3
0
        public static void JsonParseResultAsString()
        {
            string jsonResult = File.ReadAllText(@"C:\test\json_out.txt");

            AceQLConsole.WriteLine(jsonResult);
            AceQLConsole.WriteLine();

            dynamic xj = JsonConvert.DeserializeObject(jsonResult);
            dynamic xjParametersOutPername = xj.parameters_out_per_name;

            if (xjParametersOutPername != null)
            {
                String dictStr = xjParametersOutPername.ToString();
                AceQLConsole.WriteLine("dictStr:" + dictStr);
                AceQLConsole.WriteLine();

                Dictionary <string, string> dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(dictStr);

                // For each parameter 1) get the index 2) get the dbType
                foreach (KeyValuePair <String, string> theParameter in dict)
                {
                    AceQLConsole.WriteLine(theParameter.Key + " / " + theParameter.Value);
                }
            }
            else
            {
                AceQLConsole.WriteLine("No Out parameters per name");
            }
        }
Пример #4
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();
            }
        }
Пример #5
0
 public static void TheMain()
 {
     try
     {
         AceQLConsole.WriteLine("AceQLTestMetadata Begin...");
         DoIt().Wait();
     }
     catch (Exception exception)
     {
         AceQLConsole.WriteLine(exception.ToString());
         AceQLConsole.WriteLine(exception.StackTrace);
         AceQLConsole.WriteLine("Press enter to close...");
         Console.ReadLine();
     }
 }
Пример #6
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();
            }
        }
Пример #7
0
 public static void TheMain(string[] args)
 {
     try
     {
         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();
     }
 }
        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();
                }
            }
        }
        /// <summary>
        /// Example of MS SQL Server Stored Procedure.
        /// </summary>
        /// <exception cref="AceQLException">If any Exception occurs.</exception>
        public async Task CallStoredProcedure()
        {
            string sql = "{call ProcedureName(@parm1, @parm2, @parm3)}";

            AceQLCommand command = new AceQLCommand(sql, connection);

            command.CommandType = CommandType.StoredProcedure;

            AceQLParameter aceQLParameter2 = new AceQLParameter("@parm2", 2)
            {
                Direction = ParameterDirection.InputOutput
            };

            AceQLParameter aceQLParameter1 = new AceQLParameter("@parm1", 0);

            AceQLParameter aceQLParameter3 = new AceQLParameter("@parm3")
            {
                Direction = ParameterDirection.Output
            };

            command.Parameters.Add(aceQLParameter1);
            command.Parameters.Add(aceQLParameter2);
            command.Parameters.Add(aceQLParameter3);

            AceQLConsole.WriteLine(sql);
            AceQLConsole.WriteLine("BEFORE execute @parm1: " + aceQLParameter1.ParameterName + " / " + aceQLParameter1.Value + " (" + aceQLParameter2.Value.GetType() + ")");
            AceQLConsole.WriteLine("BEFORE execute @parm2: " + aceQLParameter2.ParameterName + " / " + aceQLParameter2.Value + " (" + aceQLParameter2.Value.GetType() + ")");
            AceQLConsole.WriteLine("BEFORE execute @parm3: " + aceQLParameter3.ParameterName + " / " + aceQLParameter3.Value);
            AceQLConsole.WriteLine();

            // 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())
                {
                    int i = 2;
                    AceQLConsole.WriteLine("GetValue: " + dataReader.GetValue(i));
                }
            }
            AceQLConsole.WriteLine();
            AceQLConsole.WriteLine("AFTER execute @parm2: " + aceQLParameter2.ParameterName + " / " + aceQLParameter2.Value + " (" + aceQLParameter2.Value.GetType() + ")");
            AceQLConsole.WriteLine("AFTER execute @parm3: " + aceQLParameter3.ParameterName + " / " + aceQLParameter3.Value);
        }
Пример #10
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));
                    }
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Test the HTTP code
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public static async Task DoIt()
        {
            string url    = "https://www.runsafester.net/api/login";
            Uri    theUri = new Uri(url);

            AceQLConsole.WriteLine("calling: " + url);

            Dictionary <string, string> parametersMap = new Dictionary <string, string>
            {
                { "username", "*****@*****.**" },
                { "passphrase", "82223bafcd814f5d5600" },
            };

            AceQLConsole.WriteLine("calling parameters:");

            foreach (KeyValuePair <string, string> kvp in parametersMap)
            {
                AceQLConsole.WriteLine("Key/Value = " + kvp.Key + "/" + kvp.Value);
            }
            AceQLConsole.WriteLine();

            HttpTest httpTest = new HttpTest();

            String result = null;

            using (Stream input = await httpTest.CallWithPostAsync(theUri, parametersMap).ConfigureAwait(false))
            {
                if (input != null)
                {
                    result = new StreamReader(input).ReadToEnd();
                }
            }

            AceQLConsole.WriteLine("result: " + result);
            Console.ReadLine();
        }
Пример #12
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.");
        }
Пример #14
0
        /// <summary>
        /// Executes our example using an <see cref="AceQLConnection"/>
        /// </summary>
        /// <param name="connection"></param>
        public static async Task ExecuteExample(AceQLConnection connection)
        {
            string IN_DIRECTORY  = "c:\\test\\";
            string OUT_DIRECTORY = "c:\\test\\out\\";

            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());

            //AceQLTransaction transaction = await connection.BeginTransactionAsync();
            //await transaction.CommitAsync();
            //transaction.Dispose();

            AceQLTransaction transaction = null;

            string sql = "delete from customer";

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

            command.Prepare();

            await command.ExecuteNonQueryAsync();

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

                command = new AceQLCommand(sql, connection);

                int customer_id = i;

                command.Parameters.AddWithValue("@parm1", customer_id);
                command.Parameters.AddWithValue("@parm2", ""); // HACK NDP
                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", new AceQLNullValue(AceQLNullType.VARCHAR))); //null value for NULL SQL insert.

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

            command.Dispose();

            int maxSelect = 10;

            for (int j = 0; j < maxSelect; j++)
            {
                sql     = "select * from customer where customer_id > @parm1";
                command = new AceQLCommand(sql, connection);
                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));
                    }
                }
            }

            AceQLConsole.WriteLine("Before delete from orderlog");

            // Do next delete in a transaction because of BLOB
            sql     = "delete from orderlog";
            command = new AceQLCommand(sql, connection);
            await command.ExecuteNonQueryAsync();

            transaction = await connection.BeginTransactionAsync();

            AceQLConsole.WriteLine("Before insert into orderlog");
            try
            {
                for (int j = 1; j < 4; j++)
                {
                    sql =
                        "insert into orderlog values (@parm1, @parm2, @parm3, @parm4, @parm5, @parm6, @parm7, @parm8, @parm9)";

                    command = new AceQLCommand(sql, connection);

                    int customer_id = j;

                    string blobPath = IN_DIRECTORY + "username_koala.jpg";
                    Stream stream   = new FileStream(blobPath, FileMode.Open, System.IO.FileAccess.Read);

                    //customer_id integer NOT NULL,
                    //item_id integer NOT NULL,
                    //description character varying(64) NOT NULL,
                    //cost_price numeric,
                    //date_placed date NOT NULL,
                    //date_shipped timestamp without time zone,
                    //jpeg_image oid,
                    //is_delivered numeric,
                    //quantity integer NOT NULL,

                    command.Parameters.AddWithValue("@parm1", customer_id);
                    command.Parameters.AddWithValue("@parm2", customer_id);
                    command.Parameters.AddWithValue("@parm3", "Description_" + customer_id);
                    //command.Parameters.Add(new AceQLParameter("@parm4", new AceQLNullValue(AceQLNullType.DECIMAL))); //null value for NULL SQL insert.
                    command.Parameters.AddWithValue("@parm4", 45.4);
                    command.Parameters.AddWithValue("@parm5", DateTime.UtcNow);
                    command.Parameters.AddWithValue("@parm6", DateTime.UtcNow);
                    // Adds the Blob. (Stream will be closed by AceQLCommand)
                    bool useBlob = true;
                    if (useBlob)
                    {
                        command.Parameters.Add(new AceQLParameter("@parm7", stream));
                    }
                    else
                    {
                        command.Parameters.Add(new AceQLParameter("@parm7", new AceQLNullValue(AceQLNullType.BLOB)));
                    }

                    command.Parameters.AddWithValue("@parm8", 1);
                    command.Parameters.AddWithValue("@parm9", j * 2000);

                    await command.ExecuteNonQueryAsync();
                }

                await transaction.CommitAsync();
            }
            catch (Exception)
            {
                await transaction.RollbackAsync();

                throw;
            }

            AceQLConsole.WriteLine("Before select *  from orderlog");

            // Do next selects in a transaction because of BLOB
            transaction = await connection.BeginTransactionAsync();

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

            using (AceQLDataReader dataReader = await command.ExecuteReaderAsync())
            {
                int k = 0;
                while (dataReader.Read())
                {
                    AceQLConsole.WriteLine();
                    AceQLConsole.WriteLine("Get values using ordinal values:");
                    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));

                    //customer_id
                    //item_id
                    //description
                    //item_cost
                    //date_placed
                    //date_shipped
                    //jpeg_image
                    //is_delivered
                    //quantity

                    AceQLConsole.WriteLine();
                    AceQLConsole.WriteLine("Get values using column name values:");
                    AceQLConsole.WriteLine("GetValue: " + dataReader.GetValue(dataReader.GetOrdinal("customer_id"))
                                           + "\n"
                                           + "GetValue: " + dataReader.GetValue(dataReader.GetOrdinal("item_id")) + "\n"
                                           + "GetValue: " + dataReader.GetValue(dataReader.GetOrdinal("description")) + "\n"
                                           + "GetValue: " + dataReader.GetValue(dataReader.GetOrdinal("item_cost")) + "\n"
                                           + "GetValue: " + dataReader.GetValue(dataReader.GetOrdinal("date_placed")) + "\n"
                                           + "GetValue: " + dataReader.GetValue(dataReader.GetOrdinal("date_shipped")) + "\n"
                                           + "GetValue: " + dataReader.GetValue(dataReader.GetOrdinal("jpeg_image")) + "\n"
                                           + "GetValue: " + dataReader.GetValue(dataReader.GetOrdinal("is_delivered")) + "\n"
                                           + "GetValue: " + dataReader.GetValue(dataReader.GetOrdinal("quantity")));


                    AceQLConsole.WriteLine("==> dataReader.IsDBNull(3): " + dataReader.IsDBNull(3));
                    AceQLConsole.WriteLine("==> dataReader.IsDBNull(4): " + dataReader.IsDBNull(4));

                    // Download Blobs
                    string blobPath = OUT_DIRECTORY + "username_koala_" + k + ".jpg";
                    k++;

                    using (Stream stream = await dataReader.GetStreamAsync(6))
                    {
                        using (var fileStream = File.Create(blobPath))
                        {
                            stream.CopyTo(fileStream);
                        }
                    }
                }
            }

            await transaction.CommitAsync();
        }
Пример #15
0
        public static void JsonParseResultAsFile()
        {
            Dictionary <int, string>    valuesPerParamIndex = new Dictionary <int, string>();
            Dictionary <string, string> valuesPerParamName  = new Dictionary <string, string>();

            Stream stream = File.OpenRead(@"C:\test\json_out.txt");

            TextReader textReader = new StreamReader(stream);
            var        reader     = new JsonTextReader(textReader);

            // Necessary because a SQL columns could have the name "row_count".
            // We know that we are reading the good end of file "row_count" if
            // We are not any more in a array
            bool isInsideArray = false;

            while (reader.Read())
            {
                if (reader.TokenType != JsonToken.PropertyName || !reader.Value.Equals("parameters_out_per_index") || isInsideArray)
                {
                    continue;
                }

                String typeParameter = "per_index";

                string paramName  = null;
                string paramValue = null;

                while (reader.Read())
                {
                    if (reader.Value != null && reader.TokenType == JsonToken.PropertyName && reader.Value.Equals("parameters_out_per_name"))
                    {
                        typeParameter = "per_name";
                    }

                    if (reader.TokenType == JsonToken.PropertyName)
                    {
                        paramName = reader.Value.ToString();
                        paramName = paramName.Trim();
                        AceQLConsole.WriteLine("property: " + paramName + ":");
                    }
                    else if (reader.TokenType == JsonToken.String)
                    {
                        paramValue = reader.Value.ToString();
                        AceQLConsole.WriteLine("paramIndex: " + paramName + ":");
                        AceQLConsole.WriteLine("value     : " + paramValue + ":");
                        if (paramValue.Equals("NULL"))
                        {
                            paramValue = null;
                        }

                        if (typeParameter.Equals("per_index"))
                        {
                            int paramIndexInt = Int32.Parse(paramName);
                            valuesPerParamIndex.Add(paramIndexInt, paramValue);
                        }
                        else
                        {
                            valuesPerParamName.Add(paramName, paramValue);
                        }
                    }
                }
            }

            AceQLConsole.WriteLine();
            AceQLConsole.WriteLine("------- dict display ------");
            AceQLConsole.WriteLine();

            foreach (KeyValuePair <int, string> outParameter in valuesPerParamIndex)
            {
                AceQLConsole.WriteLine(outParameter.Key + " / " + outParameter.Value);
            }

            AceQLConsole.WriteLine();

            foreach (KeyValuePair <string, string> outParameter in valuesPerParamName)
            {
                AceQLConsole.WriteLine(outParameter.Key + " / " + outParameter.Value);
            }

            stream.Close();
        }