public LinkStreamListContext(StatusControlContext statusContext) { StatusContext = statusContext ?? new StatusControlContext(); SortListCommand = new Command <string>(x => StatusContext.RunNonBlockingTask(() => SortList(x))); ToggleListSortDirectionCommand = new Command(() => StatusContext.RunNonBlockingTask(async() => { SortDescending = !SortDescending; await SortList(_lastSortColumn); })); OpenUrlCommand = new Command <string>(x => StatusContext.RunNonBlockingTask(() => OpenUrl(x))); CopyUrlCommand = new Command <string>(x => StatusContext.RunNonBlockingTask(async() => { await ThreadSwitcher.ResumeForegroundAsync(); Clipboard.SetText(x); StatusContext.ToastSuccess($"To Clipboard {x}"); })); ListSelectedLinksNotOnPinboardCommand = new Command(x => StatusContext.RunBlockingTask(async() => await ListSelectedLinksNotOnPinboard(StatusContext.ProgressTracker()))); StatusContext.RunFireAndForgetBlockingTaskWithUiMessageReturn(LoadData); DataNotifications.DataNotificationChannel().MessageReceived += OnDataNotificationReceived; }
private static async void OnHtmlChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (d is WebView wb) { await ThreadSwitcher.ResumeForegroundAsync(); wb.NavigateToString(e.NewValue as string ?? "<h2>Loading...</h2>".ToHtmlDocument("...", string.Empty)); } }
public static async Task AllEventsExcelReport() { await ThreadSwitcher.ResumeBackgroundAsync(); var log = await Db.Log(); var htmlTable = log.EventLogs.OrderByDescending(x => x.RecordedOn).Cast <object>().ToList(); ExcelHelpers.ContentToExcelFileAsTable(htmlTable, "AllEventsReport"); }
private void PointContextOnRaisePointLatitudeLongitudeChange(object sender, PointLatitudeLongitudeChange e) { _webViewWorkQueue.Enqueue(async() => { await ThreadSwitcher.ResumeForegroundAsync(); await PointContentWebView.ExecuteScriptAsync( $@"pointContentMarker.setLatLng([{e.Latitude},{e.Longitude}]); map.setView([{e.Latitude},{e.Longitude}], map.getZoom());"); }); }
public static async Task AllPhotoMetadataToHtml(FileInfo selectedFile, StatusControlContext statusContext) { await ThreadSwitcher.ResumeBackgroundAsync(); if (selectedFile == null) { statusContext.ToastError("No photo..."); return; } selectedFile.Refresh(); if (!selectedFile.Exists) { statusContext.ToastError($"File {selectedFile.FullName} doesn't exist?"); return; } var photoMetaTags = ImageMetadataReader.ReadMetadata(selectedFile.FullName); var tagHtml = photoMetaTags.SelectMany(x => x.Tags).OrderBy(x => x.DirectoryName).ThenBy(x => x.Name) .ToList().Select(x => new { DataType = x.Type.ToString(), x.DirectoryName, Tag = x.Name, TagValue = ObjectDumper.Dump(x.Description) }).ToHtmlTable(new { @class = "pure-table pure-table-striped" }); var xmpDirectory = ImageMetadataReader.ReadMetadata(selectedFile.FullName).OfType <XmpDirectory>() .FirstOrDefault(); var xmpMetadata = xmpDirectory?.GetXmpProperties().Select(x => new { XmpKey = x.Key, XmpValue = x.Value }) .ToHtmlTable(new { @class = "pure-table pure-table-striped" }); await ThreadSwitcher.ResumeForegroundAsync(); var file = new FileInfo(Path.Combine(UserSettingsUtilities.TempStorageDirectory().FullName, $"PhotoMetadata-{Path.GetFileNameWithoutExtension(selectedFile.Name)}-{DateTime.Now:yyyy-MM-dd---HH-mm-ss}.htm")); var htmlString = ($"<h1>Metadata Report:</h1><h1>{HttpUtility.HtmlEncode(selectedFile.FullName)}</h1><br><h1>Metadata - Part 1</h1><br>" + tagHtml + "<br><br><h1>XMP - Part 2</h1><br>" + xmpMetadata) .ToHtmlDocumentWithPureCss("Photo Metadata", "body {margin: 12px;}"); await File.WriteAllTextAsync(file.FullName, htmlString); var ps = new ProcessStartInfo(file.FullName) { UseShellExecute = true, Verb = "open" }; Process.Start(ps); }
public static async Task DiagnosticEventsExcelReport() { await ThreadSwitcher.ResumeBackgroundAsync(); var log = await Db.Log(); var htmlTable = log.EventLogs.Where(x => x.Category == "Diagnostic" || x.Category == "Startup") .OrderByDescending(x => x.RecordedOn).Cast <object>().ToList(); ExcelHelpers.ContentToExcelFileAsTable(htmlTable, "DiagnosticEventsReport"); }
public static async Task AllEventsHtmlReport() { var log = await Db.Log(); var htmlTable = log.EventLogs.Take(5000).OrderByDescending(x => x.RecordedOn).ToList() .ToHtmlTable(new { @class = "pure-table pure-table-striped" }); await ThreadSwitcher.ResumeForegroundAsync(); var reportWindow = new HtmlViewerWindow(htmlTable.ToHtmlDocumentWithPureCss("Events Report", string.Empty)); reportWindow.Show(); }
public static async Task GenerationListHtmlReport(List <GenerationReturn> generationReturns, string title, string intro) { var bodyBuilder = new StringBuilder(); bodyBuilder.AppendLine($"<p>{HttpUtility.HtmlEncode(intro)}</p>"); bodyBuilder.AppendLine(generationReturns.ToHtmlTable(new { @class = "pure-table pure-table-striped" })); await ThreadSwitcher.ResumeForegroundAsync(); var reportWindow = new HtmlViewerWindow(bodyBuilder.ToString().ToHtmlDocumentWithPureCss(title, string.Empty)); reportWindow.Show(); }
public PostContentEditorWindow(PostContent toLoad) { InitializeComponent(); StatusContext = new StatusControlContext(); StatusContext.RunFireAndForgetBlockingTaskWithUiMessageReturn(async() => { PostContent = await PostContentEditorContext.CreateInstance(StatusContext, toLoad); PostContent.RequestContentEditorWindowClose += (_, _) => { Dispatcher?.Invoke(Close); }; AccidentalCloserHelper = new WindowAccidentalClosureHelper(this, StatusContext, PostContent); await ThreadSwitcher.ResumeForegroundAsync(); DataContext = this; }); }
private void PointContentEditorControl_OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { if (e.NewValue is PointContentEditorContext pointContext) { _webViewWorkQueue.Enqueue(async() => { await ThreadSwitcher.ResumeForegroundAsync(); PointContentWebView.NavigateToString(WpfHtmlDocument.ToHtmlLeafletPointDocument("Point Map", pointContext.LatitudeEntry.UserValue, pointContext.LongitudeEntry.UserValue, string.Empty)); }); RaisePointLatitudeLongitudeChange += pointContext.OnRaisePointLatitudeLongitudeChange; pointContext.RaisePointLatitudeLongitudeChange += PointContextOnRaisePointLatitudeLongitudeChange; } }
public FileContentEditorWindow(FileInfo initialFile) { InitializeComponent(); StatusContext = new StatusControlContext(); StatusContext.RunFireAndForgetBlockingTaskWithUiMessageReturn(async() => { FileContent = await FileContentEditorContext.CreateInstance(StatusContext, initialFile); FileContent.RequestContentEditorWindowClose += (sender, args) => { Dispatcher?.Invoke(Close); }; AccidentalCloserHelper = new WindowAccidentalClosureHelper(this, StatusContext, FileContent); await ThreadSwitcher.ResumeForegroundAsync(); DataContext = this; }); }
public static async Task ExceptionEventsHtmlReport() { await ThreadSwitcher.ResumeBackgroundAsync(); var log = await Db.Log(); var htmlTable = log.EventLogs.Where(x => x.Category == "Exception" || x.Category == "Startup").Take(1000) .OrderByDescending(x => x.RecordedOn).ToList() .ToHtmlTable(new { @class = "pure-table pure-table-striped" }); await ThreadSwitcher.ResumeForegroundAsync(); var reportWindow = new HtmlViewerWindow(htmlTable.ToHtmlDocumentWithPureCss("Exception Events Report", string.Empty)); reportWindow.Show(); }
/// <summary> /// Take screen shot of a Window. /// </summary> /// <remarks> /// - Usage example: screen shot icon in every window header. /// - Keep well away from any Windows Forms based methods that involve screen pixels. You will run into scaling issues /// at different /// monitor DPI values. Quote: "Keep in mind though that WPF units aren't pixels, they're device-independent @ 96DPI /// "pixelish-units"; so really what you want, is the scale factor between 96DPI and the current screen DPI (so like /// 1.5 for /// 144DPI) - Paul Betts." /// </remarks> public static async Task <bool> TryScreenShotToClipboardAsync(FrameworkElement frameworkElement) { await ThreadSwitcher.ResumeForegroundAsync(); //2020/5/6 - The line below is in the original stack overflow post but I had an error that this //call is not compatible with 'Window' and that is what I want to pass so commented out... original stack overflow comment //notes "hUses ClipToBounds so it is compatible with multiple docked windows in Infragistics." //frameworkElement.ClipToBounds = true; // Can remove if everything still works when the screen is maximized. var relativeBounds = VisualTreeHelper.GetDescendantBounds(frameworkElement); var areaWidth = frameworkElement.RenderSize .Width; // Cannot use relativeBounds.Width as this may be incorrect if a window is maximized. var areaHeight = frameworkElement.RenderSize.Height; // Cannot use relativeBounds.Height for same reason. var xLeft = relativeBounds.X; var xRight = xLeft + areaWidth; var yTop = relativeBounds.Y; var yBottom = yTop + areaHeight; var bitmap = new RenderTargetBitmap((int)Math.Round(xRight, MidpointRounding.AwayFromZero), (int)Math.Round(yBottom, MidpointRounding.AwayFromZero), 96, 96, PixelFormats.Default); // Render framework element to a bitmap. This works better than any screen-pixel-scraping methods which will pick up unwanted // artifacts such as the taskbar or another window covering the current window. var dv = new DrawingVisual(); using (var ctx = dv.RenderOpen()) { var vb = new VisualBrush(frameworkElement); ctx.DrawRectangle(vb, null, new Rect(new Point(xLeft, yTop), new Point(xRight, yBottom))); } bitmap.Render(dv); await ThreadSwitcher.ResumeBackgroundAsync(); return(await TryCopyBitmapToClipboard(bitmap)); }
private static async Task <bool> TryCopyBitmapSourceToClipboard(BitmapSource bmpCopied) { var tries = 3; while (tries-- > 0) { try { await ThreadSwitcher.ResumeForegroundAsync(); // This must be executed on the calling dispatcher. Clipboard.SetImage(bmpCopied); return(true); } catch (COMException) { // Windows clipboard is optimistic concurrency. On fail (as in use by another process), retry. await Task.Delay(TimeSpan.FromMilliseconds(100)); } } return(false); }