Ejemplo n.º 1
0
 public MemoryItem GetLastItemByTagList(List <string> tagList)
 {
     if (itemList.Count == 0)
     {
         return(null);
     }
     else
     {
         Monitor.Enter(lockObject);
         int index = 0;
         while (index < itemList.Count)
         {
             MemoryItem item     = itemList[index];
             Boolean    matching = true;
             foreach (string tag in tagList)
             {
                 if (!item.TagList.Contains(tag))
                 {
                     matching = false;
                     break;
                 }
             }
             if (matching)
             {
                 MemoryItem accessedItem = item.Copy();
                 Monitor.Exit(lockObject);
                 return(accessedItem);
             }
             index++;
         }
         Monitor.Exit(lockObject);
         return(null); // No match found.
     }
 }
Ejemplo n.º 2
0
        /*   public MemoryItem GetItemByTag(string tag, DateTime firstAllowedTime)
         * {
         *     if (itemList.Count == 0) { return null; }
         *     else
         *     {
         *         Monitor.Enter(lockObject);
         *         int index = 0;
         *         DateTime dateTime = itemList[index].InsertionTime;
         *         while (dateTime > firstAllowedTime)
         *         {
         *             MemoryItem item = itemList[index];
         *             if (item.TagList.Contains(tag))
         *             {
         *                 MemoryItem accessedItem = item.Copy();
         *                 Monitor.Exit(lockObject);
         *                 return accessedItem;
         *             }
         *             index++;
         *             if (index >= itemList.Count) { break; }
         *             else { dateTime = itemList[index].InsertionTime; }
         *         }
         *         Monitor.Exit(lockObject);
         *         return null;
         *     }
         * }
         *
         * public MemoryItem GetItemByTagList(List<string> tagList, DateTime firstAllowedTime)
         * {
         *     return null; // TBW
         * }  */

        public MemoryItem GetLastItemByTag(string tag)
        {
            if (itemList.Count == 0)
            {
                return(null);
            }
            else
            {
                Monitor.Enter(lockObject);
                int index = 0;
                while (index < itemList.Count)
                {
                    MemoryItem item = itemList[index];
                    if (item.TagList.Contains(tag))
                    {
                        MemoryItem accessedItem = item.Copy();
                        Monitor.Exit(lockObject);
                        return(accessedItem);
                    }
                    index++;
                }
                Monitor.Exit(lockObject);
                return(null);
            }
        }
Ejemplo n.º 3
0
 // Sets the dateTime of the item to the current time (the time of insertion), adds
 // the item, and then triggers the Changed event.
 public void AddItem(MemoryItem addedItem)
 {
     Monitor.Enter(lockObject);
     addedItem.InsertionTime = DateTime.Now;
     itemList.Insert(0, addedItem);
     Monitor.Exit(lockObject);
     OnItemInserted();
 }