Пример #1
0
        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 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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
0
        public void UpdateMyStatus(ChannelStatusUpdate update)
        {
            BuildRestClient();

            if (String.IsNullOrEmpty(update.InReplyTo))
            {
                client.SetStatus(update.Status);
            }
            else
            {
                client.PostComment(update.Status, update.InReplyTo);
            }
        }
        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);
            }
        }
Пример #9
0
        public static bool IsValid(this ChannelStatusUpdate status)
        {
            bool result = false;

            if (status != null)
            {
                if (!string.IsNullOrEmpty(status.ChannelId))
                {
                    result = true;
                }
            }

            return(result);
        }
Пример #10
0
        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);
        }
Пример #11
0
        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 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);
            }
        }
Пример #13
0
        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);
        }
Пример #14
0
        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 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);
                }
            }
        }
Пример #16
0
        public void ProcessStatusUpdate(ChannelStatusUpdate statusupdate, int statusType)
        {
            try
            {
                ChannelStatusUpdate statusupdate1 = statusupdate;
                UserStatus          status;

                using (mailbox.StatusUpdates.ReaderLock)
                    if (String.IsNullOrEmpty(searchKeyword))
                    {
                        status = mailbox.StatusUpdates.FirstOrDefault(
                            s => s.SourceChannelId == config.ChannelId &&
                            s.ChannelStatusKey == statusupdate1.ChannelStatusKey &&
                            s.StatusType == statusType);
                    }
                    else
                    {
                        status = mailbox.StatusUpdates.FirstOrDefault(
                            s => s.SearchKeyword == searchKeyword &&
                            s.ChannelStatusKey == statusupdate1.ChannelStatusKey &&
                            s.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);
            }
        }
        protected override void ExecuteChannelCore()
        {
            var channel = (IClientStatusUpdatesChannel)Channel;

            Status = channel.GetUserUpdates(address.Address, 1).FirstOrDefault();
        }