Ejemplo n.º 1
0
        private void AsyncGetViewData(LoadingControlInterface lc)
        {
            string isFirstStart = (string)ViewData["IsFirstStart"];

            ViewData["IsFirstStart"] = "0";

            lc.Current = 2;

            ActivityResponse      newActivityResponse      = null;
            UpdatesPhotosResponse newUpdatesPhotosResponse = null;

            // первичные данные формы
            try
            {
                // загружаем новые новости
                newActivityResponse = Globals.BaseLogic.LoadActivityDataList(25, true, false);
                lc.Current          = 4;

                // загружаем новые фото
                newUpdatesPhotosResponse = Globals.BaseLogic.LoadUpdatesPhotos(25, true, false);
                lc.Current = 10;

                ViewData["FirstActivate"] = string.Empty;
            }
            catch (VKException ex)
            {
                timerKeepAwake.Enabled = false;
                string error = ExceptionTranslation.TranslateException(ex);

                if (!string.IsNullOrEmpty(error))
                {
                    ViewData["GetViewDataResponseMessage"] = error;
                    view.UpdateView("GetViewDataResponseNegative");

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

                        //view.UpdateView("GoToLogin");
                        OnViewStateChanged("GoToLogin");
                    }
                }
            }
            catch (OutOfMemoryException)
            {
                ViewData["GetViewDataResponseMessage"] = Resources.OutOfMemory;
                view.UpdateView("GetViewDataResponseNegative");
            }

            if (newActivityResponse != null)
            {
                FillListModel(newActivityResponse, true);
            }

            if (newUpdatesPhotosResponse != null)
            {
                FillListModel(newUpdatesPhotosResponse, true);
            }

            ViewData["ListID"] = Globals.BaseLogic.IDataLogic.GetUid(); // сохраняем ID пользователя для которого был построен список

            view.UpdateView("LoadListResponse");

            // прочие данные при старте приложения
            if (isFirstStart.Equals("1") && Configuration.DataRenewType != DataRenewVariants.DontUpdate)
            {
                try
                {
                    int  totalCount;
                    int  alreadyGet;
                    bool isData;

                    // список друзей
                    Globals.BaseLogic.LoadFriendsList(true, false);
                    lc.Current = 12;

                    // список комментариев к фотографиям пользователя
                    Globals.BaseLogic.LoadPhotosComments(25, true, false);
                    lc.Current = 14;

                    // список заголовков цепочек сообщений пользователя
                    Globals.BaseLogic.GetShortCorrespondence(true, false);
                    lc.Current = 16;

                    // список статусов пользователя (для формы поделиться)
                    Globals.BaseLogic.LoadUserActivityDataList(25, true, false);
                    lc.Current = 18;

                    // список фотографий пользователя
                    Globals.BaseLogic.ReloadUserPhotos(true, false);
                    lc.Current = 20;

                    // З А Г Р У З К А   Ц Е П О Ч Е К   П Е Р Е П И С О К
                    Globals.BaseLogic.ClearMessageCorrespondence();
                    totalCount = Globals.BaseLogic.PredictCorrespondCount();
                    alreadyGet = 0;
                    isData     = false;

                    MessShortCorrespondence newMessShortCorrespondence = DataModel.Data.MessageShortCorrespondence;

                    if (newMessShortCorrespondence == null)
                    {
                        newMessShortCorrespondence = new MessShortCorrespondence();
                    }

                    MessCorrespondence newMessCorrespondence = DataModel.Data.MessageCorrespondence;

                    if (newMessCorrespondence == null)
                    {
                        newMessCorrespondence = new MessCorrespondence();
                    }

                    do
                    {
                        isData = Globals.BaseLogic.UploadNextUserCorrespond(newMessShortCorrespondence, newMessCorrespondence);

                        if (isData)
                        {
                            alreadyGet++;

                            if (totalCount > 0)
                            {
                                lc.Current = 40 - (int)(20 * (((double)(totalCount - alreadyGet)) / ((double)totalCount)));
                            }
                        }
                    }while (isData);

                    DataModel.Data.MessageCorrespondence = newMessCorrespondence;

                    // З А Г Р У З К А   К О М М Е Н Т А Р И Е В
                    Globals.BaseLogic.ClearAllPhotoComments();
                    totalCount = Globals.BaseLogic.PredictPhotoCommentsCount();
                    alreadyGet = 0;
                    isData     = false;

                    PhotosCommentsResponseHistory newPhotosCommentsRespounseHistory = DataModel.Data.PhotosCommentsResponseHistoryData;

                    if (newPhotosCommentsRespounseHistory == null)
                    {
                        newPhotosCommentsRespounseHistory = new PhotosCommentsResponseHistory();
                    }

                    PhotosCommentsResponse newPhotosCommentsRespounse = DataModel.Data.PhotosCommentsResponseData;

                    if (newPhotosCommentsRespounse == null)
                    {
                        newPhotosCommentsRespounse = new PhotosCommentsResponse();
                    }

                    UpdatesPhotosResponse nwUpdatesPhotosResponse = DataModel.Data.UpdatesPhotosResponseData;

                    if (nwUpdatesPhotosResponse == null)
                    {
                        nwUpdatesPhotosResponse = new UpdatesPhotosResponse();
                    }

                    do
                    {
                        isData = Globals.BaseLogic.UploadNextPhotoComments(newPhotosCommentsRespounseHistory, newPhotosCommentsRespounse, nwUpdatesPhotosResponse);

                        if (isData)
                        {
                            alreadyGet++;

                            if (totalCount > 0)
                            {
                                lc.Current = 60 - (int)(20 * (((double)(totalCount - alreadyGet)) / ((double)totalCount)));
                            }
                        }
                    }while (isData);

                    DataModel.Data.PhotosCommentsResponseHistoryData = newPhotosCommentsRespounseHistory;

                    // З А Г Р У З К А   П Р О Ф И Л Е Й   П О Л Ь З О В А Т Е Л Е Й
                    totalCount = Globals.BaseLogic.PredictFriendsCount();
                    alreadyGet = 0;
                    isData     = false;

                    FriendsListResponse additionalFriendsListResponse = additionalFriendsListResponse = DataModel.Data.FriendsListAdditionalResponseData;

                    if (additionalFriendsListResponse == null)
                    {
                        additionalFriendsListResponse = new FriendsListResponse();
                    }

                    FriendsListResponse oldFriendsListResponse = DataModel.Data.FriendsListResponseData;

                    if (oldFriendsListResponse == null)
                    {
                        oldFriendsListResponse = new FriendsListResponse();
                    }

                    do
                    {
                        isData = Globals.BaseLogic.GetNextFriendsInfo(true, false, additionalFriendsListResponse, oldFriendsListResponse);

                        if (isData)
                        {
                            alreadyGet++;

                            if (totalCount > 0)
                            {
                                lc.Current = 98 - (int)(38 * (((double)(totalCount - alreadyGet)) / ((double)totalCount)));
                            }
                        }
                    } while (isData);

                    DataModel.Data.FriendsListAdditionalResponseData = additionalFriendsListResponse;

                    // все фото
                    Globals.BaseLogic.DownloadAllPhotoData();

                    lc.Current = 99;
                }
                catch (VKException)
                {
                    DebugHelper.WriteLogEntry("Ошибка при загрузке данных при старте приложения");
                }
                catch (OutOfMemoryException)
                {
                    DebugHelper.WriteLogEntry("Ошибка при загрузке данных при старте приложения");
                }
                catch (Exception)
                {
                    DebugHelper.WriteLogEntry("Ошибка при загрузке данных при старте приложения");
                }
            }

            // запускаем поток || прогрузки фотографий
            var t = new Thread(delegate { Globals.BaseLogic.ICommunicationLogic.LoadImagesInDictionary(); })
            {
                IsBackground = true
            };

            t.Start();

            lc.Current = 100;
        }
Ejemplo 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>();
            }
        }