public async Task TestQrDecode() { MacroscopeJobMaster JobMaster = new MacroscopeJobMaster(JobRunTimeMode: MacroscopeConstants.RunTimeMode.LIVE); MacroscopeHttpImageLoader ImageLoader = new MacroscopeHttpImageLoader(); Uri ImageUri = new Uri("https://nazuke.github.io/MacroscopeTestHarness/htdocs/qrcodes/seo-macroscope-home-page-qrcode.png"); string QrCodeImageFilename = await ImageLoader.DownloadImageFromUriToFile(JobMaster : JobMaster, TargetUri : ImageUri); MacroscopeQrCodeAnalysis QrCodeAnalysis = new MacroscopeQrCodeAnalysis(); string ResultText = QrCodeAnalysis.Decode(ImageFilename: QrCodeImageFilename); Assert.AreEqual("https://nazuke.github.io/SEOMacroscope/", ResultText); }
/** -------------------------------------------------------------------- **/ private async Task _ProcessImagePage() { MacroscopeHttpTwoClient Client = this.DocCollection.GetJobMaster().GetHttpClient(); MacroscopeHttpTwoClientResponse Response = null; string ResponseErrorCondition = null; try { Response = await Client.Head( this.GetUri(), this.ConfigureImagePageRequestHeadersCallback, this.PostProcessRequestHttpHeadersCallback ); } catch (MacroscopeDocumentException ex) { this.DebugMsg(string.Format("_ProcessImagePage :: MacroscopeDocumentException: {0}", ex.Message)); ResponseErrorCondition = ex.Message; this.SetStatusCode(HttpStatusCode.BadRequest); this.AddRemark("_ProcessImagePage", ex.Message); } catch (Exception ex) { this.DebugMsg(string.Format("_ProcessImagePage :: Exception: {0}", ex.Message)); ResponseErrorCondition = ex.Message; this.SetStatusCode(HttpStatusCode.BadRequest); this.AddRemark("_ProcessImagePage", ex.Message); } if (Response != null) { this.ProcessResponseHttpHeaders(Response: Response); /** Title ---------------------------------------------------------- **/ { MatchCollection reMatches = Regex.Matches(this.DocUrl, "/([^/]+)$"); string DocumentTitle = null; foreach (Match match in reMatches) { if (match.Groups[1].Value.Length > 0) { DocumentTitle = match.Groups[1].Value.ToString(); break; } } if (DocumentTitle != null) { this.SetTitle(DocumentTitle, MacroscopeConstants.TextProcessingMode.NO_PROCESSING); this.DebugMsg(string.Format("TITLE: {0}", this.GetTitle())); } else { this.DebugMsg(string.Format("TITLE: {0}", "MISSING")); } } /** QR Codes ------------------------------------------------------- **/ if (MacroscopePreferencesManager.GetDetectQrCodeInImage()) { MacroscopeHttpImageLoader ImageLoader = new MacroscopeHttpImageLoader(); Uri QrCodeImageUri = null; string QrCodeImageFilename = await ImageLoader.DownloadImageFromUriToFile(JobMaster : this.DocCollection.GetJobMaster(), TargetUri : this.GetUri()); if ((!string.IsNullOrEmpty(QrCodeImageFilename)) && File.Exists(QrCodeImageFilename)) { MacroscopeQrCodeAnalysis QrCodeAnalysis = new MacroscopeQrCodeAnalysis(); string ResultText = QrCodeAnalysis.Decode(ImageFilename: QrCodeImageFilename); if (!string.IsNullOrEmpty(ResultText)) { try { QrCodeImageUri = new Uri(ResultText); } catch (UriFormatException ex) { this.DebugMsg(string.Format("UriFormatException: {0}", ResultText)); this.DebugMsg(string.Format("UriFormatException: {0}", ex.Message)); } if (QrCodeImageUri != null) { MacroscopeLink Outlink = null; Outlink = this.AddDocumentOutlink( AbsoluteUrl: QrCodeImageUri.AbsoluteUri, LinkType: MacroscopeConstants.InOutLinkType.QRCODE, Follow: true ); if (Outlink != null) { Outlink.SetRawTargetUrl(TargetUrl: QrCodeImageUri.AbsoluteUri); this.AddRemark("QRCODEIMAGE", "This image appears to be a QR Code."); } } } } } /** ---------------------------------------------------------------- **/ } if (ResponseErrorCondition != null) { this.ErrorCondition = ResponseErrorCondition; } }