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