예제 #1
0
 public BingWallpaperLoader(IWorkItemManager workItemManager)
 {
     _workItemManager = workItemManager;
     Source           = new WallpaperSource
     {
         Name    = "Bing",
         BaseUri = new Uri(URI)
     };
 }
예제 #2
0
 public SpotlightImageLoader(IWorkItemManager workItemManager)
 {
     Source = new WallpaperSource
     {
         Name    = "Spotlight",
         BaseUri = new Uri("http://arc.msn.com/")
     };
     _workItemManager = workItemManager;
 }
예제 #3
0
        private static async Task <string> GetRandomWallhavenImage(WallpaperSource source)
        {
            string baseUrl     = FormatWallhavenQueryString(source.Query, source.WallhavenOptions);
            var    htmlWeb     = new HtmlWeb();
            var    mainSearch  = htmlWeb.Load(baseUrl).DocumentNode.SelectNodes("//a[@class='preview']");
            var    rndImageUrl = htmlWeb.Load(mainSearch[_rand.Next(mainSearch.Count - 1)].Attributes["href"].Value).DocumentNode.SelectNodes("//img[@id='wallpaper']");

            return("http:" + rndImageUrl.First().Attributes["src"].Value);
        }
예제 #4
0
        public async void DeleteSource(WallpaperSource source)
        {
            if (!await _dialog.ShowConfirmationAsync("Confirmation", string.Format("Are you sure you want to delete [{0}] from your source list?", source.Query)))
            {
                return;
            }
            await _db.RemoveSource(source);

            Sources.Remove(source);
        }
예제 #5
0
 /// <summary>
 /// 实例化一个壁纸对象
 /// </summary>
 public Wallpaper(String title, String url, String description, Int32 width, Int32 height, String md5, Int32 userId = 0, WallpaperSource wallpaperSource = default(WallpaperSource))
 {
     Title       = title;
     Url         = url;
     Description = description;
     Width       = width;
     Height      = height;
     Source      = wallpaperSource;
     UserId      = userId;
     Md5         = md5;
 }
예제 #6
0
 /// <summary>
 /// 实例化一个壁纸对象
 /// </summary>
 /// <param name="title"></param>
 /// <param name="url"></param>
 /// <param name="description"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="md5"></param>
 /// <param name="accountId"></param>
 /// <param name="wallpaperSource"></param>
 public Wallpaper(String title, String url, String description, Int32 width, Int32 height, String md5, Int32 accountId = default(Int32), WallpaperSource wallpaperSource = default(WallpaperSource))
 {
     Title = title;
     Url = url;
     Description = description;
     Width = width;
     Height = height;
     Source = wallpaperSource;
     AccountId = accountId;
     Md5 = md5;
 }
예제 #7
0
 public GoogleEarthImageLoader(IWorkItemManager workItemManager)
 {
     Source = new WallpaperSource
     {
         Name    = "Google-EarthView",
         BaseUri = new Uri("https://www.gstatic.com/prettyearth/assets/data/v3/")
     };
     _httpClient             = new HttpClient();
     _httpClient.BaseAddress = Source.BaseUri;
     _workItemManager        = workItemManager;
 }
예제 #8
0
        public static async Task <string> GetRandomImageUrl(WallpaperSource source, string clientId, List <string> current)
        {
            _clientId = clientId;
            switch (source.Source)
            {
            case Source.Reddit:
                return(await GetRandomRedditImage(source.Query));

            case Source.Wallhaven:
                return(await GetRandomWallhavenImage(source));

            case Source.Local:
                return(await GetRandomLocalImage(source.Query, current));
            }
            return(null);
        }
예제 #9
0
        public async void AddSubreddit()
        {
            string sub = await _dialog.ShowInputAsync("Add new Subreddit", "Please enter subreddit name");

            if (string.IsNullOrEmpty(sub))
            {
                return;
            }
            if (!sub.Contains("/r/"))
            {
                sub = "/r/" + sub;
            }
            var source = new WallpaperSource {
                Query = sub, Source = Source.Reddit
            };
            await _db.AddSource(source);

            Sources.Add(source);
        }
예제 #10
0
        public async void EditSource(WallpaperSource source)
        {
            if (source.Source == Source.Reddit || source.Source == Source.Local)
            {
                await _dialog.ShowMessageAsync("Error", "There are no options to edit on Reddit sources!");

                return;
            }
            source.WallhavenOptions = await _db.GetWallhavenOptions(source);

            var wallhavenDialog = new WallhavenDialog("Edit Wallhaven Source options")
            {
                Query   = source.Query,
                General = Convert.ToBoolean(source.WallhavenOptions.General),
                Anime   = Convert.ToBoolean(source.WallhavenOptions.Anime),
                People  = Convert.ToBoolean(source.WallhavenOptions.People),
                SFW     = Convert.ToBoolean(source.WallhavenOptions.SFW),
                Sketchy = Convert.ToBoolean(source.WallhavenOptions.Sketchy),
            };

            if (!string.IsNullOrEmpty(source.WallhavenOptions.Resolution))
            {
                source.WallhavenOptions.Resolution.Split(',').AsParallel().ForAll(x => wallhavenDialog.Resolutions.FirstOrDefault(y => y.ObjectData == x).IsSelected = true);
            }
            if (!string.IsNullOrEmpty(source.WallhavenOptions.Ratio))
            {
                source.WallhavenOptions.Ratio.Split(',').AsParallel().ForAll(x => wallhavenDialog.Ratios.FirstOrDefault(y => y.ObjectData == x).IsSelected = true);
            }
            var editedSource = (WallpaperSource)await _dialog.ShowCustomDialog(wallhavenDialog);

            if (editedSource == null)
            {
                return;
            }
            if (string.IsNullOrEmpty(editedSource.Query))
            {
                await _dialog.ShowMessageAsync("Error", "The search query cannot be blank");

                return;
            }
            source = editedSource;
            await _db.EditSource(source);
        }
예제 #11
0
        public async Task RemoveSource(WallpaperSource source)
        {
            switch (source.Source)
            {
            case Source.Reddit:
                await db.ExecuteAsync("DELETE FROM Subreddit WHERE Query=@Query", source);

                break;

            case Source.Wallhaven:
                await db.ExecuteAsync("DELETE FROM Wallhaven WHERE Query=@Query", source);

                break;

            case Source.Local:
                await db.ExecuteAsync("DELETE From Local WHERE Query=@Query", source);

                break;
            }
        }
예제 #12
0
        public async Task AddSource(WallpaperSource source)
        {
            switch (source.Source)
            {
            case Source.Reddit:
                await db.ExecuteAsync("INSERT INTO Subreddit (Query) VALUES (@Query)", source);

                break;

            case Source.Wallhaven:
                await db.ExecuteAsync("INSERT INTO Wallhaven (Query, General, Anime, People, SFW, Sketchy, Resolution, Ratio) VALUES (@Query, @General, @Anime, @People, @SFW, @Sketchy, @Resolution, @Ratio)",
                                      new
                {
                    Query      = source.Query,
                    General    = source.WallhavenOptions.General,
                    Anime      = source.WallhavenOptions.Anime,
                    People     = source.WallhavenOptions.People,
                    SFW        = source.WallhavenOptions.SFW,
                    Sketchy    = source.WallhavenOptions.Sketchy,
                    Resolution = source.WallhavenOptions.Resolution,
                    Ratio      = source.WallhavenOptions.Ratio
                });

                break;

            case Source.Local:
                await db.ExecuteAsync("INSERT INTO Local (Name, Query) Values (@Name, @Query)",
                                      new
                {
                    Name  = source.Name,
                    Query = source.Query
                });

                break;
            }
        }
예제 #13
0
        public async Task EditSource(WallpaperSource source)
        {
            switch (source.Source)
            {
            case Source.Reddit:
                break;

            case Source.Wallhaven:
                await db.ExecuteAsync("UPDATE Wallhaven SET General=@General, Anime=@Anime, People=@People, SFW=@SFW, Sketchy=@Sketchy, Resolution=@Resolution, Ratio=@Ratio WHERE Query=@Query",
                                      new
                {
                    Query      = source.Query,
                    General    = source.WallhavenOptions.General,
                    Anime      = source.WallhavenOptions.Anime,
                    People     = source.WallhavenOptions.People,
                    SFW        = source.WallhavenOptions.SFW,
                    Sketchy    = source.WallhavenOptions.Sketchy,
                    Resolution = source.WallhavenOptions.Resolution,
                    Ratio      = source.WallhavenOptions.Ratio
                });

                break;
            }
        }
예제 #14
0
 public async Task <WallhavenOptions> GetWallhavenOptions(WallpaperSource source)
 {
     return((await db.QueryAsync <WallhavenOptions>("SELECT * FROM Wallhaven WHERE Query=@Query", source)).FirstOrDefault());
 }
예제 #15
0
 public IMaybe <Common.Model.Wallpaper> GetByHashAndSource(WallpaperSource source, string hash)
 => _repository.GetByHash(source.Name, hash);
예제 #16
0
 public bool Exists(WallpaperSource source, string hash)
 => _repository.Exists(source.Name, hash);