/**************************************************************************/ public static async Task <string> GetMimeTypeOfUrl(MacroscopeJobMaster JobMaster, Uri TargetUri) { MacroscopeHttpTwoClient Client = JobMaster.GetHttpClient(); MacroscopeHttpTwoClientResponse Response = null; string MimeType = null; try { Response = await Client.Head(TargetUri, ConfigureHeadRequestHeadersCallback, PostProcessRequestHttpHeadersCallback); if (Response != null) { MimeType = Response.GetMimeType().ToString(); } } catch (MacroscopeDocumentException ex) { DebugMsgStatic(string.Format("MacroscopeDocumentException: {0}", ex.Message)); DebugMsgStatic(string.Format("MacroscopeDocumentException: {0}", TargetUri.ToString())); } catch (Exception ex) { DebugMsgStatic(string.Format("Exception: {0}", ex.Message)); DebugMsgStatic(string.Format("Exception: {0}", TargetUri.ToString())); } return(MimeType); }
/**************************************************************************/ public async Task <Image> LoadImageFromUri(MacroscopeJobMaster JobMaster, Uri TargetUri) { MacroscopeHttpTwoClient Client = JobMaster.GetHttpClient(); MacroscopeHttpTwoClientResponse Response = null; Image LoadedImage = null; try { Response = await Client.Get( TargetUri, this.ConfigureHeadRequestHeadersCallback, this.PostProcessRequestHttpHeadersCallback ); } catch (MacroscopeDocumentException ex) { this.DebugMsg(string.Format("MacroscopeDocumentException: {0}", ex.Message)); this.DebugMsg(string.Format("MacroscopeDocumentException: {0}", TargetUri.ToString())); } catch (Exception ex) { this.DebugMsg(string.Format("Exception: {0}", ex.Message)); this.DebugMsg(string.Format("Exception: {0}", TargetUri.ToString())); } if (Response != null) { try { string ImageFilename = Path.GetTempFileName(); byte[] ByteData = Response.GetContentAsBytes(); using (FileStream ImageStream = File.Create(ImageFilename)) { foreach (byte b in ByteData) { ImageStream.WriteByte(b); } ImageStream.Close(); } if (File.Exists(ImageFilename)) { TemporaryFiles.Add(ImageFilename); LoadedImage = Image.FromFile(ImageFilename); } } catch (Exception ex) { this.DebugMsg(string.Format("Exception: {0}", ex.Message)); } } return(LoadedImage); }
/** -------------------------------------------------------------------- **/ private async Task <byte[]> _LoadMemoryStreamFromUrl(MacroscopeJobMaster JobMaster, Uri TargetUri) { MacroscopeHttpTwoClient Client = JobMaster.GetHttpClient(); MacroscopeHttpTwoClientResponse Response = null; byte[] ByteData = null; try { Response = await Client.Get( TargetUri, this.ConfigureHeadRequestHeadersCallback, this.PostProcessRequestHttpHeadersCallback ); } catch (MacroscopeDocumentException ex) { this.DebugMsg(string.Format("MacroscopeDocumentException: {0}", ex.Message)); this.DebugMsg(string.Format("MacroscopeDocumentException: {0}", TargetUri.ToString())); } catch (Exception ex) { this.DebugMsg(string.Format("Exception: {0}", ex.Message)); this.DebugMsg(string.Format("Exception: {0}", TargetUri.ToString())); } if (Response != null) { try { ByteData = Response.GetContentAsBytes(); } catch (Exception ex) { this.DebugMsg(string.Format("Exception: {0}", ex.Message)); } } else { this.DebugMsg("NULL"); } return(ByteData); }