private void SendMessage(FeedMessage[] feedMsgArr) { try { FeedCallback.SendDataFeed(feedMsgArr); try { if (logMessages) // messages sent to lightStreamer DataAdapter should be logged. { FeedMessagesLog.Add(feedMsgArr); } } catch (Exception exp) { m_NLog.Error("Error lin log of FeedMessages routine. Error Details: {0}", exp.ToString()); } } catch (CommunicationObjectAbortedException abortException) { this.FeedCallback = null; m_NLog.Error("Error : {0}", abortException.Message); m_NLog.Error("Client : {0} disconnected .", this.UserName); } catch (Exception exp) { m_NLog.Error("Error while sending feed to client : {0} ", this.UserName); m_NLog.Error("Error Details : {0} ", exp.ToString()); } }
/// <summary> /// Requests the asynchronous feed download from your game's target. /// </summary> /// <param name="callback">The <see cref="FeedCallback"/> delegate.</param> /// <param name="offset">The offset from feed begin.</param> /// <param name="limit">The maximum amount of stomts to load.</param> public void LoadFeed(FeedCallback callback, int offset = 0, int limit = 15) { LoadFeed(_targetId, callback, offset, limit); }
IEnumerator LoadFeedAsync(string target, FeedCallback callback, int offset, int limit) { HttpWebRequest request = WebRequest("GET", string.Format("{0}/targets/{1}/stomts/received?offset={2}&limit={3}", restServerURL, target, offset, limit)); // Send request and wait for response var async1 = request.BeginGetResponse(null, null); while (!async1.IsCompleted) { yield return(null); } HttpWebResponse response; var responseDataText = string.Empty; try { response = (HttpWebResponse)request.EndGetResponse(async1); } catch (WebException ex) { Debug.LogException(ex); yield break; } // Store access token _accessToken = response.Headers["accesstoken"]; // Read response stream using (var responseStream = response.GetResponseStream()) { if (responseStream == null) { yield break; } var buffer = new byte[2048]; int length; while ((length = responseStream.Read(buffer, 0, buffer.Length)) > 0) { responseDataText += Encoding.UTF8.GetString(buffer, 0, length); } } // Analyze JSON data LitJson.JsonData responseData = LitJson.JsonMapper.ToObject(responseDataText); if (responseData.Keys.Contains("error")) { Debug.LogError((string)responseData["error"]["msg"]); yield break; } responseData = responseData["data"]; var feed = new StomtItem[responseData.Count]; for (int i = 0; i < responseData.Count; i++) { var item = responseData[i]; feed[i] = new StomtItem { Id = (string)item["id"], Positive = (bool)item["positive"], Text = (string)item["text"], Language = (string)item["lang"], CreationDate = DateTime.Parse((string)item["created_at"]), Anonym = (bool)item["anonym"] }; if (feed[i].Anonym) { continue; } feed[i].CreatorId = (string)item["creator"]["id"]; feed[i].CreatorName = (string)item["creator"]["displayname"]; } callback(feed); }
/// <summary> /// Requests the asynchronous feed download from the specified target. /// </summary> /// <param name="target">The target to download the feed from.</param> /// <param name="callback">The <see cref="FeedCallback"/> delegate.</param> /// <param name="offset">The offset from feed begin.</param> /// <param name="limit">The maximum amount of stomts to load.</param> public void LoadFeed(string target, FeedCallback callback, int offset = 0, int limit = 15) { StartCoroutine(LoadFeedAsync(target, callback, offset, limit)); }