Esempio n. 1
0
        public bool UploadNextUserCorrespond(MessShortCorrespondence newMessShortCorrespondence, MessCorrespondence newMessCorrespondence)
        {
            try
            {
                if (newMessShortCorrespondence == null)
                {
                    throw new Exception();
                }

                try
                {
                    foreach (var val in newMessShortCorrespondence.MessList)
                    {
                        if (!newMessCorrespondence.UserIsInList(val.mUserID))
                        {
                            RefreshUserCorrespondence(val.mUserID, true, false, newMessCorrespondence); // для каждого пользователя грузим цепочку
                            return true;
                        }
                    }
                }
                catch (VKException)
                {
                    throw;
                }
                catch (OutOfMemoryException)
                {
                    throw;
                }
            }
            catch (Exception)
            {
                // если нет в кэше то выходим

                return false;
            }

            return false;
        }
Esempio n. 2
0
        //public
        /// <summary>
        /// Загружает краткую переписку с пользователями
        /// </summary>
        /// <param name="isRefresh">Указывает на необходимость обновления с сайта, если true - данные из кэша не считываются</param>
        /// <param name="restoreSession">Возобновить сессию</param>
        public MessShortCorrespondence GetShortCorrespondence(bool isRefresh, bool restoreSession)
        {
            DebugHelper.WriteLogEntry("BaseLogic.GetShortCorrespondence");

            try
            {
                if (isRefresh)
                {
                    throw new Exception();
                }

                try
                {
                    //MessShortCorrespondence newMessShortCorrespondence = Cache.Cache.LoadFromCache<MessShortCorrespondence>(string.Empty, "MessageShortCorrespondence");
                    MessShortCorrespondence newMessShortCorrespondence = DataModel.Data.MessageShortCorrespondence;
                    return newMessShortCorrespondence;
                }
                catch (IOException)
                {
                    return null;
                }

            }
            catch (Exception)
            {
                //WiFi
                if (_iDataLogic.GetOnlyWIFI() == "1")
                    if (!CoreHelper.TurnWiFi(true)) throw new VKException(ExceptionMessage.NoConnection);

                // восстановливаем сессию
                if (restoreSession)
                {
                    AutoLogin();
                }

                MessShortCorrespondence newMessCorrespondence = new MessShortCorrespondence();

                MessResponse newMessResponseInbox = null;
                MessResponse newMessResponseOutbox = null;

                ErrorResponse newErrorResponseInbox = null;
                ErrorResponse newErrorResponseOutbox = null;

                try
                {
                    newMessResponseInbox = _iCommunicationLogic.LoadMessages("inbox", _iDataLogic.GetUid(), _iDataLogic.GetSessionKey(), "0", "50", 0, out newErrorResponseInbox);
                    newMessResponseOutbox = _iCommunicationLogic.LoadMessages("outbox", _iDataLogic.GetUid(), _iDataLogic.GetSessionKey(), "0", "50", 0, out newErrorResponseOutbox);
                    //throw new ObjectDisposedException("obj1");
                }
                catch (VKException)
                {
                    throw;
                }
                catch (TimeoutException ex)
                {
                    DebugHelper.WriteLogEntry("BaseLogic.GetShortCorrespondence TimeoutException Message: " + ex.Message);
                    DebugHelper.WriteLogEntry("BaseLogic.GetShortCorrespondence TimeoutException StackTrace: " + ex.StackTrace);

                    throw new VKException(ExceptionMessage.NoConnection);
                }
                catch (WebException ex)
                {
                    DebugHelper.WriteLogEntry("BaseLogic.GetShortCorrespondence WebException Message: " + ex.Message);
                    DebugHelper.WriteLogEntry("BaseLogic.GetShortCorrespondence WebException StackTrace: " + ex.StackTrace);

                    throw new VKException(ExceptionMessage.NoConnection);
                }
                catch (OutOfMemoryException ex)
                {
                    DebugHelper.WriteLogEntry("BaseLogic.GetShortCorrespondence OutOfMemoryException Message: " + ex.Message);
                    DebugHelper.WriteLogEntry("BaseLogic.GetShortCorrespondence OutOfMemoryException StackTrace: " + ex.StackTrace);

                    throw;
                }
                catch (Exception ex)
                {
                    DebugHelper.WriteLogEntry("BaseLogic.GetShortCorrespondence Exception Message: " + ex.Message);
                    DebugHelper.WriteLogEntry("BaseLogic.GetShortCorrespondence Exception StackTrace: " + ex.StackTrace);
                }

                if (newMessResponseInbox != null || newMessResponseOutbox != null)
                {
                    // вход.
                    foreach (MessageCover newMessageCover in newMessResponseInbox.mMessages)
                    {
                        MessShort newMessShort = newMessCorrespondence.UserIsInList(newMessageCover.mMesSender);

                        if (newMessShort == null)
                        {
                            newMessShort = new MessShort();

                            newMessShort.mID = newMessageCover.mID;

                            newMessShort.mUserID = newMessageCover.mMesSender.mUserID;
                            newMessShort.mUserName = newMessageCover.mMesSender.mUserName;
                            newMessShort.mUserPhotoURL = newMessageCover.mMesSender.mUserPhotoURL;

                            newMessShort.mLastMessageText = newMessageCover.mData.mText;
                            newMessShort.mTime = newMessageCover.mTime;
                            newMessShort.mType = newMessageCover.mIOType;

                            newMessShort.mIsRead = newMessageCover.mMesIsRead;

                            newMessCorrespondence.MessList.Add(newMessShort);
                        }
                        else
                        {
                            if (newMessageCover.mTime > newMessShort.mTime)
                            {
                                newMessShort.mID = newMessageCover.mID;

                                newMessShort.mLastMessageText = newMessageCover.mData.mText;
                                newMessShort.mTime = newMessageCover.mTime;
                                newMessShort.mType = newMessageCover.mIOType;
                            }

                            if (!newMessageCover.mMesIsRead)
                            {
                                newMessShort.mIsRead = false;
                            }
                        }
                    }

                    // исход.
                    foreach (MessageCover newMessageCover in newMessResponseOutbox.mMessages)
                    {
                        MessShort newMessShort = newMessCorrespondence.UserIsInList(newMessageCover.mMesReceiver);

                        if (newMessShort == null)
                        {
                            newMessShort = new MessShort();

                            newMessShort.mID = newMessageCover.mID;

                            newMessShort.mUserID = newMessageCover.mMesReceiver.mUserID;
                            newMessShort.mUserName = newMessageCover.mMesReceiver.mUserName;
                            newMessShort.mUserPhotoURL = newMessageCover.mMesReceiver.mUserPhotoURL;

                            newMessShort.mLastMessageText = newMessageCover.mData.mText;
                            newMessShort.mTime = newMessageCover.mTime;
                            newMessShort.mType = newMessageCover.mIOType;

                            newMessShort.mIsRead = newMessageCover.mMesIsRead;

                            newMessCorrespondence.MessList.Add(newMessShort);
                        }
                        else
                        {
                            if (newMessageCover.mTime > newMessShort.mTime)
                            {
                                newMessShort.mID = newMessageCover.mID;

                                newMessShort.mLastMessageText = newMessageCover.mData.mText;
                                newMessShort.mTime = newMessageCover.mTime;
                                newMessShort.mType = newMessageCover.mIOType;
                            }
                        }
                    }
                }
                else
                {
                    if (newErrorResponseInbox != null)
                    {
                        if (newErrorResponseInbox.error_code == "1")
                        {
                            if (!restoreSession)
                            {
                                return GetShortCorrespondence(isRefresh, true);
                            }
                            else
                            {
                                throw new VKException(ExceptionMessage.ServerUnavalible);
                            }
                        }
                        else if (newErrorResponseInbox.error_code == "2")
                        {
                            throw new VKException(ExceptionMessage.AccountBloked);
                        }
                        else
                        {
                            throw new VKException(ExceptionMessage.UnknownError);
                        }
                    }
                    else if (newErrorResponseOutbox != null)
                    {
                        if (newErrorResponseOutbox.error_code == "1")
                        {
                            if (!restoreSession)
                            {
                                return GetShortCorrespondence(isRefresh, true);
                            }
                            else
                            {
                                throw new VKException(ExceptionMessage.ServerUnavalible);
                            }
                        }
                        else if (newErrorResponseOutbox.error_code == "2")
                        {
                            throw new VKException(ExceptionMessage.AccountBloked);
                        }
                        else
                        {
                            throw new VKException(ExceptionMessage.UnknownError);
                        }
                    }
                    else
                    {
                        throw new VKException(ExceptionMessage.UnknownError);
                    }
                }

                DataModel.Data.MessageShortCorrespondence = newMessCorrespondence;
                /*
                try
                {
                    bool result;

                    result = Cache.Cache.SaveToCache(newMessCorrespondence, string.Empty, "MessageShortCorrespondence");

                    if (result)
                    {
                        DebugHelper.WriteLogEntry("Данные MessageShortCorrespondence сохранены в кэш.");
                    }
                    else
                    {
                        DebugHelper.WriteLogEntry("Данные MessageShortCorrespondence не сохранены в кэш.");
                    }

                }
                catch (Exception newException)
                {
                    DebugHelper.WriteLogEntry("Ошибка сохранения данных MessageShortCorrespondence в кэш: " + newException.Message);
                }
                */

                return newMessCorrespondence;
            }
        }