private void tag_ToolTipOpening(object sender, ToolTipEventArgs e)
        {
            ToggleButton button      = sender as ToggleButton;
            Tag          selectedTag = (button.Tag as Tag);

            String tooltip = selectedTag.Name;

            try
            {
                using (TagDbCommands tagCommands = new TagDbCommands())
                {
                    Tag tag = tagCommands.getTagByName(selectedTag.Name);
                    if (tag == null)
                    {
                        return;
                    }

                    foreach (Tag child in tag.ChildTags)
                    {
                        tooltip += "\n" + child.Name;
                    }
                }
            }
            finally
            {
                button.ToolTip = tooltip;
            }
        }
        void updateTag(Action <TagDbCommands> function)
        {
            int nrTries = 3;

            using (TagDbCommands tagCommands = new TagDbCommands())
            {
                do
                {
                    try
                    {
                        function(tagCommands);
                        unselectAllTags();
                        nrTries = 0;
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        if (nrTries > 0)
                        {
                            nrTries -= 1;
                        }
                        else
                        {
                            Logger.Log.Error("Error updating tag", ex);
                            MessageBox.Show("Error updating tag\n\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Log.Error("Error updating tag", ex);
                        MessageBox.Show("Error updating tag\n\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                } while (nrTries > 0);
            }
        }
Example #3
0
        public void import(String filename)
        {
            WindowTitle = "Importing Tags";

            XmlTextReader inFile = null;

            try
            {
                inFile = new XmlTextReader(filename);
                Type[] knownTypes = new Type[] { typeof(TagDTO), typeof(TagCategoryDTO) };

                DataContractSerializer tagSerializer = new DataContractSerializer(typeof(List <TagDTO>), knownTypes);

                List <Tag>    tags    = new List <Tag>();
                List <TagDTO> tagDTOs = (List <TagDTO>)tagSerializer.ReadObject(inFile);

                foreach (TagDTO tagDTO in tagDTOs)
                {
                    var tag = Mapper.Map <TagDTO, Tag>(tagDTO, new Tag());
                    tags.Add(tag);
                }

                TotalProgressMax = tags.Count;
                TotalProgress    = 0;

                using (TagDbCommands tagCommands = new TagDbCommands())
                {
                    foreach (Tag tag in tags)
                    {
                        if (CancellationToken.IsCancellationRequested == true)
                        {
                            return;
                        }

                        ItemInfo     = "Merging: " + tag.Name;
                        ItemProgress = 0;
                        tagCommands.merge(tag);
                        ItemProgress = 100;
                        TotalProgress++;
                        InfoMessages.Add("Merged: " + tag.Name);
                    }
                }
            }
            catch (Exception e)
            {
                InfoMessages.Add("Error importing tags " + e.Message);
            }
            finally
            {
                operationFinished();

                if (inFile != null)
                {
                    inFile.Dispose();
                }
            }
        }
        void linkTags(TagDbCommands tagCommands)
        {
            Tag        parent   = selectedTags[0].Tag as Tag;
            List <Tag> children = new List <Tag>();

            for (int i = 1; i < selectedTags.Count; i++)
            {
                children.Add(selectedTags[i].Tag as Tag);
            }

            tagCommands.linkChildTags(parent, children);
        }
        public void import(String filename)
        {
            WindowTitle = "Importing Tags";

            XmlTextReader inFile = null;
            try
            {
                inFile = new XmlTextReader(filename);
                Type[] knownTypes = new Type[] { typeof(TagDTO), typeof(TagCategoryDTO) };

                DataContractSerializer tagSerializer = new DataContractSerializer(typeof(List<TagDTO>), knownTypes);

                List<Tag> tags = new List<Tag>();
                List<TagDTO> tagDTOs = (List<TagDTO>)tagSerializer.ReadObject(inFile);

                foreach (TagDTO tagDTO in tagDTOs)
                {
                    var tag = Mapper.Map<TagDTO, Tag>(tagDTO, new Tag());                 
                    tags.Add(tag);
                }

                TotalProgressMax = tags.Count;
                TotalProgress = 0;

                using (TagDbCommands tagCommands = new TagDbCommands())
                {
                    foreach (Tag tag in tags)
                    {
                        if (CancellationToken.IsCancellationRequested == true) return;

                        ItemInfo = "Merging: " + tag.Name;
                        ItemProgress = 0;
                        tagCommands.merge(tag);
                        ItemProgress = 100;
                        TotalProgress++;
                        InfoMessages.Add("Merged: " + tag.Name);
                    }
                }                
            }
            catch (Exception e)
            {
                InfoMessages.Add("Error importing tags " + e.Message);         
            }
            finally
            {
                operationFinished();

                if (inFile != null)
                {
                    inFile.Dispose();
                }
            }
        }
        private void addTag(string tagName)
        {
            if (String.IsNullOrEmpty(tagName) || String.IsNullOrWhiteSpace(tagName))
            {
                return;
            }

            tagName = tagName.Trim();

            addTagAutoCompleteBox.Text = "";

            // add linked tags

            using (TagDbCommands tc = new TagDbCommands(null))
            {
                Tag tag = tc.getTagByName(tagName);

                if (tag != null)
                {
                    if (AddLinkedTags)
                    {
                        foreach (Tag childTag in tag.ChildTags)
                        {
                            if (!Tags.Contains(childTag))
                            {
                                Tags.Add(childTag);
                            }
                        }
                    }
                }
                else
                {
                    if (AcceptOnlyExistingTags)
                    {
                        return;
                    }

                    tag      = new Tag();
                    tag.Name = tagName;
                }

                if (!Tags.Contains(tag))
                {
                    CollectionsSort.insertIntoSortedCollection <Tag>(Tags, tag);
                }
            }
        }
Example #7
0
        public void clear()
        {
            List <Tag> tags;

            try
            {
                if (CancellationToken.IsCancellationRequested)
                {
                    return;
                }

                using (TagDbCommands tagCommands = new TagDbCommands())
                {
                    tags          = tagCommands.getAllUnusedTags();
                    TotalProgress = tags.Count();

                    foreach (Tag tag in tags)
                    {
                        if (CancellationToken.IsCancellationRequested)
                        {
                            return;
                        }

                        ItemInfo     = "Deleting: " + tag.Name;
                        ItemProgress = 0;

                        tagCommands.delete(tag);

                        ItemProgress = 100;
                        InfoMessages.Add("Deleting: " + tag.Name);
                        TotalProgress++;
                    }
                }
            }
            catch (Exception e)
            {
                InfoMessages.Add("Error deleting tags: " + e.Message);
            }
            finally
            {
                operationFinished();
            }
        }
        //TagPickerTagCollection tagPickerTags;

        public TagPickerView()
        {
            InitializeComponent();

            addTagAutoCompleteBox.CustomFindMatchesFunction = new UserControls.AutoCompleteBox.AutoCompleteBoxView.CustomFindMatchesDelegate((text) =>
            {
                List <Tag> results = new List <Tag>();

                using (TagDbCommands tc = new TagDbCommands())
                {
                    results = tc.getTagAutocompleteMatches(text, 50, IsStartsWithAutoCompleteMode);
                }

                return(results.Cast <Object>().ToList());
            });

            DependencyPropertyDescriptor.FromProperty(AutoCompleteBoxView.TextProperty, typeof(AutoCompleteBoxView)).AddValueChanged(addTagAutoCompleteBox, addTagAutoCompleteBox_TextChanged);
            DependencyPropertyDescriptor.FromProperty(AutoCompleteBoxView.SelectedItemProperty, typeof(AutoCompleteBoxView)).AddValueChanged(addTagAutoCompleteBox, addTagAutoCompleteBox_SelectedItemChanged);

            addButton.IsEnabled   = false;
            clearButton.IsEnabled = false;
            selectedTags          = new List <ToggleButton>();
        }
        //TagPickerTagCollection tagPickerTags;
      
        public TagPickerView()
        {

            InitializeComponent();

            addTagAutoCompleteBox.CustomFindMatchesFunction = new UserControls.AutoCompleteBox.AutoCompleteBoxView.CustomFindMatchesDelegate((text) =>
            {
                List<Tag> results = new List<Tag>();

                using (TagDbCommands tc = new TagDbCommands())
                {
                    results = tc.getTagAutocompleteMatches(text, 50, IsStartsWithAutoCompleteMode);
                }

                return (results.Cast<Object>().ToList());
            });

            DependencyPropertyDescriptor.FromProperty(AutoCompleteBoxView.TextProperty, typeof(AutoCompleteBoxView)).AddValueChanged(addTagAutoCompleteBox, addTagAutoCompleteBox_TextChanged);
            DependencyPropertyDescriptor.FromProperty(AutoCompleteBoxView.SelectedItemProperty, typeof(AutoCompleteBoxView)).AddValueChanged(addTagAutoCompleteBox, addTagAutoCompleteBox_SelectedItemChanged);

            addButton.IsEnabled = false;
            clearButton.IsEnabled = false;
            selectedTags = new List<ToggleButton>();
        }
        public void clear()
        {
            List<Tag> tags;

            try
            {
                if (CancellationToken.IsCancellationRequested) return;

                using (TagDbCommands tagCommands = new TagDbCommands())
                {
                    tags = tagCommands.getAllUnusedTags();
                    TotalProgress = tags.Count();

                    foreach (Tag tag in tags)
                    {
                        if (CancellationToken.IsCancellationRequested) return;

                        ItemInfo = "Deleting: " + tag.Name;
                        ItemProgress = 0;

                        tagCommands.delete(tag);

                        ItemProgress = 100;
                        InfoMessages.Add("Deleting: " + tag.Name);
                        TotalProgress++;                        
                    }
                }

            }
            catch (Exception e)
            {
                InfoMessages.Add("Error deleting tags: " + e.Message);  
            }
            finally
            {
                operationFinished();   
            }
          
        }
Example #11
0
        public void export(String fileName)
        {
            WindowTitle = "Exporting Tags";

            XmlTextWriter outFile = null;

            try
            {
                if (CancellationToken.IsCancellationRequested)
                {
                    return;
                }

                outFile            = new XmlTextWriter(fileName, Encoding.UTF8);
                outFile.Formatting = Formatting.Indented;
                Type[] knownTypes = new Type[] { typeof(TagDTO), typeof(TagCategoryDTO) };

                DataContractSerializer tagSerializer = new DataContractSerializer(typeof(List <TagDTO>), knownTypes);

                using (var tagCommands = new TagDbCommands())
                {
                    tagCommands.Db.Configuration.ProxyCreationEnabled = false;
                    List <Tag> tags = tagCommands.getAllTags(true);
                    TotalProgressMax = tags.Count;
                    TotalProgress    = 0;
                    List <TagDTO> tagsDTO = new List <TagDTO>();

                    foreach (Tag tag in tags)
                    {
                        if (CancellationToken.IsCancellationRequested)
                        {
                            return;
                        }

                        var tagDTO = Mapper.Map <Tag, TagDTO>(tag, new TagDTO());

                        ItemInfo     = "Exporting: " + tagDTO.Name;
                        ItemProgress = 0;

                        tagsDTO.Add(tagDTO);

                        ItemProgress = 100;
                        InfoMessages.Add("Exported: " + tagDTO.Name);
                        TotalProgress++;
                    }

                    tagSerializer.WriteObject(outFile, tagsDTO);
                }
            }
            catch (Exception e)
            {
                InfoMessages.Add("Error exporting tags: " + e.Message);
            }
            finally
            {
                operationFinished();

                if (outFile != null)
                {
                    outFile.Dispose();
                }
            }
        }
        private void tag_ToolTipOpening(object sender, ToolTipEventArgs e)
        {
            ToggleButton button = sender as ToggleButton;
            Tag selectedTag = (button.Tag as Tag);

            String tooltip = selectedTag.Name;              

            try
            {
                using (TagDbCommands tagCommands = new TagDbCommands())
                {
                    Tag tag = tagCommands.getTagByName(selectedTag.Name);
                    if (tag == null) return;

                    foreach (Tag child in tag.ChildTags)
                    {
                        tooltip += "\n" + child.Name;
                    }
                }
            }
            finally
            {
                button.ToolTip = tooltip;
            }
        }
        void updateTag(Action<TagDbCommands> function) {

            int nrTries = 3;

            using (TagDbCommands tagCommands = new TagDbCommands())
            {
                do
                {
                    try
                    {
                        function(tagCommands);
                        unselectAllTags();
                        nrTries = 0;
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        if (nrTries > 0)
                        {
                            nrTries -= 1;
                        }
                        else
                        {
                            Logger.Log.Error("Error updating tag", ex);
                            MessageBox.Show("Error updating tag\n\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Log.Error("Error updating tag", ex);
                        MessageBox.Show("Error updating tag\n\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }

                } while (nrTries > 0);
            }
        }
 void unlinkTags(TagDbCommands tagCommands)
 {
     tagCommands.unlinkChildTags(selectedTags[0].Tag as Tag);           
 }
        private void addTag(string tagName)
        {
            if (String.IsNullOrEmpty(tagName) || String.IsNullOrWhiteSpace(tagName)) return;

            tagName = tagName.Trim();

            addTagAutoCompleteBox.Text = "";

            // add linked tags

            using (TagDbCommands tc = new TagDbCommands(null))
            {
                Tag tag = tc.getTagByName(tagName);

                if (tag != null)
                {
                    if (AddLinkedTags)
                    {
                        foreach (Tag childTag in tag.ChildTags)
                        {
                            if (!Tags.Contains(childTag))
                            {
                                Tags.Add(childTag);
                            }
                        }
                    }
                }
                else
                {
                    if (AcceptOnlyExistingTags) return;
                                        
                    tag = new Tag();
                    tag.Name = tagName;
                    
                }
                             
                if (!Tags.Contains(tag))
                {
                    CollectionsSort.insertIntoSortedCollection<Tag>(Tags, tag);
                }
            }           
        }
 void unlinkTags(TagDbCommands tagCommands)
 {
     tagCommands.unlinkChildTags(selectedTags[0].Tag as Tag);
 }
        public void export(String fileName)
        {
            WindowTitle = "Exporting Tags";

            XmlTextWriter outFile = null;
            try
            {
                if (CancellationToken.IsCancellationRequested) return;

                outFile = new XmlTextWriter(fileName, Encoding.UTF8);
                outFile.Formatting = Formatting.Indented;
                Type[] knownTypes = new Type[] { typeof(TagDTO), typeof(TagCategoryDTO) };

                DataContractSerializer tagSerializer = new DataContractSerializer(typeof(List<TagDTO>), knownTypes);

                using (var tagCommands = new TagDbCommands())
                {
                    tagCommands.Db.Configuration.ProxyCreationEnabled = false;
                    List<Tag> tags = tagCommands.getAllTags(true);
                    TotalProgressMax = tags.Count;
                    TotalProgress = 0;
                    List<TagDTO> tagsDTO = new List<TagDTO>();

                    foreach (Tag tag in tags)
                    {
                        if (CancellationToken.IsCancellationRequested) return;

                        var tagDTO = Mapper.Map<Tag, TagDTO>(tag, new TagDTO());

                        ItemInfo = "Exporting: " + tagDTO.Name;
                        ItemProgress = 0;

                        tagsDTO.Add(tagDTO);

                        ItemProgress = 100;
                        InfoMessages.Add("Exported: " + tagDTO.Name);
                        TotalProgress++;
                    }

                    tagSerializer.WriteObject(outFile, tagsDTO);
                }               
            }
            catch (Exception e)
            {
                InfoMessages.Add("Error exporting tags: " + e.Message);                           
            }
            finally
            {
                operationFinished();    

                if (outFile != null)
                {
                    outFile.Dispose();
                }
            }
        }
        void linkTags(TagDbCommands tagCommands)
        {
            Tag parent = selectedTags[0].Tag as Tag;
            List<Tag> children = new List<Tag>();

            for (int i = 1; i < selectedTags.Count; i++)
            {
                children.Add(selectedTags[i].Tag as Tag);
            }

            tagCommands.linkChildTags(parent, children);
            
        }