예제 #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();
        }
예제 #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();
            }
        }
예제 #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();
        }
예제 #4
0
        private void PolyForm_Load(object sender, EventArgs args)
        {
            // Build a connection string and connect to the database
            PolyConnectionStringBuilder builder = new PolyConnectionStringBuilder();

            builder.Service = service;

            connection = new PolyConnection(builder.ConnectionString);

            DialogResult result = DialogResult.Retry;

            // Allow connection attempt to be retried if it fails
            while (result == DialogResult.Retry)
            {
                try
                {
                    connection.Open();
                    break;
                }
                catch (Exception exception)
                {
                    result = MessageBox.Show(GetExceptionMessage(exception), Text, MessageBoxButtons.RetryCancel);
                    if (result != DialogResult.Retry)
                    {
                        Close();
                        return;
                    }
                }
            }

            // Create an active data adapter to perform the active query (on the currency table)
            dataAdapter = new PolyActiveDataAdapter("select * from currency", connection);

            // Create a data table to hold the data
            dataTable = new DataTable();

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

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

            // Do not automatically accept changes made to the data table when updating
            dataAdapter.AcceptChangesDuringUpdate = false;

            // Start active query and obtain initial data
            dataAdapter.Fill(dataTable);

            // Provide the data table as the data source to the data grid
            dataGridView.DataSource = dataTable;

            // Sort data by currency code
            dataGridView.Sort(dataGridView.Columns["code"], ListSortDirection.Ascending);

            // Right-align column containing dollar value
            dataGridView.Columns["usdollar"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;

            // Turn edit mode off
            SetEditMode(false);

            // Note that the connection must remain open for the active data adapter to function
        }
예제 #5
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();
        }
예제 #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();
        }
예제 #7
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;
            }

            Console.WriteLine("Connection made successfully.");

            // Create an active data adapter to perform the active query
            PolyActiveDataAdapter adapter = new PolyActiveDataAdapter("select code,usdollar from currency", connection);

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

            // Create a data table to hold the result
            DataSet dataSet = new DataSet();

            DataTable dataTable = dataSet.Tables.Add("currency");

            // Add a column to record the starting usdollar value
            DataColumn dataColumn = dataTable.Columns.Add("usdollar_starting", typeof(double));

            dataColumn.DefaultValue = 0.0;

            // Add a column to record the last change made to the currency
            dataColumn = dataTable.Columns.Add("change", typeof(double));

            dataColumn.DefaultValue = 0.0;

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

            // Change the results of the initial fill
            ChangeData(dataTable, adapter);

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

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

                    // Apply the delta to the data table
                    adapter.FillDelta(dataTable);
                }
                else
                {
                    ChangeData(dataTable, adapter);
                }
            }

            connection.Close();
        }