Exemplo n.º 1
0
        /// <summary>Archives a Type 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="typeCode">The value for the TypeCode 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 typeCode)
        {
            // Accessor for the Type Table.
            ServerMarketData.TypeDataTable typeTable = ServerMarketData.Type;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.TypeRow typeRow = typeTable.FindByTypeCode(typeCode);
            if ((typeRow == null))
            {
                throw new Exception(string.Format("The Type table does not have an element identified by {0}", typeCode));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((typeRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            for (int index = 0; (index < typeRow.GetObjectRows().Length); index = (index + 1))
            {
                ServerMarketData.ObjectRow childObjectRow = typeRow.GetObjectRows()[index];
                Object.Archive(adoTransaction, sqlTransaction, childObjectRow.RowVersion, childObjectRow.ObjectId);
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Delete the record in the ADO database.
            typeRow[typeTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(typeRow);
            typeRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Type\" set \"IsArchived\" = 1 where \"TypeCode\"=@typeCode");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@typeCode", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, typeCode));
            sqlCommand.ExecuteNonQuery();
        }
Exemplo n.º 2
0
 /// <summary>Updates a Object 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 Object Table.
     ServerMarketData.ObjectDataTable objectTable = ServerMarketData.Object;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     object description = parameters["description"].Value;
     object groupPermission = parameters["groupPermission"].Value;
     object hidden = parameters["hidden"].Value;
     object name = parameters["name"].Value;
     string externalObjectId = ((string)(parameters["objectId"]));
     object owner = parameters["owner"].Value;
     object ownerPermission = parameters["ownerPermission"].Value;
     object readOnly = parameters["readOnly"].Value;
     object externalTypeCode = parameters["typeCode"].Value;
     object worldPermission = parameters["worldPermission"].Value;
     // The row versioning is largely disabled for external operations.
     long rowVersion = long.MinValue;
     // Resolve External Identifiers
     int objectId = Object.FindRequiredKey(configurationId, "objectId", externalObjectId);
     object typeCode = Type.FindOptionalKey(configurationId, "typeCode", externalTypeCode);
     // 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.ObjectRow objectRow = objectTable.FindByObjectId(objectId);
     rowVersion = ((long)(objectRow[objectTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Guardian.Core.Object.Update(adoTransaction, sqlTransaction, ref rowVersion, description, null, null, null, null, null, null, null, null, groupPermission, hidden, name, objectId, owner, ownerPermission, readOnly, typeCode, worldPermission);
     // Return values.
     parameters["rowVersion"] = rowVersion;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Authorizes a Object to be returned to the client.
        /// </summary>
        /// <param name="userDataRow">Identifies the current user.</param>
        /// <param name="objectDataRow">The record to be tested for authorization.</param>
        /// <returns>true if the record belongs in the user's hierarchy.</returns>
        public static bool FilterObject(DataRow userDataRow, DataRow objectDataRow)
        {
            // This will test the record and return true if it belongs to the hierarchies this user is authorized to view.  False
            // if the record should not be included in the user's data model.
            ServerMarketData.UserRow   userRow   = (ServerMarketData.UserRow)userDataRow;
            ServerMarketData.ObjectRow objectRow = (ServerMarketData.ObjectRow)objectDataRow;

            foreach (ServerMarketData.SecurityRow securityRow in objectRow.GetSecurityRows())
            {
                foreach (ServerMarketData.SourceOrderRow sourceOrderRow in securityRow.GetSourceOrderRowsBySecuritySourceOrderSecurityId())
                {
                    if (Hierarchy.IsDescendant(userRow.SystemFolderRow.FolderRow.ObjectRow, sourceOrderRow.WorkingOrderRow.BlotterRow.ObjectRow))
                    {
                        return(true);
                    }
                }

                foreach (ServerMarketData.SourceOrderRow sourceOrderRow in securityRow.GetSourceOrderRowsBySecuritySourceOrderSettlementId())
                {
                    if (Hierarchy.IsDescendant(userRow.SystemFolderRow.FolderRow.ObjectRow, sourceOrderRow.WorkingOrderRow.BlotterRow.ObjectRow))
                    {
                        return(true);
                    }
                }

                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
 /// <summary>Archives a Object 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 Object Table.
     ServerMarketData.ObjectDataTable objectTable = ServerMarketData.Object;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     string externalObjectId = parameters["objectId"];
     // 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 objectId = Object.FindRequiredKey(configurationId, "objectId", externalObjectId);
     // 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.ObjectRow objectRow = objectTable.FindByObjectId(objectId);
     rowVersion = ((long)(objectRow[objectTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Guardian.Core.Object.Archive(adoTransaction, sqlTransaction, rowVersion, objectId);
 }
Exemplo n.º 5
0
 /// <summary>Loads a Object 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 Object Table.
     ServerMarketData.ObjectDataTable objectTable = ServerMarketData.Object;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     object description = parameters["description"].Value;
     object externalId0 = parameters["externalId0"].Value;
     object externalId1 = parameters["externalId1"].Value;
     object externalId2 = parameters["externalId2"].Value;
     object externalId3 = parameters["externalId3"].Value;
     object externalId4 = parameters["externalId4"].Value;
     object externalId5 = parameters["externalId5"].Value;
     object externalId6 = parameters["externalId6"].Value;
     object externalId7 = parameters["externalId7"].Value;
     object groupPermission = parameters["groupPermission"].Value;
     object hidden = parameters["hidden"].Value;
     string name = parameters["name"];
     object externalObjectId = parameters["objectId"].Value;
     object owner = parameters["owner"].Value;
     object ownerPermission = parameters["ownerPermission"].Value;
     object readOnly = parameters["readOnly"].Value;
     object externalTypeCode = parameters["typeCode"].Value;
     object worldPermission = parameters["worldPermission"].Value;
     // 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 objectId = Object.FindKey(configurationId, "objectId", externalObjectId);
     object typeCode = Type.FindOptionalKey(configurationId, "typeCode", externalTypeCode);
     // 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 ((objectId == 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 = Object.GetExternalKeyIndex(configurationId, "objectId");
         object[] externalIdArray = new object[8];
         externalIdArray[externalKeyIndex] = externalObjectId;
         externalId0 = externalIdArray[0];
         externalId1 = externalIdArray[1];
         externalId2 = externalIdArray[2];
         externalId3 = externalIdArray[3];
         externalId4 = externalIdArray[4];
         externalId5 = externalIdArray[5];
         externalId6 = externalIdArray[6];
         externalId7 = externalIdArray[7];
         // Call the internal method to complete the operation.
         MarkThree.Guardian.Core.Object.Insert(adoTransaction, sqlTransaction, ref rowVersion, description, externalId0, externalId1, externalId2, externalId3, externalId4, externalId5, externalId6, externalId7, groupPermission, hidden, name, owner, ownerPermission, readOnly, typeCode, worldPermission);
     }
     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.ObjectRow objectRow = objectTable.FindByObjectId(objectId);
         rowVersion = ((long)(objectRow[objectTable.RowVersionColumn]));
         // Call the internal method to complete the operation.
         MarkThree.Guardian.Core.Object.Update(adoTransaction, sqlTransaction, ref rowVersion, description, externalId0, externalId1, externalId2, externalId3, externalId4, externalId5, externalId6, externalId7, groupPermission, hidden, name, objectId, owner, ownerPermission, readOnly, typeCode, worldPermission);
     }
     // Return values.
     parameters["rowVersion"] = rowVersion;
 }
Exemplo n.º 6
0
        /// <summary>Inserts a Object record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="description">The value for the Description column.</param>
        /// <param name="externalId0">The value for the ExternalId0 column.</param>
        /// <param name="externalId1">The value for the ExternalId1 column.</param>
        /// <param name="externalId2">The value for the ExternalId2 column.</param>
        /// <param name="externalId3">The value for the ExternalId3 column.</param>
        /// <param name="externalId4">The value for the ExternalId4 column.</param>
        /// <param name="externalId5">The value for the ExternalId5 column.</param>
        /// <param name="externalId6">The value for the ExternalId6 column.</param>
        /// <param name="externalId7">The value for the ExternalId7 column.</param>
        /// <param name="groupPermission">The value for the GroupPermission column.</param>
        /// <param name="hidden">The value for the Hidden column.</param>
        /// <param name="name">The value for the Name column.</param>
        /// <param name="owner">The value for the Owner column.</param>
        /// <param name="ownerPermission">The value for the OwnerPermission column.</param>
        /// <param name="readOnly">The value for the ReadOnly column.</param>
        /// <param name="typeCode">The value for the TypeCode column.</param>
        /// <param name="worldPermission">The value for the WorldPermission column.</param>
        public static int Insert(
            AdoTransaction adoTransaction,
            SqlTransaction sqlTransaction,
            ref long rowVersion,
            object description,
            object externalId0,
            object externalId1,
            object externalId2,
            object externalId3,
            object externalId4,
            object externalId5,
            object externalId6,
            object externalId7,
            object groupPermission,
            object hidden,
            string name,
            object owner,
            object ownerPermission,
            object readOnly,
            object typeCode,
            object worldPermission)
        {
            // Accessor for the Object Table.
            ServerMarketData.ObjectDataTable objectTable = ServerMarketData.Object;
            // Apply Defaults
            if ((description == null))
            {
                description = System.DBNull.Value;
            }
            if ((externalId0 == null))
            {
                externalId0 = System.DBNull.Value;
            }
            if ((externalId1 == null))
            {
                externalId1 = System.DBNull.Value;
            }
            if ((externalId2 == null))
            {
                externalId2 = System.DBNull.Value;
            }
            if ((externalId3 == null))
            {
                externalId3 = System.DBNull.Value;
            }
            if ((externalId4 == null))
            {
                externalId4 = System.DBNull.Value;
            }
            if ((externalId5 == null))
            {
                externalId5 = System.DBNull.Value;
            }
            if ((externalId6 == null))
            {
                externalId6 = System.DBNull.Value;
            }
            if ((externalId7 == null))
            {
                externalId7 = System.DBNull.Value;
            }
            if ((groupPermission == null))
            {
                groupPermission = 0;
            }
            if ((hidden == null))
            {
                hidden = false;
            }
            if ((owner == null))
            {
                owner = 0;
            }
            if ((ownerPermission == null))
            {
                ownerPermission = 0;
            }
            if ((readOnly == null))
            {
                readOnly = false;
            }
            if ((typeCode == null))
            {
                typeCode = "Object";
            }
            if ((worldPermission == null))
            {
                worldPermission = 0;
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Insert the record into the ADO database.
            ServerMarketData.ObjectRow objectRow = objectTable.NewObjectRow();
            objectRow[objectTable.RowVersionColumn]      = rowVersion;
            objectRow[objectTable.DescriptionColumn]     = description;
            objectRow[objectTable.ExternalId0Column]     = externalId0;
            objectRow[objectTable.ExternalId1Column]     = externalId1;
            objectRow[objectTable.ExternalId2Column]     = externalId2;
            objectRow[objectTable.ExternalId3Column]     = externalId3;
            objectRow[objectTable.ExternalId4Column]     = externalId4;
            objectRow[objectTable.ExternalId5Column]     = externalId5;
            objectRow[objectTable.ExternalId6Column]     = externalId6;
            objectRow[objectTable.ExternalId7Column]     = externalId7;
            objectRow[objectTable.GroupPermissionColumn] = groupPermission;
            objectRow[objectTable.HiddenColumn]          = hidden;
            objectRow[objectTable.NameColumn]            = name;
            objectRow[objectTable.OwnerColumn]           = owner;
            objectRow[objectTable.OwnerPermissionColumn] = ownerPermission;
            objectRow[objectTable.ReadOnlyColumn]        = readOnly;
            objectRow[objectTable.TypeCodeColumn]        = typeCode;
            objectRow[objectTable.WorldPermissionColumn] = worldPermission;
            objectTable.AddObjectRow(objectRow);
            adoTransaction.DataRows.Add(objectRow);
            // Insert the record into the SQL database.
            SqlCommand sqlCommand = new SqlCommand(@"insert ""Object"" (""rowVersion"",""Description"",""ExternalId0"",""ExternalId1"",""ExternalId2"",""ExternalId3"",""ExternalId4"",""ExternalId5"",""ExternalId6"",""ExternalId7"",""GroupPermission"",""Hidden"",""Name"",""ObjectId"",""Owner"",""OwnerPermission"",""ReadOnly"",""TypeCode"",""WorldPermission"") values (@rowVersion,@description,@externalId0,@externalId1,@externalId2,@externalId3,@externalId4,@externalId5,@externalId6,@externalId7,@groupPermission,@hidden,@name,@objectId,@owner,@ownerPermission,@readOnly,@typeCode,@worldPermission)");

            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("@description", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, description));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId0", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId0));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId1", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId1));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId2", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId2));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId3", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId3));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId4", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId4));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId5", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId5));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId6", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId6));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId7", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId7));
            sqlCommand.Parameters.Add(new SqlParameter("@groupPermission", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, groupPermission));
            sqlCommand.Parameters.Add(new SqlParameter("@hidden", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, hidden));
            sqlCommand.Parameters.Add(new SqlParameter("@name", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, name));
            sqlCommand.Parameters.Add(new SqlParameter("@objectId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, objectRow[objectTable.ObjectIdColumn]));
            sqlCommand.Parameters.Add(new SqlParameter("@owner", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, owner));
            sqlCommand.Parameters.Add(new SqlParameter("@ownerPermission", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, ownerPermission));
            sqlCommand.Parameters.Add(new SqlParameter("@readOnly", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, readOnly));
            sqlCommand.Parameters.Add(new SqlParameter("@typeCode", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, typeCode));
            sqlCommand.Parameters.Add(new SqlParameter("@worldPermission", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, worldPermission));
            sqlCommand.ExecuteNonQuery();
            // Return Statements
            return(objectRow.ObjectId);
        }
Exemplo n.º 7
0
        /// <summary>Archives a Object 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="objectId">The value for the ObjectId 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 objectId)
        {
            // Accessor for the Object Table.
            ServerMarketData.ObjectDataTable objectTable = ServerMarketData.Object;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.ObjectRow objectRow = objectTable.FindByObjectId(objectId);
            if ((objectRow == null))
            {
                throw new Exception(string.Format("The Object table does not have an element identified by {0}", objectId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((objectRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            for (int index = 0; (index < objectRow.GetAccountBaseRows().Length); index = (index + 1))
            {
                ServerMarketData.AccountBaseRow childAccountBaseRow = objectRow.GetAccountBaseRows()[index];
                AccountBase.ArchiveChildren(adoTransaction, sqlTransaction, childAccountBaseRow.RowVersion, childAccountBaseRow.AccountBaseId);
            }
            for (int index = 0; (index < objectRow.GetBlotterRows().Length); index = (index + 1))
            {
                ServerMarketData.BlotterRow childBlotterRow = objectRow.GetBlotterRows()[index];
                Blotter.ArchiveChildren(adoTransaction, sqlTransaction, childBlotterRow.RowVersion, childBlotterRow.BlotterId);
            }
            for (int index = 0; (index < objectRow.GetFolderRows().Length); index = (index + 1))
            {
                ServerMarketData.FolderRow childFolderRow = objectRow.GetFolderRows()[index];
                Folder.ArchiveChildren(adoTransaction, sqlTransaction, childFolderRow.RowVersion, childFolderRow.FolderId);
            }
            for (int index = 0; (index < objectRow.GetIssuerRows().Length); index = (index + 1))
            {
                ServerMarketData.IssuerRow childIssuerRow = objectRow.GetIssuerRows()[index];
                Issuer.ArchiveChildren(adoTransaction, sqlTransaction, childIssuerRow.RowVersion, childIssuerRow.IssuerId);
            }
            for (int index = 0; (index < objectRow.GetObjectTreeRowsByObjectObjectTreeChildId().Length); index = (index + 1))
            {
                ServerMarketData.ObjectTreeRow childObjectTreeRow = objectRow.GetObjectTreeRowsByObjectObjectTreeChildId()[index];
                ObjectTree.Archive(adoTransaction, sqlTransaction, childObjectTreeRow.RowVersion, childObjectTreeRow.ObjectTreeId);
            }
            for (int index = 0; (index < objectRow.GetObjectTreeRowsByObjectObjectTreeParentId().Length); index = (index + 1))
            {
                ServerMarketData.ObjectTreeRow childObjectTreeRow = objectRow.GetObjectTreeRowsByObjectObjectTreeParentId()[index];
                ObjectTree.Archive(adoTransaction, sqlTransaction, childObjectTreeRow.RowVersion, childObjectTreeRow.ObjectTreeId);
            }
            for (int index = 0; (index < objectRow.GetSecurityRows().Length); index = (index + 1))
            {
                ServerMarketData.SecurityRow childSecurityRow = objectRow.GetSecurityRows()[index];
                Security.ArchiveChildren(adoTransaction, sqlTransaction, childSecurityRow.RowVersion, childSecurityRow.SecurityId);
            }
            for (int index = 0; (index < objectRow.GetUserRows().Length); index = (index + 1))
            {
                ServerMarketData.UserRow childUserRow = objectRow.GetUserRows()[index];
                User.ArchiveChildren(adoTransaction, sqlTransaction, childUserRow.RowVersion, childUserRow.UserId);
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Delete the record in the ADO database.
            objectRow[objectTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(objectRow);
            objectRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Object\" set \"IsArchived\" = 1 where \"ObjectId\"=@objectId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@objectId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, objectId));
            sqlCommand.ExecuteNonQuery();
        }
Exemplo n.º 8
0
        /// <summary>Updates a Object 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="description">The value for the Description column.</param>
        /// <param name="externalId0">The value for the ExternalId0 column.</param>
        /// <param name="externalId1">The value for the ExternalId1 column.</param>
        /// <param name="externalId2">The value for the ExternalId2 column.</param>
        /// <param name="externalId3">The value for the ExternalId3 column.</param>
        /// <param name="externalId4">The value for the ExternalId4 column.</param>
        /// <param name="externalId5">The value for the ExternalId5 column.</param>
        /// <param name="externalId6">The value for the ExternalId6 column.</param>
        /// <param name="externalId7">The value for the ExternalId7 column.</param>
        /// <param name="groupPermission">The value for the GroupPermission column.</param>
        /// <param name="hidden">The value for the Hidden column.</param>
        /// <param name="name">The value for the Name column.</param>
        /// <param name="objectId">The value for the ObjectId column.</param>
        /// <param name="owner">The value for the Owner column.</param>
        /// <param name="ownerPermission">The value for the OwnerPermission column.</param>
        /// <param name="readOnly">The value for the ReadOnly column.</param>
        /// <param name="typeCode">The value for the TypeCode column.</param>
        /// <param name="worldPermission">The value for the WorldPermission column.</param>
        public static void Update(
            AdoTransaction adoTransaction,
            SqlTransaction sqlTransaction,
            ref long rowVersion,
            object description,
            object externalId0,
            object externalId1,
            object externalId2,
            object externalId3,
            object externalId4,
            object externalId5,
            object externalId6,
            object externalId7,
            object groupPermission,
            object hidden,
            object name,
            int objectId,
            object owner,
            object ownerPermission,
            object readOnly,
            object typeCode,
            object worldPermission)
        {
            // Accessor for the Object Table.
            ServerMarketData.ObjectDataTable objectTable = ServerMarketData.Object;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.ObjectRow objectRow = objectTable.FindByObjectId(objectId);
            if ((objectRow == null))
            {
                throw new Exception(string.Format("The Object table does not have an element identified by {0}", objectId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((objectRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Apply Defaults
            if ((description == null))
            {
                description = objectRow[objectTable.DescriptionColumn];
            }
            if ((externalId0 == null))
            {
                externalId0 = objectRow[objectTable.ExternalId0Column];
            }
            if ((externalId1 == null))
            {
                externalId1 = objectRow[objectTable.ExternalId1Column];
            }
            if ((externalId2 == null))
            {
                externalId2 = objectRow[objectTable.ExternalId2Column];
            }
            if ((externalId3 == null))
            {
                externalId3 = objectRow[objectTable.ExternalId3Column];
            }
            if ((externalId4 == null))
            {
                externalId4 = objectRow[objectTable.ExternalId4Column];
            }
            if ((externalId5 == null))
            {
                externalId5 = objectRow[objectTable.ExternalId5Column];
            }
            if ((externalId6 == null))
            {
                externalId6 = objectRow[objectTable.ExternalId6Column];
            }
            if ((externalId7 == null))
            {
                externalId7 = objectRow[objectTable.ExternalId7Column];
            }
            if ((groupPermission == null))
            {
                groupPermission = objectRow[objectTable.GroupPermissionColumn];
            }
            if ((hidden == null))
            {
                hidden = objectRow[objectTable.HiddenColumn];
            }
            if ((name == null))
            {
                name = objectRow[objectTable.NameColumn];
            }
            if ((owner == null))
            {
                owner = objectRow[objectTable.OwnerColumn];
            }
            if ((ownerPermission == null))
            {
                ownerPermission = objectRow[objectTable.OwnerPermissionColumn];
            }
            if ((readOnly == null))
            {
                readOnly = objectRow[objectTable.ReadOnlyColumn];
            }
            if ((typeCode == null))
            {
                typeCode = objectRow[objectTable.TypeCodeColumn];
            }
            if ((worldPermission == null))
            {
                worldPermission = objectRow[objectTable.WorldPermissionColumn];
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Update the record in the ADO database.
            objectRow[objectTable.RowVersionColumn]      = rowVersion;
            objectRow[objectTable.DescriptionColumn]     = description;
            objectRow[objectTable.ExternalId0Column]     = externalId0;
            objectRow[objectTable.ExternalId1Column]     = externalId1;
            objectRow[objectTable.ExternalId2Column]     = externalId2;
            objectRow[objectTable.ExternalId3Column]     = externalId3;
            objectRow[objectTable.ExternalId4Column]     = externalId4;
            objectRow[objectTable.ExternalId5Column]     = externalId5;
            objectRow[objectTable.ExternalId6Column]     = externalId6;
            objectRow[objectTable.ExternalId7Column]     = externalId7;
            objectRow[objectTable.GroupPermissionColumn] = groupPermission;
            objectRow[objectTable.HiddenColumn]          = hidden;
            objectRow[objectTable.NameColumn]            = name;
            objectRow[objectTable.OwnerColumn]           = owner;
            objectRow[objectTable.OwnerPermissionColumn] = ownerPermission;
            objectRow[objectTable.ReadOnlyColumn]        = readOnly;
            objectRow[objectTable.TypeCodeColumn]        = typeCode;
            objectRow[objectTable.WorldPermissionColumn] = worldPermission;
            adoTransaction.DataRows.Add(objectRow);
            // Update the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand(@"update ""Object"" set ""RowVersion""=@rowVersion,""Description""=@description,""ExternalId0""=@externalId0,""ExternalId1""=@externalId1,""ExternalId2""=@externalId2,""ExternalId3""=@externalId3,""ExternalId4""=@externalId4,""ExternalId5""=@externalId5,""ExternalId6""=@externalId6,""ExternalId7""=@externalId7,""GroupPermission""=@groupPermission,""Hidden""=@hidden,""Name""=@name,""Owner""=@owner,""OwnerPermission""=@ownerPermission,""ReadOnly""=@readOnly,""TypeCode""=@typeCode,""WorldPermission""=@worldPermission where ""ObjectId""=@objectId");

            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("@description", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, description));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId0", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId0));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId1", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId1));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId2", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId2));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId3", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId3));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId4", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId4));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId5", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId5));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId6", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId6));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId7", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId7));
            sqlCommand.Parameters.Add(new SqlParameter("@groupPermission", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, groupPermission));
            sqlCommand.Parameters.Add(new SqlParameter("@hidden", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, hidden));
            sqlCommand.Parameters.Add(new SqlParameter("@name", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, name));
            sqlCommand.Parameters.Add(new SqlParameter("@objectId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, objectId));
            sqlCommand.Parameters.Add(new SqlParameter("@owner", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, owner));
            sqlCommand.Parameters.Add(new SqlParameter("@ownerPermission", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, ownerPermission));
            sqlCommand.Parameters.Add(new SqlParameter("@readOnly", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, readOnly));
            sqlCommand.Parameters.Add(new SqlParameter("@typeCode", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, typeCode));
            sqlCommand.Parameters.Add(new SqlParameter("@worldPermission", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, worldPermission));
            // Update the record in the SQL database.
            sqlCommand.ExecuteNonQuery();
        }