예제 #1
0
        /// <summary>
        /// Merges two tagging profiles with the same profile name by merging the tags in each profile
        /// </summary>
        /// <param name="currentProfile">The <see cref="TaggingProfile">TaggingProfile</see> object that
        /// represents the current tagging profile</param>
        /// <param name="newProfile">The <see cref="TaggingProfile">TaggingProfile</see> object that
        /// represents the new tagging profile</param>
        /// <returns>the number of tags merged, -1 if the profiles are null or they have different
        /// profile name</returns>
        public static int MergeProfile(TaggingProfile currentProfile, TaggingProfile newProfile)
        {
            //the number of updates/
            int updateCount = 0;
            //if any of the profile is null.
            if (currentProfile == null || newProfile == null)
            {
                //should not happen. but take care of it anyway.
                return -1;
            }
            //if profile have a different name do not merge
            if (!currentProfile.ProfileName.Equals(newProfile.ProfileName))
            {
                //might want to throw a exception here
                return -1;
            }
            //list of tags from the new profile.
            List<Tag> newTagList = new List<Tag>();
            newTagList.AddRange(newProfile.ReadOnlyTagList);
            List<Tag> monitorList = new List<Tag>();
            foreach (Tag newTag in newTagList)//handles the new tag from new profile
            {
                Tag oldTag = currentProfile.FindTag(newTag.TagName);
                if (oldTag != null)
                {
                    bool merge = MergeTag(oldTag, newTag);
                    if (merge)
                    {
                        updateCount++;
                    }
                }
                else
                {
                    TaggingLayer.Instance.AddTag(newTag);
                    monitorList.Add(newTag);
                    updateCount++;
                }
            }

            foreach (Tag tag in monitorList)//start monitoring each new tag
            {
                ServiceLocator.LogicLayerNotificationQueue().Enqueue(new AddTagNotification(tag));
            }

            return updateCount;
        }
예제 #2
0
 /// <summary>
 /// Initializes tagging profile object. If a tagging.xml file has already been created, 
 /// loads the information from the file; otherwise, instantiates a new tagging profile object.
 /// </summary>
 /// <param name="paths">The list of strings which represent the paths of the tagging.xml 
 /// files to be loaded from</param>
 /// <remarks>paths[0] is always the root</remarks>
 public void Init(List<string> paths)
 {
     string profileFilePath = paths[0];
     if (!File.Exists(profileFilePath))
     {
         _taggingProfile = new TaggingProfile(TaggingHelper.GetCurrentTime());
     }
     else
     {
         _taggingProfile = TaggingXMLHelper.LoadFrom(profileFilePath);
         Debug.Assert(_taggingProfile != null);
     }
     for (int i = 1; i < paths.Count; i++)
     {
         if (File.Exists(paths[i]))
         {
             TaggingProfile profile = TaggingXMLHelper.LoadFrom(paths[i]);
             int updateCount = TagMerger.MergeProfile(_taggingProfile, profile);
         }
     }
 }
예제 #3
0
 /// <summary>
 /// Creates a new TaggingLayer object
 /// </summary>
 private TaggingLayer()
 {
     _taggingProfile = new TaggingProfile(TaggingHelper.GetCurrentTime());
 }
예제 #4
0
 public void Init(string profileFilePath)
 {
     _folderTagList = LoadFolderTagList(profileFilePath);
     _fileTagList = LoadFileTagList(profileFilePath);
     _taggingProfile = LoadTaggingProfile(profileFilePath);
 }
예제 #5
0
 private TaggingLayer()
 {
     _folderTagList = new List<FolderTag>();
     _fileTagList = new List<FileTag>();
     _taggingProfile = new TaggingProfile();
 }
예제 #6
0
 private static TaggingProfile CreateTaggingProfile(XmlElement profileElement)
 {
     TaggingProfile taggingProfile = new TaggingProfile();
     string profilename = profileElement.GetAttribute("name");
     long profilecreated = long.Parse(profileElement.GetAttribute("created"));
     long profilelastupdated = long.Parse(profileElement.GetAttribute("lastUpdated"));
     taggingProfile.ProfileName = profilename;
     taggingProfile.Created = profilecreated;
     taggingProfile.LastUpdated = profilelastupdated;
     return taggingProfile;
 }
예제 #7
0
 /// <summary>
 /// Creates a tagging profile Xml element from the tagging profile that is passed as parameter
 /// </summary>
 /// <param name="xmldoc">The Xmldocument object that represents the Xml document that the
 /// Xml element to be created belongs to</param>
 /// <param name="taggingProfile">The <see cref="TaggingProfile">TaggingProfile</see> object that
 /// represents the tagging profile to be used to create the Xml element</param>
 /// <returns>the tagging profile Xml element that is created</returns>
 private static XmlElement CreateTaggingProfileElement(XmlDocument xmldoc, TaggingProfile taggingProfile)
 {
     XmlElement profileElement = xmldoc.CreateElement(ELE_PROFILE_ROOT);
     profileElement.SetAttribute(ATTR_PROFILE_NAME, taggingProfile.ProfileName);
     profileElement.SetAttribute(ATTR_PROFILE_CREATEDDATE, taggingProfile.CreatedDate.ToString());
     profileElement.SetAttribute(ATTR_PROFILE_LASTUPDATEDDATE, taggingProfile.LastUpdatedDate.ToString());
     foreach (Tag tag in taggingProfile.ReadOnlyTagList)
     {
         profileElement.AppendChild(CreateTagElement(xmldoc, tag));
     }
     return profileElement;
 }
예제 #8
0
 private static XmlDocument ConvertTaggingProfileToXml(TaggingProfile taggingProfile)
 {
     XmlDocument TaggingDataDocument = new XmlDocument();
     XmlElement taggingElement = TaggingDataDocument.CreateElement("tagging");
     XmlElement profileElement = TaggingDataDocument.CreateElement("profile");
     profileElement.SetAttribute("name", taggingProfile.ProfileName);
     profileElement.SetAttribute("createdDate", taggingProfile.Created.ToString());
     profileElement.SetAttribute("lastUpdated", taggingProfile.LastUpdated.ToString());
     foreach (FolderTag folderTag in taggingProfile.FolderTagList)
     {
         profileElement.AppendChild(CreateFolderTagElement(TaggingDataDocument, folderTag));
     }
     foreach (FileTag fileTag in taggingProfile.FileTagList)
     {
         profileElement.AppendChild(CreateFileTagElement(TaggingDataDocument, fileTag));
     }
     taggingElement.AppendChild(profileElement);
     TaggingDataDocument.AppendChild(taggingElement);
     return TaggingDataDocument;
 }
예제 #9
0
 /// <summary>
 /// Creates a tagging profile from the Xml element that is passed as parameter
 /// </summary>
 /// <param name="profileElement">The XmlElement object that represents the Xml element that is to
 /// be used to create the tagging profile</param>
 /// <returns>the tagging profile that is created if there is no FormatException thrown; 
 /// otherwise, null</returns>
 private static TaggingProfile CreateTaggingProfile(XmlElement profileElement)
 {
     try
     {
         string profilename = profileElement.GetAttribute(ATTR_PROFILE_NAME);
         long profilecreated = long.Parse(profileElement.GetAttribute(ATTR_PROFILE_CREATEDDATE));
         long profilelastupdated = long.Parse(profileElement.GetAttribute(ATTR_PROFILE_LASTUPDATEDDATE));
         TaggingProfile taggingProfile = new TaggingProfile(profilecreated);
         taggingProfile.ProfileName = profilename;
         taggingProfile.CreatedDate = profilecreated;
         taggingProfile.LastUpdatedDate = profilelastupdated;
         return taggingProfile;
     }
     catch (FormatException)
     {
         return null;
     }
     catch (XmlException)
     {
         return null;
     }
 }
예제 #10
0
 /// <summary>
 /// Appends a tagging profile to the tagging.xml saved in the list of locations passed as
 /// parameter
 /// </summary>
 /// <param name="profile">The <see cref="TaggingProfile">TaggingProfile</see> object that
 /// represents the tagging profile to be saved to the list of locations</param>
 /// <param name="locations">The list of locations containing tagging.xml where the profile
 /// that is passed as parameter is to be saved to</param>
 public static void AppendProfile(TaggingProfile profile, List<string> locations)
 {
     foreach (string location in locations)
     {
         try
         {
             XmlDocument xmldoc = CommonXmlHelper.LoadXml(location);
             if (xmldoc == null)
             {
                 SaveTo(profile, location);
             }
             else
             {
                 XmlElement newProfileElement = CreateTaggingProfileElement(xmldoc, profile);
                 XmlElement oldProfileElement = (XmlElement)xmldoc.SelectSingleNode(@"//" + ELE_PROFILE_ROOT + "[@" + ATTR_PROFILE_NAME + @"='" + profile.ProfileName + @"']");
                 if (oldProfileElement != null)
                 {
                     xmldoc.SelectSingleNode(@"//" + ELE_TAGGING_ROOT).RemoveChild(oldProfileElement);
                 }
                 xmldoc.SelectSingleNode(@"//" + ELE_TAGGING_ROOT).AppendChild(newProfileElement);
             }
         }
         catch (Exception e)
         {
             Console.WriteLine(e.StackTrace);
         }
     }
 }
예제 #11
0
 /// <summary>
 /// Converts a tagging profile to a Xml document
 /// </summary>
 /// <param name="taggingProfile">The <see cref="TaggingProfile">TaggingProfile</see> object
 /// that represents the tagging profile to be converted</param>
 /// <returns>the Xml document that is created from the tagging profile that is passed as parameter
 /// </returns>
 private static XmlDocument ConvertTaggingProfileToXml(TaggingProfile taggingProfile)
 {
     XmlDocument xmldoc = new XmlDocument();
     XmlElement taggingElement = xmldoc.CreateElement(ELE_TAGGING_ROOT);
     XmlElement profileElement = CreateTaggingProfileElement(xmldoc, taggingProfile);
     taggingElement.AppendChild(profileElement);
     xmldoc.AppendChild(taggingElement);
     return xmldoc;
 }
예제 #12
0
 /// <summary>
 /// Saves a tagging profile to a path that is passed as parameter
 /// </summary>
 /// <param name="taggingProfile">The <see cref="TaggingProfile">TaggingProfile</see> object
 /// that represents the tagging profile to be saved</param>
 /// <param name="xmlFilePath">The string value that represents the path where the tagging profile
 /// is to be saved to</param>
 public static void SaveTo(TaggingProfile taggingProfile, string xmlFilePath)
 {
     XmlDocument xmlDoc = ConvertTaggingProfileToXml(taggingProfile);
     CommonXmlHelper.SaveXml(xmlDoc, xmlFilePath);
 }
예제 #13
0
 /// <summary>
 /// Saves a tagging profile to a list of paths that is passed as paramater
 /// </summary>
 /// <param name="taggingProfile">The <see cref="TaggingProfile">TaggingProfile</see> object
 /// that represents the tagging profile to be saved</param>
 /// <param name="xmlFilePaths">The list of strings that represents the list of paths where
 /// the tagging profile is to be saved to</param>
 public static void SaveToLocations(TaggingProfile taggingProfile, List<string> xmlFilePaths)
 {
     foreach (string path in xmlFilePaths)
     {
         SaveTo(taggingProfile, path);
     }
 }