Esempio n. 1
0
 private void tag_ValueChanging(FileTag sender, FileTagEventArgs e)
 {
     FileTag newTag = new FileTag(e.NewValue);
     
     // Don't allow the tag to be change into a value that already exists
     if (this.tags.Exists(newTag.Compare))
     {
         e.Cancel = true;
         throw new InvalidOperationException(string.Format(
             "Can't change tag value from '{1}' to '{0}' because the tag '{0}' already exists in the file's tags list", 
             e.NewValue, e.OldValue));
     }
     
     // Raise event (removeTag and addTag)
     if (this.TagRemoved != null)
     {
         FileWithTagsEventArgs e2 = new FileWithTagsEventArgs(sender);
         this.TagRemoved(this, e2);
     }
     if (this.TagAdded != null)
     {
         FileWithTagsEventArgs e2 = new FileWithTagsEventArgs(newTag);
         this.TagAdded(this, e2);
     }
 }
Esempio n. 2
0
 private void menuManyTags_RevesreChoice_Click(object sender, EventArgs e)
 {
     foreach (ListViewItem item in this.listViewTags.SelectedItems)
     {
         FileTag tag = (FileTag)item.Tag;
         FileTag newTag = new FileTag(tag.Value);
         newTag.Inverse = true;
         this.tagsCombination.Add(newTag);
     }
     this.showCurrentDatabse();
 }
Esempio n. 3
0
        /// <summary>
        /// Compares the "tag" param with this current instance of the FileTag object.
        /// The criteria is that both FileTag value member is equal.
        /// </summary>
        /// <param name="tag">The FileTag instance to compare to</param>
        /// <returns>true if both FileTag value member is equal, false otherwise</returns>
        public bool Compare(FileTag tag)
        {
            // The return value
            bool ret;

            // If the input param was null then the return value should be false, i.e, not equal
            if (tag == null)
                ret = false;
            else // Compare the values of the two FileTag instances
                ret = (this.value == tag.value);

            return ret;
        }
Esempio n. 4
0
 public FileWithTagsEventArgs(FileTag tag)
 {
     this.tag = tag;
 }
Esempio n. 5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="tag"></param>
        /// <returns></returns>
        public int CountFilesByTag(FileTag tag)
        {
            int i = this.Tags.FindIndex(tag.Compare);

            if (i >= 0)
                return this.counters[i];
            else
                return 0;
        }
Esempio n. 6
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="tag"></param>
 /// <param name="groupName"></param>
 public void MapTagToGroup(string tagValue, string groupName)
 {
     FileTag newTag = new FileTag(tagValue);
     int tagIndex = this.tags.FindIndex(newTag.Compare);
     if (tagIndex >= 0) // Tag found
     {
         int groupIndex = this.groupsNames.IndexOf(groupName);
         if (groupIndex >= 0)
             this.tagGroupMapping[tagIndex] = groupIndex;
         //else
             //throw new ArgumentException(string.Format("Group {0} does not exists", groupName));
     }
     //else
         //throw new ArgumentException(string.Format("Tag {0} does not exists", tagValue));
 }
Esempio n. 7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static TagFilesDatabase DeSerialize(string fileName)
        {
            TagFilesDatabase ret = new TagFilesDatabase();
            
            if (File.Exists(fileName))
            {
                string line = "";

                FileStream fileStream = new FileStream(fileName, FileMode.Open);
                StreamReader reader = new StreamReader(fileStream);

                while (!reader.EndOfStream)
                {
                    line = reader.ReadLine();

                    // Read the files
                    if (line == fileBeginString)
                    {
                        // Read the file name
                        FileWithTags file = new FileWithTags();
                        file.FileName = reader.ReadLine();

                        // Read the tags
                        line = reader.ReadLine();
                        while (line != fileEndString)
                        {
                            FileTag tag = new FileTag();
                            tag.Value = line;
                            file.Tags.Add(tag);

                            line = reader.ReadLine();
                        }
                        ret.Files.Add(file);
                    }
                    // Read the groups
                    else if (line == groupsBeginString)
                    {
                        line = reader.ReadLine();
                        while (line != groupsEndString)
                        {
                            string name = line;
                            string key = reader.ReadLine();
                            ret.CreateGroup(name, key);
                            line = reader.ReadLine();
                        }
                    }
                    // Read the mapping between tags and groups
                    else if (line == mappingBeginString)
                    {                        
                        line = reader.ReadLine();                        
                        int index = 0;
                        while (line != mappingEndString)
                        {
                            // read the tag line
                            FileTag tag = new FileTag(line);
                            // read the group index line
                            int groupIndex = int.Parse(reader.ReadLine());

                            // find the tag in the list
                            index = ret.tags.FindIndex(tag.Compare);
                            if (index >= 0)
                            {
                                ret.tagGroupMapping[index] = groupIndex;
                            }                                                      
                            line = reader.ReadLine();
                        }
                    }
                }

                reader.Dispose();
                fileStream.Close();
            }

            return ret;
        }
Esempio n. 8
0
        public TagFilesDatabase GetReversePartialDatabase(FileTag matchTag)
        {
            TagFilesDatabase ret = new TagFilesDatabase();

            List<FileTag> list = new List<FileTag>();
            list.Add(matchTag);

            ret = this.GetReversePartialDatabase(list);
            return ret;
        }
Esempio n. 9
0
 public TagFilesDatabaseEventArgs(FileWithTags file,  FileTag tag)
 {
     this.file = file;
     this.tag = tag;
 }
Esempio n. 10
0
        private void raiseEvent(DatabaseAction action, FileWithTags file, FileTag tag)
        {
            TagFilesDatabaseEventArgs e = new TagFilesDatabaseEventArgs(file, tag);

            if (action == DatabaseAction.AddingTag)
            {
                if (this.TagAdded != null)
                    this.TagAdded(this, e);
            }
            else if (action == DatabaseAction.RemovingTag)
            {
                if (this.TagRemoved != null)
                    this.TagRemoved(this, e);
            }
            else if (action == DatabaseAction.RemovingFile)
            {
                if (this.FileRemoved != null)
                    this.FileRemoved(this, e);
            }
            else if (action == DatabaseAction.AddingFile)
            {
                if (this.FileAdded != null)
                    this.FileAdded(this, e);
            }            
        }
Esempio n. 11
0
 private void removeTag(string tagValue)
 {
     FileTag tag = new FileTag(tagValue);
     int i = this.tags.FindIndex(tag.Compare);
     if (i >= 0) // Found
     {
         this.counters[i]--;
         if (this.counters[i] <= 0)
         {
             this.counters.RemoveAt(i);
             this.tagGroupMapping.RemoveAt(i);
             this.tags.RemoveAt(i);
         }
     }
 }
Esempio n. 12
0
 private void addTag(string tagValue)
 {
     FileTag newTag = new FileTag(tagValue);
     int i = this.tags.FindIndex(newTag.Compare);
     if (i >= 0)
     {
         this.counters[i]++;
     }
     else
     {
         this.counters.Add(1);
         this.tagGroupMapping.Add(0);
         this.tags.Add(newTag);
     }
 }
Esempio n. 13
0
 // Handles ValueChanging event for any tag in any file
 private void tag_ValueChanging(FileTag sender, FileTagEventArgs e)
 {
     if (this.currentAction == DatabaseAction.Idle)
         throw new InvalidOperationException("This object is read-only");            
 }