public UserStatus ParseStatusUpdate(ChannelStatusUpdate statusupdate, int statusType) { var status = new UserStatus { From = statusupdate.From, To = statusupdate.To, Status = statusupdate.Status, StatusType = statusType, SortDate = statusupdate.DatePosted, SourceChannelId = IsInSearchMode ? 0 : config.ChannelId, ChannelStatusKey = statusupdate.ChannelStatusKey, SearchKeyword = searchKeyword, IsRead = IsRead, IsNew = true, DateCreated = DateTime.Now, }; foreach (var statusattachment in statusupdate.Attachments) { var attachment = new UserStatusAttachment { StatusKey = status.StatusKey, PreviewAltText = statusattachment.PreviewAltText, PreviewImageUrl = statusattachment.PreviewImageUrl, TargetUrl = statusattachment.TargetUrl, MediaType = statusattachment.MediaType, DateCreated = DateTime.Now }; status.Attachments.Add(attachment); } return status; }
public void ProcessStatusUpdate(ChannelStatusUpdate statusupdate, int statusType) { try { ChannelStatusUpdate statusupdate1 = statusupdate; UserStatus status; if (String.IsNullOrEmpty(searchKeyword)) status = dataService.SelectBy<UserStatus>(new { SourceChannelId = config.ChannelId, ChannelStatusKey = statusupdate1.ChannelStatusKey, StatusType = statusType }); else status = dataService.SelectBy<UserStatus>(new { SearchKeyword = searchKeyword, ChannelStatusKey = statusupdate1.ChannelStatusKey, StatusType = statusType }); if (status != null) { // Allready have this status update if (status.Children.Count == statusupdate1.Children.Count) return; // Have received more replies to an existing thread foreach (var child in statusupdate1.Children) { var child1 = child; var oldChild = status.Children.FirstOrDefault(s => s.ChannelStatusKey == child1.ChannelStatusKey); if (oldChild == null) ProcessChild(status, child1, statusType); } } else { // Have received a new thread status = ProcessParent(statusupdate1, statusType); foreach (var child in statusupdate1.Children) ProcessChild(status, child, statusType); if (!String.IsNullOrEmpty(searchKeyword)) status.SearchKeyword = searchKeyword; } } catch (Exception ex) { Logger.Error("An error has occured while matching status update. Exception = {0}", LogSource.AppServer, ex); } }
ChannelStatusUpdate ParseFbStatus(FbStatus fbStatus) { var status = new ChannelStatusUpdate(); status.ChannelStatusKey = fbStatus.StatusId; status.From = fbStatus.From; status.To = fbStatus.To; status.Status = fbStatus.Message; status.DatePosted = fbStatus.DateCreated; foreach (var fbAttachment in fbStatus.Attachments) { var attachment = new ChannelStatusUpdateAttachment(); attachment.MediaType = (short)fbAttachment.MediaType; attachment.PreviewAltText = fbAttachment.PreviewAltText; attachment.PreviewImageUrl = fbAttachment.PreviewImageUrl; attachment.TargetUrl = fbAttachment.TargetUrl; status.Attachments.Add(attachment); } return status; }
public void UpdateMyStatus(ChannelStatusUpdate update) { BuildRestClient(); if (String.IsNullOrEmpty(update.InReplyTo)) client.SetStatus(update.Status); else client.PostComment(update.Status, update.InReplyTo); }
UserStatus ProcessParent(ChannelStatusUpdate statusupdate, int statusType) { UserStatus status = ParseStatusUpdate(statusupdate, statusType); ClientState.Current.DataService.Save(status); status.Attachments.ForEach(ClientState.Current.DataService.Save); mailbox.StatusUpdates.Add(status); EventBroker.Publish(AppEvents.StatusUpdateReceived, status); return status; }
void ProcessChild(UserStatus status, ChannelStatusUpdate child, int statusType) { var childStatus = ParseStatusUpdate(child, statusType); childStatus.ParentKey = status.StatusKey; childStatus.Attachments.ForEach(ClientState.Current.DataService.Save); ClientState.Current.DataService.Save(childStatus); status.Add(childStatus); EventBroker.Publish(AppEvents.StatusUpdateReceived, status); }
void ProcessChild(UserStatus status, ChannelStatusUpdate child, int statusType) { var childStatus = ParseStatusUpdate(child, statusType); childStatus.ParentKey = status.StatusKey; childStatus.Attachments.ForEach(ClientState.Current.DataService.Save); ClientState.Current.DataService.Save(childStatus); ClientState.Current.Search.Store(status); }
UserStatus ProcessParent(ChannelStatusUpdate statusupdate, int statusType) { UserStatus status = ParseStatusUpdate(statusupdate, statusType); ClientState.Current.DataService.Save(status); status.Attachments.ForEach(ClientState.Current.DataService.Save); ClientState.Current.Search.Store(status); return status; }
public IEnumerable<ChannelStatusUpdate> GetUserUpdates(string username, int pageSize) { const string url = "https://www.yammer.com/api/v1/messages/from_user/{0}.xml"; var result = YammerWebRequest.PerformRequest(new Uri(String.Format(url, username)), ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret); foreach (var element in result.Element("response").Elements("messages").Elements("message")) { var update = new ChannelStatusUpdate(); update.ChannelStatusKey = element.Element("id").Value; update.From = new SourceAddress(element.Element("sender-id").Value, username); update.Status = element.Element("body").Element("plain").Value; update.DatePosted = DateTime.Parse(element.Element("created-at").Value); yield return update; } }
public void UpdateMyStatus(ChannelStatusUpdate update) { var p = new Dictionary<string, object> { {"body", update.Status} }; if (!String.IsNullOrEmpty(update.InReplyTo)) p.Add("replied_to_id", update.InReplyTo); YammerWebRequest.PerformRequest(new Uri("https://www.yammer.com/api/v1/messages/"), ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret, p); }
public IEnumerable<ChannelStatusUpdate> GetUpdates(int pageSize) { var contacts = GetYammerContacts(); var result = YammerWebRequest.PerformRequest(new Uri("https://www.yammer.com/api/v1/messages.xml"), ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret); var dict = new Dictionary<string, List<ChannelStatusUpdate>>(); foreach (var element in result.Element("response").Elements("messages").Elements("message")) { var update = new ChannelStatusUpdate(); var contact = contacts.First(c => c.Id == element.Element("sender-id").Value); update.ChannelStatusKey = element.Element("id").Value; update.From = new SourceAddress(contact.Id, contact.FullName, contact.AvatarUrl); update.Status = element.Element("body").Element("plain").Value; update.DatePosted = DateTime.Parse(element.Element("created-at").Value); foreach (var attachmentElement in element.Descendants("attachment")) { var attachment = new ChannelStatusUpdateAttachment(); var type = attachmentElement.Element("type").Value; attachment.PreviewAltText = attachmentElement.Element("name").Value; attachment.TargetUrl = attachmentElement.Element("web-url").Value; if (type == "image") { attachment.MediaType = StatusAttachmentTypes.Photo; attachment.PreviewImageUrl = attachmentElement.Element("image").Element("thumbnail-url").Value; } else { attachment.MediaType = StatusAttachmentTypes.Document; } update.Attachments.Add(attachment); } var threadid = element.Element("thread-id").Value; if (!dict.ContainsKey(threadid)) dict.Add(threadid, new List<ChannelStatusUpdate>()); dict[threadid].Add(update); } var updates = new List<ChannelStatusUpdate>(); foreach (var value in dict.Values) { var sortedList = value.OrderBy(c => c.DatePosted).ToList(); var first = sortedList.First(); first.Children.AddRange(sortedList.Skip(1)); updates.Add(first); } return updates.OrderByDescending(s => s.SortDate); }
public void UpdateMyStatus(ChannelStatusUpdate update) { var service = new TwitterService(ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret); if (!String.IsNullOrEmpty(update.InReplyTo)) service.SendTweet(update.Status, Int64.Parse(update.InReplyTo)); else service.SendTweet(update.Status); }
public void UpdateMyStatus(ChannelStatusUpdate update) { var element = new XElement("current-status", update.Status.StripHtml()); LinkedInWebRequest.Put(new Uri("http://api.linkedin.com/v1/people/~/current-status"), element.ToString(), ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret); }
public IEnumerable<ChannelStatusUpdate> GetUserUpdates(string username, int pageSize) { var result = LinkedInWebRequest.PerformRequest(new Uri(String.Concat("http://api.linkedin.com/v1/people/id=", username, ":(current-status,current-status-timestamp)")), ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret); if (result.Elements("person").Elements().Count() == 0) yield break; foreach (var response in result.Elements("person")) { var update = new ChannelStatusUpdate(); update.Status = response.Element("current-status").Value; var ts = TimeSpan.FromMilliseconds(Double.Parse(response.Element("current-status-timestamp").Value)); update.DatePosted = ((long) ts.TotalSeconds).ToUnixTime(); yield return update; } }
public IEnumerable<ChannelStatusUpdate> GetUpdates(int pageSize) { var result = LinkedInWebRequest.PerformRequest(new Uri("http://api.linkedin.com/v1/people/~/network"), ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret); if (result.Element("network").Elements().Count() == 0) yield break; foreach (var response in result.Element("network").Element("updates").Elements("update")) { ChannelStatusUpdate statusUpdate = null; var updateType = (LinkedInUpdateType)Enum.Parse(typeof(LinkedInUpdateType), response.Element("update-type").Value); switch (updateType) { case LinkedInUpdateType.ANSW: // TODO : Answer Update break; case LinkedInUpdateType.APPS: case LinkedInUpdateType.APPM: // TODO : Application Update break; case LinkedInUpdateType.CONN: case LinkedInUpdateType.NCON: case LinkedInUpdateType.CCEM: // Connection updates statusUpdate = new ChannelStatusUpdate { ChannelStatusKey = BuildChannelStatusKey(response), From = BuildSourceAddress(response), Status = BuildConnectionStatusMessage(response), DatePosted = GetDateTime(response) }; break; case LinkedInUpdateType.JOBS: case LinkedInUpdateType.JOBP: // TODO : Posted a job break; case LinkedInUpdateType.JGRP: // TODO : Joined a group break; case LinkedInUpdateType.PICT: case LinkedInUpdateType.PICU: // TODO : Changed a picture break; case LinkedInUpdateType.RECU: case LinkedInUpdateType.PREC: // TODO : Recommendations break; case LinkedInUpdateType.PRFU: case LinkedInUpdateType.PROF: // TODO : Changed profile break; case LinkedInUpdateType.QSTN: // TODO : Question update break; case LinkedInUpdateType.STAT: // Status update statusUpdate = new ChannelStatusUpdate { ChannelStatusKey = BuildChannelStatusKey(response), From = BuildSourceAddress(response), Status = response.Element("update-content").Element("person").Element("current-status").Value, DatePosted = GetDateTime(response) }; break; } if (statusUpdate != null) yield return statusUpdate; } }