Example #1
0
        /// <summary>ArchiveChildrens a SystemFolder 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="systemFolderId">The value for the SystemFolderId column.</param>
        /// <param name="archive">true to archive the object, false to unarchive it.</param>
        internal new static void ArchiveChildren(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int systemFolderId)
        {
            // Accessor for the SystemFolder Table.
            ServerDataModel.SystemFolderDataTable systemFolderTable = ServerDataModel.SystemFolder;
            // This record can be used to iterate through all the children.
            ServerDataModel.SystemFolderRow systemFolderRow = systemFolderTable.FindBySystemFolderId(systemFolderId);
            // Archive the child records.
            for (int index = 0; (index < systemFolderRow.GetUserRows().Length); index = (index + 1))
            {
                ServerDataModel.UserRow childUserRow = systemFolderRow.GetUserRows()[index];
                User.ArchiveChildren(adoTransaction, sqlTransaction, childUserRow.RowVersion, childUserRow.UserId);
            }
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Delete the record in the ADO database.
            systemFolderRow[systemFolderTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(systemFolderRow);
            systemFolderRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"SystemFolder\" set \"IsArchived\" = 1 where \"SystemFolderId\"=@systemFolderId" +
                                                   "");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@systemFolderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, systemFolderId));
            sqlCommand.ExecuteNonQuery();
        }
Example #2
0
        /// <summary>
        /// Authorizes a Equity to be returned to the client.
        /// </summary>
        /// <param name="userDataRow">Identifies the current user.</param>
        /// <param name="equityDataRow">The record to be tested for authorization.</param>
        /// <returns>true if the record belongs in the user's hierarchy.</returns>
        public static bool FilterEquity(DataRow userDataRow, DataRow equityDataRow)
        {
            // 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.
            ServerDataModel.UserRow   userRow   = (ServerDataModel.UserRow)userDataRow;
            ServerDataModel.EquityRow equityRow = (ServerDataModel.EquityRow)equityDataRow;

            return(true);
        }
Example #3
0
        /// <summary>ArchiveChildrens a User 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="userId">The value for the UserId column.</param>
        /// <param name="archive">true to archive the object, false to unarchive it.</param>
        internal static void ArchiveChildren(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int userId)
        {
            // Accessor for the User Table.
            ServerDataModel.UserDataTable userTable = ServerDataModel.User;
            // This record can be used to iterate through all the children.
            ServerDataModel.UserRow userRow = userTable.FindByUserId(userId);
            // Archive the child records.
            for (int index = 0; (index < userRow.GetAllocationRowsByFKUserAllocationCreatedUserId().Length); index = (index + 1))
            {
                ServerDataModel.AllocationRow childAllocationRow = userRow.GetAllocationRowsByFKUserAllocationCreatedUserId()[index];
                Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId);
            }
            for (int index = 0; (index < userRow.GetAllocationRowsByFKUserAllocationModifiedUserId().Length); index = (index + 1))
            {
                ServerDataModel.AllocationRow childAllocationRow = userRow.GetAllocationRowsByFKUserAllocationModifiedUserId()[index];
                Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId);
            }
            for (int index = 0; (index < userRow.GetExecutionRowsByFKUserExecutionCreatedUserId().Length); index = (index + 1))
            {
                ServerDataModel.ExecutionRow childExecutionRow = userRow.GetExecutionRowsByFKUserExecutionCreatedUserId()[index];
                Execution.Archive(adoTransaction, sqlTransaction, childExecutionRow.RowVersion, childExecutionRow.ExecutionId);
            }
            for (int index = 0; (index < userRow.GetExecutionRowsByFKUserExecutionModifiedUserId().Length); index = (index + 1))
            {
                ServerDataModel.ExecutionRow childExecutionRow = userRow.GetExecutionRowsByFKUserExecutionModifiedUserId()[index];
                Execution.Archive(adoTransaction, sqlTransaction, childExecutionRow.RowVersion, childExecutionRow.ExecutionId);
            }
            for (int index = 0; (index < userRow.GetPlacementRowsByFKUserPlacementCreatedUserId().Length); index = (index + 1))
            {
                ServerDataModel.PlacementRow childPlacementRow = userRow.GetPlacementRowsByFKUserPlacementCreatedUserId()[index];
                Placement.Archive(adoTransaction, sqlTransaction, childPlacementRow.RowVersion, childPlacementRow.PlacementId);
            }
            for (int index = 0; (index < userRow.GetPlacementRowsByFKUserPlacementModifiedUserId().Length); index = (index + 1))
            {
                ServerDataModel.PlacementRow childPlacementRow = userRow.GetPlacementRowsByFKUserPlacementModifiedUserId()[index];
                Placement.Archive(adoTransaction, sqlTransaction, childPlacementRow.RowVersion, childPlacementRow.PlacementId);
            }
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Delete the record in the ADO database.
            userRow[userTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(userRow);
            userRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"User\" set \"IsArchived\" = 1 where \"UserId\"=@userId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@userId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, userId));
            sqlCommand.ExecuteNonQuery();
        }
Example #4
0
        /// <summary>Archives a User 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="userId">The value for the UserId column.</param>
        /// <param name="archive">true to archive the object, false to unarchive it.</param>
        public new static void Archive(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int userId)
        {
            // Accessor for the User Table.
            ServerDataModel.UserDataTable userTable = ServerDataModel.User;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.UserRow userRow = userTable.FindByUserId(userId);
            if ((userRow == null))
            {
                throw new Exception(string.Format("The User table does not have an element identified by {0}", userId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((userRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Delete the base class record.  Note that optimistic concurrency is only used
            // by the top level type in the hierarchy, it is bypassed after you pass the first test.
            long baseRowVersion = userRow.ObjectRow.RowVersion;

            Object.Archive(adoTransaction, sqlTransaction, baseRowVersion, userId);
        }
Example #5
0
 /// <summary>Archives a User record using Metadata Parameters.</summary>
 /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
 public new static void Archive(ParameterList parameters)
 {
     // Accessor for the User Table.
     ServerDataModel.UserDataTable userTable = ServerDataModel.User;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     string externalUserId = parameters["userId"];
     // 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;
     // Find the internal identifier using the primary key elements.
     // identifier is used to determine if a record exists with the same key.
     int userId = User.FindRequiredKey(configurationId, "userId", externalUserId);
     // This disables the concurrency checking logic by finding the current row version and passing it to the
     // internal method.
     ServerDataModel.UserRow userRow = userTable.FindByUserId(userId);
     rowVersion = ((long)(userRow[userTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Quasar.Core.User.Archive(adoTransaction, sqlTransaction, rowVersion, userId);
 }
Example #6
0
 /// <summary>Updates a User record using Metadata Parameters.</summary>
 /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
 public new static void Update(ParameterList parameters)
 {
     // Accessor for the User Table.
     ServerDataModel.UserDataTable userTable = ServerDataModel.User;
     // 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;
     object owner = parameters["owner"].Value;
     object ownerPermission = parameters["ownerPermission"].Value;
     object readOnly = parameters["readOnly"].Value;
     object worldPermission = parameters["worldPermission"].Value;
     object preferences = parameters["preferences"].Value;
     object externalSystemFolderId = parameters["systemFolderId"].Value;
     object externalTypeCode = parameters["typeCode"].Value;
     string externalUserId = ((string)(parameters["userId"]));
     object userName = parameters["userName"].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
     object systemFolderId = SystemFolder.FindOptionalKey(configurationId, "systemFolderId", externalSystemFolderId);
     object typeCode = Type.FindOptionalKey(configurationId, "typeCode", externalTypeCode);
     int userId = Object.FindRequiredKey(configurationId, "userId", externalUserId);
     // This disables the concurrency checking logic by finding the current row version and passing it to the
     // internal method.
     ServerDataModel.UserRow userRow = userTable.FindByUserId(userId);
     rowVersion = ((long)(userRow[userTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Quasar.Core.User.Update(adoTransaction, sqlTransaction, ref rowVersion, description, null, null, null, null, null, null, null, null, groupPermission, hidden, name, owner, ownerPermission, readOnly, worldPermission, preferences, systemFolderId, typeCode, userId, userName);
     // Return values.
     parameters["rowVersion"] = rowVersion;
 }
Example #7
0
 /// <summary>Loads a User record using Metadata Parameters.</summary>
 /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
 public new static void Load(ParameterList parameters)
 {
     // Accessor for the User Table.
     ServerDataModel.UserDataTable userTable = ServerDataModel.User;
     // 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;
     string name = parameters["name"];
     object owner = parameters["owner"].Value;
     object ownerPermission = parameters["ownerPermission"].Value;
     object readOnly = parameters["readOnly"].Value;
     object worldPermission = parameters["worldPermission"].Value;
     object preferences = parameters["preferences"].Value;
     object externalSystemFolderId = parameters["systemFolderId"].Value;
     object externalTypeCode = parameters["typeCode"].Value;
     string externalUserId = parameters["userId"];
     string userName = parameters["userName"];
     // 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
     object systemFolderId = SystemFolder.FindOptionalKey(configurationId, "systemFolderId", externalSystemFolderId);
     object typeCode = Type.FindOptionalKey(configurationId, "typeCode", externalTypeCode);
     int userId = Object.FindKey(configurationId, "userId", externalUserId);
     ServerDataModel.UserRow userRow = userTable.FindByUserId(userId);
     // 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 ((userRow == null))
     {
         // 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 = User.GetExternalKeyIndex(configurationId, "userId");
         object[] externalIdArray = new object[8];
         externalIdArray[externalKeyIndex] = externalUserId;
         object externalId0 = externalIdArray[0];
         object externalId1 = externalIdArray[1];
         object externalId2 = externalIdArray[2];
         object externalId3 = externalIdArray[3];
         object externalId4 = externalIdArray[4];
         object externalId5 = externalIdArray[5];
         object externalId6 = externalIdArray[6];
         object externalId7 = externalIdArray[7];
         // Call the internal method to complete the operation.
         MarkThree.Quasar.Core.User.Insert(adoTransaction, sqlTransaction, ref rowVersion, description, externalId0, externalId1, externalId2, externalId3, externalId4, externalId5, externalId6, externalId7, groupPermission, hidden, name, owner, ownerPermission, readOnly, worldPermission, preferences, systemFolderId, typeCode, userName);
     }
     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.
         rowVersion = ((long)(userRow[userTable.RowVersionColumn]));
         // Call the internal method to complete the operation.
         MarkThree.Quasar.Core.User.Update(adoTransaction, sqlTransaction, ref rowVersion, description, null, null, null, null, null, null, null, null, groupPermission, hidden, name, owner, ownerPermission, readOnly, worldPermission, preferences, systemFolderId, typeCode, userId, userName);
     }
     // Return values.
     parameters["rowVersion"] = rowVersion;
 }
Example #8
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.
            ServerDataModel.ObjectDataTable objectTable = ServerDataModel.Object;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.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.GetFolderRows().Length); index = (index + 1))
            {
                ServerDataModel.FolderRow childFolderRow = objectRow.GetFolderRows()[index];
                Folder.ArchiveChildren(adoTransaction, sqlTransaction, childFolderRow.RowVersion, childFolderRow.FolderId);
            }
            for (int index = 0; (index < objectRow.GetAccountRows().Length); index = (index + 1))
            {
                ServerDataModel.AccountRow childAccountRow = objectRow.GetAccountRows()[index];
                Account.ArchiveChildren(adoTransaction, sqlTransaction, childAccountRow.RowVersion, childAccountRow.AccountId);
            }
            for (int index = 0; (index < objectRow.GetBlotterRows().Length); index = (index + 1))
            {
                ServerDataModel.BlotterRow childBlotterRow = objectRow.GetBlotterRows()[index];
                Blotter.ArchiveChildren(adoTransaction, sqlTransaction, childBlotterRow.RowVersion, childBlotterRow.BlotterId);
            }
            for (int index = 0; (index < objectRow.GetBrokerRows().Length); index = (index + 1))
            {
                ServerDataModel.BrokerRow childBrokerRow = objectRow.GetBrokerRows()[index];
                Broker.ArchiveChildren(adoTransaction, sqlTransaction, childBrokerRow.RowVersion, childBrokerRow.BrokerId);
            }
            for (int index = 0; (index < objectRow.GetIssuerRows().Length); index = (index + 1))
            {
                ServerDataModel.IssuerRow childIssuerRow = objectRow.GetIssuerRows()[index];
                Issuer.ArchiveChildren(adoTransaction, sqlTransaction, childIssuerRow.RowVersion, childIssuerRow.IssuerId);
            }
            for (int index = 0; (index < objectRow.GetUserRows().Length); index = (index + 1))
            {
                ServerDataModel.UserRow childUserRow = objectRow.GetUserRows()[index];
                User.ArchiveChildren(adoTransaction, sqlTransaction, childUserRow.RowVersion, childUserRow.UserId);
            }
            for (int index = 0; (index < objectRow.GetModelRows().Length); index = (index + 1))
            {
                ServerDataModel.ModelRow childModelRow = objectRow.GetModelRows()[index];
                Model.ArchiveChildren(adoTransaction, sqlTransaction, childModelRow.RowVersion, childModelRow.ModelId);
            }
            for (int index = 0; (index < objectRow.GetObjectTreeRowsByFKObjectObjectTreeChildId().Length); index = (index + 1))
            {
                ServerDataModel.ObjectTreeRow childObjectTreeRow = objectRow.GetObjectTreeRowsByFKObjectObjectTreeChildId()[index];
                ObjectTree.Archive(adoTransaction, sqlTransaction, childObjectTreeRow.RowVersion, childObjectTreeRow.ParentId, childObjectTreeRow.ChildId);
            }
            for (int index = 0; (index < objectRow.GetObjectTreeRowsByFKObjectObjectTreeParentId().Length); index = (index + 1))
            {
                ServerDataModel.ObjectTreeRow childObjectTreeRow = objectRow.GetObjectTreeRowsByFKObjectObjectTreeParentId()[index];
                ObjectTree.Archive(adoTransaction, sqlTransaction, childObjectTreeRow.RowVersion, childObjectTreeRow.ParentId, childObjectTreeRow.ChildId);
            }
            for (int index = 0; (index < objectRow.GetSchemeRows().Length); index = (index + 1))
            {
                ServerDataModel.SchemeRow childSchemeRow = objectRow.GetSchemeRows()[index];
                Scheme.ArchiveChildren(adoTransaction, sqlTransaction, childSchemeRow.RowVersion, childSchemeRow.SchemeId);
            }
            for (int index = 0; (index < objectRow.GetSectorRows().Length); index = (index + 1))
            {
                ServerDataModel.SectorRow childSectorRow = objectRow.GetSectorRows()[index];
                Sector.ArchiveChildren(adoTransaction, sqlTransaction, childSectorRow.RowVersion, childSectorRow.SectorId);
            }
            for (int index = 0; (index < objectRow.GetSecurityRows().Length); index = (index + 1))
            {
                ServerDataModel.SecurityRow childSecurityRow = objectRow.GetSecurityRows()[index];
                Security.ArchiveChildren(adoTransaction, sqlTransaction, childSecurityRow.RowVersion, childSecurityRow.SecurityId);
            }
            // Increment the row version
            rowVersion = ServerDataModel.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();
        }
Example #9
0
        /// <summary>Inserts a User 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="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="worldPermission">The value for the WorldPermission column.</param>
        /// <param name="preferences">The value for the Preferences column.</param>
        /// <param name="systemFolderId">The value for the SystemFolderId column.</param>
        /// <param name="typeCode">The value for the TypeCode column.</param>
        /// <param name="userName">The value for the UserName 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 worldPermission,
            object preferences,
            object systemFolderId,
            object typeCode,
            string userName)
        {
            // Accessor for the User Table.
            ServerDataModel.UserDataTable userTable = ServerDataModel.User;
            // Apply Defaults
            if ((preferences == null))
            {
                preferences = System.DBNull.Value;
            }
            if ((systemFolderId == null))
            {
                systemFolderId = System.DBNull.Value;
            }
            if ((typeCode == null))
            {
                typeCode = "User";
            }
            // Insert the base members using the base class.
            int userId = Object.Insert(adoTransaction, sqlTransaction, ref rowVersion, description, externalId0, externalId1, externalId2, externalId3, externalId4, externalId5, externalId6, externalId7, groupPermission, hidden, name, owner, ownerPermission, readOnly, typeCode, worldPermission);

            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Insert the record into the ADO database.
            ServerDataModel.UserRow userRow = userTable.NewUserRow();
            userRow[userTable.RowVersionColumn]     = rowVersion;
            userRow[userTable.PreferencesColumn]    = preferences;
            userRow[userTable.SystemFolderIdColumn] = systemFolderId;
            userRow[userTable.UserIdColumn]         = userId;
            userRow[userTable.UserNameColumn]       = userName;
            userTable.AddUserRow(userRow);
            adoTransaction.DataRows.Add(userRow);
            // Insert the record into the SQL database.
            SqlCommand sqlCommand = new SqlCommand("insert \"User\" (\"rowVersion\",Preferences,SystemFolderId,UserId,UserName) values (@" +
                                                   "rowVersion,@preferences,@systemFolderId,@userId,@userName)");

            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("@preferences", SqlDbType.Image, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, preferences));
            sqlCommand.Parameters.Add(new SqlParameter("@systemFolderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, systemFolderId));
            sqlCommand.Parameters.Add(new SqlParameter("@userId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, userId));
            sqlCommand.Parameters.Add(new SqlParameter("@userName", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, userName));
            sqlCommand.ExecuteNonQuery();
            // Return Statements
            return(userRow.UserId);
        }
Example #10
0
        /// <summary>Updates a User 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="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="worldPermission">The value for the WorldPermission column.</param>
        /// <param name="preferences">The value for the Preferences column.</param>
        /// <param name="systemFolderId">The value for the SystemFolderId column.</param>
        /// <param name="typeCode">The value for the TypeCode column.</param>
        /// <param name="userId">The value for the UserId column.</param>
        /// <param name="userName">The value for the UserName 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,
            object owner,
            object ownerPermission,
            object readOnly,
            object worldPermission,
            object preferences,
            object systemFolderId,
            object typeCode,
            int userId,
            object userName)
        {
            // Accessor for the User Table.
            ServerDataModel.UserDataTable userTable = ServerDataModel.User;
            // Rule #1: Make sure the record exists before updating it.
            ServerDataModel.UserRow userRow = userTable.FindByUserId(userId);
            if ((userRow == null))
            {
                throw new Exception(string.Format("The User table does not have an element identified by {0}", userId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((userRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Apply Defaults
            if ((preferences == null))
            {
                preferences = userRow[userTable.PreferencesColumn];
            }
            if ((systemFolderId == null))
            {
                systemFolderId = userRow[userTable.SystemFolderIdColumn];
            }
            if ((userName == null))
            {
                userName = userRow[userTable.UserNameColumn];
            }
            // Insert the base members using the base class.  Note that optimistic concurrency is only used
            // by the top level type in the hierarchy, it is bypassed after you pass the first test.
            long baseRowVersion = userRow.ObjectRow.RowVersion;

            Object.Update(adoTransaction, sqlTransaction, ref baseRowVersion, description, externalId0, externalId1, externalId2, externalId3, externalId4, externalId5, externalId6, externalId7, groupPermission, hidden, name, userId, owner, ownerPermission, readOnly, typeCode, worldPermission);
            // Increment the row version
            rowVersion = ServerDataModel.RowVersion.Increment();
            // Update the record in the ADO database.
            userRow[userTable.RowVersionColumn]     = rowVersion;
            userRow[userTable.PreferencesColumn]    = preferences;
            userRow[userTable.SystemFolderIdColumn] = systemFolderId;
            userRow[userTable.UserNameColumn]       = userName;
            adoTransaction.DataRows.Add(userRow);
            // Update the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"User\" set \"RowVersion\"=@rowVersion,\"Preferences\"=@preferences,\"SystemFold" +
                                                   "erId\"=@systemFolderId,\"UserName\"=@userName where \"UserId\"=@userId");

            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("@preferences", SqlDbType.Image, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, preferences));
            sqlCommand.Parameters.Add(new SqlParameter("@systemFolderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, systemFolderId));
            sqlCommand.Parameters.Add(new SqlParameter("@userId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, userId));
            sqlCommand.Parameters.Add(new SqlParameter("@userName", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, userName));
            // Update the record in the SQL database.
            sqlCommand.ExecuteNonQuery();
        }
Example #11
0
        /// <summary>
        /// Retrieves the records in the ServerDataModel that are newer than the given 'RowVersion'.
        /// </summary>
        /// <param name="RowVersion">A value which reflects the most recent record on the client.  This value will be
        /// updated by the server based on the returned DataSet and can be used for the next cycle.</param>
        /// <returns>All the records in a ServerDataModel that are newer than the given 'RowVersion'.</returns>
        public static void Reconcile(ParameterList parameters)
        {
            // Extract the client's current row version from the batch.
            long clientRowVersion = parameters["rowVersion"];

            // IMPORTANT CONCEPT: The data returned to the client is the set of rows that have been modified since the last call to
            // the 'reconcile' method.  The new data destined for the client is arranged in generic lists and arrays. This should
            // be done with structures, but the transmission of the type details of a structure over the network takes a measurable
            // amount of time.  This generic data structure of base types has the advantage of requiring less bandwidth to
            // serialize.  The big picture is that the data is passed back as an ArrayList containing essentially the table
            // information and a list of inserted, updated and deleted rows associated with each table structure.
            ArrayList reconciledData = null;

            // The "User" record of the current user is used to filter rows.
            int recordIndex = ServerDataModel.User.KeyUserUserName.Find(new object[] { System.Environment.UserName });

            if (recordIndex == -1)
            {
                throw new Exception(string.Format("The user '{0}' is not mapped to a User", System.Environment.UserName));
            }
            ServerDataModel.UserRow userRow = (ServerDataModel.UserRow)ServerDataModel.User.KeyUserUserName[recordIndex].Row;

            // The big picture is to scan through the tables looking for any row that has been modified after the 'RowVersion'
            // value passed to this method.  The 'RowVersion' acts as a one-size-fits-all state of the client data.  A generic data
            // structure will be constructed here with only the more recent records.  When the client merges this 'incremental'
            // data structure with the existing set, the server and client will be synchronized.
            foreach (Table sourceTable in ServerDataModel.Tables)
            {
                // IMPORTANT CONCEPT:  Only after we've determined that a table has new data exists will we move the schema into
                // the result set.  If there's no data in this table, it won't be initialized and a 'null' is returned to the
                // client.
                ArrayList targetRows = null;

                // IMPORTANT CONCEPT: Start scanning the table from the most recent to the eldest record.  To accomplish this, we
                // need to view the data according to 'RowVersion' (in descending order to make the loop easier to read).  While
                // the view adds a little overhead for inserting and updating, the time is more than recovered during this
                // operation.
                foreach (System.Data.DataRowView dataRowView in sourceTable.DefaultView)
                {
                    // Extract the source row from the view.  It is used several times below.
                    Row sourceRow = (Row)dataRowView.Row;

                    // This record's RowVersion will determine whether it is returned to the client or not.  Note that deleted
                    // records as well as current are included in the view and passed back to the client when appropriate.
                    long sourceRowVersion = (long)sourceRow[sourceTable.RowVersionColumn, DataRowVersion.Original];

                    // To prevent the entire table from being scanned, only the records that are newer than the client's timestamp
                    // are considered for transmission back to the client.  The default DataView on every table is organized by
                    // RowVersions, so it's safe to quit this loop when a record is older than the client's data model.
                    if (sourceRowVersion <= clientRowVersion)
                    {
                        break;
                    }

                    // All current records are compared against an optional filter and prevented from returning to the client if
                    // they are not part of what the client is authorized to view.  Some tables are public and can be shared
                    // without filters, other tables contain confidential information which is only transmitted to an entitled
                    // client.  The entitlements are generally specified by the object tree.
                    if (sourceRow.RowState != DataRowState.Deleted && sourceTable.UserFilter != null &&
                        !sourceTable.UserFilter(userRow, sourceRow))
                    {
                        continue;
                    }

                    // The bucket to hold the rows isn't created until at least one row has been discovered that needs to be
                    // returned to the client.  This is to keep the size of the returned data structure to a minimum when
                    // transmitting the incremental records.
                    if (targetRows == null)
                    {
                        // Like the bucket to hold the rows, the bucket that holds the tables -- the 'reconciledData' variable --
                        // isn't created until there is at least one table to be returned to the client.
                        if (reconciledData == null)
                        {
                            reconciledData = new ArrayList();
                        }

                        // The table-level record holds the name of the table, which will be used to look up the table on the
                        // client from the DataSet's "Table" member.  It also holds a list that contains all the records in that
                        // table.  There is one of these records for every table that has updated data that needs to be
                        // transmitted back to the client.
                        object[] targetTable = new object[2];
                        targetTable[0] = sourceTable.TableName;
                        targetTable[1] = targetRows = new ArrayList();
                        reconciledData.Add(targetTable);
                    }

                    // Deleted records are added as just the key elements.  Inserted and updated rows are added as the entire
                    // record.  The RowState is passed back to the client to tell it whether to delete, insert or update the client
                    // data model with this record.
                    targetRows.Add(new object[2] {
                        sourceRow.RowState, sourceRow.RowState == DataRowState.Deleted ?
                        DeletedRow(sourceRow) : sourceRow.ItemArray
                    });
                }
            }

            // When this data structure is merged with the client data model, the server and client databases will be in synch.  A
            // 'null' in the return data indicates that there is no data that is new since the last reconcilliation.
            parameters.Return.Value = reconciledData;
        }