public static YariMediaType ParseFromReader(IDataReader r, int idOffset, int dataOffset) { YariMediaType yariMediaType = new YariMediaType(); FillFromReader(yariMediaType, r, idOffset, dataOffset); return(yariMediaType); }
/// <summary> /// Makes a deep copy of the current YariMediaType. /// </summary> /// <returns> A new YariMediaType object reflecting the cloned YariMediaType object.</returns> /// <param name="isolation">Placeholders are used to isolate the YariMediaType from its children.</param> public YariMediaType Copy(bool isolation) { YariMediaType yariMediaType = new YariMediaType(); CopyTo(yariMediaType, isolation); return(yariMediaType); }
/// <summary> /// Deep copies the current YariMediaType to another instance of YariMediaType. /// </summary> /// <param name="YariMediaType">The YariMediaType to copy to.</param> /// <param name="isolation">Placeholders are used to isolate the YariMediaType from its children.</param> public void CopyTo(YariMediaType yariMediaType, bool isolation) { yariMediaType.iD = iD; yariMediaType.isPlaceHolder = isPlaceHolder; yariMediaType.isSynced = isSynced; yariMediaType.name = name; }
internal static bool _fill(YariMediaType yariMediaType) { StringBuilder query; Database database; DbCommand dbCommand; query = new StringBuilder("SELECT "); query.Append(string.Join(",", InnerJoinFields)); query.Append(" FROM kitYari_MediaTypes WHERE YariMediaTypeID="); query.Append(yariMediaType.iD); query.Append(";"); database = DatabaseFactory.CreateDatabase(); dbCommand = database.GetSqlStringCommand(query.ToString()); IDataReader r = database.ExecuteReader(dbCommand); if (!r.Read()) { throw(new Exception(string.Format("Cannot find YariMediaTypeID '{0}'.", yariMediaType.iD))); } FillFromReader(yariMediaType, r, 0, 1); return(true); }
/// <summary> /// Makes a deep copy of the current YariMediaType. /// </summary> /// <returns> A new YariMediaType object reflecting the cloned YariMediaType object.</returns> public YariMediaType Copy() { YariMediaType yariMediaType = new YariMediaType(); CopyTo(yariMediaType); return(yariMediaType); }
/// <summary> /// Fills the {0} from a OleIDataReader. /// </summary> public static void FillFromReader(YariMediaType yariMediaType, IDataReader r, int idOffset, int dataOffset) { yariMediaType.iD = r.GetInt32(idOffset); yariMediaType.isSynced = true; yariMediaType.isPlaceHolder = false; yariMediaType.name = r.GetString(0 + dataOffset); }
private static void fillParameters(Database database, DbCommand dbCommand, YariMediaType yariMediaType) { #region Default addParameter(database, dbCommand, "Name", DbType.String, yariMediaType.name); #endregion }
/// <summary> /// Duplicates YariMediaType object into a database; may or may not be the same database /// as the parent object. /// </summary> /// <returns> A new YariMediaType object reflecting the replicated YariMediaType object.</returns> public YariMediaType Duplicate() { YariMediaType clonedYariMediaType = this.Clone(); // Insert must be called after children are replicated! clonedYariMediaType.iD = YariMediaTypeManager._insert(clonedYariMediaType); clonedYariMediaType.isSynced = true; return(clonedYariMediaType); }
public static YariMediaType NewPlaceHolder(int iD) { YariMediaType yariMediaType = new YariMediaType(); yariMediaType.iD = iD; yariMediaType.isPlaceHolder = true; yariMediaType.isSynced = true; return(yariMediaType); }
public bool Equals(YariMediaType yariMediaType) { if (yariMediaType == null) { return(false); } return(this.iD == yariMediaType.iD); }
public void Remove(YariMediaType value) { OnCollectionChanged(EventArgs.Empty); int index = IndexOf(value); if (index == -1) { throw(new Exception("YariMediaType not found in collection.")); } RemoveAt(index); }
/// <summary> /// Clones YariMediaType object and clones child objects with cloning or replication. /// as the parent object. /// </summary> /// <returns> A new YariMediaType object reflecting the replicated YariMediaType object.</returns> public YariMediaType Clone() { YariMediaType clonedYariMediaType = new YariMediaType(); clonedYariMediaType.iD = iD; clonedYariMediaType.isSynced = isSynced; clonedYariMediaType.name = name; return(clonedYariMediaType); }
public int Add(YariMediaType value) { OnCollectionChanged(EventArgs.Empty); lock (this) { count++; ensureArrays(); addIndexKey(value.ID); YariMediaTypeArray[count - 1] = value; return(count - 1); } }
public void Add(YariMediaType yariMediaType, TimeSpan slidingExpiration) { lock (this) { count++; ensureArrays(); yariMediaTypeArray[count - 1] = yariMediaType; timeStamps[count - 1] = DateTime.Now; absoluteExpirations[count - 1] = DateTime.Now.Add(slidingExpiration); // Never Expires slidingExpirations[count - 1] = slidingExpiration; // Never slides quickSort(0, count - 1); } }
public int IndexOf(YariMediaType value) { lock (this) { for (int x = 0; x < count; x++) { if (YariMediaTypeArray[x].Equals(value)) { return(x); } } return(-1); } }
public void Insert(int index, YariMediaType value) { OnCollectionChanged(EventArgs.Empty); lock (this) { count++; ensureArrays(); addIndexKey(value.ID); for (int x = index + 1; x == count - 2; x++) { YariMediaTypeArray[x] = YariMediaTypeArray[x - 1]; } YariMediaTypeArray[index] = value; } }
/// <summary> /// Ensures that the index and object array are sized correctly /// for additions. This method should be protected by locks /// issued by calling methods. /// </summary> private void ensureArrays() { if (count > YariMediaTypeArray.GetUpperBound(0) + 1) { int[,] tempIndex = new int[count * 2, 2]; YariMediaType[] tempYariMediaTypeArray = new YariMediaType[count * 2]; for (int x = 0; x <= YariMediaTypeArray.GetUpperBound(0); x++) { tempIndex[x, 0] = index[x, 0]; // Copy ID tempIndex[x, 1] = index[x, 1]; // Copy Location tempYariMediaTypeArray[x] = YariMediaTypeArray[x]; // Copy Object } index = tempIndex; YariMediaTypeArray = tempYariMediaTypeArray; } }
public int Add(YariMediaType value) { OnCollectionChanged(EventArgs.Empty); lock (this) { count++; // Resize the array if the count is greater than the length // of the array. if (count > YariMediaTypeArray.GetUpperBound(0) + 1) { YariMediaType[] tempYariMediaTypeArray = new YariMediaType[count * 2]; Array.Copy(YariMediaTypeArray, tempYariMediaTypeArray, count - 1); YariMediaTypeArray = tempYariMediaTypeArray; } YariMediaTypeArray[count - 1] = value; } return(count - 1); }
/// <summary> /// Ensures that the index and object array are sized correctly /// for additions. This method should be protected by locks /// issued by calling methods. /// </summary> private void ensureArrays() { if (count > yariMediaTypeArray.GetUpperBound(0) + 1) { YariMediaType[] tempYariMediaTypeArray = new YariMediaType[count * 2]; DateTime[] tempTimeStamps = new DateTime[count * 2]; DateTime[] tempAbsoluteExpirations = new DateTime[count * 2]; TimeSpan[] tempSlidingExpirations = new TimeSpan[count * 2]; Array.Copy(yariMediaTypeArray, tempYariMediaTypeArray, count - 1); Array.Copy(timeStamps, tempTimeStamps, count - 1); Array.Copy(absoluteExpirations, tempAbsoluteExpirations, count - 1); Array.Copy(slidingExpirations, tempSlidingExpirations, count - 1); yariMediaTypeArray = tempYariMediaTypeArray; timeStamps = tempTimeStamps; absoluteExpirations = tempAbsoluteExpirations; slidingExpirations = tempSlidingExpirations; } }
internal static int _update(YariMediaType yariMediaType) { Database database; DbCommand dbCommand; database = DatabaseFactory.CreateDatabase(); dbCommand = database.GetSqlStringCommand("UPDATE kitYari_MediaTypes SET Name=@Name WHERE YariMediaTypeID=@YariMediaTypeID;"); fillParameters(database, dbCommand, yariMediaType); database.AddInParameter(dbCommand, "YariMediaTypeID", DbType.Int32, yariMediaType.iD); // Abandon remaining updates if no rows have been updated by returning false immediately. if (database.ExecuteNonQuery(dbCommand) == 0) { return(-1); } return(yariMediaType.iD); }
public void Insert(int index, YariMediaType value) { OnCollectionChanged(EventArgs.Empty); lock (this) { count++; // Resize the array if the count is greater than the length // of the array. if (count > YariMediaTypeArray.GetUpperBound(0) + 1) { YariMediaType[] tempYariMediaTypeArray = new YariMediaType[count * 2]; Array.Copy(YariMediaTypeArray, tempYariMediaTypeArray, count - 1); YariMediaTypeArray = tempYariMediaTypeArray; } for (int x = index + 1; x == count - 2; x++) { YariMediaTypeArray[x] = YariMediaTypeArray[x - 1]; } YariMediaTypeArray[index] = value; } }
public void CheckedAdd(YariMediaType yariMediaType, TimeSpan slidingExpiration) { lock (this) { int i = binarySearch(yariMediaType.iD); if (i != -1) { yariMediaTypeArray[i] = yariMediaType; absoluteExpirations[i] = DateTime.Now.Add(slidingExpiration); // Expires slidingExpirations[i] = slidingExpiration; // Never slides return; } count++; ensureArrays(); yariMediaTypeArray[count - 1] = yariMediaType; timeStamps[count - 1] = DateTime.Now; absoluteExpirations[count - 1] = DateTime.Now.Add(slidingExpiration); // Expires slidingExpirations[count - 1] = slidingExpiration; // Never slides quickSort(0, count - 1); } }
/// <summary> /// Inserts a YariMediaType into the database. All children should have been /// saved to the database before insertion. New children will not be /// related to this object in the database. /// </summary> /// <param name="_YariMediaType">The YariMediaType to insert into the database.</param> internal static int _insert(YariMediaType yariMediaType) { int id; string query; Database database; DbCommand dbCommand; database = DatabaseFactory.CreateDatabase(); query = "INSERT INTO kitYari_MediaTypes " + "(" + "Name) VALUES (" + "@Name);"; if (database.ConnectionStringWithoutCredentials.StartsWith("provider=microsoft.jet.oledb.4.0")) { // Microsoft Access // Connection must remain open for IDENTITY to return correct value, // therefore use the dbCommand object's Connection directly to control // connection state. dbCommand = database.GetSqlStringCommand(query); fillParameters(database, dbCommand, yariMediaType); dbCommand.Connection = database.CreateConnection(); dbCommand.Connection.Open(); dbCommand.ExecuteNonQuery(); dbCommand.CommandText = "SELECT @@IDENTITY AS LastID"; id = (int)dbCommand.ExecuteScalar(); dbCommand.Connection.Close(); } else { //// Microsoft SQL Server dbCommand = database.GetSqlStringCommand(query + " SELECT @LastID = SCOPE_IDENTITY();"); fillParameters(database, dbCommand, yariMediaType); database.AddOutParameter(dbCommand, "@LastID", DbType.Int32, 10); database.ExecuteNonQuery(dbCommand); id = (int)dbCommand.Parameters["@LastID"].Value; } return(id); }
public YariMediaTypeCollection GetCollection(int topCount, string whereClause, string sortClause) { StringBuilder query; Database database; DbCommand dbCommand; IDataReader r; YariMediaTypeCollection yariMediaTypeCollection; query = new StringBuilder("SELECT "); if (topCount > 0) { query.Append("TOP "); query.Append(topCount); query.Append(" "); } foreach (string columnName in InnerJoinFields) { query.Append("kitYari_MediaTypes."); query.Append(columnName); query.Append(","); } // // Remove trailing comma // query.Length--; query.Append(" FROM kitYari_MediaTypes "); // // 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 yariMediaTypeCollection = new YariMediaTypeCollection(); while (r.Read()) { YariMediaType yariMediaType = ParseFromReader(r, 0, 1); yariMediaTypeCollection.Add(yariMediaType); } return(yariMediaTypeCollection); }
public bool Contains(YariMediaType value) { return(IndexOf(value) != -1); }
/// <summary> /// Compares the object's ID to another object's ID. /// </summary> public int CompareTo(YariMediaType yariMediaType) { return(this.iD - yariMediaType.iD); }
/// <summary> /// Compares the object's ID to another object's ID. /// </summary> int IComparable.CompareTo(object obj) { YariMediaType yariMediaType = (YariMediaType)obj; return(this.iD - yariMediaType.iD); }
/// <summary> /// Deep copies the current YariMediaType to another instance of YariMediaType. /// This method does not provide isolated copies; use overriden method for this feature. /// </summary> /// <param name="YariMediaType">The YariMediaType to copy to.</param> public void CopyTo(YariMediaType yariMediaType) { CopyTo(yariMediaType, false); }