Пример #1
0
        private static List <SteamScreenshot> GetFileIdAndThumbnails(List <SteamScreenshot> screenshots, String steamId, Int32 pageNo)
        {
            Console.WriteLine("Getting file ids and thumbnails for {0}, page {1}", steamId, pageNo);
            var requestScreenshots = new List <SteamScreenshot>();

            const String fileDetailPattern = @"<div style=""background-image: url\('(?<ThumbnailUrl>.*?)'\);"" class=""imgWallItem.*?id=""imgWallItem_(?<FileId>\d{1,})";

            var url             = "";
            var urlFormatString = GetAppSetting("ScreenshotGridUrlFormatString");

            if (String.IsNullOrWhiteSpace(urlFormatString))
            {
                url = String.Format("https://steamcommunity.com/id/{0}/screenshots/?p={1}&sort=newestfirst&view=grid", steamId, pageNo);
            }
            else
            {
                url = String.Format(urlFormatString, steamId, pageNo);
            }

            var webRequest = WebRequest.Create(url) as HttpWebRequest;

            using (var response = TryGetResponse(webRequest))
            {
                // TODO: Handle null responses...
                if (response == null)
                {
                    return(new List <SteamScreenshot>());
                }

                using (var stream = response.GetResponseStream())
                    using (var streamReader = new StreamReader(stream))
                    {
                        var html = streamReader.ReadToEnd();

                        var fileIdMatches = Regex.Matches(html, fileDetailPattern, RegexOptions.IgnoreCase);

                        for (int i = 0; i < fileIdMatches.Count; i++)
                        {
                            var match             = fileIdMatches[i];
                            var fileIdValue       = Int32.Parse(match.Groups["FileId"].Value.Trim());
                            var thumbnailUrlValue = match.Groups["ThumbnailUrl"].Value.Trim();
                            var newScreenshot     = new SteamScreenshot {
                                FileId = fileIdValue, ThumbnailUrl = thumbnailUrlValue
                            };

                            Console.WriteLine("Added File Id: {0}, with Thumbnail Url: {1}", newScreenshot.FileId, newScreenshot.ThumbnailUrl);

                            requestScreenshots.Add(newScreenshot);
                        }
                    }
            }

            if (requestScreenshots.Any())
            {
                screenshots.AddRange(requestScreenshots);
                GetFileIdAndThumbnails(screenshots, steamId, pageNo + 1);
            }

            return(screenshots);
        }
        private static List<SteamScreenshot> GetFileIdAndThumbnails(List<SteamScreenshot> screenshots, String steamId, Int32 pageNo)
        {
            Console.WriteLine("Getting file ids and thumbnails for {0}, page {1}", steamId, pageNo);
            var requestScreenshots = new List<SteamScreenshot>();

            const String fileDetailPattern = @"<div style=""background-image: url\('(?<ThumbnailUrl>.*?)'\);"" class=""imgWallItem.*?id=""imgWallItem_(?<FileId>\d{1,})";
            var url = String.Format("http://steamcommunity.com/id/{0}/screenshots/?p={1}&sort=newestfirst&view=grid", steamId, pageNo);
            var webRequest = WebRequest.Create(url) as HttpWebRequest;

            using (var response = TryGetResponse(webRequest))
            {
                // TODO: Handle null responses...
                if (response != null)
                {
                    using (var stream = response.GetResponseStream())
                    using (var streamReader = new StreamReader(stream))
                    {
                        var html = streamReader.ReadToEnd();

                        var fileIdMatches = Regex.Matches(html, fileDetailPattern, RegexOptions.IgnoreCase);

                        for (int i = 0; i < fileIdMatches.Count; i++)
                        {
                            var match = fileIdMatches[i];
                            var fileIdValue = Int32.Parse(match.Groups["FileId"].Value.Trim());
                            var thumbnailUrlValue = match.Groups["ThumbnailUrl"].Value.Trim();
                            var newScreenshot = new SteamScreenshot { FileId = fileIdValue, ThumbnailUrl = thumbnailUrlValue };

                            Console.WriteLine("Added File Id: {0}, with Thumbnail Url: {1}", newScreenshot.FileId, newScreenshot.ThumbnailUrl);

                            requestScreenshots.Add(newScreenshot);
                        }
                    }
                }
            }

            if (requestScreenshots.Any())
            {
                screenshots.AddRange(requestScreenshots);
                GetFileIdAndThumbnails(screenshots, steamId, pageNo + 1);
            }

            return screenshots;
        }