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. } }
/* 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); } }