Exemple #1
0
 /// <summary>
 /// Merges two tags with the same tag name by merging the tagged paths in each tag
 /// </summary>
 /// <param name="current">The <see cref="Tag">Tag</see> object that represents the current tag</param>
 /// <param name="newTag">The <see cref="Tag">Tag</see> object that represents the new tag</param>
 /// <returns>true if the tags are merged, false if the tags have different tag name or 
 /// same last updated date or different last updated date</returns>
 private static bool MergeTag(Tag current, Tag newTag)
 {
     if (!newTag.TagName.ToLower().Equals(current.TagName.ToLower()))
     {
         //Since Tag name is different , do not merge.
         //Should not Happen.
         return false;
     }
     if (newTag.LastUpdatedDate == current.LastUpdatedDate)
     {
         //Since Tag updated time is same , shall not do anything
         return false;
     }
     else
     {//Since time different , merge.
         //if new Tag is deleted and current is not
         if (newTag.IsDeleted && !current.IsDeleted)
         {
             //delete only if deleted date is more than created date.
             if (newTag.DeletedDate > current.CreatedDate)
             {
                 ServiceLocator.LogicLayerNotificationQueue().Enqueue(new RemoveTagNotification(newTag));
                 return true;
             }
             //do nothing
             return false;
         }
         //for each taggedPath found in the new Tag.
         //if the path is not found , just create
         //if the path is found , attempt to merge.
         if (current.IsDeleted && !newTag.IsDeleted)
         {
             if (newTag.CreatedDate > current.DeletedDate)
             {
                 TaggingLayer.Instance.AddTag(newTag);
                 ServiceLocator.LogicLayerNotificationQueue().Enqueue(new AddTagNotification(newTag));
                 return true;
             }
         }
         foreach (TaggedPath newPath in newTag.UnfilteredPathList)
         {
             TaggedPath currentPath = current.FindPath(newPath.PathName, false);
             if (currentPath == null)
             {
                 ServiceLocator.LogicLayerNotificationQueue().Enqueue(new MonitorPathNotification(current,newPath));
                 current.AddPath(newPath);
             }
             else
             {
                 //update only if the new path is more updated than the current path
                 if (currentPath.LastUpdatedDate <= newPath.LastUpdatedDate)
                 {
                     //if the path is delete in the new tag but not in the old tag
                     if (newPath.IsDeleted && !currentPath.IsDeleted)
                     {
                         if (newPath.DeletedDate > currentPath.CreatedDate)
                         {
                             current.RemovePath(newPath);
                             ServiceLocator.LogicLayerNotificationQueue().Enqueue(new UnMonitorPathNotification(current,newPath));
                         }
                     }
                     else if (!newPath.IsDeleted && currentPath.IsDeleted)
                     {
                         if (newPath.CreatedDate > currentPath.DeletedDate)
                         {
                             //a new path is created in the new tag but is deleted in the old tag.
                             current.AddPath(newPath);
                             ServiceLocator.LogicLayerNotificationQueue().Enqueue(new MonitorPathNotification(current,newPath));
                         }
                     }
                 }
             }
         }
     }
     return true;
 }
Exemple #2
0
 /// <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;
             }
         }
     }
 }