コード例 #1
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
        }
コード例 #2
0
        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);
                    });
            }
        }