예제 #1
0
        private void SetAccessorKey(string key = "")
        {
            if (string.IsNullOrEmpty(key))
            {
                pixabayAccessor = new PixabayAccessor();
                key             = "default";
            }
            else
            {
                pixabayAccessor = new PixabayAccessor(key);
            }

            if (pixabayAccessor.GetImagePages(new List <string> {
                "sea"
            }).Any())
            {
                labelKey.Text = $"connected - {key}";
            }
            else
            {
                labelKey.Text = $"key failure - {key}";
            }
        }
예제 #2
0
        private static IEnumerable <WebImage> GetWebImages(List <string> tags)
        {
            int count = tags.Count();
            IEnumerable <WebImage> images = pixabayAccessor.GetImagePages(tags);

            if (images.Any() || count == 1)
            {
                return(images);
            }

            List <string> removedTags = new List <string>();

            while (count > 1)
            {
                removedTags.Add(tags[count - 1]);
                tags.RemoveAt(count - 1);
                images = pixabayAccessor.GetImagePages(tags);
                if (images.Any())
                {
                    return(images);
                }

                count = tags.Count();
            }

            removedTags.Reverse();
            foreach (string tag in removedTags)
            {
                images = pixabayAccessor.GetImagePages(new string[] { "tags" });
                if (images.Any())
                {
                    return(images);
                }
            }

            return(images);
        }