Exemple #1
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();
        }
Exemple #2
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();
        }
Exemple #3
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();
        }
Exemple #4
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();
        }