private static string FilterTags(DanbooruPost post,
                                         List <DanbooruTag> groupedTags,
                                         DanbooruTagType tagType,
                                         int tagLimit,
                                         string tagReplacement,
                                         string missingTagReplacement,
                                         bool isReplaceMode,
                                         bool isReplaceUnderScore)
        {
            var selectedTags = post.TagsEntity.Where <DanbooruTag>(x => x.Type == tagType).Select(x => x.Name).ToList();
            var tagStr       = "";

            if (selectedTags != null)
            {
                if (isReplaceUnderScore)
                {
                    for (int i = 0; i < selectedTags.Count; i++)
                    {
                        selectedTags[i] = selectedTags[i].Replace("_", " ").Trim();
                    }
                }
                if (selectedTags.Count() >= tagLimit)
                {
                    if (isReplaceMode && !string.IsNullOrWhiteSpace(tagReplacement))
                    {
                        tagStr = tagReplacement;
                        if (isReplaceUnderScore)
                        {
                            tagStr = tagReplacement.Replace("_", " ").Trim();
                        }
                        groupedTags.RemoveAll(x => x.Type == tagType);
                        groupedTags.Add(new DanbooruTag()
                        {
                            Name = tagReplacement
                        });
                    }
                    else
                    {
                        var tempTags = selectedTags.Take(tagLimit);
                        tagStr = String.Join(" ", tempTags);
                    }
                }
                else
                {
                    tagStr = string.Join(" ", selectedTags);
                }
            }

            if (string.IsNullOrWhiteSpace(tagStr))
            {
                tagStr = missingTagReplacement;
            }
            return(tagStr);
        }
Beispiel #2
0
        /// <summary>
        /// Return string from tag filtered by tag type.
        /// Replace the returned string with tagReplacement if tag count over tagLimit.
        /// Replace the returned string with missingTagReplacement if tag count is 0.
        /// </summary>
        /// <param name="post"></param>
        /// <param name="groupedTags"></param>
        /// <param name="tagType"></param>
        /// <param name="tagLimit"></param>
        /// <param name="tagReplacement"></param>
        /// <param name="missingTagReplacement"></param>
        /// <param name="isReplaceMode"></param>
        /// <param name="isReplaceUnderScore"></param>
        /// <returns>Return string from tag filtered by tag type.</returns>
        private static string FilterTags(DanbooruPost post,
                                         List<DanbooruTag> groupedTags,
                                         DanbooruTagType tagType,
                                         int tagLimit,
                                         string tagReplacement,
                                         string missingTagReplacement,
                                         bool isReplaceMode,
                                         bool isReplaceUnderScore)
        {
            var selectedTags = post.TagsEntity.Where<DanbooruTag>(x => x.Type == tagType).Select(x => x.Name).ToList();
            var tagStr = "";
            if (selectedTags != null)
            {
                if (isReplaceUnderScore)
                {
                    for (int i = 0; i < selectedTags.Count; i++)
                    {
                        selectedTags[i] = selectedTags[i].Replace("_", " ").Trim();
                    }
                }
                if (tagLimit > 0 && selectedTags.Count() >= tagLimit)
                {
                    if (isReplaceMode && !string.IsNullOrWhiteSpace(tagReplacement))
                    {
                        tagStr = tagReplacement;
                        if (isReplaceUnderScore)
                            tagStr = tagReplacement.Replace("_", " ").Trim();
                        //groupedTags.RemoveAll(x => x.Type == tagType);
                        //groupedTags.Add(new DanbooruTag() { Name = tagReplacement });
                    }
                    else
                    {
                        var tempTags = selectedTags.Take(tagLimit);
                        tagStr = String.Join(" ", tempTags);
                    }
                }
                else
                {
                    tagStr = string.Join(" ", selectedTags);
                }
            }

            if (string.IsNullOrWhiteSpace(tagStr)) tagStr = missingTagReplacement;
            return tagStr;
        }
Beispiel #3
0
        /// <summary>
        /// Return string from tag filtered by tag type.
        /// Replace the returned string with tagReplacement if tag count over tagLimit.
        /// Replace the returned string with missingTagReplacement if tag count is 0.
        /// </summary>
        /// <param name="post"></param>
        /// <param name="groupedTags"></param>
        /// <param name="tagType"></param>
        /// <param name="tagLimit"></param>
        /// <param name="tagReplacement"></param>
        /// <param name="missingTagReplacement"></param>
        /// <param name="isReplaceMode"></param>
        /// <param name="isReplaceUnderScore"></param>
        /// <returns>Return string from tag filtered by tag type.</returns>
        private static string FilterTags(DanbooruPost post,
                                         List <DanbooruTag> groupedTags,
                                         DanbooruTagType tagType,
                                         int tagLimit,
                                         string tagReplacement,
                                         string missingTagReplacement,
                                         bool isReplaceMode,
                                         bool isReplaceUnderScore)
        {
            var selectedTags = post.TagsEntity.Where <DanbooruTag>(x => x.Type == tagType).Select(x => x.Name).ToList();
            var tagStr       = "";

            if (selectedTags != null)
            {
                if (isReplaceUnderScore)
                {
                    for (int i = 0; i < selectedTags.Count; i++)
                    {
                        selectedTags[i] = selectedTags[i].Replace("_", " ").Trim();
                    }
                }
                if (tagLimit > 0 && selectedTags.Count() >= tagLimit)
                {
                    if (isReplaceMode && !string.IsNullOrWhiteSpace(tagReplacement))
                    {
                        tagStr = tagReplacement;
                        if (isReplaceUnderScore)
                        {
                            tagStr = tagReplacement.Replace("_", " ").Trim();
                        }
                        //groupedTags.RemoveAll(x => x.Type == tagType);
                        //groupedTags.Add(new DanbooruTag() { Name = tagReplacement });
                    }
                    else
                    {
                        var tempTags = selectedTags.Take(tagLimit);
                        tagStr = String.Join(" ", tempTags);
                    }
                }
                else
                {
                    tagStr = string.Join(" ", selectedTags);
                }
            }

            if (string.IsNullOrWhiteSpace(tagStr))
            {
                switch (tagType)
                {
                case DanbooruTagType.Artist:
                    tagStr = Properties.Settings.Default.tagNoArtistValue;
                    break;

                case DanbooruTagType.Character:
                    tagStr = Properties.Settings.Default.tagNoCharacterValue;
                    break;

                case DanbooruTagType.Circle:
                    tagStr = Properties.Settings.Default.tagNoCircleValue;
                    break;

                case DanbooruTagType.Copyright:
                    tagStr = Properties.Settings.Default.tagNoCopyrightValue;
                    break;

                case DanbooruTagType.Faults:
                    tagStr = Properties.Settings.Default.tagNoFaultValue;
                    break;

                default:
                    tagStr = missingTagReplacement;
                    break;
                }
            }
            return(tagStr);
        }