//Read in all of the TagTypes, //create TagType objects for them, and puts them in a lookup table public Dictionary<string, TagType> readTagTypes() { Dictionary<string, TagType> list = new Dictionary<string, TagType>(); TagType newType; foreach (XmlElement node in tagTypeRoot.ChildNodes) { newType = new TagType(int.Parse(node.GetAttribute("dataType")), node.GetAttribute("name")); list.Add(newType.name, newType); } return list; }
//Remove the specified TagType from the XML file //this will orphan any remaining tags of this type! public void removeTagType( TagType tagType ) { //loop through each node, remove the correct one if it exists foreach (XmlElement node in tagTypeRoot.ChildNodes) { if (node.GetAttribute("name").Equals(tagType.name)) { tagTypeRoot.RemoveChild(node); } } //save! tagTypeDoc.Save(FILE_TAGTYPE); }
//Creates a TagType in the XML file public void writeTagType( TagType tagType ) { bool found = false; //loop through every node, try to find one with the same name foreach (XmlElement node in tagTypeRoot.ChildNodes) { if (node.GetAttribute("name").Equals(tagType.name)) { //found it, change the dataType node.SetAttribute("dataType", tagType.dataType.ToString()); found = true; } } //if we didn't find it before, make one if (found != true) { //make a new node XmlElement newType = tagTypeDoc.CreateElement("type"); newType.SetAttribute("name", tagType.name); newType.SetAttribute("dataType", tagType.dataType.ToString()); //insert as last node in the root tag tagTypeDoc.LastChild.AppendChild(newType); //tagTypeDoc.LastChild.InsertAfter(newType, tagTypeDoc.LastChild.LastChild); } //save! tagTypeDoc.Save(FILE_TAGTYPE); }
/// <summary> /// Returns a list of all TagType objects in the tag type reference file specified /// in Constants.FILE_TAGTYPES. /// </summary> /// <returns>A TagType list in <![CDATA[Dictionary<string name, TagType tagType>]]> format where /// "name" is the name of the TagType object, and tagType is the TagType object.</returns> public Dictionary<string, TagType> readTagTypes() { Dictionary<string, TagType> list = new Dictionary<string, TagType>(); TagType newType; //add a new tag type for every TagType object in the tagTypes reference file. foreach (XmlElement node in tagTypeRoot.ChildNodes) { newType = new TagType(int.Parse(node.GetAttribute("dataType")), node.GetAttribute("name")); list.Add(newType.name, newType); } return list; }
/// <summary> /// Create a new Tag object with the specified TagType and value. /// </summary> /// <param name="type">The TagType of the image.</param> /// <param name="val">The value of the tag applied to an image.</param> public Tag( TagType type, object val ) { _tagType = type; _tagValue = val; }
/// <summary> /// Returns a list of all images which have a Tag of TagType.dataType Constants.DATATYPE_INT, /// whose value, on the interval [lowerBound, upperBound]. /// </summary> /// <param name="type">The TagType of the Tag to be searched for.</param> /// <param name="lowerBound">The lower boundary on the search.</param> /// <param name="upperBound">The upper boundary on the search.</param> /// <returns>The ArrayList of images in <![CDATA[KeyValuePair<string name, SourceImage image>]]> /// format that match the search criteria.</returns> public ArrayList sortTags( TagType type, int? lowerBound, int? upperBound ) { Dictionary<string, SourceImage> imagesWithTags = searchTags(type); SortedList< string, SourceImage > sortedList = new SortedList<string, SourceImage>(); if (lowerBound == null) { lowerBound = int.MinValue; } if (upperBound == null) { upperBound = int.MaxValue; } //add each element which is on the interval foreach (KeyValuePair<string, SourceImage> kvp in imagesWithTags) { if (int.Parse(tagList[kvp.Key][type.name].tagValue.ToString()) > lowerBound && int.Parse(tagList[kvp.Key][type.name].tagValue.ToString()) < upperBound) { sortedList.Add(kvp.Key, kvp.Value); } } return new ArrayList( sortedList ); }
/// <summary> /// Returns a list of all images which have a Tag of TagType.dataType Constants.DATATYPE_DATE, /// whose value, on the interval [lowerBound, upperBound]. /// </summary> /// <param name="type">The TagType of the Tag to be searched for.</param> /// <param name="lowerBound">The lower boundary on the search.</param> /// <param name="upperBound">The upper boundary on the search.</param> /// <returns>The ArrayList of images in <![CDATA[KeyValuePair<string name, SourceImage image>]]> /// format that match the search criteria.</returns> public ArrayList sortTags( TagType type, DateTime lowerBound, DateTime upperBound ) { Dictionary<string, SourceImage> imagesWithTags = searchTags(type); SortedList< string, SourceImage > sortedList = new SortedList<string, SourceImage>(); foreach(KeyValuePair<string, SourceImage> kvp in imagesWithTags) { if(DateTime.Parse(tagList[kvp.Key][type.name].tagValue.ToString()).CompareTo(lowerBound) > 0 && DateTime.Parse(tagList[kvp.Key][type.name].tagValue.ToString()).CompareTo(upperBound) < 0) { sortedList.Add(kvp.Key, kvp.Value); } } return new ArrayList( sortedList ); }
//Return a list of all images which have the specified TagType private Dictionary<string, SourceImage> searchTags( TagType type ) { Dictionary<string, SourceImage> imageList = imageOrganizer.getImageMap(); Dictionary<string, SourceImage> imagesWithTags = new Dictionary<string, SourceImage>(); foreach( KeyValuePair<string, SourceImage> kvp in imageList ) { if( tagList.ContainsKey( kvp.Key ) && tagList[kvp.Key].ContainsKey( type.name ) ) { imagesWithTags.Add( kvp.Key, kvp.Value ); } } return imagesWithTags; }
/// <summary> /// Returns a list of all images which have a Tag of TagType.dataType Constants.DATATYPE_STRING, /// whose value contains the specified search string. /// </summary> /// <param name="type">The TagType of the Tag to be searched for.</param> /// <param name="searchPattern">The string to be searched for.</param> /// <returns>The ArrayList of images in <![CDATA[KeyValuePair<string name, SourceImage image>]]> /// format that match the search criteria.</returns> public ArrayList sortTags( TagType type, string searchPattern ) { Dictionary<string, SourceImage> imagesWithTags = searchTags( type ); SortedList< string, SourceImage > sortedList = new SortedList<string, SourceImage>(); foreach(KeyValuePair<string, SourceImage> kvp in imagesWithTags) { if(tagList[kvp.Key][type.name].tagValue.ToString().Contains(searchPattern) == true) { sortedList.Add(kvp.Key, kvp.Value); } } return new ArrayList( sortedList ); }
/// <summary> /// Adds a new TagType to the system, and calls TagFactory to add it to the /// reference file. /// </summary> /// <param name="name">The name of the TagType to be created.</param> /// <param name="dataType">The datatype of the TagType to be created.</param> public void addTagType( string name, int dataType ) { TagType newTagType = new TagType(dataType, name); tagTypeList.Add(name, newTagType); tagFactory.writeTagType(newTagType); }
//used to search for a date public ArrayList sortTags( TagType type, DateTime lowerBound, DateTime upperBound ) { ArrayList imageList = searchTags(type); foreach (string imageName in imageList) { if (DateTime.Parse(tagList[imageName][type.name].tagValue.ToString()).CompareTo(lowerBound) < 0 || DateTime.Parse(tagList[imageName][type.name].tagValue.ToString()).CompareTo(upperBound) > 0) { imageList.Remove(imageName); } } imageList.Sort(); return imageList; }
//used to search for a string value //recall, (int?) is a nullable int //results will be ascending order public ArrayList sortTags( TagType type, int? lowerBound, int? upperBound ) { ArrayList imageList = searchTags(type); if (lowerBound == null) { lowerBound = int.MinValue; } if (upperBound == null) { upperBound = int.MaxValue; } foreach (string imageName in imageList) { if (int.Parse(tagList[imageName][type.name].tagValue.ToString()) < lowerBound || int.Parse(tagList[imageName][type.name].tagValue.ToString()) > upperBound) { imageList.Remove(imageName); } } imageList.Sort(); return imageList; }
//search for a partial string //results will be alpha-ordered public ArrayList sortTags( TagType type, string searchPattern ) { ArrayList imageList = searchTags( type ); foreach (string imageName in imageList) { if (tagList[imageName][type.name].tagValue.ToString().Contains(searchPattern) != true) { imageList.Remove(imageName); } } imageList.Sort(); return imageList; }
public ArrayList searchTags( TagType type ) { ArrayList imageList = new ArrayList(); //cycle through all images foreach (KeyValuePair<string, Dictionary<string, Tag>> kvp in tagList) { //if the image has a tag with the correct name, return it. if (kvp.Value.ContainsKey(type.name)) { imageList.Add(kvp.Key); } } return imageList; }