protected void NagControl_SelectedIndexChanged(object sender, EventArgs e) { try { string msg; if (NagControl.SelectedValue == "T") { DonationNagsControl.UpdateIsNaggingEnabled(true); msg = "The Donation Nag Dialog has been ENABLED."; } else { DonationNagsControl.UpdateIsNaggingEnabled(false); msg = "The Donation Nag Dialog has been DISABLED."; } CommonCacheInvalidation.ScheduleInvalidateNagsAll(); NagControlFeedback.AddInfo(msg); NagControlFeedback.AddInfo("It will take effect in 5 to 10 minutes."); } catch (Exception ex) { NagControlFeedback.AddError( "The operation failed due to an unexpected error."); NagControlFeedback.HandleException(ex); } }
private void AddButton_Click(object sender, EventArgs e) { // Adds a new message to the database try { var newMsgNo = GetMsgNoFromForm(); CheckForDuplicateMsgNo(newMsgNo); var nextMsgNo = GetNextMsgFromForm(); var messageText = GetMsgTextFromForm(); if (NagFeedback.ValidationErrorCount != 0) { return; } var table = new DonationNagsTable(); table.AddRow(newMsgNo, null, messageText, nextMsgNo); DonationNags.UpdateTable(table); var feedback = $"MsgNo {newMsgNo} was successfully added"; NagFeedback.AddInfo(feedback); CommonCacheInvalidation.ScheduleInvalidateNagsAll(); NagEditMode.Value = Empty; BuildHtmlTable(); } catch (Exception ex) { NagFeedback.AddError("The operation failed due to an unexpected error."); NagFeedback.HandleException(ex); } }
protected void ButtonNoCrop_Click(object sender, EventArgs e) { try { var politicianKey = LabelPoliticianKey.Text; // We get the current profile original, convert it to a stream, then // use it as the HeadshotOriginal image var blob = PoliticiansImagesBlobs.GetProfileOriginal(politicianKey); if (blob == null) { return; } var uploadTime = DateTime.UtcNow; var stream = new MemoryStream(blob); Size originalSize; ImageManager.UpdateAllPoliticianHeadshotImages(politicianKey, stream, uploadTime, out originalSize); CommonCacheInvalidation.ScheduleInvalidation("politicianimage", politicianKey); MarkProcessed(); UpdateRowCountAfterChange(); } catch (Exception ex) { HandleException(ex); } }
protected void ButtonRevertToLog_ServerClick(object sender, EventArgs e) { try { var politicianKey = LabelPoliticianKey.Text; var latestLogDate = LogDataChange.GetSecondLatestProfileImageDate(politicianKey, out _); var logTime = new DateTime(latestLogDate.Ticks); var loggedBlob = LatestLoggedImagePage.GetLoggedImageByDate(politicianKey, logTime); if (latestLogDate.IsDefaultDate() || loggedBlob == null || loggedBlob.Length == 0) { Msg.Text = Fail("No log profile image for ID " + politicianKey + " was found."); } else { var now = DateTime.UtcNow; ImageManager.UpdatePoliticianProfileImages(politicianKey, new MemoryStream(loggedBlob), now, out _); CommonCacheInvalidation.ScheduleInvalidation("politicianimage", politicianKey); LogImageChange(politicianKey, null, loggedBlob, now); Msg.Text = Ok("The profile image for ID " + politicianKey + " was reverted to the most recent logged version."); } } catch (Exception ex) { HandleException(ex); } }
protected void ButtonRemoveAllPages_Click(object sender, EventArgs e) { try { CommonCacheInvalidation.ScheduleInvalidateAll(); SetAllCacheLabels(); PageCachingFeedback.AddInfo("All Cached Pages will be cleared in 5 to 10 minutes."); } catch (Exception ex) { PageCachingFeedback.HandleException(ex); } }
protected void ButtonUploadPictureProfile_ServerClick(object sender, EventArgs e) { try { var postedFile = Request.Files[ImageFileProfile.Name]; var politicianKey = LabelPoliticianKey.Text; var uploadTime = DateTime.UtcNow; if ((postedFile == null) || (postedFile.ContentLength == 0)) { return; } Size originalSize; ImageManager.UpdatePoliticianProfileImages(politicianKey, postedFile.InputStream, uploadTime, out originalSize); CommonCacheInvalidation.ScheduleInvalidation("politicianimage", politicianKey); // We only want to propagate the profile to the headshot if there // is no current Headshot -- we check Headshot100 if (PoliticiansImagesBlobs.GetHeadshot100(politicianKey) == null) { ImageManager.UpdateResizedPoliticianHeadshotImages(politicianKey, postedFile.InputStream, uploadTime, out originalSize); } var memoryStream = new MemoryStream(); postedFile.InputStream.Position = 0; postedFile.InputStream.CopyTo(memoryStream); postedFile.InputStream.Position = 0; var imageBlob = memoryStream.ToArray(); LogPoliticiansImagesOriginal.Insert(politicianKey, imageBlob, uploadTime, UserSecurityClass, UserName, 0); UpdateRowCountAfterChange(); Msg.Text = Ok("The profile image for ID " + politicianKey + " was uploaded."); } catch (Exception ex) { HandleException(ex); } }
protected void ButtonAsIs_Click(object sender, EventArgs e) { try { var politicianKey = LabelPoliticianKey.Text.Trim(); PoliticiansImagesData.GuaranteePoliticianKeyExists(politicianKey); PoliticiansImagesBlobs.GuaranteePoliticianKeyExists(politicianKey); PoliticiansImagesData.UpdateHeadshotDate(DateTime.UtcNow, politicianKey); CommonCacheInvalidation.ScheduleInvalidation("politicianimage", politicianKey); MarkProcessed(); UpdateRowCountAfterChange(); } catch (Exception ex) { HandleException(ex); } }
private void DeleteButton_Click(object sender, EventArgs e) { try { Debug.Assert(sender is Control, "sender is Control"); var msgNo = GetMsgNoFromId(((Control)sender).ID); DonationNags.DeleteByMessageNumber(msgNo); var feedback = $"MsgNo {msgNo} was successfully deleted"; NagFeedback.AddInfo(feedback); CommonCacheInvalidation.ScheduleInvalidateNagsAll(); NagEditMode.Value = Empty; BuildHtmlTable(); } catch (Exception ex) { NagFeedback.AddError("The operation failed due to an unexpected error."); NagFeedback.HandleException(ex); } }
private void UpdateButton_Click(object sender, EventArgs e) { try { // Get the existing record Debug.Assert(sender is Control, "sender is Control"); var msgNo = GetMsgNoFromId(((Control)sender).ID); var table = DonationNags.GetDataByMessageNumber(msgNo); var newMsgNo = GetMsgNoFromForm(); if (newMsgNo != msgNo) { CheckForDuplicateMsgNo(newMsgNo); } var nextMsgNo = GetNextMsgFromForm(); var messageText = GetMsgTextFromForm(); if (NagFeedback.ValidationErrorCount != 0) { return; } table[0].MessageNumber = newMsgNo; table[0].NextMessageNumber = nextMsgNo; table[0].MessageText = messageText; DonationNags.UpdateTable(table); var feedback = newMsgNo != msgNo ? $"MsgNo {msgNo} was successfully updated and its MsgNo changed to {newMsgNo}" : $"MsgNo {msgNo} was successfully updated"; NagFeedback.AddInfo(feedback); CommonCacheInvalidation.ScheduleInvalidateNagsAll(); NagEditMode.Value = Empty; BuildHtmlTable(); } catch (Exception ex) { NagFeedback.AddError("The operation failed due to an unexpected error."); NagFeedback.HandleException(ex); } }
protected void ButtonRevertToLog_ServerClick(object sender, EventArgs e) { try { var politicianKey = LabelPoliticianKey.Text; string user; var latestLogDate = LogDataChange.GetSecondLatestProfileImageDate(politicianKey, out user); var logTime = new DateTime(latestLogDate.Ticks); var loggedBlob = LatestLoggedImagePage.GetLoggedImageByDate( politicianKey, logTime); if ((latestLogDate == DefaultDbDate) || (loggedBlob == null) || (loggedBlob.Length == 0)) { Msg.Text = Fail("No log profile image for ID " + politicianKey + " was found."); } else { var now = DateTime.UtcNow; Size originalSize; ImageManager.UpdatePoliticianProfileImages(politicianKey, new MemoryStream(loggedBlob), now, out originalSize); CommonCacheInvalidation.ScheduleInvalidation("politicianimage", politicianKey); LogPoliticiansImagesOriginal.Insert(politicianKey, loggedBlob, now, UserSecurityClass, UserName, 0); Msg.Text = Ok("The profile image for ID " + politicianKey + " was reverted to the most recent logged version."); } } catch (Exception ex) { HandleException(ex); } }
protected void ButtonUploadPicture_ServerClick(object sender, EventArgs e) { try { var postedFile = Request.Files[ImageFile.Name]; var politicianKey = LabelPoliticianKey.Text; var uploadTime = DateTime.UtcNow; if ((postedFile == null) || (postedFile.ContentLength == 0) || string.IsNullOrEmpty(politicianKey)) { return; } Size originalSize; ImageManager.UpdateAllPoliticianHeadshotImages(politicianKey, postedFile.InputStream, uploadTime, out originalSize); CommonCacheInvalidation.ScheduleInvalidation("politicianimage", politicianKey); var memoryStream = new MemoryStream(); postedFile.InputStream.Position = 0; postedFile.InputStream.CopyTo(memoryStream); postedFile.InputStream.Position = 0; var imageBlob = memoryStream.ToArray(); LogPoliticiansImagesHeadshot.Insert(politicianKey, imageBlob, uploadTime, UserSecurityClass, UserName, 0); MarkProcessed(); UpdateRowCountAfterChange(); Msg.Text = Ok("The headshot image for ID " + politicianKey + " was uploaded."); } catch (Exception ex) { HandleException(ex); } }
protected void Page_Load(object sender, EventArgs e) { var result = new AjaxResponse(); try { // assume success unless an exception is thrown result.Success = true; // copy back the groupname and uploadid result.GroupName = Request.Form["groupname"]; result.UploadId = Request.Form["uploadid"]; // there should always be exactly one file if (Request.Files.Count == 0) { throw new VoteException("The upload file is missing"); } if (Request.Files.Count > 1) { throw new VoteException("Unexpected files in the upload package"); } // Test error handling //throw new VoteException("Some weird-ass error"); // get the file var postedFile = Request.Files[0]; // save the timestamp so the time we post to all the various tables matches // exactly... var uploadTime = DateTime.UtcNow; // We only update headshot images if there is no Headshot -- // we check Headshot100 determine if this is so // We request duplicate testing... byte[] blob; Size originalSize; byte[] originalBlob; if (PoliticiansImagesBlobs.GetHeadshot100(PoliticianKey) == null) { blob = ImageManager.UpdateAllPoliticianImages(PoliticianKey, postedFile.InputStream, uploadTime, true, out originalSize, out originalBlob); } else { blob = ImageManager.UpdatePoliticianProfileImages(PoliticianKey, postedFile.InputStream, uploadTime, true, out originalSize, out originalBlob); } if (blob == null) // means it was a duplicate { result.Duplicate = true; result.Message = "The uploaded picture is the same as we already have on our servers."; } else { result.Message = "The picture uploaded successfully. Original file length = " + postedFile.InputStream.Length.ToString(CultureInfo.InvariantCulture); result.Length = postedFile.InputStream.Length; result.Width = originalSize.Width; result.Height = originalSize.Height; // invalidate cached image on load-balanced servers CommonCacheInvalidation.ScheduleInvalidation("politicianimage", PoliticianKey); LogImageChange(originalBlob, blob, uploadTime); Politicians.UpdateDatePictureUploaded(uploadTime, PoliticianKey); } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } WriteJsonResultToResponse(result); }