public async Task Start() { var primaryScreenBounds = Screen.PrimaryScreen.Bounds; var primaryScreenWidth = primaryScreenBounds.Width; var primaryScreenHeight = primaryScreenBounds.Height; var destinationX = 0; var destinationY = 0; using (var bitmapScreenCapture = new Bitmap(primaryScreenWidth, primaryScreenHeight)) { using (var graphics = Graphics.FromImage(bitmapScreenCapture)) { while (this.isRunning) { graphics.CopyFromScreen( primaryScreenBounds.X, primaryScreenBounds.Y, destinationX, destinationY, bitmapScreenCapture.Size, CopyPixelOperation.SourceCopy); var imageAsByteArray = ConvertionOperations.ImageToByteArray(bitmapScreenCapture); try { var model = new SnapshotViewModel { SessionId = this.SessionId, SnapshotAsByteArray = imageAsByteArray }; await this.HttpService.SendAsBson(model, this.Settings.RequestUrl); } catch (Exception exc) { // TODO: Log the exception cause } Thread.Sleep(this.Settings.SnapshotDelayInMilliseconds); } } } }
public IHttpActionResult PostSnapshot(SnapshotViewModel model) { var currentDate = DateTime.Now; var year = currentDate.Year; var month = currentDate.ToString("MMMM"); var mm = currentDate.ToString("MMM"); var day = currentDate.Day; var timeOfDay = currentDate.TimeOfDay; var hours = timeOfDay.Hours.ToTimeString(); var minutes = timeOfDay.Minutes.ToTimeString(); var seconds = timeOfDay.Seconds.ToTimeString(); var image = ConvertionOperations.ImageFromByteArray(model.SnapshotAsByteArray); var fileName = $"{year}-{month}-{day}-{hours}-{minutes}-{seconds}.jpeg"; var filePath = $@"{this.BasePath}Sessions\{model.SessionId}"; var fullFilePath = $@"{filePath}\{fileName}"; this.CreateDirectory(filePath); image.Save(fullFilePath); return(this.Ok()); }