Example #1
0
        public List <ScreenshotResponseModel> Execute(List <string> urlList)
        {
            var result = new List <ScreenshotResponseModel>();

            ParallelOptions opt = new ParallelOptions
            {
                MaxDegreeOfParallelism = Environment.ProcessorCount
            };

            Parallel.ForEach(urlList, opt, (currentUrl =>
            {
                try
                {
                    var computedName = $"{currentUrl}{Guid.NewGuid()}";
                    var hashValue = _HashService.GetHash(computedName);
                    using (MemoryStream memoryStream = _ProcessImage.MakeScreenshot(currentUrl, hashValue, 0, 0))
                    {
                        _PersistData.PersistImage(memoryStream, hashValue);
                        result.Add(new ScreenshotResponseModel {
                            SourceUrl = currentUrl, RemoteFileKey = hashValue
                        });
                    }
                }
                catch (Exception ex)
                {
                    _Logger.LogError($"Error occured: ", ex);
                }
            }));

            return(result);
        }