示例#1
0
        /// <summary>
        /// Makes a deep copy of the current YariMediaKeyword.
        /// </summary>
        /// <returns> A new YariMediaKeyword object reflecting the cloned YariMediaKeyword object.</returns>
        public YariMediaKeyword Copy()
        {
            YariMediaKeyword yariMediaKeyword = new YariMediaKeyword();

            CopyTo(yariMediaKeyword);
            return(yariMediaKeyword);
        }
示例#2
0
 /// <summary>
 /// Deep copies the current YariMediaKeyword to another instance of YariMediaKeyword.
 /// </summary>
 /// <param name="YariMediaKeyword">The YariMediaKeyword to copy to.</param>
 /// <param name="isolation">Placeholders are used to isolate the YariMediaKeyword from its children.</param>
 public void CopyTo(YariMediaKeyword yariMediaKeyword, bool isolation)
 {
     yariMediaKeyword.iD            = iD;
     yariMediaKeyword.isPlaceHolder = isPlaceHolder;
     yariMediaKeyword.isSynced      = isSynced;
     yariMediaKeyword.keyword       = keyword;
 }
示例#3
0
        /// <summary>
        /// Makes a deep copy of the current YariMediaKeyword.
        /// </summary>
        /// <returns> A new YariMediaKeyword object reflecting the cloned YariMediaKeyword object.</returns>
        /// <param name="isolation">Placeholders are used to isolate the YariMediaKeyword from its children.</param>
        public YariMediaKeyword Copy(bool isolation)
        {
            YariMediaKeyword yariMediaKeyword = new YariMediaKeyword();

            CopyTo(yariMediaKeyword, isolation);
            return(yariMediaKeyword);
        }
示例#4
0
        public static YariMediaKeyword ParseFromReader(IDataReader r, int idOffset, int dataOffset)
        {
            YariMediaKeyword yariMediaKeyword = new YariMediaKeyword();

            FillFromReader(yariMediaKeyword, r, idOffset, dataOffset);
            return(yariMediaKeyword);
        }
示例#5
0
        internal static bool _fill(YariMediaKeyword yariMediaKeyword)
        {
            StringBuilder query;
            Database      database;
            DbCommand     dbCommand;

            query = new StringBuilder("SELECT ");
            query.Append(string.Join(",", InnerJoinFields));
            query.Append(" FROM kitYari_MediaKeywords WHERE YariMediaKeywordID=");
            query.Append(yariMediaKeyword.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 YariMediaKeywordID '{0}'.",
                                                  yariMediaKeyword.iD)));
            }

            FillFromReader(yariMediaKeyword, r, 0, 1);

            return(true);
        }
示例#6
0
        /// <summary>
        /// Fills the {0} from a OleIDataReader.
        /// </summary>
        public static void FillFromReader(YariMediaKeyword yariMediaKeyword, IDataReader r, int idOffset, int dataOffset)
        {
            yariMediaKeyword.iD            = r.GetInt32(idOffset);
            yariMediaKeyword.isSynced      = true;
            yariMediaKeyword.isPlaceHolder = false;

            yariMediaKeyword.keyword = r.GetString(0 + dataOffset);
        }
示例#7
0
        private static void fillParameters(Database database, DbCommand dbCommand, YariMediaKeyword yariMediaKeyword)
        {
            #region Default

            addParameter(database, dbCommand, "Keyword", DbType.String, yariMediaKeyword.keyword);

            #endregion
        }
示例#8
0
        /// <summary>
        /// Duplicates YariMediaKeyword object into a database; may or may not be the same database
        /// as the parent object.
        /// </summary>
        /// <returns> A new YariMediaKeyword object reflecting the replicated YariMediaKeyword object.</returns>
        public YariMediaKeyword Duplicate()
        {
            YariMediaKeyword clonedYariMediaKeyword = this.Clone();

            // Insert must be called after children are replicated!
            clonedYariMediaKeyword.iD       = YariMediaKeywordManager._insert(clonedYariMediaKeyword);
            clonedYariMediaKeyword.isSynced = true;
            return(clonedYariMediaKeyword);
        }
示例#9
0
        public static YariMediaKeyword NewPlaceHolder(int iD)
        {
            YariMediaKeyword yariMediaKeyword = new YariMediaKeyword();

            yariMediaKeyword.iD            = iD;
            yariMediaKeyword.isPlaceHolder = true;
            yariMediaKeyword.isSynced      = true;
            return(yariMediaKeyword);
        }
示例#10
0
        public bool Equals(YariMediaKeyword yariMediaKeyword)
        {
            if (yariMediaKeyword == null)
            {
                return(false);
            }

            return(this.iD == yariMediaKeyword.iD);
        }
示例#11
0
        /// <summary>
        /// Clones YariMediaKeyword object and clones child objects with cloning or replication.
        /// as the parent object.
        /// </summary>
        /// <returns> A new YariMediaKeyword object reflecting the replicated YariMediaKeyword object.</returns>
        public YariMediaKeyword Clone()
        {
            YariMediaKeyword clonedYariMediaKeyword = new YariMediaKeyword();

            clonedYariMediaKeyword.iD       = iD;
            clonedYariMediaKeyword.isSynced = isSynced;
            clonedYariMediaKeyword.keyword  = keyword;


            return(clonedYariMediaKeyword);
        }
示例#12
0
        public void Remove(YariMediaKeyword value)
        {
            OnCollectionChanged(EventArgs.Empty);
            int index = IndexOf(value);

            if (index == -1)
            {
                throw(new Exception("YariMediaKeyword not found in collection."));
            }
            RemoveAt(index);
        }
示例#13
0
 public int Add(YariMediaKeyword value)
 {
     OnCollectionChanged(EventArgs.Empty);
     lock (this)
     {
         count++;
         ensureArrays();
         addIndexKey(value.ID);
         YariMediaKeywordArray[count - 1] = value;
         return(count - 1);
     }
 }
示例#14
0
 public void Add(YariMediaKeyword yariMediaKeyword, TimeSpan slidingExpiration)
 {
     lock (this)
     {
         count++;
         ensureArrays();
         yariMediaKeywordArray[count - 1] = yariMediaKeyword;
         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(YariMediaKeyword value)
 {
     lock (this)
     {
         for (int x = 0; x < count; x++)
         {
             if (YariMediaKeywordArray[x].Equals(value))
             {
                 return(x);
             }
         }
     }
     return(-1);
 }
示例#16
0
 public void Insert(int index, YariMediaKeyword value)
 {
     OnCollectionChanged(EventArgs.Empty);
     lock (this)
     {
         count++;
         ensureArrays();
         addIndexKey(value.ID);
         for (int x = index + 1; x == count - 2; x++)
         {
             YariMediaKeywordArray[x] = YariMediaKeywordArray[x - 1];
         }
         YariMediaKeywordArray[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 > YariMediaKeywordArray.GetUpperBound(0) + 1)
     {
         int[,] tempIndex = new int[count * 2, 2];
         YariMediaKeyword[] tempYariMediaKeywordArray = new YariMediaKeyword[count * 2];
         for (int x = 0; x <= YariMediaKeywordArray.GetUpperBound(0); x++)
         {
             tempIndex[x, 0] = index[x, 0];                           // Copy ID
             tempIndex[x, 1] = index[x, 1];                           // Copy Location
             tempYariMediaKeywordArray[x] = YariMediaKeywordArray[x]; // Copy Object
         }
         index = tempIndex;
         YariMediaKeywordArray = tempYariMediaKeywordArray;
     }
 }
示例#18
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 > yariMediaKeywordArray.GetUpperBound(0) + 1)
     {
         YariMediaKeyword[] tempYariMediaKeywordArray = new YariMediaKeyword[count * 2];
         DateTime[]         tempTimeStamps            = new DateTime[count * 2];
         DateTime[]         tempAbsoluteExpirations   = new DateTime[count * 2];
         TimeSpan[]         tempSlidingExpirations    = new TimeSpan[count * 2];
         Array.Copy(yariMediaKeywordArray, tempYariMediaKeywordArray, count - 1);
         Array.Copy(timeStamps, tempTimeStamps, count - 1);
         Array.Copy(absoluteExpirations, tempAbsoluteExpirations, count - 1);
         Array.Copy(slidingExpirations, tempSlidingExpirations, count - 1);
         yariMediaKeywordArray = tempYariMediaKeywordArray;
         timeStamps            = tempTimeStamps;
         absoluteExpirations   = tempAbsoluteExpirations;
         slidingExpirations    = tempSlidingExpirations;
     }
 }
示例#19
0
 public int Add(YariMediaKeyword value)
 {
     OnCollectionChanged(EventArgs.Empty);
     lock (this)
     {
         count++;
         // Resize the array if the count is greater than the length
         // of the array.
         if (count > YariMediaKeywordArray.GetUpperBound(0) + 1)
         {
             YariMediaKeyword[] tempYariMediaKeywordArray = new YariMediaKeyword[count * 2];
             Array.Copy(YariMediaKeywordArray, tempYariMediaKeywordArray, count - 1);
             YariMediaKeywordArray = tempYariMediaKeywordArray;
         }
         YariMediaKeywordArray[count - 1] = value;
     }
     return(count - 1);
 }
示例#20
0
        internal static int _update(YariMediaKeyword yariMediaKeyword)
        {
            Database  database;
            DbCommand dbCommand;

            database = DatabaseFactory.CreateDatabase();

            dbCommand = database.GetSqlStringCommand("UPDATE kitYari_MediaKeywords SET Keyword=@Keyword WHERE YariMediaKeywordID=@YariMediaKeywordID;");

            fillParameters(database, dbCommand, yariMediaKeyword);
            database.AddInParameter(dbCommand, "YariMediaKeywordID", DbType.Int32, yariMediaKeyword.iD);
            // Abandon remaining updates if no rows have been updated by returning false immediately.
            if (database.ExecuteNonQuery(dbCommand) == 0)
            {
                return(-1);
            }

            return(yariMediaKeyword.iD);
        }
示例#21
0
        //--- Begin Custom Code ---

        public YariMediaKeyword FindByKeyword(string keyword, bool placeHolderOnly)
        {
            StringBuilder query = new StringBuilder();

            query.Append("SELECT ");
            if (placeHolderOnly)
            {
                query.Append(InnerJoinFields[0]);
            }
            else
            {
                query.Append(string.Join(",", InnerJoinFields));
            }
            query.Append(" FROM kitYari_MediaKeywords");
            query.Append(" WHERE Keyword=@Keyword;");

            Database  database  = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = database.GetSqlStringCommand(query.ToString());

            addParameter(database, dbCommand, "Keyword", DbType.String, keyword);
            IDataReader      r = database.ExecuteReader(dbCommand);
            YariMediaKeyword k;

            if (r.Read())
            {
                if (placeHolderOnly)
                {
                    k = YariMediaKeyword.NewPlaceHolder(r.GetInt32(0));
                }
                else
                {
                    k = YariMediaKeywordManager.ParseFromReader(r, 0, 1);
                }
            }
            else
            {
                k         = new YariMediaKeyword();
                k.Keyword = keyword;
            }
            return(k);
        }
示例#22
0
 public void Insert(int index, YariMediaKeyword value)
 {
     OnCollectionChanged(EventArgs.Empty);
     lock (this)
     {
         count++;
         // Resize the array if the count is greater than the length
         // of the array.
         if (count > YariMediaKeywordArray.GetUpperBound(0) + 1)
         {
             YariMediaKeyword[] tempYariMediaKeywordArray = new YariMediaKeyword[count * 2];
             Array.Copy(YariMediaKeywordArray, tempYariMediaKeywordArray, count - 1);
             YariMediaKeywordArray = tempYariMediaKeywordArray;
         }
         for (int x = index + 1; x == count - 2; x++)
         {
             YariMediaKeywordArray[x] = YariMediaKeywordArray[x - 1];
         }
         YariMediaKeywordArray[index] = value;
     }
 }
示例#23
0
 public void CheckedAdd(YariMediaKeyword yariMediaKeyword, TimeSpan slidingExpiration)
 {
     lock (this)
     {
         int i = binarySearch(yariMediaKeyword.iD);
         if (i != -1)
         {
             yariMediaKeywordArray[i] = yariMediaKeyword;
             absoluteExpirations[i]   = DateTime.Now.Add(slidingExpiration); // Expires
             slidingExpirations[i]    = slidingExpiration;                   // Never slides
             return;
         }
         count++;
         ensureArrays();
         yariMediaKeywordArray[count - 1] = yariMediaKeyword;
         timeStamps[count - 1]            = DateTime.Now;
         absoluteExpirations[count - 1]   = DateTime.Now.Add(slidingExpiration); // Expires
         slidingExpirations[count - 1]    = slidingExpiration;                   // Never slides
         quickSort(0, count - 1);
     }
 }
示例#24
0
        /// <summary>
        /// Inserts a YariMediaKeyword 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="_YariMediaKeyword">The YariMediaKeyword to insert into the database.</param>
        internal static int _insert(YariMediaKeyword yariMediaKeyword)
        {
            int       id;
            string    query;
            Database  database;
            DbCommand dbCommand;

            database = DatabaseFactory.CreateDatabase();

            query = "INSERT INTO kitYari_MediaKeywords " +
                    "(" +
                    "Keyword) VALUES (" +
                    "@Keyword);";

            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, yariMediaKeyword);
                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, yariMediaKeyword);
                database.AddOutParameter(dbCommand, "@LastID", DbType.Int32, 10);
                database.ExecuteNonQuery(dbCommand);
                id = (int)dbCommand.Parameters["@LastID"].Value;
            }
            return(id);
        }
示例#25
0
 /// <summary>
 /// Compares the object's ID to another object's ID.
 /// </summary>
 public int CompareTo(YariMediaKeyword yariMediaKeyword)
 {
     return(this.iD - yariMediaKeyword.iD);
 }
示例#26
0
        /// <summary>
        /// Compares the object's ID to another object's ID.
        /// </summary>
        int IComparable.CompareTo(object obj)
        {
            YariMediaKeyword yariMediaKeyword = (YariMediaKeyword)obj;

            return(this.iD - yariMediaKeyword.iD);
        }
示例#27
0
        public YariMediaKeywordCollection GetCollection(int topCount, string whereClause, string sortClause)
        {
            StringBuilder query;
            Database      database;
            DbCommand     dbCommand;
            IDataReader   r;
            YariMediaKeywordCollection yariMediaKeywordCollection;


            query = new StringBuilder("SELECT ");

            if (topCount > 0)
            {
                query.Append("TOP ");
                query.Append(topCount);
                query.Append(" ");
            }

            foreach (string columnName in InnerJoinFields)
            {
                query.Append("kitYari_MediaKeywords.");
                query.Append(columnName);
                query.Append(",");
            }

            //
            // Remove trailing comma
            //
            query.Length--;
            query.Append(" FROM kitYari_MediaKeywords ");
            //
            // 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

            yariMediaKeywordCollection = new YariMediaKeywordCollection();

            while (r.Read())
            {
                YariMediaKeyword yariMediaKeyword = ParseFromReader(r, 0, 1);

                yariMediaKeywordCollection.Add(yariMediaKeyword);
            }

            return(yariMediaKeywordCollection);
        }
示例#28
0
 /// <summary>
 /// Deep copies the current YariMediaKeyword to another instance of YariMediaKeyword.
 /// This method does not provide isolated copies; use overriden method for this feature.
 /// </summary>
 /// <param name="YariMediaKeyword">The YariMediaKeyword to copy to.</param>
 public void CopyTo(YariMediaKeyword yariMediaKeyword)
 {
     CopyTo(yariMediaKeyword, false);
 }
示例#29
0
 public bool Contains(YariMediaKeyword value)
 {
     return(IndexOf(value) != -1);
 }