Пример #1
0
        private void Service_MessageCreateCompleted(object sender, MessageCreateCompletedEventArgs e)
        {
            #if(DEBUG)
            System.Diagnostics.Debug.WriteLine("Message create completed!");
            #endif

            LOLMessageClient service = (LOLMessageClient)sender;
            service.MessageCreateCompleted -= Service_MessageCreateCompleted;

            if (null == e.Error)
            {
                Message result = e.Result;
                ContentInfo contentInfo = (ContentInfo)e.UserState;

                if (result.Errors.Count > 0)
                {
            #if(DEBUG)
                    System.Diagnostics.Debug.WriteLine("Error sending message! {0}", StringUtils.CreateErrorMessageFromMessageGeneralErrors(result .Errors).ToString());
            #endif
                    this.IsSendingMessage = false;
                    contentInfo.IsMessageCreateFailed = true;
                    RunOnUiThread(() => Toast.MakeText(context, Resource.String.errorMessageSendFail, ToastLength.Short).Show());
                    this.ContentInfoQ.Enqueue(contentInfo);
                } else
                {
                    contentInfo.Message.MessageID = result.MessageID;

                    MessageDB messageDB = MessageDB.ConvertFromMessage(result);
                    messageDB.MessageStepDBList = MessageDB.ConvertFromMessage(contentInfo.Message).MessageStepDBList;
                    foreach (MessageStepDB eachStep in messageDB.MessageStepDBList)
                    {
                        eachStep.MessageID = messageDB.MessageID;
                    }//end foreach

                    dbm.InsertOutgoingMessage(messageDB);

                    ContentState ulState = new ContentState(messageDB);
                    contentInfo.ContentState = ulState;

                    this.SendNextStep(contentInfo, service);
                }//end if else
            } else
            {
                this.IsSendingMessage = false;
            }//end if else

            this.SendNextMessage(service);
        }
Пример #2
0
        public List<ContentInfo> GetAllContentInfo()
        {
            lock (this.dbLock)
            {

                using (SQLiteConnection sqlCon = new SQLiteConnection(this.DBPath))
                {

                    sqlCon.Execute(WZConstants.DBClauseSyncOff);

                    List<ContentInfo> toReturn =
                        sqlCon.Query<ContentInfo>("SELECT * FROM ContentInfo");

                    foreach (ContentInfo eachContentInfo in toReturn)
                    {

                        MessageDB msg = sqlCon.Query<MessageDB>("SELECT * FROM MessageDB WHERE ID=?", eachContentInfo.MessageDBID)
                            .FirstOrDefault();
                        eachContentInfo.Message = MessageDB.ConvertFromMessageDB(msg);

                        List<MessageStepDBCache> msgSteps =
                            sqlCon.Query<MessageStepDBCache>("SELECT * FROM MessageStepDBCache WHERE MessageDBID=?", eachContentInfo.MessageDBID);
                        eachContentInfo.Message.MessageSteps = new List<MessageStep>();

                        for (int i = 0; i < msgSteps.Count; i++)
                        {
                            eachContentInfo.Message.MessageSteps [i] = MessageStepDBCache.ConvertFromMessageStepDB(msgSteps [i]);

                        }//end for

                        List<MessageRecipientDBCache> msgRcp =
                            sqlCon.Query<MessageRecipientDBCache>("SELECT * FROM MessageRecipientDBCache WHERE MessageDBID=?", eachContentInfo.MessageDBID);
                        eachContentInfo.Recipients = new List<Guid>();
                        eachContentInfo.Message.MessageRecipients = new List<Message.MessageRecipient>();

                        for (int i = 0; i < msgRcp.Count; i++)
                        {
                            eachContentInfo.Recipients [i] = new Guid(msgRcp [i].AccountGuid);
                            eachContentInfo.Message.MessageRecipients [i] = new Message.MessageRecipient() {

                                AccountID = eachContentInfo.Recipients[i],
                                IsRead = false

                            };
                        }//end for

                        List<VoiceCache> voiceRecordings =
                            sqlCon.Query<VoiceCache>("SELECT * FROM VoiceCache WHERE ContentInfoID=?", eachContentInfo.ID);
                        eachContentInfo.VoiceRecordings =
                            voiceRecordings.ToDictionary(s => s.StepNumber, s => s.VoiceData);

                        List<PollingStepDBCache> pollingSteps =
                            sqlCon.Query<PollingStepDBCache>("SELECT * FROM PollingStepDBCache WHERE ContentInfoID=?", eachContentInfo.ID);
                        eachContentInfo.PollingSteps =
                            pollingSteps.ToDictionary(s => s.StepNumber, s => PollingStepDB.ConvertFromPollingStepDB(s));

                        if (sqlCon.Query<ContentState>("SELECT * FROM ContentState WHERE ContentInfoID=?", eachContentInfo.ID).Count == 1)
                        {

                            ContentState contentState = new ContentState(MessageDB.ConvertFromMessage(eachContentInfo.Message));
                            //TODO: Set animation items to remove in DBManager.GetAllContentInfo()!
            #if(DEBUG)
                            Console.WriteLine("TODO: Set animation items to remove in DBManager.GetAllContentInfo()!");
            #endif
                            contentState.RemoveExistingItems(null,
                                                             new List<int>(voiceRecordings
                                                             .Where(s => s.IsSent)
                                                             .Select(s => s.StepNumber)),
                                                             new List<int>(pollingSteps
                                                             .Where(s => s.IsSent)
                                                             .Select(s => s.StepNumber)), null);

                            eachContentInfo.ContentState = contentState;

                        }//end if

                    }//end foreach

                    return toReturn;

                }//end using sqlCon

            }//end lock
        }
        private void PlayMessage(MessageDB message)
        {
            voiceFiles.Clear();
            contentPackItems.Clear();
            pollSteps.Clear();

            MessageInfo messageInfo = this.MessageItems [message.MessageID];
            ContentState dlState = new ContentState(message);
            contentPackItems = getLocalContentPackItems(dlState.ContentPackIDQ.ToList())
                .ToDictionary(s => s.ContentPackItemID, s => ContentPackItemDB.ConvertFromContentPackItemDB(s));

            if (messageInfo.HasContentInfo)
            {
                RunOnUiThread(delegate
                {
                    if (progress != null)
                        progress.Dismiss();
                    this.PlayUnsentMessage(messageInfo.ContentInfo);
                });
            } else
            {
                Dictionary<Guid, Dictionary<int, string>> localVoiceFiles =
                    getLocalVoiceFiles(new List<Pair<Guid, List<int>>>() { new Pair<Guid, List<int>>(dlState.Message.MessageID, dlState.VoiceIDQ.ToList()) });

                if (!localVoiceFiles.TryGetValue(dlState.Message.MessageID, out voiceFiles))
                    voiceFiles = new Dictionary<int, string>();

                pollSteps = getLocalPollingStepsForMessage(dlState.Message.MessageGuid)
                    .ToDictionary(s => s.StepNumber, s => PollingStepDB.ConvertFromPollingStepDB(s));

                List<int> animationStepNumbers =
                    dlState.Message.MessageStepDBList
                        .Where(s => s.StepType == MessageStep.StepTypes.Animation)
                        .Select(s => s.StepNumber)
                        .ToList();

                dlState.RemoveExistingItems(contentPackItems.Keys.ToList(), voiceFiles.Keys.ToList(), pollSteps.Keys.ToList(), animationItems.Keys.ToList());
                if (dlState.HasContentForDownload)
                {
            #if DEBUG
                    System.Diagnostics.Debug.WriteLine("dlState has content for download");
            #endif
                    if (dlState.HasContentPackItems)
                    {
            #if DEBUG
                        System.Diagnostics.Debug.WriteLine("dlState has contentpackitems for download");
            #endif
                        LOLConnectClient service = new LOLConnectClient(LOLConstants.DefaultHttpBinding, LOLConstants.LOLConnectEndpoint);
                        service.ContentPackGetItemCompleted += Service_ContentPackGetItemCompleted;
                        service.ContentPackGetItemAsync(dlState.ContentPackIDQ.Peek(), ContentPackItem.ItemSize.Small, AndroidData.CurrentUser.AccountID,
                                                         new Guid(AndroidData.ServiceAuthToken), dlState);
                    } else
                    if (dlState.HasVoiceRecordings)
                    {
            #if DEBUG
                        System.Diagnostics.Debug.WriteLine("dlState has voicerecordings for download");
            #endif
                        LOLMessageClient service = new LOLMessageClient(LOLConstants.DefaultHttpBinding, LOLConstants.LOLMessageEndpoint);
                        service.MessageGetStepDataCompleted += Service_MessageGetStepData;
                        service.MessageGetStepDataAsync(dlState.Message.MessageID, dlState.VoiceIDQ.Peek(), AndroidData.CurrentUser.AccountID,
                                                         new Guid(AndroidData.ServiceAuthToken), dlState);
                    } else
                    if (dlState.HasPollingSteps)
                    {
                        RunOnUiThread(delegate
                        {
            #if DEBUG
                            System.Diagnostics.Debug.WriteLine("dlState has pollingsteps for download");
            #endif
                            LOLMessageClient service = new LOLMessageClient(LOLConstants.DefaultHttpBinding, LOLConstants.LOLMessageEndpoint);
                            service.PollingStepGetCompleted += Service_PollingStepGetCompleted;
                            service.PollingStepGetAsync(dlState.Message.MessageID, dlState.PollingIDQ.Peek(), AndroidData.CurrentUser.AccountID,
                                                         new Guid(AndroidData.ServiceAuthToken), dlState);
                        });
                    } else if (dlState.HasAnimationSteps)
                    {

                        LOLMessageClient msgService = new LOLMessageClient(LOLConstants.DefaultHttpBinding, LOLConstants.LOLMessageEndpoint);
                        msgService.AnimationStepGetCompleted += Service_AnimationStepGetCompleted;
                        msgService.AnimationStepGetAsync(dlState.Message.MessageID,
                                                         dlState.AnimationIDQ.Peek(),
                                                         AndroidData.CurrentUser.AccountID,
                                                         new Guid(AndroidData.ServiceAuthToken), dlState);

                    }
                } else
                    RunOnUiThread(delegate
                    {
                        StartPlayMessage(message);
                    });
            }
        }