protected override void OnViewStateChanged(string key) { if (key == "CheckUpdate") { ViewData["UpdateMessage"] = string.Empty; ViewData["IsNewVersionAvailable"] = "false"; var updateHelper = new UpdateHelper((UIViewBase)ViewData["AboutViewThis"]); using (new WaitWrapper()) { updateHelper.CheckInternal(true); } if (!updateHelper.IsUnableToDefineLatestVersion) { if (updateHelper.IsNewVersionAvailable) { ViewData["IsNewVersionAvailable"] = "true"; ViewData["NewVersion"] = Globals.BaseLogic.IDataLogic.GetLastCheckedVersionStr(); ViewData["NewVersionInfo"] = Globals.BaseLogic.IDataLogic.GetLastCheckedVersionInfo(); ViewData["NewVersionURL"] = Globals.BaseLogic.IDataLogic.GetLastCheckedVersionUpdateURL(); } } else { ViewData["UpdateMessage"] = Resources.ApplicationUpdate_Message_Undefined; } view.UpdateView("CheckUpdateResponse"); } if (key == "UploadUpdate") { string lastCheckedVersionUpdateURL = Globals.BaseLogic.IDataLogic.GetLastCheckedVersionUpdateURL(); if (!string.IsNullOrEmpty(lastCheckedVersionUpdateURL)) { Process.Start(lastCheckedVersionUpdateURL, null); } } if (key == "Back") { using (new WaitWrapper(false)) { NavigationService.GoBack(); } } if (key == "ShowVersion") { ViewData["CurrentVersion"] = SystemConfiguration.CurrentProductVersion.ToString(3); view.UpdateView("ShowVersionResponse"); } }
protected override void OnViewStateChanged(string key) { #region Check AutoLogin if (key == "CheckAutoLogin") { try { using (new WaitWrapper()) { Globals.BaseLogic.AutoLogin(); } Initialize("LoginSuccess"); } catch (VKException ex) { string message = ExceptionTranslation.TranslateException(ex); if (!string.IsNullOrEmpty(message)) { if (ex.LocalizedMessage == ExceptionMessage.IncorrectLoginOrPassword) { Globals.BaseLogic.IDataLogic.SetToken(string.Empty); MasterForm.Navigate <LoginController>("IncorrectLoginOrPassword"); } else if (ex.LocalizedMessage == ExceptionMessage.NoSavedToken) { MasterForm.Navigate <LoginController>(); } else if (ex.LocalizedMessage == ExceptionMessage.UnknownError) { MasterForm.Navigate <LoginController>("UnknownError"); } else { Initialize("LoginSuccess"); } } } catch (OutOfMemoryException) { DialogControl.ShowQuery(Resources.OutOfMemory, DialogButtons.OK); } } #endregion #region InitializeSettings else if (key == "InitializeSettings") { using (new WaitWrapper()) { // если приложение запущено при остановленном нотификаторе, то очищаем кэш // это единственное место, где осуществляется это действие //if (!Interprocess.IsServiceRunning) { Cache.DeleteEntryFromCache(string.Empty, "ShortActivityResponse"); Cache.DeleteEntryFromCache(string.Empty, "ShortUpdatesPhotosResponse"); Cache.DeleteEntryFromCache(string.Empty, "ShortWallResponse"); Cache.DeleteEntryFromCache(string.Empty, "ShortPhotosCommentsRespounse"); } #region SetShowEventButtons if (Globals.BaseLogic.IDataLogic.GetShowButtonMessages()) { Globals.BaseLogic.IDataLogic.SetShowButtonMessages(); } if (Globals.BaseLogic.IDataLogic.GetShowButtonComments()) { Globals.BaseLogic.IDataLogic.SetShowButtonComments(); } if (Globals.BaseLogic.IDataLogic.GetShowButtonFriends()) { Globals.BaseLogic.IDataLogic.SetShowButtonFriends(); } if (Globals.BaseLogic.IDataLogic.GetShowButtonFriendsNews()) { Globals.BaseLogic.IDataLogic.SetShowButtonFriendsNews(); } if (Globals.BaseLogic.IDataLogic.GetShowButtonFriendsPhotos()) { Globals.BaseLogic.IDataLogic.SetShowButtonFriendsPhotos(); } if (Globals.BaseLogic.IDataLogic.GetShowButtonWallMessages()) { Globals.BaseLogic.IDataLogic.SetShowButtonWallMessages(); } #endregion Configuration.LoadConfigSettings(); Configuration.SaveConfigSettings(); #region старт/стоп нотификатора if (Configuration.BackgroundNotification != BackgroundNotificationTypes.Off) { Globals.BaseLogic.IDataLogic.SetNtfAutorun(); OnViewStateChanged("StartNotificator"); } else { OnViewStateChanged("StopNotificator"); Globals.BaseLogic.IDataLogic.DelNtfAutorun(); } OnViewStateChanged("StopNotificator"); #endregion } } #endregion #region StartNotificator if (key == "StartNotificator") { if (!string.IsNullOrEmpty(Globals.BaseLogic.IDataLogic.GetToken())) { //// запуск службы нотификатора //try //{ // if (!Interprocess.IsServiceRunning) // { // Interprocess.StartService(); // } //} //catch (Exception ex) //{ // ViewData["NotificatorStartError"] = ex.Message; // view.UpdateView("NotificatorStartFail"); //} } else { DialogControl.ShowQuery(Resources.MainView_Button_NotificatorCantStart, DialogButtons.OK); } } #endregion #region StopNotificator if (key == "StopNotificator") { // остановка службы нотификатора //Interprocess.StopService(); } #endregion #region GetMainViewData if (key == "GetMainViewData") { LoadingControlInterface lc = LoadingControl.CreateLoading(Resources.DataLoading); Thread asyncDataThread = new Thread(delegate { AsyncGetMainViewData(lc); }); asyncDataThread.IsBackground = true; asyncDataThread.Start(); lc.ShowLoading(false); if (lc.Abort) { asyncDataThread.Abort(); } } #endregion #region GoToUploadPhoto if (key == "GoToUploadPhoto") { MasterForm.Navigate <UploadPhotoController>(); } #endregion #region AutoUpdate if (key == "AutoUpdate") { var updateHelper = new UpdateHelper((UIViewBase)ViewData["MainViewThis"]); updateHelper.CheckNewVersion(); } #endregion #region ChangeStatus if (key == "ChangeStatus") { MasterForm.Navigate <ChangeStatusController>((string)ViewData["UserStatus"]); } #endregion #region CheckNewEvents if (key == "CheckNewEvents") { // проверка флага необходимости обновления списка событий if (Globals.BaseLogic.IDataLogic.GetRefreshEventsFlag() == "1") { try { // загрузка событий EventsGetResponse newEventsGetResponse = Globals.BaseLogic.EventsGet(false, false, false); ViewData["MessagesCount"] = string.Empty; ViewData["CommentsCount"] = string.Empty; ViewData["FriendsCount"] = string.Empty; ViewData["FriendsNewsCount"] = string.Empty; ViewData["FriendsPhotosCount"] = string.Empty; ViewData["WallCount"] = string.Empty; foreach (Event newEvent in newEventsGetResponse.events) { switch (newEvent.type) { case EventType.Messages: ViewData["MessagesCount"] = newEvent.number.ToString(); break; case EventType.Comments: ViewData["CommentsCount"] = newEvent.number.ToString(); break; case EventType.Friends: ViewData["FriendsCount"] = newEvent.number.ToString(); break; case EventType.FriendsNews: ViewData["FriendsNewsCount"] = newEvent.number.ToString(); break; case EventType.FriendsPhotos: ViewData["FriendsPhotosCount"] = newEvent.number.ToString(); break; case EventType.WallMessages: ViewData["WallCount"] = newEvent.number.ToString(); break; } } view.UpdateView("RefreshEventsInfo"); } catch (Exception ex) { // } } } #endregion #region GoToNews if (key == "GoToNews") { MasterForm.Navigate <StatusUpdatesListController>(); } #endregion #region GoToFriends if (key == "GoToFriends") { MasterForm.Navigate <FriendsListController>(); } #endregion #region GoToMessages if (key == "GoToMessages") { MasterForm.Navigate <MessagesChainsListController>(); } #endregion #region GoToExtras if (key == "GoToExtras") { MasterForm.Navigate <ExtraController>(); } #endregion }
protected override void OnViewStateChanged(string key) { #region InitializeSettings if (key == "InitializeSettings") { using (new WaitWrapper()) { // если приложение запущено при остановленном нотификаторе, то очищаем кэш // это единственное место, где осуществляется это действие //if (!Interprocess.IsServiceRunning) { Cache.DeleteEntryFromCache(string.Empty, "ShortActivityResponse"); Cache.DeleteEntryFromCache(string.Empty, "ShortUpdatesPhotosResponse"); Cache.DeleteEntryFromCache(string.Empty, "ShortWallResponse"); Cache.DeleteEntryFromCache(string.Empty, "ShortPhotosCommentsRespounse"); } Configuration.LoadConfigSettings(); Configuration.SaveConfigSettings(); #region старт/стоп нотификатора if (Configuration.BackgroundNotification != BackgroundNotificationTypes.Off) { Globals.BaseLogic.IDataLogic.SetNtfAutorun(); OnViewStateChanged("StartNotificator"); } else { OnViewStateChanged("StopNotificator"); Globals.BaseLogic.IDataLogic.DelNtfAutorun(); } OnViewStateChanged("StopNotificator"); #endregion } } #endregion #region StartNotificator if (key == "StartNotificator") { if (!string.IsNullOrEmpty(Globals.BaseLogic.IDataLogic.GetToken())) { // запуск службы нотификатора try { //if (!Interprocess.IsServiceRunning) //{ // Interprocess.StartService(); //} } catch (Exception ex) { ViewData["NotificatorStartError"] = ex.Message; view.UpdateView("NotificatorStartFail"); } } else { DialogControl.ShowQuery(Resources.MainView_Button_NotificatorCantStart, DialogButtons.OK); } } #endregion #region StopNotificator if (key == "StopNotificator") { // остановка службы нотификатора //Interprocess.StopService(); } #endregion #region GetViewData if (key == "GetViewData") { bool isRefrsh = Convert.ToBoolean(ViewData["IsRefresh"]); if (isRefrsh) { LoadingControlInterface lc = LoadingControl.CreateLoading((string)ViewData["NeedChangeText"] != "1" ? Resources.DataLoading : Resources.FirstDataLoading); ViewData["NeedChangeText"] = "0"; timerKeepAwake.Enabled = true; Thread asyncDataThread = new Thread(delegate { try { timerKeepAwake.Enabled = true; AsyncGetViewData(lc); } finally { timerKeepAwake.Enabled = false; } }); asyncDataThread.IsBackground = true; asyncDataThread.Start(); lc.ShowLoading(true); if (lc.Abort) { asyncDataThread.Abort(); } } else { try { ActivityResponse newActivityResponse = Globals.BaseLogic.LoadActivityDataList(25, false, false); UpdatesPhotosResponse newUpdatesPhotosResponse = Globals.BaseLogic.LoadUpdatesPhotos(25, false, false); if (newActivityResponse != null) { FillListModel(newActivityResponse, false); } else { view.Model.Statuses.Clear(); } if (newUpdatesPhotosResponse != null) { FillListModel(newUpdatesPhotosResponse, false); } else { view.Model.Photos.Clear(); } view.UpdateView("LoadListResponse"); } catch { // гасим } } } #endregion #region Check AutoLogin if (key == "CheckAutoLogin") { try { using (new WaitWrapper()) { //Globals.BaseLogic.AutoLogin(); } Initialize("AutoLoginSuccess"); } catch (VKException ex) { string message = ExceptionTranslation.TranslateException(ex); //if (!string.IsNullOrEmpty(message)) //{ // if (ex.LocalizedMessage == ExceptionMessage.IncorrectLoginOrPassword) // { // Globals.BaseLogic.IDataLogic.SetToken(string.Empty); // MasterForm.Navigate<LoginController>("IncorrectLoginOrPassword"); // } // else if (ex.LocalizedMessage == ExceptionMessage.NoSavedToken) // { // MasterForm.Navigate<LoginController>("NoSavedToken"); // } // else if (ex.LocalizedMessage == ExceptionMessage.UnknownError) // { // MasterForm.Navigate<LoginController>("UnknownError"); // } // else // { // Initialize("LoginSuccess"); // } //} } catch (OutOfMemoryException) { DialogControl.ShowQuery(Resources.OutOfMemory, DialogButtons.OK); } } #endregion #region AutoUpdate if (key == "AutoUpdate") { UpdateHelper updateHelper = new UpdateHelper((UIViewBase)ViewData["StatusUpdatesListView"]); updateHelper.CheckNewVersion(); } #endregion #region GoToSendMessage if (key == "GoToSendMessage") { MasterForm.Navigate <SendMessageController>("FriendsStatus", ViewData["Uid"]); } #endregion // верхнее меню #region ReloadList if (key == "ReloadList") { view.UpdateView("ReloadListResponse"); } #endregion #region RefreshList if (key == "RefreshList") { view.UpdateView("RefreshListResponse"); } #endregion #region GoToPhotoComments if (key == "GoToPhotoComments") { MasterForm.Navigate <PhotoCommentsUpdatesListController>(); } #endregion #region GoToMessages if (key == "GoToMessages") { MasterForm.Navigate <MessagesChainsListController>(); } #endregion #region GoToFriends if (key == "GoToFriends") { MasterForm.Navigate <FriendsListController>(); } #endregion #region GoToPhoto if (key == "GoToPhotos") { //MasterForm.Navigate<UploadPhotoController>(); MasterForm.Navigate <ShareController>(); } #endregion #region GoDetailedView if (key == "GoDetailedView") { int uid = Convert.ToInt32((string)ViewData["Uid"]); int photoID = Convert.ToInt32((string)ViewData["PhotoID"]); string largePhotoURL = (string)ViewData["LargePhotoURL"]; if (uid > 0 && photoID > 0) { MasterForm.Navigate <ImageCommentController>("Load", uid.ToString(), photoID.ToString(), largePhotoURL); } } #endregion #region GoToExtras if (key == "GoToExtras") { MasterForm.Navigate <ExtraController>(); } #endregion #region ListActualization if (key == "ListActualization") { // на этой форме необходимости проверять нет, так как переход Login -> this вызывает Reload списка //string currentID = Globals.BaseLogic.IDataLogic.GetUid(); //string listID = (string)ViewData["ListID"]; //if (currentID != listID) //{ // OnViewStateChanged("GetViewData"); //} } #endregion if (key == "GoGoToLogin") { MasterForm.Navigate <LoginController>(); } }