Пример #1
0
        public static void SavePageConversations(string AccessToken, string ProfileId)
        {
            try
            {
                Domain.Socioboard.Models.Mongo.MongoTwitterDirectMessages _TwitterDirectMessages;
                dynamic data = FbUser.conversations(AccessToken);
                if (data != null)
                {
                    apiHitsCount++;
                    foreach (var item in data["data"])
                    {
                        foreach (var msg_item in item["messages"]["data"])
                        {
                            _TwitterDirectMessages = new Domain.Socioboard.Models.Mongo.MongoTwitterDirectMessages();

                            try
                            {
                                _TwitterDirectMessages.messageId = msg_item["id"].ToString();
                            }
                            catch (Exception ex)
                            {
                            }
                            try
                            {
                                _TwitterDirectMessages.createdDate = Convert.ToDateTime(msg_item["created_time"].ToString()).ToString("yyyy/MM/dd HH:mm:ss");
                            }
                            catch (Exception ex)
                            {
                            }
                            try
                            {
                                _TwitterDirectMessages.senderId = msg_item["from"]["id"].ToString();
                            }
                            catch (Exception ex)
                            {
                            }
                            try
                            {
                                _TwitterDirectMessages.senderScreenName = msg_item["from"]["name"].ToString();
                            }
                            catch (Exception ex)
                            {
                            }
                            try
                            {
                                _TwitterDirectMessages.senderProfileUrl = "http://graph.facebook.com/" + _TwitterDirectMessages.senderId + "/picture?type=small";
                            }
                            catch (Exception ex)
                            {
                            }
                            try
                            {
                                _TwitterDirectMessages.recipientId = msg_item["to"]["data"][0]["id"].ToString();
                            }
                            catch (Exception ex)
                            {
                            }
                            try
                            {
                                _TwitterDirectMessages.recipientScreenName = msg_item["to"]["data"][0]["name"].ToString();
                            }
                            catch (Exception ex)
                            {
                            }
                            try
                            {
                                _TwitterDirectMessages.recipientProfileUrl = "http://graph.facebook.com/" + _TwitterDirectMessages.recipientId + "/picture?type=small";
                            }
                            catch (Exception ex)
                            {
                            }
                            try
                            {
                                _TwitterDirectMessages.message = msg_item["message"].ToString();
                                if (string.IsNullOrEmpty(_TwitterDirectMessages.message))
                                {
                                    if ((msg_item["attachments"]["data"][0]["mime_type"].ToString()).Contains("image"))
                                    {
                                        _TwitterDirectMessages.image = msg_item["attachments"]["data"][0]["image_data"]["url"].ToString();
                                    }
                                    else
                                    {
                                        _TwitterDirectMessages.message = msg_item["attachments"]["data"][0]["name"].ToString();
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                            }
                            try
                            {
                                _TwitterDirectMessages.image = msg_item["shares"]["data"][0]["link"].ToString();
                            }
                            catch (Exception ex)
                            {
                            }
                            if (_TwitterDirectMessages.senderId == ProfileId)
                            {
                                _TwitterDirectMessages.type = Domain.Socioboard.Enum.TwitterMessageType.FacebookPageDirectMessageSent;
                            }
                            else
                            {
                                _TwitterDirectMessages.type = Domain.Socioboard.Enum.TwitterMessageType.FacebookPagDirectMessageReceived;
                            }

                            //code to add facebook page conversations
                            MongoRepository mongorepo = new MongoRepository("MongoTwitterDirectMessages");
                            var             ret       = mongorepo.Find <Domain.Socioboard.Models.Mongo.MongoTwitterDirectMessages>(t => t.messageId == _TwitterDirectMessages.messageId);
                            var             task      = Task.Run(async() =>
                            {
                                return(await ret);
                            });
                            int count = task.Result.Count;
                            if (count > 0)
                            {
                            }
                            else
                            {
                                mongorepo.Add(_TwitterDirectMessages);
                            }
                        }
                    }
                }
                else
                {
                    apiHitsCount = MaxapiHitsCount;
                }
            }
            catch (Exception ex)
            {
                apiHitsCount = MaxapiHitsCount;
            }
        }