Esempio n. 1
0
        public bool UploadNextPhotoComments(PhotosCommentsResponseHistory newPhotosCommentsRespounseHistory, PhotosCommentsResponse newPhotosCommentsRespounse, UpdatesPhotosResponse newUpdatesPhotosResponse)
        {
            // загрузка комментариев со списка Новости (Комментарии)
            try
            {
                if (newPhotosCommentsRespounse == null)
                {
                    throw new Exception();
                }

                foreach (var val in newPhotosCommentsRespounse.pcrComments)
                {
                    try
                    {
                        PhotosCommentsResponse oldPhotosCommentsResponse = newPhotosCommentsRespounseHistory.GetItem(val.cpPhotoData.pdPhotoID);

                        if (oldPhotosCommentsResponse == null)
                        {
                            LoadCommentsToPhoto(Convert.ToInt32(_iDataLogic.GetUid()), val.cpPhotoData.pdPhotoID, 50, true, false, newPhotosCommentsRespounseHistory);

                            return true;
                        }
                    }
                    catch (VKException)
                    {
                        throw;
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }
            catch (Exception)
            {
                //
            }

            // загрузка комментариев со списка Новости (Друзья)
            try
            {
                if (newUpdatesPhotosResponse == null)
                {
                    throw new Exception();
                }

                foreach (var val in newUpdatesPhotosResponse.uprPhotoDatas)
                {
                    try
                    {
                        PhotosCommentsResponse oldPhotosCommentsResponse = newPhotosCommentsRespounseHistory.GetItem(val.pdPhotoID);

                        if (oldPhotosCommentsResponse == null)
                        {
                            LoadCommentsToPhoto(val.pdUserID, val.pdPhotoID, 50, true, false, newPhotosCommentsRespounseHistory);

                            return true;
                        }
                    }
                    catch (VKException)
                    {
                        throw;
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }
            catch (Exception)
            {
                //
            }

            return false;
        }
Esempio n. 2
0
        protected override void OnViewStateChanged(string key)
        {
            #region SendMessage

            if (key == "SendMessage")
            {

                try
                {
                    using (new WaitWrapper(false))
                    {
                        Globals.BaseLogic.AddComments((string) ViewData["Message"],
                                                      (string) ViewData["UserID"] + "_" +
                                                      (string) ViewData["PhotoID"],
                                                      false);
                    }
                    view.UpdateView("SendCommentSuccess");

                    using (new WaitWrapper(false))
                    {
                        PhotosCommentsResponseHistory pchResponse = null;
                        PhotosCommentsResponse pcResponse = null;

                        try
                        {
                            //pchResponse = Cache.LoadFromCache<PhotosCommentsResponseHistory>(string.Empty, "PhotosCommentsResponseHistory");

                            pchResponse = DataModel.Data.PhotosCommentsResponseHistoryData;

                            if (pchResponse == null)
                            {
                                throw new Exception();
                            }
                        }
                        catch (Exception)
                        {
                            pchResponse = new PhotosCommentsResponseHistory();
                        }

                        pcResponse = pchResponse.GetItem(Convert.ToInt32((string) ViewData["PhotoID"]));

                        if (pcResponse == null)
                        {
                            pcResponse = new PhotosCommentsResponse();
                            pchResponse.AddItem(pcResponse);
                        }

                        var newPhotoData = new PhotoData
                                               {
                                                   pdPhotoID = Convert.ToInt32((string) ViewData["PhotoID"]),
                                                   pdUserID = Convert.ToInt32((string) ViewData["UserID"]),
                                                   pdPhotoURL604px = (string) ViewData["LargePhotoUrl"]
                                               };

                        var newPostReceiver = new PostReceiver
                                                  {
                                                      prUserID = Convert.ToInt32((string) ViewData["UserID"])
                                                  };

                        var newPostSender = new PostSender
                                                {
                                                    psUserID =
                                                        Convert.ToInt32(Globals.BaseLogic.IDataLogic.GetUid()),
                                                    psUserName = Resources.MessageI
                                                };

                        var newWallData = new WallData
                                              {
                                                  wdWallDataType = WallDataType.PlainText,
                                                  wdText = (string) ViewData["Message"]
                                              };

                        pcResponse.pcrPhotoID = Convert.ToInt32((string) ViewData["PhotoID"]);
                        pcResponse.pcrComments.Insert(0, new CommentPost
                                                             {
                                                                 cpID = 0,
                                                                 cpTime = DateTime.Now,
                                                                 cpPhotoData = newPhotoData,
                                                                 cpPostReceiver = newPostReceiver,
                                                                 cpPostSender = newPostSender,
                                                                 cpWallData = newWallData
                                                             }
                            );

                        //try
                        //{
                        //    bool result = Cache.SaveToCache(pchResponse, string.Empty,
                        //                                    "PhotosCommentsResponseHistory");
                        //    DebugHelper.WriteLogEntry(result
                        //                                  ? "Новый комментарий сохранен в кэш."
                        //                                  : "Новый комментарий не сохранены в кэш.");
                        //}
                        //catch (IOException newException)
                        //{
                        //    DebugHelper.WriteLogEntry("Ошибка сохранения комментария к фото в кэш: " +
                        //                              newException.Message);
                        //}

                        DataModel.Data.PhotosCommentsResponseHistoryData = pchResponse;

                        if ((string)ViewData["UserID"] == Globals.BaseLogic.IDataLogic.GetUid())
                        {
                            try
                            {
                                //pcResponse = Cache.LoadFromCache<PhotosCommentsResponse>(string.Empty,
                                //                                                         "PhotosCommentsResponse");

                                pcResponse = DataModel.Data.PhotosCommentsResponseData;

                                if (pcResponse == null)
                                    throw new Exception();
                            }
                            catch (Exception)
                            {
                                pcResponse = new PhotosCommentsResponse();
                            }

                            pcResponse.pcrPhotoID = Convert.ToInt32((string)ViewData["PhotoID"]);
                            pcResponse.pcrComments.Insert(0, new CommentPost
                                                                 {
                                                                     cpID = 0,
                                                                     cpTime = DateTime.Now,
                                                                     cpPhotoData = newPhotoData,
                                                                     cpPostReceiver = newPostReceiver,
                                                                     cpPostSender = newPostSender,
                                                                     cpWallData = newWallData
                                                                 }
                                );

                            //try
                            //{
                            //    bool result = Cache.SaveToCache(pcResponse, string.Empty, "PhotosCommentsResponse");
                            //    DebugHelper.WriteLogEntry(result
                            //                                  ? "Новый комментарий сохранен в кэш комментариев к своим фото."
                            //                                  : "Новый комментарий не сохранен в кэш комментариев к своим фото.");
                            //}
                            //catch (IOException newException)
                            //{
                            //    DebugHelper.WriteLogEntry("Ошибка сохранения комментария к своему фото в кэш: " +
                            //                              newException.Message);
                            //}

                            DataModel.Data.PhotosCommentsResponseData = pcResponse;
                        }
                        NavigationService.GoBack();

                    }
                }
                catch (VKException ex)
                {
                    //timerKeepAwake.Enabled = false;
                    string err = ExceptionTranslation.TranslateException(ex);
                    if (!string.IsNullOrEmpty(err))
                    {
                        ViewData["SendCommentError"] = err;
                        view.UpdateView("SendCommentFail");

                        if (ex.LocalizedMessage == ExceptionMessage.IncorrectLoginOrPassword)
                        {
                            Globals.BaseLogic.IDataLogic.SetToken(string.Empty);

                            view.UpdateView("GoToLogin");
                        }
                    }
                }
                catch (OutOfMemoryException)
                {
                    ViewData["SendCommentError"] = Resources.OutOfMemory;
                    view.UpdateView("SendCommentFail");
                }

            }

            #endregion

            #region GoBack

            if (key == "GoBack")
            {
                using (new WaitWrapper(false))
                {
                    NavigationService.GoBack();
                }
            }

            #endregion

            if (key == "GoGoToLogin")
            {
                MasterForm.Navigate<LoginController>();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Загрузка списка комменарием для конкретного фото
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="photoID"></param>
        /// <param name="count"></param>
        /// <param name="isRefresh"></param>
        /// <param name="restoreSession"></param>
        /// <returns></returns>
        public PhotosCommentsResponse LoadCommentsToPhoto(int uid, int photoID, int count, bool isRefresh, bool restoreSession, PhotosCommentsResponseHistory photosCommentsRespounseHistory)
        {
            DebugHelper.WriteLogEntry("BaseLogic.LoadCommentsToPhoto");

            // т.к. "общий" кэш все равно нужен в работе
            PhotosCommentsResponseHistory newPhotosCommentsRespounseHistory;

            try
            {
                if (photosCommentsRespounseHistory == null)
                {
                    //newPhotosCommentsRespounseHistory = Cache.Cache.LoadFromCache<PhotosCommentsResponseHistory>(string.Empty, "PhotosCommentsResponseHistory");
                    newPhotosCommentsRespounseHistory = DataModel.Data.PhotosCommentsResponseHistoryData;
                }
                else
                {
                    newPhotosCommentsRespounseHistory = photosCommentsRespounseHistory;
                }

                if (newPhotosCommentsRespounseHistory == null)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                newPhotosCommentsRespounseHistory = new PhotosCommentsResponseHistory();
            }

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

                // ищем нужный айтем
                PhotosCommentsResponse newPhotosCommentsResponse = newPhotosCommentsRespounseHistory.GetItem(photoID);

                if (newPhotosCommentsResponse != null)
                {
                    return newPhotosCommentsResponse; // выводим, если нашли
                }
                else
                {
                    throw new Exception(); // обращаемся к серверу, если нет
                }
            }
            catch (Exception)
            {
                if (!isRefresh) return null;

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

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

                ErrorResponse newErrorResponse = null;
                PhotosCommentsResponse newPhotosCommentsResponse = null;

                // считываем требуемое количество комментариев к фотографии
                try
                {
                    //throw new NullReferenceException();

                    newPhotosCommentsResponse = _iCommunicationLogic.LoadPhotosCommentsData(_iDataLogic.GetUid(), _iDataLogic.GetSessionKey(), "0", Convert.ToString(count - 1), uid.ToString() + "_" + photoID.ToString(), out newErrorResponse);
                }
                catch (VKException)
                {
                    throw;
                }
                catch (TimeoutException ex)
                {
                    DebugHelper.WriteLogEntry("BaseLogic.LoadCommentsToPhoto TimeoutException Message: " + ex.Message);
                    DebugHelper.WriteLogEntry("BaseLogic.LoadCommentsToPhoto TimeoutException StackTrace: " + ex.StackTrace);

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

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

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

                if (newPhotosCommentsResponse == null)
                {
                    if (newErrorResponse != null)
                    {
                        if (newErrorResponse.error_code == "1")
                        {
                            if (!restoreSession)
                            {
                                return LoadCommentsToPhoto(uid, photoID, count, isRefresh, true, null);
                            }
                            else
                            {
                                throw new VKException(ExceptionMessage.ServerUnavalible);
                            }
                        }
                        else if (newErrorResponse.error_code == "2")
                        {
                            throw new VKException(ExceptionMessage.AccountBloked);
                        }
                        else
                        {
                            throw new VKException(ExceptionMessage.UnknownError);
                        }
                    }
                    else
                    {
                        //throw new VKException(ExceptionMessage.UnknownError);
                    }
                }

                newPhotosCommentsResponse.pcrPhotoID = photoID; // устанавливаем ID фото

                newPhotosCommentsRespounseHistory.DelItem(photoID); // удаляем данные по фото, на случай если они есть
                newPhotosCommentsRespounseHistory.AddItem(newPhotosCommentsResponse); // добавляем полученные данные

                ////сохраняем в кэш всю историю
                //try
                //{
                //    DebugHelper.WriteLogEntry("(Кэш) Сохранение данных PhotosCommentsResponseHistory...");

                //    bool result;

                //    if (photosCommentsRespounseHistory == null)
                //    {
                //        result = Cache.Cache.SaveToCache(newPhotosCommentsRespounseHistory, string.Empty, "PhotosCommentsResponseHistory");
                //    }
                //    else
                //    {
                //        result = true;
                //    }

                //    if (result)
                //    {
                //        DebugHelper.WriteLogEntry("(Кэш) Данные PhotosCommentsResponseHistory успешно сохранены.");
                //    }
                //    else
                //    {
                //        DebugHelper.WriteLogEntry("(Кэш) Данные PhotosCommentsResponseHistory не сохранены.");
                //    }
                //}
                //catch (Exception)
                //{
                //    DebugHelper.WriteLogEntry("(Кэш) В процессе сохранения данных PhotosCommentsResponseHistory произошла ошибка.");
                //}

                if (photosCommentsRespounseHistory == null)
                {
                    //result = Cache.Cache.SaveToCache(newPhotosCommentsRespounseHistory, string.Empty, "PhotosCommentsResponseHistory");
                    DataModel.Data.PhotosCommentsResponseHistoryData = newPhotosCommentsRespounseHistory;
                }

                return newPhotosCommentsResponse;
            }
        }