Пример #1
0
        private void okButton_Click(object sender, EventArgs e)
        {
            var tags = tagsBox.Text;

            if (tags.Contains("|"))
            {
                MessageBox.Show("Cannot use character '|' in tags.");
                return;
            }
            EditedFile.XMPTags_fts = Helpers.TagStringToHash(tags);
            var editResult = _searchTagEditor.setSearchTag(EditedFile.FullName, EditedFile.XMPTags_fts.ToHashSet());

            if (editResult == false)
            {
                MessageBox.Show("Could not set XMP tags for image.", "ImageGallery", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                using (var ctx = new FilesContext())
                {
                    ctx.UpdateXMPFileTags(EditedFile);
                }
            }
        }
Пример #2
0
        private void addButton_Click(object sender, EventArgs e)
        {
            var tagsText = addTagsTextBox.Text;

            if (tagsText.Contains('|') || tagsText.Contains('"'))
            {
                MessageBox.Show(
                    "Cannot use character '|' or '\"' in tags.",
                    "Invalid tags",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation
                    );
                return;
            }
            var newTags = Helpers.TagStringToHash(tagsText);

            if (newTags.Count == 0)
            {
                return;
            }
            int  count     = 0;
            var  succeeded = new List <File>();
            bool finished  = false;

            using (var ctx = new FilesContext())
            {
                foreach (var file in _files)
                {
                    if (!System.IO.File.Exists(file.FullName))
                    {
                        continue;
                    }
                    var currentTags = file.XMPTags_fts;
                    if (currentTags == null)
                    {
                        file.XMPTags_fts = newTags;
                    }
                    else
                    {
                        currentTags.UnionWith(newTags);
                    }
                }
                succeeded = ctx.UpdateXMPFilesTags(_files);
            }

            var watcherIds = succeeded.Select(file => file.WatcherId).ToHashSet();

            try
            {
                foreach (var id in watcherIds)
                {
                    _watcherMonitor.DisableFSOperations(id);
                }

                int currentFile = 1;
                foreach (var file in succeeded)
                {
                    addStatusLabel.Text = $"Status: ({currentFile}/{succeeded.Count}) Adding tag to {file.Name}...";
                    addStatusLabel.Update();
                    ++currentFile;
                    bool successfullySetTags = _searchTagEditor.setSearchTag(file.FullName, file.XMPTags_fts);
                    if (successfullySetTags)
                    {
                        count++;
                    }
                    else
                    {
                        Console.WriteLine($"Failed: {file.FullName}");
                    }
                }
                removeStatusLabel.Text = $"Status: Syncing...";
                removeStatusLabel.Update();
                foreach (var id in watcherIds)
                {
                    _watcherMonitor.SyncById(id, false);
                }
                finished = true;
            }
            finally
            {
                foreach (var id in watcherIds)
                {
                    _watcherMonitor.ReenableFSOperations(id);
                }
                if (finished)
                {
                    addStatusLabel.Text = $"Status: Done. Successfully added tags to {count} of {_files.Count} file(s).";
                }
                else
                {
                    addStatusLabel.Text = $"Status: Failed.";
                }
                addStatusLabel.Update();
            }
            RefreshView();
        }