コード例 #1
0
        private void LoadContactsAndMessages(bool fromLocalOnly)
        {
            this.MessageItems.Clear ();
            conversationItems.Clear ();
            contacts.Clear ();
            this.contacts = dbm.GetAllContactsForOwner (AndroidData.CurrentUser.AccountID.ToString ()).ToDictionary (s => s.ContactAccountID, s => s);
            List<MessageDB> message = new List<MessageDB> ();
            message = dbm.GetAllMessagesForOwner (AndroidData.CurrentUser.AccountID.ToString ());
            List<MessageDB> messages = new List<MessageDB> ();
            List<UserDB> users = new List<UserDB> ();

            foreach (MessageDB eachMessageDB in message) {
                ContactDB msgContact = null;
                UserDB contactUser = null;
                MessageInfo msgInfoItem = null;

                if (eachMessageDB.FromAccountID != AndroidData.CurrentUser.AccountID) {
                    if (this.contacts.TryGetValue (eachMessageDB.FromAccountID, out msgContact))
                        contactUser = UserDB.ConvertFromUser (msgContact.ContactUser);
                    else
                        contactUser = dbm.GetUserWithAccountID (eachMessageDB.FromAccountGuid);

                    msgInfoItem = new MessageInfo (eachMessageDB, contactUser);
                } else {
                    contactUser = UserDB.ConvertFromUser (AndroidData.CurrentUser);
                    msgInfoItem = new 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;
                /*if (isConversation == false) {
                    RunOnUiThread (delegate {
                        createUI (messages, users);
                    });
                }*/
            }

            if (fromLocalOnly) {
                RunOnUiThread (delegate {
                    if (progress != null)
                        progress.Dismiss ();
                    GetRowsForMessages ();
                    CreatePreviewUI ();
                });
            } else {
                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 ();

                LOLMessageClient service = new LOLMessageClient (LOLConstants.DefaultHttpBinding, LOLConstants.LOLMessageEndpoint);
            #if DEBUG
                System.Diagnostics.Debug.WriteLine ("**Will call MessageGetConversations with params: account id {0}, start date: new DateTime(1900, 1, 1), end date: new DateTime(2099, 1, 1), service auth token: {1}",
                                  AndroidData.CurrentUser.AccountID, new Guid (AndroidData.ServiceAuthToken));
            #endif
            #if DEBUG
                if (null == excludeMessageGuids) {

                    System.Diagnostics.Debug.WriteLine ("**Exclude message ids is NULL!");

                } else {
                    System.Diagnostics.Debug.WriteLine ("**Exclude message ids count: {0}", excludeMessageGuids.Count);

                    foreach (Guid eachMessageID in excludeMessageGuids) {
                        System.Diagnostics.Debug.WriteLine ("**Each message id to exclude: {0}", eachMessageID);
                    }//end foreach
                }//end if
                #endif

                service.MessageGetConversationsCompleted += Service_MessageGetConversationsCompleted;
                service.MessageGetConversationsAsync (AndroidData.CurrentUser.AccountID,
                                                     new DateTime (1900, 1, 1),
                                                     new DateTime (2099, 1, 1), 50,
                                                     excludeMessageGuids,
                                                     new Guid (AndroidData.ServiceAuthToken));
            }//end if else
        }