// use this method to request an image from a file and to store it in the cache public void requestImageFromFile(String _fileName, delegate_OnReqestImageDone _sink) { try { String imageId = _fileName; // if image is already in cache, we immediately notify the sinks if (this.existsImage(_fileName)) { if (_sink != null) { ((delegate_OnReqestImageDone)_sink)(_fileName); } } else { this.addImage(imageId, Image.FromFile(_fileName)); if (_sink != null) { ((delegate_OnReqestImageDone)_sink)(_fileName); } } } catch (Exception e) { this.writeLog(LogType.Error, String.Format("Fehler bei 'requestImageFromFile' für Datei '{0}'", _fileName), e); } }
// use this method to request an image from an url and to store it in the cache public void requestImageFromUrl(String _imageUrl, delegate_OnReqestImageDone _sink) { try { // if image is already in cache, we immediately notify the sinks // otherwise start web request for url if (this.existsImage(_imageUrl)) { if (_sink != null) { ((delegate_OnReqestImageDone)_sink)(_imageUrl); } } else { lock (imageUrlOnRequest) { if (!imageUrlOnRequest.ContainsKey(_imageUrl)) { imageUrlOnRequest.Add(_imageUrl, new List <delegate_OnReqestImageDone>()); webRequestHelper.httpPostRequestAsync(_imageUrl, null, null, (response) => requestImageFromUrlSink(response, _sink, _imageUrl)); } else { imageUrlOnRequest[_imageUrl].Add(_sink); } } } } catch (Exception e) { this.writeLog(LogType.Error, String.Format("Fehler bei 'requestImageFromUrl' für Url '{0}'", _imageUrl), e); } }
// this method is called if a reqestImageFromUrl action has retrieved the data protected virtual void requestImageFromUrlSink(HttpWebResponse _reponse, delegate_OnReqestImageDone _sink, String _imageId) { try { String imageId = _imageId; Stream stream = _reponse.GetResponseStream(); if (stream == null) { return; } this.addImage(imageId, Image.FromStream(stream)); if (_sink != null) { ((delegate_OnReqestImageDone)_sink)(imageId); } } catch (Exception e) { this.writeLog(LogType.Error, String.Format("Fehler bei 'requestImageFromUrlSink' für Url '{0}'", _reponse.ResponseUri.AbsoluteUri), e); } lock (imageUrlOnRequest) { if (imageUrlOnRequest.ContainsKey(_imageId)) { foreach (var delegateLink in imageUrlOnRequest[_imageId]) { if (delegateLink != null) { ((delegate_OnReqestImageDone)delegateLink)(_imageId); } } imageUrlOnRequest.Remove(_imageId); } } }
// this method is called if a reqestImageFromUrl action has retrieved the data protected virtual void requestImageFromUrlSink(HttpWebResponse _reponse, delegate_OnReqestImageDone _sink, String _imageId) { try { String imageId = _imageId; Stream stream = _reponse.GetResponseStream(); if (stream == null) return; this.addImage(imageId, Image.FromStream(stream)); if (_sink != null) ((delegate_OnReqestImageDone)_sink)(imageId); } catch(Exception e) { this.writeLog(LogType.Error, String.Format("Fehler bei 'requestImageFromUrlSink' für Url '{0}'", _reponse.ResponseUri.AbsoluteUri), e); } lock (imageUrlOnRequest) { if (imageUrlOnRequest.ContainsKey(_imageId)) { foreach(var delegateLink in imageUrlOnRequest[_imageId]) { if (delegateLink != null) ((delegate_OnReqestImageDone)delegateLink)(_imageId); } imageUrlOnRequest.Remove(_imageId); } } }
// use this method to request an image from an url and to store it in the cache public void requestImageFromUrl(String _imageUrl, delegate_OnReqestImageDone _sink) { try { // if image is already in cache, we immediately notify the sinks // otherwise start web request for url if (this.existsImage(_imageUrl)) { if (_sink != null) ((delegate_OnReqestImageDone)_sink)(_imageUrl); } else { lock (imageUrlOnRequest) { if (!imageUrlOnRequest.ContainsKey(_imageUrl)) { imageUrlOnRequest.Add(_imageUrl, new List<delegate_OnReqestImageDone>()); webRequestHelper.httpPostRequestAsync(_imageUrl, null, null, (response) => requestImageFromUrlSink(response, _sink, _imageUrl)); } else { imageUrlOnRequest[_imageUrl].Add(_sink); } } } } catch (Exception e) { this.writeLog(LogType.Error, String.Format("Fehler bei 'requestImageFromUrl' für Url '{0}'", _imageUrl), e); } }
// use this method to request an image from a file and to store it in the cache public void requestImageFromFile(String _fileName, delegate_OnReqestImageDone _sink) { try { String imageId = _fileName; // if image is already in cache, we immediately notify the sinks if (this.existsImage(_fileName)) { if (_sink != null) ((delegate_OnReqestImageDone)_sink)(_fileName); } else { this.addImage(imageId, Image.FromFile(_fileName)); if (_sink != null) ((delegate_OnReqestImageDone)_sink)(_fileName); } } catch (Exception e) { this.writeLog(LogType.Error, String.Format("Fehler bei 'requestImageFromFile' für Datei '{0}'", _fileName),e); } }