private void MakeNewImages() { if (LimitPresenter == null) { return; } _calcImage = LimitPresenter.TmpCalcImage; _selectedTemperatureProfile = LimitPresenter.PreviewTemperatureProfile; _geographicLocation = LimitPresenter.PreviewGeographicLocation; if (LimitPresenter.ThisTimeLimit.RootEntry == null) { throw new LPGException("root entry was null"); } _rootEntry = LimitPresenter.ThisTimeLimit.RootEntry; _household = LimitPresenter.PreviewHousehold; TimeLimitPresenter p = null; if (Dispatcher == null || Thread.CurrentThread == Dispatcher.Thread) { p = LimitPresenter; } var t = new Thread(() => UpdatePictures(p)); t.Start(); }
private void UpdatePictures([CanBeNull] TimeLimitPresenter p) { if (p == null) { return; } if (_household?.Vacation == null) { return; } if (_timeLimitEntry == null) { return; } lock (_pictureLock) { _concurrentlyRunningPreviewCount++; if (_concurrentlyRunningPreviewCount > 1) { throw new LPGException("this should never happen!"); } Action <Image, BitmapImage> setsingleimage = (i1, bitmapImage) => { p.BitmapSinglePermittedTime = bitmapImage; Logger.Debug("Setting the new image with " + bitmapImage.Width + " pixels width."); }; Action <Image, BitmapImage> setMergedImage = (i1, bitmapImage) => { p.BitmapAllPermittedTime = bitmapImage; Logger.Debug("Setting the new image with " + bitmapImage.Width + " pixels width."); }; Dispatcher?.Invoke(DispatcherPriority.Normal, setsingleimage, ImageShort, _calcImage); Dispatcher?.Invoke(DispatcherPriority.Normal, setMergedImage, ImageShort, _calcImage); var r = new Random(); var vacationTimeframes = _household.Vacation?.VacationTimeframes(); var previewKey = "TimeLimitView" + DateTime.Now.ToLongTimeString(); var br = _timeLimitEntry.GetOneYearHourArray(_selectedTemperatureProfile, _geographicLocation, r, vacationTimeframes, previewKey, out _); var bmp = MakeBitmapFromBitArray(br); BitmapImage totalImage; #pragma warning disable S2930 // "IDisposables" should be disposed var ms = new MemoryStream(); #pragma warning restore S2930 // "IDisposables" should be disposed { bmp.Save(ms, ImageFormat.Png); ms.Position = 0; var singleImage = new BitmapImage(); singleImage.BeginInit(); ms.Seek(0, SeekOrigin.Begin); singleImage.StreamSource = ms; singleImage.EndInit(); singleImage.Freeze(); if (singleImage.IsDownloading) { Logger.Info("image is downloading"); } ImageShort.Dispatcher?.Invoke(DispatcherPriority.Normal, setsingleimage, ImageShort, singleImage); } ms = new MemoryStream(); { var br3 = _rootEntry.GetOneYearHourArray(_selectedTemperatureProfile, _geographicLocation, r, vacationTimeframes, previewKey, out _); var bmp2 = MakeBitmapFromBitArray(br3); bmp2.Save(ms, ImageFormat.Png); ms.Position = 0; totalImage = new BitmapImage(); totalImage.BeginInit(); ms.Seek(0, SeekOrigin.Begin); totalImage.StreamSource = ms; } totalImage.EndInit(); totalImage.Freeze(); ImageLong.Dispatcher?.Invoke(DispatcherPriority.Normal, setMergedImage, ImageLong, totalImage); _concurrentlyRunningPreviewCount--; } }