Пример #1
0
        public static YariMediaType ParseFromReader(IDataReader r, int idOffset, int dataOffset)
        {
            YariMediaType yariMediaType = new YariMediaType();

            FillFromReader(yariMediaType, r, idOffset, dataOffset);
            return(yariMediaType);
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
 /// <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;
 }
Пример #4
0
        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);
        }
Пример #5
0
        /// <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);
        }
Пример #6
0
        /// <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);
        }
Пример #7
0
        private static void fillParameters(Database database, DbCommand dbCommand, YariMediaType yariMediaType)
        {
            #region Default

            addParameter(database, dbCommand, "Name", DbType.String, yariMediaType.name);

            #endregion
        }
Пример #8
0
        /// <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);
        }
Пример #9
0
        public static YariMediaType NewPlaceHolder(int iD)
        {
            YariMediaType yariMediaType = new YariMediaType();

            yariMediaType.iD            = iD;
            yariMediaType.isPlaceHolder = true;
            yariMediaType.isSynced      = true;
            return(yariMediaType);
        }
Пример #10
0
        public bool Equals(YariMediaType yariMediaType)
        {
            if (yariMediaType == null)
            {
                return(false);
            }

            return(this.iD == yariMediaType.iD);
        }
Пример #11
0
        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);
        }
Пример #12
0
        /// <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);
        }
Пример #13
0
 public int Add(YariMediaType value)
 {
     OnCollectionChanged(EventArgs.Empty);
     lock (this)
     {
         count++;
         ensureArrays();
         addIndexKey(value.ID);
         YariMediaTypeArray[count - 1] = value;
         return(count - 1);
     }
 }
Пример #14
0
 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);
     }
 }
Пример #15
0
 public int IndexOf(YariMediaType value)
 {
     lock (this)
     {
         for (int x = 0; x < count; x++)
         {
             if (YariMediaTypeArray[x].Equals(value))
             {
                 return(x);
             }
         }
         return(-1);
     }
 }
Пример #16
0
 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;
     }
 }
Пример #17
0
 /// <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;
     }
 }
Пример #18
0
 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);
 }
Пример #19
0
 /// <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;
     }
 }
Пример #20
0
        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);
        }
Пример #21
0
 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;
     }
 }
Пример #22
0
 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);
     }
 }
Пример #23
0
        /// <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);
        }
Пример #24
0
        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);
        }
Пример #25
0
 public bool Contains(YariMediaType value)
 {
     return(IndexOf(value) != -1);
 }
Пример #26
0
 /// <summary>
 /// Compares the object's ID to another object's ID.
 /// </summary>
 public int CompareTo(YariMediaType yariMediaType)
 {
     return(this.iD - yariMediaType.iD);
 }
Пример #27
0
        /// <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);
        }
Пример #28
0
 /// <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);
 }