private void OnHandlerStart() { foreach (var job in _jobs.GetConsumingEnumerable(CancellationToken.None)) { if (job.StartsWith("http://www") || job.StartsWith("https://www")) { _logger.LogInformation("Processing job: " + job); Shotter shotter = new Shotter(_windowSize); ScreenShotSaver ssSaver = new ScreenShotSaver(_dbConfig[0], _dbConfig[1], _dbConfig[2]); try { ScreenShotData ssData = new ScreenShotData { Url = job, Date = DateTime.UtcNow, ContentImage = shotter.TakeScreenshot(job) }; ssSaver.Create(ssData); _logger.LogInformation("Successfully imported job: " + job); } catch (Exception ex) { _logger.LogError(ex.Message); } finally { shotter.Dispose(); } } } }
public ScreenShotData Create(ScreenShotData screenShot) { _screens.InsertOne(screenShot); return(screenShot); }
private static List <TargetItem> FilterTargetsInCamera(ScreenShotData data) { List <TargetItem> ret = new List <TargetItem>(); List <TargetItem> source = data.Items; Rectangle camRectangle = data.CameraRectangle; int imgWidth = camRectangle.Width; int imgHeight = camRectangle.Height; source.ForEach(i => { i.X -= camRectangle.X; i.Y -= camRectangle.Y; // Validation if (i.Height < 0 || i.Width < 0) { throw new InvalidDataException("Items Height or Width is negative!!"); } // Not show in screenshots at all if (i.X > imgWidth || i.Y > imgHeight) { return; } int inCameraWidth = i.Width; int inCameraHeight = i.Height; double itemArea = i.Width * i.Height; // Partial in X - left if (i.X < 0) { inCameraWidth = i.X + i.Width; if (inCameraWidth < 0) { return; } i.X = 0; } // Partial in X - right if (i.X + i.Width > imgWidth) { inCameraWidth = imgWidth - i.X; } // Partial in Y - up if (i.Y < 0) { inCameraHeight = i.Y + i.Height; if (inCameraHeight < 0) { return; } i.Y = 0; } // Partial in Y - bottom if (i.Y + i.Height > imgHeight) { inCameraHeight = imgHeight - i.Y; } double inCameraArea = inCameraHeight * imgWidth; if (inCameraArea / itemArea >= ITEM_PARTIAL_AREA_THRESHOLD) { i.Width = inCameraWidth; i.Height = inCameraHeight; ret.Add(i); } }); return(ret); }