/// <summary> /// Register() - Allows for the registration of a object that that can /// receive a posted message. If the receiver is null, it can not be /// added to the registration list. The receiver must be created with /// the MsgReceiver interface. /// </summary> /// <param name="receiver"></param> public void Register(PostReceiver receiver) { if (receiver != null) { msgReceivers.Add(receiver); } }
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>(); } }