/// <summary> /// Sets the name of a folder path name that is the same as the old path name to the new path /// name that is passed as parameter /// </summary> /// <param name="oldpath">The string value that represents the old name of a folder path</param> /// <param name="newpath">The string value that represents the new name of a folder path</param> /// <returns>the number of folder paths whose old name is replaced by the new name</returns> public int RenameFolder(string oldpath, string newpath) { int renamedCount = 0; foreach (Tag tag in _tagList) { if (tag.ContainsParent(oldpath)) { if (!tag.ContainsParent(newpath)) { CurrentTime current = new CurrentTime(); renamedCount += tag.RenamePath(oldpath, newpath, current.CurrentTimeLong); _lastUpdatedDate = current.CurrentTimeLong; } } } return renamedCount; }
/// <summary> /// Replaces the original list of filters with an updated list of filters /// </summary> /// <param name="updatedList">The list of filters that is more updated</param> private void UpdateFilterList(List<Filter> updatedList) { CurrentTime current = new CurrentTime(); _filters = updatedList; _filtersUpdatedDate = current.CurrentTimeLong; _lastUpdatedDate = current.CurrentTimeLong; }
/// <summary> /// Untags a folder path from all tags where the folder path is tagged to /// </summary> /// <param name="path">The string value that represents the path of the folder to be untagged</param> /// <returns>the number of tags the path is untagged from</returns> public int UntagFolder(string path) { int noOfPath = 0; CurrentTime current = new CurrentTime(); foreach (Tag tag in _tagList) { if (tag.Contains(path)) { if (tag.RemovePath(path, current.CurrentTimeLong)) { _lastUpdatedDate = current.CurrentTimeLong; noOfPath++; } } } return noOfPath; }
/// <summary> /// Untags a folder path from a tag with name same as the tag name that is passed as parameter /// </summary> /// <param name="path">The string value that represents the path of the folder to be untagged</param> /// <param name="tagname">The string value that represents the name of the tag the folder path is /// to be untagged from</param> /// <returns>1 if the path is removed, 0 if the path is not found in the Tag, -1 if the name that /// is passed as parameter is not used by any tag in the existing list of tags</returns> public int UntagFolder(string path, string tagname) { Tag tag = FindTag(tagname); if (tag != null) { CurrentTime current = new CurrentTime(); if (tag.RemovePath(path, current.CurrentTimeLong)) { _lastUpdatedDate = current.CurrentTimeLong; return 1; } else { return 0; } } else { return -1; } }
/// <summary> /// Tags a folder path to a tag with name same as the tag name that is passed as parameter /// </summary> /// <param name="path">The string value that represents the path of the folder to be tagged</param> /// <param name="tagname">The string value that represents the name of the tag the folder path is /// to be tagged to</param> /// <returns>the tag where the folder path is tagged to</returns> /// <exception cref="PathAlreadyExistsException">thrown if the folder path that is passed as /// parameter is already tagged to the tag</exception> /// <exception cref="RecursiveDirectoryException">thrown if the folder path that is passed as /// parameter is a parent path or a child path of another path that is already tagged to /// the tag</exception> public Tag TagFolder(string path, string tagname) { CurrentTime current = new CurrentTime(); Tag toTag = FindTag(tagname); if (toTag == null) { Tag tag = new Tag(tagname, current.CurrentTimeLong); tag.AddPath(path, current.CurrentTimeLong); lock (TagList) { _tagList.Add(tag); } _lastUpdatedDate = current.CurrentTimeLong; return tag; } else { if (toTag.IsDeleted) { lock (TagList) { _tagList.Remove(toTag); } Tag tag = new Tag(tagname, current.CurrentTimeLong); tag.AddPath(path, current.CurrentTimeLong); lock (TagList) { _tagList.Add(tag); } _lastUpdatedDate = current.CurrentTimeLong; return tag; } else { if (toTag.Contains(path)) { throw new PathAlreadyExistsException(path); } else if (TaggingHelper.CheckRecursiveDirectory(toTag, path)) { throw new RecursiveDirectoryException(path, tagname); } else { toTag.AddPath(path, current.CurrentTimeLong); _lastUpdatedDate = current.CurrentTimeLong; return toTag; } } } }
/// <summary> /// Removes the tag that is passed as parameter from the list of tags /// </summary> /// <param name="tag">The <see cref="Tag">Tag</see> object that represents the tag to be removed</param> /// <returns>the tag that is deleted if it is deleted; otherwise, null</returns> public Tag DeleteTag(Tag tag) { Tag toRemove = FindTag(tag.TagName); if (toRemove != null) { if (toRemove.IsDeleted) { return null; } else { CurrentTime updated = new CurrentTime(); toRemove.Remove(updated.CurrentTimeLong); _lastUpdatedDate = updated.CurrentTimeLong; return toRemove; } } else { return null; } }
/// <summary> /// Adds a tag with the tag name that is passed as parameter to the list of tags /// </summary> /// <param name="tagname">The string value that represents the name of the tag to be added</param> /// <returns>the tag if it is added; otherwise, null</returns> public Tag AddTag(string tagname) { Tag t = FindTag(tagname); if (t != null) { if (t.IsDeleted) { CurrentTime current = new CurrentTime(); lock (TagList) { _tagList.Remove(t); } Tag tag = new Tag(tagname, current.CurrentTimeLong); lock (TagList) { _tagList.Add(tag); } _lastUpdatedDate = current.CurrentTimeLong; return tag; } else { return null; } } else { CurrentTime current = new CurrentTime(); Tag tag = new Tag(tagname, current.CurrentTimeLong); lock (TagList) { _tagList.Add(tag); } _lastUpdatedDate = current.CurrentTimeLong; ; return tag; } }