示例#1
0
        private bool ParseDownload(string url, string path, int id, string wallId) 
        {
            var wall = new Wallpaper();
            var parsing = false;

            foreach (var cat in _categories)
            {
                foreach (var format in Enum.GetValues(typeof(Format)))
                {
                    var newUrl = url.ChangeCategory((Category)cat).ChangeExtentsion((Format)format);
                    var newPath = string.Empty;

                    if (Sort)
                        newPath = Path.Combine(Path.GetDirectoryName(path), cat.ToString(), Path.GetFileName(path)).ChangeExtentsion((Format)format);
                    else if (!Sort)
                        newPath = path;

                    var result = _UriExist(newUrl);

                    if (!parsing)
                    {
                        if (result)
                        {
                            log.AddParsingSuccess(currentId, currenctWallId);

                            wall.FileURL = newUrl;
                            wall.FilePath = newPath;
                            wall.ID = id;
                            wall.WallID = wallId;
                            wallpapers.Add(wall);
                            return true;
                        }
                        else 
                            parsing = true;
                    } 
                    else 
                    {
                        log.AddParsingAttempt(currentId, currenctWallId, (Category)cat, (Format)format);

                        if (result)
                        {
                            log.AddParsingSuccess(currentId, currenctWallId);
                            
                            wall.FileURL = newUrl;
                            wall.FilePath = newPath;
                            wall.ID = id;
                            wall.WallID = wallId;
                            wallpapers.Add(wall);
                            return true;
                        }
                    }
                }
            }

            log.AddError(currentId, currenctWallId, "Un-resolved error while parsing");

            return false;
        }
示例#2
0
        private async Task _Download(Wallpaper wall)
        {
            using (var client = new WebClient())
            {
                try 
                {
                    await client.DownloadFileTaskAsync(new Uri(wall.FileURL), wall.FilePath);                   

                    Downloaded++;
                }
                catch (WebException) 
                {
                    Failed++;
                }
            }
        }