示例#1
0
        /// <summary>Inserts a Configuration record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="columnIndex">The value for the ColumnIndex column.</param>
        /// <param name="configurationId">The value for the ConfigurationId column.</param>
        /// <param name="parameterId">The value for the ParameterId column.</param>
        public static void Insert(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, ref long rowVersion, int columnIndex, string configurationId, string parameterId)
        {
            // Accessor for the Configuration Table.
            ServerMarketData.ConfigurationDataTable configurationTable = ServerMarketData.Configuration;
            // Apply Defaults
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Insert the record into the ADO database.
            ServerMarketData.ConfigurationRow configurationRow = configurationTable.NewConfigurationRow();
            configurationRow[configurationTable.RowVersionColumn]      = rowVersion;
            configurationRow[configurationTable.ColumnIndexColumn]     = columnIndex;
            configurationRow[configurationTable.ConfigurationIdColumn] = configurationId;
            configurationRow[configurationTable.ParameterIdColumn]     = parameterId;
            configurationTable.AddConfigurationRow(configurationRow);
            adoTransaction.DataRows.Add(configurationRow);
            // Insert the record into the SQL database.
            SqlCommand sqlCommand = new SqlCommand("insert \"Configuration\" (\"rowVersion\",\"ColumnIndex\",\"ConfigurationId\",\"ParameterId" +
                                                   "\") values (@rowVersion,@columnIndex,@configurationId,@parameterId)");

            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("@columnIndex", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, columnIndex));
            sqlCommand.Parameters.Add(new SqlParameter("@configurationId", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, configurationId));
            sqlCommand.Parameters.Add(new SqlParameter("@parameterId", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, parameterId));
            sqlCommand.ExecuteNonQuery();
        }
示例#2
0
        /// <summary>Archives a Configuration 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="configurationId">The value for the ConfigurationId column.</param>
        /// <param name="parameterId">The value for the ParameterId 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, string configurationId, string parameterId)
        {
            // Accessor for the Configuration Table.
            ServerMarketData.ConfigurationDataTable configurationTable = ServerMarketData.Configuration;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.ConfigurationRow configurationRow = configurationTable.FindByConfigurationIdParameterId(configurationId, parameterId);
            if ((configurationRow == null))
            {
                throw new Exception(string.Format("The Configuration table does not have an element identified by {0}{0}", configurationId, parameterId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((configurationRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Delete the record in the ADO database.
            configurationRow[configurationTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(configurationRow);
            configurationRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Configuration\" set \"IsArchived\" = 1 where \"ConfigurationId\"=@configuratio" +
                                                   "nId and \"ParameterId\"=@parameterId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@configurationId", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, configurationId));
            sqlCommand.Parameters.Add(new SqlParameter("@parameterId", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, parameterId));
            sqlCommand.ExecuteNonQuery();
        }
示例#3
0
 /// <summary>Loads a Configuration 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 Configuration Table.
     ServerMarketData.ConfigurationDataTable configurationTable = ServerMarketData.Configuration;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     int columnIndex = parameters["columnIndex"];
     string configurationId = parameters["configurationId"];
     string parameterId = parameters["parameterId"];
     // The row versioning is largely disabled for external operations.
     long rowVersion = long.MinValue;
     // Find the record using the unique identifier.  If it doesn't exist, it will be inserted, if it does exist,
     // it will be updated.
     ServerMarketData.ConfigurationRow configurationRow = configurationTable.FindByConfigurationIdParameterId(configurationId, parameterId);
     if ((configurationRow == null))
     {
         // Call the internal 'Insert' method to complete the operation.
         MarkThree.Guardian.Core.Configuration.Insert(adoTransaction, sqlTransaction, ref rowVersion, columnIndex, configurationId, parameterId);
     }
     else
     {
         // This will bypass the optimistic concurrency checking required by the internal method.
         rowVersion = ((long)(configurationRow[configurationTable.RowVersionColumn]));
         // Call the internal 'Update' method to complete the operation.
         MarkThree.Guardian.Core.Configuration.Update(adoTransaction, sqlTransaction, ref rowVersion, columnIndex, configurationId, parameterId);
     }
     // Return values
     parameters["rowVersion"] = rowVersion;
 }
示例#4
0
 /// <summary>Calculates which index to uses when searching for external identifiers.</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>
 /// <returns>An index into the array of keys to search for an external identifier.</returns>
 public static int GetExternalKeyIndex(object configurationId, string parameterId)
 {
     // Translate the configurationId and the predefined parameter name into an index into the array of user ids.  The index
     // is where we expect to find the identifier.  That is, an index of 1 will guide the lookup logic to use the external
     // identifiers found in the 'ExternalId1' column.
     int externalKeyIndex = 0;
     if ((configurationId != null))
     {
         // Attempt to find a external column specification for the given configuration and parameter.  This record tells us
         // which column to use in the array of external columns.
         ServerMarketData.ConfigurationRow configurationRow = ServerMarketData.Configuration.FindByConfigurationIdParameterId(((string)(configurationId)), parameterId);
         if ((configurationRow != null))
         {
             externalKeyIndex = configurationRow.ColumnIndex;
         }
     }
     // This is the index into the array of keys to be used when searching for an external identifier.
     return externalKeyIndex;
 }
示例#5
0
 /// <summary>Archives a Configuration 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 Configuration Table.
     ServerMarketData.ConfigurationDataTable configurationTable = ServerMarketData.Configuration;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     string configurationId = parameters["configurationId"];
     string parameterId = parameters["parameterId"];
     // The row versioning is largely disabled for external operations.
     long rowVersion = long.MinValue;
     // 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.ConfigurationRow configurationRow = configurationTable.FindByConfigurationIdParameterId(configurationId, parameterId);
     rowVersion = ((long)(configurationRow[configurationTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Guardian.Core.Configuration.Archive(adoTransaction, sqlTransaction, rowVersion, configurationId, parameterId);
 }
示例#6
0
 /// <summary>Updates a Configuration 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 Configuration Table.
     ServerMarketData.ConfigurationDataTable configurationTable = ServerMarketData.Configuration;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object columnIndex = parameters["columnIndex"].Value;
     string configurationId = parameters["configurationId"];
     string parameterId = parameters["parameterId"];
     // The row versioning is largely disabled for external operations.
     long rowVersion = long.MinValue;
     // This will bypass the internal optimistic concurrency checking by providing the current rowVersion to the 
     // internal method.
     ServerMarketData.ConfigurationRow configurationRow = configurationTable.FindByConfigurationIdParameterId(configurationId, parameterId);
     rowVersion = ((long)(configurationRow[configurationTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Guardian.Core.Configuration.Update(adoTransaction, sqlTransaction, ref rowVersion, columnIndex, configurationId, parameterId);
     // Return values.
     parameters["rowVersion"] = rowVersion;
 }