public void GetLastDweet() { var uri = "https://dweet.io/get/latest/dweet/for/" + _thing; Log.Instance.Debug("Get last dweet from: {0}", uri); try { using (var wc = new CustomWebClient()) { wc.OpenReadCompleted += WebClient_OpenReadCompleted; wc.OpenReadAsync(new Uri(uri)); } } catch (Exception e) { Log.Instance.Error(e); } }
public bool ListenForDweets(Action <Dweet> dweetHandler) { _dweetHandler = dweetHandler; Log.Instance.Debug("Initialize CustomWebClient..."); _webClient = new CustomWebClient { KeepAlive = true, Timeout = new TimeSpan(0, 0, 0, 3) }; var uri = "https://dweet.io/listen/for/dweets/from/" + _thing; Log.Instance.Debug("Begin listening dweets from: {0}", uri); var wr = (HttpWebRequest)WebRequest.Create(uri); wr.ProtocolVersion = Version.Parse("1.0"); var response = (HttpWebResponse)wr.GetResponse(); try { _webClient.OpenReadCompleted += WebClient_OpenReadCompleted; _webClient.OpenReadAsync(new Uri(uri)); } catch (Exception e) { Log.Instance.Error(e); } // If web client is busy, then connection is open _isListening = _webClient.IsBusy; return(_isListening); }