Ejemplo n.º 1
0
        private void Run(string[] args)
        {
            string service = "8001";

            // Check the correct number of arguments have been supplied
            if (args.Length > 1)
            {
                Console.WriteLine("usage: {0} [<data service>]", System.AppDomain.CurrentDomain.FriendlyName);
                return;
            }

            // Check whether a service argument has been supplied
            if (args.Length >= 1)
            {
                service = args[0];
            }

            // Build a connection string and connect to the database
            PolyConnectionStringBuilder builder = new PolyConnectionStringBuilder();

            builder.Service = service;

            PolyConnection connection = new PolyConnection(builder.ConnectionString);

            Console.WriteLine("Connecting to database at {0}...", service);

            try
            {
                connection.Open();
            }
            catch (Exception)
            {
                Console.WriteLine("Failed to connect to database");
                return;
            }

            // Create a command and execute a reader to perform the query
            Console.WriteLine("Connected, now launch query...");

            PolyCommand command = new PolyCommand("select * from currency", connection);

            PolyDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Console.WriteLine("Currency code: {0}: 1 US Dollar buys {1:F2} {2} {3}.", reader["code"], reader["usdollar"], reader["country"], reader["name"]);
            }

            Console.WriteLine("All rows returned.");

            reader.Close();

            connection.Close();
        }
Ejemplo n.º 2
0
        private void Run(string[] args)
        {
            string service = "8001";

            // Check the correct number of arguments have been supplied
            if (args.Length < 1 || args.Length > 2)
            {
                Console.WriteLine("usage: {0} <sql> [<data service>]", System.AppDomain.CurrentDomain.FriendlyName);
                return;
            }

            string sql = args[0];

            // Check whether a service argument has been supplied
            if (args.Length >= 2)
            {
                service = args[1];
            }

            // Build a connection string and connect to the database
            PolyConnectionStringBuilder builder = new PolyConnectionStringBuilder();

            builder.Service = service;

            PolyConnection connection = new PolyConnection(builder.ConnectionString);

            Console.WriteLine("Connecting to port {0}...", service);

            try
            {
                connection.Open();
            }
            catch (Exception)
            {
                Console.WriteLine("Failed to connect to database");
                return;
            }

            Console.WriteLine("Connected successfully. Start the transaction:");
            Console.WriteLine("{0}", sql);

            // Create a command and execute it as a non-query to execute the statement
            PolyCommand command = new PolyCommand(sql, connection);

            try
            {
                command.ExecuteNonQuery();

                Console.WriteLine("Transaction completed successfully");
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to execute statement");

                WriteException(e);
            }
            finally
            {
                connection.Close();
            }
        }
Ejemplo n.º 3
0
        private void Run(string[] args)
        {
            string service = "8001";
            bool ftEnable = false;

            // Check the correct number of arguments have been supplied
            if (args.Length > 2)
            {
                Console.WriteLine("usage: {0} [<data service> [FT]]", System.AppDomain.CurrentDomain.FriendlyName);
                return;
            }

            // Check whether a service argument has been supplied
            if (args.Length >= 1)
            {
                service = args[0];
            }

            // Check wether an FT argument has been supplied
            if (args.Length >= 2)
            {
                ftEnable = args[1].Equals("FT");
            }

            // Build a connection string and connect to the database
            PolyConnectionStringBuilder builder = new PolyConnectionStringBuilder();

            builder.Service = service;

            // Set FT connection settings
            builder.FTEnable = ftEnable;
            builder.FTHeartbeatInterval = 1000;
            builder.FTHeartbeatTimeout = 1000;
            builder.FTReconnectionCount = 1000;
            builder.FTReconnectionInterval = 1000;
            builder.FTReconnectionTimeout = 1000;

            PolyConnection connection = new PolyConnection(builder.ConnectionString);

            // Register for state change events on the connection
            // This is used to detect loss of connection to the database
            connection.StateChange += OnStateChange;

            // Register for FT mode change events on the connection
            connection.FTModeChange += OnFTModeChange;

            Console.WriteLine("Connecting to {0}{1}...", service, ftEnable ? " Fault Tolerant" : "");

            try
            {
                connection.Open();
            }
            catch (Exception)
            {
                Console.WriteLine("Failed to connect to database");
                return;
            }

            // Create and command and an active adapter to perform the active query
            Console.WriteLine("Connected, now launch active query...");

            PolyCommand command = new PolyCommand("select code,usdollar from currency", connection);

            PolyActiveDataAdapter adapter = new PolyActiveDataAdapter(command);

            // Primary key information must be added to the data table
            adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

            DataSet dataSet = new DataSet();

            // Perform an initial fill of the data table
            adapter.Fill(dataSet, "currency");

            DataTable dataTable = dataSet.Tables["currency"];

            // Display the results of the initial fill
            WriteTable(dataTable);

            // Register for data change events
            // This indicates when a delta is available for the active query
            adapter.DataChange += OnDataChange;

            // Register for row changed and row deleted events on the data table
            // This is used to determine the changes made when applying a delta
            dataTable.RowChanged += OnRowChanged;
            dataTable.RowDeleted += OnRowDeleted;

            // Explicitly accept changes made to the data table by the delta
            adapter.AcceptChangesDuringFill = false;

            // Use the Upsert LoadOption to determine the changes made by the delta
            adapter.FillLoadOption = LoadOption.Upsert;

            while (WaitHandle.WaitOne())
            {
                // Stop when connection to the database is lost
                if (connection.State == ConnectionState.Closed)
                {
                    break;
                }

                // Apply the delta to the data table
                adapter.FillDelta(dataTable);

                Console.WriteLine("Delta complete - success.\n");

                // Accept the changes made to the data table by the delta
                dataTable.AcceptChanges();
            }

            connection.Close();
        }
Ejemplo n.º 4
0
        private void Run(string[] args)
        {
            string service = "8001";

            // Check the correct number of arguments have been supplied
            if (args.Length > 2)
            {
                Console.WriteLine("usage: {0} <max size of load_file> [<data service>]", System.AppDomain.CurrentDomain.FriendlyName);
                return;
            }

            // Maximum file size allowed
            MaxFileSize = long.Parse(args[0]);

            // Check whether a service argument has been supplied
            if (args.Length >= 2)
            {
                service = args[1];
            }

            // Build a connection string and connect to the database
            PolyConnectionStringBuilder builder = new PolyConnectionStringBuilder();

            builder.Service = service;

            Connection = new PolyConnection(builder.ConnectionString);

            // Register for state change events on the connection
            // This is used to detect loss of connection to the database
            Connection.StateChange += OnStateChange;

            Console.WriteLine("Connecting to database at {0}...", service);

            try
            {
                Connection.Open();
            }
            catch (Exception)
            {
                Console.WriteLine("Failed to connect to database");
                return;
            }

            // Create and command and an active adapter to perform the active query
            Console.WriteLine("Connected, now launch active query on journal control");
            Console.WriteLine("and monitor file_size for it reaching {0}", MaxFileSize);

            PolyCommand command = new PolyCommand("select id,file_size from journalcontrol", Connection);

            PolyActiveDataAdapter adapter = new PolyActiveDataAdapter(command);

            // Primary key information must be added to the data table
            adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

            DataSet dataSet = new DataSet();

            // Perform an initial fill of the data table
            adapter.Fill(dataSet, "journalcontrol");

            DataTable dataTable = dataSet.Tables["journalcontrol"];

            // Display the results of the initial fill
            WriteTable(dataTable);

            // Register for data change events
            // This indicates when a delta is available for the active query
            adapter.DataChange += OnDataChange;

            while (WaitHandle.WaitOne())
            {
                // Stop when connection to the database is lost
                if (Connection.State == ConnectionState.Closed)
                {
                    break;
                }

                // Apply the delta to the data table
                adapter.FillDelta(dataTable);

                // Display the results of the delta
                WriteTable(dataTable);
            }

            Connection.Close();
        }
Ejemplo n.º 5
0
        private void SaveDatabase(long currentSize)
        {
            // The maximum allowable filesize has been exceeded so issue a save statement
            Console.WriteLine("File size has reached {0}, so time to create new load_file.", currentSize);

            SizeAtSave = currentSize;

            // Create a command and execute it in a transaction as a non-query to execute the save statement
            PolyTransaction transaction = Connection.BeginTransaction();

            // Enable safe-commit mode
            transaction.SafeCommit = true;

            PolyCommand command = new PolyCommand("save", Connection);

            command.Transaction = transaction;

            command.ExecuteNonQuery();

            try
            {
                transaction.Commit();
                Console.WriteLine("Save into completed.");
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to execute statement");
                WriteException(e);
            }
        }
Ejemplo n.º 6
0
        private void Run(string[] args)
        {
            string service = "8001";

            // Check the correct number of arguments have been supplied
            if (args.Length > 1)
            {
                Console.WriteLine("usage: {0} [<data service>]", System.AppDomain.CurrentDomain.FriendlyName);
                return;
            }

            // Check whether a service argument has been supplied
            if (args.Length >= 1)
            {
                service = args[0];
            }

            // Build a connection string and connect to the database
            PolyConnectionStringBuilder builder = new PolyConnectionStringBuilder();

            builder.Service = service;

            PolyConnection connection = new PolyConnection(builder.ConnectionString);

            // Register for state change events on the connection
            // This is used to detect loss of connection to the database
            connection.StateChange += OnStateChange;

            Console.WriteLine("Connecting to {0}...", service);

            try
            {
                connection.Open();
            }
            catch (Exception)
            {
                Console.WriteLine("Failed to connect to database");
                return;
            }

            // Create and command and an active adapter to perform the active query
            Console.WriteLine("Connected, now launch active query...");

            PolyCommand command = new PolyCommand("select code,usdollar,low_limit,high_limit from currency_limits", connection);

            PolyActiveDataAdapter adapter = new PolyActiveDataAdapter(command);

            // Primary key information must be added to the data table
            adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

            DataSet dataSet = new DataSet();

            // Explicitly accept changes made to the data table by the delta
            adapter.AcceptChangesDuringFill = false;

            // Register for data change events
            // This indicates when a delta is available for the active query
            adapter.DataChange += OnDataChange;

            // Perform an initial fill of the data table
            adapter.Fill(dataSet, "currency_limits");

            DataTable dataTable = dataSet.Tables["currency_limits"];

            // Display the results of the initial fill
            WriteTable(dataTable);

            // Accept the changes made to the data table by the delta
            dataTable.AcceptChanges();

            // Use the Upsert LoadOption to determine the changes made by the delta
            adapter.FillLoadOption = LoadOption.Upsert;

            while (WaitHandle.WaitOne())
            {
                // Stop when connection to the database is lost
                if (connection.State == ConnectionState.Closed)
                {
                    break;
                }

                // Apply the delta to the data table
                adapter.FillDelta(dataTable);

                // Display the results of the delta
                WriteTable(dataTable);

                // Accept the changes made to the data table by the delta
                dataTable.AcceptChanges();
            }

            connection.Close();
        }