public GreyFoxEventCollection Clone() { GreyFoxEventCollection clonedGreyFoxEvent = new GreyFoxEventCollection(count); lock (this) { foreach (GreyFoxEvent item in this) { clonedGreyFoxEvent.Add(item); } } return(clonedGreyFoxEvent); }
/// <summary> /// Makes a deep copy of the current GreyFoxEvent. /// </summary> /// <param name="isolation">Placeholders are used to isolate the /// items in the GreyFoxEventCollection from their children.</param> public GreyFoxEventCollection Copy(bool isolated) { GreyFoxEventCollection isolatedCollection = new GreyFoxEventCollection(count); lock (this) { if (isolated) { for (int i = 0; i < count; i++) { isolatedCollection.Add(GreyFoxEventArray[i].NewPlaceHolder()); } } else { for (int i = 0; i < count; i++) { isolatedCollection.Add(GreyFoxEventArray[i].Copy()); } } } return(isolatedCollection); }
public GreyFoxEventCollection GetCollection(int topCount, string whereClause, string sortClause, params GreyFoxEventFlags[] optionFlags) { StringBuilder query; Database database; DbCommand dbCommand; IDataReader r; GreyFoxEventCollection greyFoxEventCollection; int innerJoinOffset; query = new StringBuilder("SELECT "); if (topCount > 0) { query.Append("TOP "); query.Append(topCount); query.Append(" "); } foreach (string columnName in InnerJoinFields) { query.Append("GreyFoxEvent."); query.Append(columnName); query.Append(","); } innerJoinOffset = InnerJoinFields.GetUpperBound(0) + 1; int userOffset = -1; int userContactOffset = -1; // // Append Option Flag Fields // if (optionFlags != null) { for (int x = 0; x < optionFlags.Length; x++) { switch (optionFlags[x]) { case GreyFoxEventFlags.User: for (int i = 0; i <= GreyFoxUserManager.InnerJoinFields.GetUpperBound(0); i++) { query.Append("User."); query.Append(GreyFoxUserManager.InnerJoinFields[i]); query.Append(","); } userOffset = innerJoinOffset; innerJoinOffset = userOffset + GreyFoxUserManager.InnerJoinFields.GetUpperBound(0) + 1; break; case GreyFoxEventFlags.UserContact: for (int i = 0; i <= GreyFoxContactManager.InnerJoinFields.GetUpperBound(0); i++) { query.Append("User_Contact."); query.Append(GreyFoxContactManager.InnerJoinFields[i]); query.Append(","); } userContactOffset = innerJoinOffset; innerJoinOffset = userContactOffset + GreyFoxContactManager.InnerJoinFields.GetUpperBound(0) + 1; break; } } } // // Remove trailing comma // query.Length--; if (optionFlags != null) { query.Append(" FROM "); // // Start INNER JOIN expressions // for (int x = 0; x < optionFlags.Length; x++) { query.Append("("); } query.Append(tableName); query.Append(" AS GreyFoxEvent"); } else { query.Append(" FROM "); query.Append(tableName); query.Append(" AS GreyFoxEvent"); } // // Finish INNER JOIN expressions // if (optionFlags != null) { for (int x = 0; x < optionFlags.Length; x++) { switch (optionFlags[x]) { case GreyFoxEventFlags.User: query.Append(" LEFT JOIN sysGlobal_Users ON "); query.Append(tableName); query.Append(" AS GreyFoxEvent"); query.Append(".UserID = GreyFoxEvent.ID)"); break; case GreyFoxEventFlags.UserContact: query.Append(" LEFT JOIN sysGlobal_Contacts AS User_Contact ON User.ContactID = User_Contact.GreyFoxContactID)"); break; } } } // // Render where clause // if (whereClause != string.Empty) { query.Append(" WHERE "); query.Append(whereClause); } // // Render sort clause // if (sortClause != string.Empty) { query.Append(" ORDER BY "); query.Append(sortClause); } // // Render final semicolon // query.Append(";"); database = DatabaseFactory.CreateDatabase(); dbCommand = database.GetSqlStringCommand(query.ToString()); #if DEBUG try { r = database.ExecuteReader(dbCommand); } catch (Exception e) { string msg = e.Message; throw(new Exception(msg + " --- Query: " + query.ToString())); } #else r = database.ExecuteReader(dbCommand); #endif greyFoxEventCollection = new GreyFoxEventCollection(); while (r.Read()) { GreyFoxEvent greyFoxEvent = ParseFromReader(tableName, r, 0, 1); // Fill User if (userOffset != -1 && !r.IsDBNull(userOffset)) { GreyFoxUserManager.FillFromReader(greyFoxEvent.user, r, userOffset, userOffset + 1); // Fill if (userContactOffset != -1 && !r.IsDBNull(userContactOffset)) { GreyFoxContactManager.FillFromReader(greyFoxEvent.user.Contact, "sysGlobal_Contacts", r, userContactOffset, userContactOffset + 1); } } greyFoxEventCollection.Add(greyFoxEvent); } // Microsoft DAAB still needs to close readers. r.Close(); return(greyFoxEventCollection); }