Ejemplo n.º 1
0
        private void GetMessages()
        {
            if (!killed)
            {
                if (Messages.MessageConversations.storedMessages.Count != 0)
                    Messages.MessageConversations.storedMessages.Clear();
                List<MessageDB> message = new List<MessageDB>();
                message = dbm.GetAllMessagesForOwner(AndroidData.CurrentUser.AccountID.ToString());
                foreach (MessageDB m in message)
                    Messages.MessageConversations.storedMessages.Add(m);
                if (Messages.MessageConversations.storedMessages.Count == 0)
                {
                    List<Guid> excludeMessageGuids = new List<Guid>();
                    /*excludeMessageGuids = this.MessageItems.Values.Where (s => s.Message.MessageStepDBList.Count (t => t.StepID == default(Guid)) == 0)
                    .Select (s => s.Message.MessageID).ToList ();*/
                    excludeMessageGuids = Messages.MessageConversations.storedMessages.Where(s => s.MessageStepDBList.Count(t => t.StepID == default(Guid)) == 0)
                        .Select(s => s.MessageID).ToList();
                    LOLMessageClient service = new LOLMessageClient(LOLConstants.DefaultHttpBinding, LOLConstants.LOLMessageEndpoint);
                    service.MessageGetNewCompleted += Service_MessageGetNewCompleted;
                    service.MessageGetNewAsync(AndroidData.CurrentUser.AccountID, AndroidData.NewDeviceID,
                                                     excludeMessageGuids,
                                                     new Guid(AndroidData.ServiceAuthToken));
                } else
                {
                    List<MessageDB> messages = new List<MessageDB>();
                    List<UserDB> users = new List<UserDB>();
                    foreach (MessageDB eachMessageDB in message)
                    {
                        if (eachMessageDB != null)
                        {
                            UserDB contactUser = null;
                            Messages.MessageInfo msgInfoItem = null;

                            if (eachMessageDB.FromAccountID != AndroidData.CurrentUser.AccountID)
                            {
                                foreach (ContactDB contact in Contacts.ContactsUtil.contacts)
                                {
                                    if (contact.ContactAccountID == eachMessageDB.FromAccountID)
                                    {
                                        contactUser = UserDB.ConvertFromUser(contact.ContactUser);
                                        break;
                                    } else
                                        contactUser = dbm.GetUserWithAccountID(eachMessageDB.FromAccountGuid);
                                }

                                msgInfoItem = new Messages.MessageInfo(eachMessageDB, contactUser);
                            } else
                            {
                                contactUser = UserDB.ConvertFromUser(AndroidData.CurrentUser);
                                msgInfoItem = new Messages.MessageInfo(eachMessageDB, contactUser);

                                if (!eachMessageDB.MessageConfirmed)
                                {
                                    ContentInfo contentInfo = dbm.GetContentInfoByMessageDBID(eachMessageDB.ID);
                                    msgInfoItem.ContentInfo = contentInfo;
                                }
                            }
                            messages.Add(eachMessageDB);
                            users.Add(contactUser);
                            this.MessageItems [eachMessageDB.MessageID] = msgInfoItem;
                        }
                    }
                }
            }
        }