示例#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;
 }