Example #1
0
 /// <summary>Updates a Timer record using Metadata Parameters.</summary>
 /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
 public static void Update(ParameterList parameters)
 {
     // Accessor for the Timer Table.
     ServerMarketData.TimerDataTable timerTable = ServerMarketData.Timer;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     object currentTime = parameters["currentTime"].Value;
     object isActive = parameters["isActive"].Value;
     object stopTime = parameters["stopTime"].Value;
     string externalTimerId = ((string)(parameters["timerId"]));
     object updateTime = parameters["updateTime"].Value;
     // The row versioning is largely disabled for external operations.
     long rowVersion = long.MinValue;
     // Resolve External Identifiers
     int timerId = Timer.FindRequiredKey(configurationId, "timerId", externalTimerId);
     // While the optimistic concurrency checking is disabled for the external methods, the internal methods
     // still need to perform the check.  This ncurrency checking logic by finding the current row version to be
     // will bypass the coused when the internal method is called.
     ServerMarketData.TimerRow timerRow = timerTable.FindByTimerId(timerId);
     rowVersion = ((long)(timerRow[timerTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Guardian.Core.Timer.Update(adoTransaction, sqlTransaction, ref rowVersion, currentTime, null, isActive, stopTime, timerId, updateTime);
     // Return values.
     parameters["rowVersion"] = rowVersion;
 }
Example #2
0
 /// <summary>Initializes the static elements of an Object.</summary>
 static Timer()
 {
     // The table must be locked before the indices can be read into an accelerator array.
     ServerMarketData.TimerLock.AcquireReaderLock(System.Threading.Timeout.Infinite);
     // Accessor for the Timer Table.
     ServerMarketData.TimerDataTable timerTable = ServerMarketData.Timer;
     // This does an indirect lookup operation using the views created for the ExternalId columns.  Take the index of the user
     // identifier column calcualted above and use it to find a record containing the external identifier.
     Timer.externalKeyArray = new DataView[] {
             timerTable.KeyTimerExternalId0};
     // The table must be released after the array is constructed.
     ServerMarketData.TimerLock.ReleaseReaderLock();
 }
Example #3
0
 /// <summary>Loads a Timer record using Metadata Parameters.</summary>
 /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
 public static void Load(ParameterList parameters)
 {
     // Accessor for the Timer Table.
     ServerMarketData.TimerDataTable timerTable = ServerMarketData.Timer;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     System.DateTime currentTime = parameters["currentTime"];
     object externalId0 = parameters["externalId0"].Value;
     bool isActive = parameters["isActive"];
     System.DateTime stopTime = parameters["stopTime"];
     object externalTimerId = parameters["timerId"].Value;
     int updateTime = parameters["updateTime"];
     // The row versioning is largely disabled for external operations.  The value is returned to the caller in the
     // event it's needed for operations within the batch.
     long rowVersion = long.MinValue;
     // Resolve External Identifiers
     int timerId = Timer.FindKey(configurationId, "timerId", externalTimerId);
     // The load operation will create a record if it doesn't exist, or update an existing record.  The external
     // identifier is used to determine if a record exists with the same key.
     if ((timerId == int.MinValue))
     {
         // Populate the 'externalId' varaibles so that the external identifier can be used to find the row when an
         // external method is called with the same 'configurationId' parameter.
         int externalKeyIndex = Timer.GetExternalKeyIndex(configurationId, "timerId");
         object[] externalIdArray = new object[1];
         externalIdArray[externalKeyIndex] = externalTimerId;
         externalId0 = externalIdArray[0];
         // Call the internal method to complete the operation.
         MarkThree.Guardian.Core.Timer.Insert(adoTransaction, sqlTransaction, ref rowVersion, currentTime, externalId0, isActive, stopTime, updateTime);
     }
     else
     {
         // While the optimistic concurrency checking is disabled for the external methods, the internal methods
         // still need to perform the check.  This ncurrency checking logic by finding the current row version to be
         // will bypass the coused when the internal method is called.
         ServerMarketData.TimerRow timerRow = timerTable.FindByTimerId(timerId);
         rowVersion = ((long)(timerRow[timerTable.RowVersionColumn]));
         // Call the internal method to complete the operation.
         MarkThree.Guardian.Core.Timer.Update(adoTransaction, sqlTransaction, ref rowVersion, currentTime, externalId0, isActive, stopTime, timerId, updateTime);
     }
     // Return values.
     parameters["rowVersion"] = rowVersion;
 }
Example #4
0
        /// <summary>Archives a Timer record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="RowVersion">The version number of this row.</param>
        /// <param name="timerId">The value for the TimerId column.</param>
        /// <param name="archive">true to archive the object, false to unarchive it.</param>
        public static void Archive(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int timerId)
        {
            // Accessor for the Timer Table.
            ServerMarketData.TimerDataTable timerTable = ServerMarketData.Timer;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.TimerRow timerRow = timerTable.FindByTimerId(timerId);
            if ((timerRow == null))
            {
                throw new Exception(string.Format("The Timer table does not have an element identified by {0}", timerId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((timerRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            for (int index = 0; (index < timerRow.GetMatchRows().Length); index = (index + 1))
            {
                ServerMarketData.MatchRow childMatchRow = timerRow.GetMatchRows()[index];
                Match.Archive(adoTransaction, sqlTransaction, childMatchRow.RowVersion, childMatchRow.MatchId);
            }
            for (int index = 0; (index < timerRow.GetWorkingOrderRows().Length); index = (index + 1))
            {
                ServerMarketData.WorkingOrderRow childWorkingOrderRow = timerRow.GetWorkingOrderRows()[index];
                WorkingOrder.Archive(adoTransaction, sqlTransaction, childWorkingOrderRow.RowVersion, childWorkingOrderRow.WorkingOrderId);
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Delete the record in the ADO database.
            timerRow[timerTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(timerRow);
            timerRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Timer\" set \"IsArchived\" = 1 where \"TimerId\"=@timerId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@timerId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, timerId));
            sqlCommand.ExecuteNonQuery();
        }
Example #5
0
 /// <summary>Finds a a Timer record using a configuration and an external identifier.</summary>
 /// <param name="configurationId">Specified which mappings (user id columns) to use when looking up external identifiers.</param>
 /// <param name="parameterId">The name of the parameter as specified in the configuration table.</param>
 /// <param name="externalId">The external (user supplied) identifier for the record.</param>
 public static int FindKey(object configurationId, string parameterId, object externalId)
 {
     // A missing key will never match a column.
     if ((externalId == null))
     {
         return int.MinValue;
     }
     // Accessor for the Timer Table.
     ServerMarketData.TimerDataTable timerTable = ServerMarketData.Timer;
     // Look for the record using the external identifier.  The configuration selected the key to use, which effectively
     // selected the external id column to use for the search.  If a record is found in the view, a translation still needs
     // to be made back to the original table before an index to the record can be returned to the caller.
     int externalKeyIndex = Timer.GetExternalKeyIndex(configurationId, parameterId);
     System.Data.DataView externalKeyView = Timer.externalKeyArray[externalKeyIndex];
     int recordIndex = externalKeyView.Find(new object[] {
                 externalId});
     if ((recordIndex == -1))
     {
         return int.MinValue;
     }
     return ((int)(externalKeyView[recordIndex].Row[timerTable.TimerIdColumn]));
 }
Example #6
0
 /// <summary>Archives a Timer record using Metadata Parameters.</summary>
 /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
 public static void Archive(ParameterList parameters)
 {
     // Accessor for the Timer Table.
     ServerMarketData.TimerDataTable timerTable = ServerMarketData.Timer;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     string externalTimerId = parameters["timerId"];
     // The row versioning is largely disabled for external operations.
     long rowVersion = long.MinValue;
     // Find the internal identifier using the primar key elements.
     // identifier is used to determine if a record exists with the same key.
     int timerId = Timer.FindRequiredKey(configurationId, "timerId", externalTimerId);
     // While the optimistic concurrency checking is disabled for the external methods, the internal methods
     // still need to perform the check.  This ncurrency checking logic by finding the current row version to be
     // will bypass the coused when the internal method is called.
     ServerMarketData.TimerRow timerRow = timerTable.FindByTimerId(timerId);
     rowVersion = ((long)(timerRow[timerTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Guardian.Core.Timer.Archive(adoTransaction, sqlTransaction, rowVersion, timerId);
 }
Example #7
0
        /// <summary>Inserts a Timer record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="currentTime">The value for the CurrentTime column.</param>
        /// <param name="externalId0">The value for the ExternalId0 column.</param>
        /// <param name="isActive">The value for the IsActive column.</param>
        /// <param name="stopTime">The value for the StopTime column.</param>
        /// <param name="updateTime">The value for the UpdateTime column.</param>
        public static int Insert(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, System.DateTime currentTime, object externalId0, bool isActive, System.DateTime stopTime, int updateTime)
        {
            // Accessor for the Timer Table.
            ServerMarketData.TimerDataTable timerTable = ServerMarketData.Timer;
            // Apply Defaults
            if ((externalId0 == null))
            {
                externalId0 = System.DBNull.Value;
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Insert the record into the ADO database.
            ServerMarketData.TimerRow timerRow = timerTable.NewTimerRow();
            timerRow[timerTable.RowVersionColumn]  = rowVersion;
            timerRow[timerTable.CurrentTimeColumn] = currentTime;
            timerRow[timerTable.ExternalId0Column] = externalId0;
            timerRow[timerTable.IsActiveColumn]    = isActive;
            timerRow[timerTable.StopTimeColumn]    = stopTime;
            timerRow[timerTable.UpdateTimeColumn]  = updateTime;
            timerTable.AddTimerRow(timerRow);
            adoTransaction.DataRows.Add(timerRow);
            // Insert the record into the SQL database.
            SqlCommand sqlCommand = new SqlCommand("insert \"Timer\" (\"rowVersion\",\"CurrentTime\",\"ExternalId0\",\"IsActive\",\"StopTime\",\"T" +
                                                   "imerId\",\"UpdateTime\") values (@rowVersion,@currentTime,@externalId0,@isActive,@s" +
                                                   "topTime,@timerId,@updateTime)");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@rowVersion", SqlDbType.BigInt, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, rowVersion));
            sqlCommand.Parameters.Add(new SqlParameter("@currentTime", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, currentTime));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId0", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId0));
            sqlCommand.Parameters.Add(new SqlParameter("@isActive", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, isActive));
            sqlCommand.Parameters.Add(new SqlParameter("@stopTime", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, stopTime));
            sqlCommand.Parameters.Add(new SqlParameter("@timerId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, timerRow[timerTable.TimerIdColumn]));
            sqlCommand.Parameters.Add(new SqlParameter("@updateTime", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, updateTime));
            sqlCommand.ExecuteNonQuery();
            // Return Statements
            return(timerRow.TimerId);
        }
Example #8
0
        /// <summary>Updates a Timer record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="rowVersion">The version number of the row</param>
        /// <param name="currentTime">The value for the CurrentTime column.</param>
        /// <param name="externalId0">The value for the ExternalId0 column.</param>
        /// <param name="isActive">The value for the IsActive column.</param>
        /// <param name="stopTime">The value for the StopTime column.</param>
        /// <param name="timerId">The value for the TimerId column.</param>
        /// <param name="updateTime">The value for the UpdateTime column.</param>
        public static void Update(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, object currentTime, object externalId0, object isActive, object stopTime, int timerId, object updateTime)
        {
            // Accessor for the Timer Table.
            ServerMarketData.TimerDataTable timerTable = ServerMarketData.Timer;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.TimerRow timerRow = timerTable.FindByTimerId(timerId);
            if ((timerRow == null))
            {
                throw new Exception(string.Format("The Timer table does not have an element identified by {0}", timerId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((timerRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Apply Defaults
            if ((currentTime == null))
            {
                currentTime = timerRow[timerTable.CurrentTimeColumn];
            }
            if ((externalId0 == null))
            {
                externalId0 = timerRow[timerTable.ExternalId0Column];
            }
            if ((isActive == null))
            {
                isActive = timerRow[timerTable.IsActiveColumn];
            }
            if ((stopTime == null))
            {
                stopTime = timerRow[timerTable.StopTimeColumn];
            }
            if ((updateTime == null))
            {
                updateTime = timerRow[timerTable.UpdateTimeColumn];
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Update the record in the ADO database.
            timerRow[timerTable.RowVersionColumn]  = rowVersion;
            timerRow[timerTable.CurrentTimeColumn] = currentTime;
            timerRow[timerTable.ExternalId0Column] = externalId0;
            timerRow[timerTable.IsActiveColumn]    = isActive;
            timerRow[timerTable.StopTimeColumn]    = stopTime;
            timerRow[timerTable.UpdateTimeColumn]  = updateTime;
            adoTransaction.DataRows.Add(timerRow);
            // Update the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Timer\" set \"RowVersion\"=@rowVersion,\"CurrentTime\"=@currentTime,\"ExternalI" +
                                                   "d0\"=@externalId0,\"IsActive\"=@isActive,\"StopTime\"=@stopTime,\"UpdateTime\"=@updateT" +
                                                   "ime where \"TimerId\"=@timerId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@rowVersion", SqlDbType.BigInt, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, rowVersion));
            sqlCommand.Parameters.Add(new SqlParameter("@currentTime", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, currentTime));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId0", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId0));
            sqlCommand.Parameters.Add(new SqlParameter("@isActive", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, isActive));
            sqlCommand.Parameters.Add(new SqlParameter("@stopTime", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, stopTime));
            sqlCommand.Parameters.Add(new SqlParameter("@timerId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, timerId));
            sqlCommand.Parameters.Add(new SqlParameter("@updateTime", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, updateTime));
            // Update the record in the SQL database.
            sqlCommand.ExecuteNonQuery();
        }