public static void CopyCommonDataToLocal(string politicianKey) { CopyCommonBlobsToLocal(politicianKey); var table = PoliticiansImagesData.GetDataByPoliticianKey(politicianKey); // suppress errors on Insert because a parallel thread may have already // copied the row into the local database try { switch (table.Count) { case 1: { var row = table[0]; DB.VoteImagesLocal.PoliticiansImagesData.Upsert(politicianKey, row.ProfileOriginalDate, row.HeadshotDate, row.HeadshotResizeDate, DateTime.UtcNow); } break; case 0: DB.VoteImagesLocal.PoliticiansImagesData.Upsert(politicianKey, VoteDb.DateTimeMin, VoteDb.DateTimeMin, VoteDb.DateTimeMin, VoteDb.DateTimeMin); break; } } // ReSharper disable once EmptyGeneralCatchClause catch {} }
private void CheckProfileContentTypeButton_Click(object sender, EventArgs e) { List <string> errors = new List <string>(); CheckProfileContentTypeButton.Enabled = false; int count = 0; var table = PoliticiansImagesData.GetAllData(); foreach (var row in table) { count++; string politicianKey = row.PoliticianKey; byte[] blob = PoliticiansImagesBlobs.GetProfileOriginalByPoliticianKey(politicianKey); if (blob != null) { string dbContentType = PoliticiansImagesData .GetProfileOriginalContentTypeByPoliticianKey(politicianKey); string actualContentType = Images.GetContentType(blob); if (dbContentType != actualContentType) { errors.Add(String.Format("PoliticianKey: {0} Database: {1} Actual: {2}", politicianKey, dbContentType == null ? "<null>" : dbContentType, actualContentType == null ? "<null>" : actualContentType)); } } } }
private void SetProfileContentTypeButton_Click(object sender, EventArgs e) { List <string> errors = new List <string>(); SetProfileContentTypeButton.Enabled = false; int count = 0; var table = PoliticiansImagesData.GetAllData(); foreach (var row in table) { count++; string politicianKey = row.PoliticianKey; byte[] blob = PoliticiansImagesBlobs.GetProfileOriginalByPoliticianKey(politicianKey); if (blob != null) { string contentType = Images.GetContentType(blob); if (contentType == null) { errors.Add(politicianKey); } else { PoliticiansImagesData.UpdateProfileOriginalContentTypeByPoliticianKey( contentType, politicianKey); } } } }
public static IEnumerable <PoliticianImagesInfo> GetStateHeadshots( string stateCode, int officeLevel, bool onlyOutOfDate) { var filterOfficeLevel = officeLevel >= 0; var table = onlyOutOfDate ? PoliticiansImagesData.GetDataByStateForOutOfDateHeadshots(stateCode) : PoliticiansImagesData.GetDataByState(stateCode); var list = ConvertTableToList(table); // Get OfficeKey and related data var tempCache = GetPageCache(); foreach (var info in list) { info.ApplyAdditionalCoding(tempCache); } // Fiter and sort list = list.Where(item => !filterOfficeLevel || (item.OfficeLevel == officeLevel)) .OrderBy(item => item, new PoliticianImagesInfo()) .ToList(); return(list); }
private void AnalyzeProfileOriginal(string key) { var profileOriginalBlob = PoliticiansImagesBlobs.GetProfileOriginal(key); if (profileOriginalBlob != null) { var dataTable = PoliticiansImagesData.GetData(key); bool nullIt = dataTable.Count == 1 && dataTable[0].ProfileOriginalDate <= dataTable[0].HeadshotDate; byte[] newBlob = null; MemoryStream memoryStream = new MemoryStream(profileOriginalBlob); Image image = Image.FromStream(memoryStream); if (nullIt) { AppendStatusText("{0}: {1}x{2} {3}->{4} [{5}:{6}]", key, image.Width, image.Height, profileOriginalBlob.Length, 0, profileOriginalBlob.Length, ImageManager.GetContentType(image).Replace("image/", "")); } else { newBlob = ImageManager.GetResizedImageBlobAsJpg(image, 0, 0); AppendStatusText("{0}: {1}x{2} {3}->{4} [{5}:{6}]", key, image.Width, image.Height, profileOriginalBlob.Length, newBlob.Length, profileOriginalBlob.Length - newBlob.Length, ImageManager.GetContentType(image).Replace("image/", "")); File.WriteAllBytes(@"c:\ProfileOriginals\" + key + ".jpg", newBlob); } } }
private void FixNoPhotoImage() { string path = @"c:\Temp\NoPhoto300.png"; string key = "NoPhoto"; DateTime now = DateTime.Now; using (Stream stream = File.OpenRead(path)) { Image image = Image.FromStream(stream); var newBlob300 = ImageManager.GetResizedImageBlob(image, 300, 0); File.WriteAllBytes(@"c:\VoteImages\Profile300\" + key + ".png", newBlob300); PoliticiansImagesBlobs.UpdateProfile300(newBlob300, key); PoliticiansImagesBlobs.UpdateProfileOriginal(newBlob300, key); var newBlob200 = ImageManager.GetResizedImageBlob(image, 200, 0); File.WriteAllBytes(@"c:\VoteImages\Profile200\" + key + ".png", newBlob200); PoliticiansImagesBlobs.UpdateProfile200(newBlob200, key); var newBlob100 = ImageManager.GetResizedImageBlob(image, 100, 0); File.WriteAllBytes(@"c:\VoteImages\Headshot100\" + key + ".png", newBlob100); PoliticiansImagesBlobs.UpdateHeadshot100(newBlob100, key); var newBlob75 = ImageManager.GetResizedImageBlob(image, 75, 0); File.WriteAllBytes(@"c:\VoteImages\Headshot75\" + key + ".png", newBlob75); PoliticiansImagesBlobs.UpdateHeadshot75(newBlob75, key); var newBlob50 = ImageManager.GetResizedImageBlob(image, 50, 0); File.WriteAllBytes(@"c:\VoteImages\Headshot50\" + key + ".png", newBlob50); PoliticiansImagesBlobs.UpdateHeadshot50(newBlob50, key); var newBlob35 = ImageManager.GetResizedImageBlob(image, 35, 0); File.WriteAllBytes(@"c:\VoteImages\Headshot35\" + key + ".png", newBlob35); PoliticiansImagesBlobs.UpdateHeadshot35(newBlob35, key); var newBlob25 = ImageManager.GetResizedImageBlob(image, 25, 0); File.WriteAllBytes(@"c:\VoteImages\Headshot25\" + key + ".png", newBlob25); PoliticiansImagesBlobs.UpdateHeadshot25(newBlob25, key); var newBlob20 = ImageManager.GetResizedImageBlob(image, 20, 0); File.WriteAllBytes(@"c:\VoteImages\Headshot20\" + key + ".png", newBlob20); PoliticiansImagesBlobs.UpdateHeadshot20(newBlob20, key); var newBlob15 = ImageManager.GetResizedImageBlob(image, 15, 0); File.WriteAllBytes(@"c:\VoteImages\Headshot15\" + key + ".png", newBlob15); PoliticiansImagesBlobs.UpdateHeadshot15(newBlob15, key); PoliticiansImagesData.UpdateHeadshotDate(now, key); PoliticiansImagesData.UpdateHeadshotResizeDate(now, key); PoliticiansImagesData.UpdateProfileOriginalDate(now, key); AppendStatusText("Complete"); } }
private static void DeleteAllPoliticianReferences(string politicianKey) { Answers2.DeleteByPoliticianKey(politicianKey); ElectionsIncumbentsRemoved.DeleteByPoliticianKey(politicianKey); ElectionsIncumbentsRemoved.UpdateRunningMateKeyByRunningMateKey(Empty, politicianKey); ElectionsPoliticians.DeleteByPoliticianKey(politicianKey); ElectionsPoliticians.UpdateRunningMateKeyByRunningMateKey(Empty, politicianKey); OfficesOfficials.DeleteByPoliticianKey(politicianKey); OfficesOfficials.UpdateRunningMateKeyByRunningMateKey(Empty, politicianKey); PoliticiansImagesBlobs.DeleteByPoliticianKey(politicianKey); PoliticiansImagesData.DeleteByPoliticianKey(politicianKey); TempEmail.DeleteByPoliticianKey(politicianKey); }
public static PoliticianImagesInfo GetHeadshotDataForPolitician(string politicianKey) { var table = PoliticiansImagesData.GetData(politicianKey); if (table.Count == 0) { return(null); } var info = ConvertTableToList(table)[0]; // Get OfficeKey and related data var tempCache = GetPageCache(); info.ApplyAdditionalCoding(tempCache); return(info); }
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); } }
public static List <PoliticianImagesInfo> GetNextOutOfDateHeadshot(int officeLevel, DateTime profileOriginalDate, string politicianKey) { var table = PoliticiansImagesData.GetDataForOutOfDateHeadshots(); var list = ConvertTableToList(table); // Get OfficeKey and related data var tempCache = GetPageCache(); foreach (var info in list) { info.ApplyAdditionalCoding(tempCache); } // Eliminate any that are prior to the current processing point list = list .Where(item => item.IsGreater(officeLevel, profileOriginalDate, politicianKey)) .OrderBy(item => item, new PoliticianImagesInfo()).ToList(); return(list); }
private static DateTime GetHeadshotResizeDate(string politicianKey, bool noCache) { if (noCache) { return(PoliticiansImagesData.GetHeadshotResizeDate(politicianKey, DateTime.MinValue)); } var result = DB.VoteImagesLocal.PoliticiansImagesData.GetHeadshotResizeDate( politicianKey); if (result != null) { return(result.Value); } CopyCommonDataToLocal(politicianKey); return (DB.VoteImagesLocal.PoliticiansImagesData.GetHeadshotResizeDate( politicianKey, DateTime.MinValue)); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPoliticianUser) { Page.Title = H1.InnerHtml = "Database Statistics"; CandidatesCount.InnerText = Politicians.CountTable().ToString("N0"); CandidatePicturesCount.InnerText = PoliticiansImagesData.CountTable().ToString("N0"); OfficesCount.InnerText = Offices.CountAllActualOffices().ToString("N0"); var officeCandidates = ElectionsPoliticians.GetOfficeCandidatesByYear(); OfficeCandidatesCount.InnerText = officeCandidates.Sum(y => y.Value).ToString("N0"); var officeCandidatesRowIndex = OfficeCandidatesRow.Parent.Controls.IndexOf(OfficeCandidatesRow); foreach (var kvp in officeCandidates.OrderBy(i => i.Key)) { var newRow = new HtmlTableRow(); newRow.AddCssClasses("office-candidates-year"); newRow.AddCssClasses(OfficeCandidatesRow.Attributes["class"].SafeString()); OfficeCandidatesRow.Parent.Controls.AddAt(++officeCandidatesRowIndex, newRow); new Literal { Text = kvp.Key }.AddTo(new HtmlTableCell().AddTo(newRow, "year")); new Literal { Text = kvp.Value.ToString("N0") }.AddTo(new HtmlTableCell().AddTo(newRow, "value")); } var officeContests = ElectionsOffices.GetOfficeContestsByYear(); OfficeContestCount.InnerText = officeContests.Sum(y => y.Value).ToString("N0"); var officeContestsRowIndex = OfficeContestsRow.Parent.Controls.IndexOf(OfficeContestsRow); foreach (var kvp in officeContests.OrderBy(i => i.Key)) { var newRow = new HtmlTableRow(); newRow.AddCssClasses("office-contests-year"); newRow.AddCssClasses(OfficeContestsRow.Attributes["class"].SafeString()); OfficeContestsRow.Parent.Controls.AddAt(++officeContestsRowIndex, newRow); new Literal { Text = kvp.Key }.AddTo(new HtmlTableCell().AddTo(newRow, "year")); new Literal { Text = kvp.Value.ToString("N0") }.AddTo(new HtmlTableCell().AddTo(newRow, "value")); } var electionsCount = Elections.CountStateElectionsByYear(); ElectionsCount.InnerText = electionsCount.Sum(y => y.Value).ToString("N0"); var electionsRowIndex = ElectionsRow.Parent.Controls.IndexOf(ElectionsRow); foreach (var kvp in electionsCount.OrderBy(i => i.Key)) { var newRow = new HtmlTableRow(); newRow.AddCssClasses("elections-year"); newRow.AddCssClasses(ElectionsRow.Attributes["class"].SafeString()); ElectionsRow.Parent.Controls.AddAt(++electionsRowIndex, newRow); new Literal { Text = kvp.Key }.AddTo(new HtmlTableCell().AddTo(newRow, "year")); new Literal { Text = kvp.Value.ToString("N0") }.AddTo(new HtmlTableCell().AddTo(newRow, "value")); } SocialMediaLinksCount.InnerText = Politicians.CountAllSocialMediaLinks().ToString("N0"); BioInfoCount.InnerText = Answers.CountBioAnswersNew().ToString("N0"); PersonalCount.InnerText = Answers.CountPersonalAnswersNew().ToString("N0"); IssueResponsesCount.InnerText = Answers.CountActiveIssueAnswersNew().ToString("N0"); } }
public static void GuaranteePoliticianKeyExists(string politicianKey) { PoliticiansImagesData.GuaranteePoliticianKeyExists(politicianKey); PoliticiansImagesBlobs.GuaranteePoliticianKeyExists(politicianKey); }
private void SetImageUrls() { var politicianKey = LabelPoliticianKey.Text.Trim(); var latestLogInfo = LogDataChange.GetTwoLatestProfileImageInfos(politicianKey); var date = latestLogInfo.Count < 1 ? PoliticiansImagesData.GetProfileOriginalDate(politicianKey, DefaultDbDate) : latestLogInfo[0].DateStamp; var dateTag = LocalDate.AsString(date, "M/D/YYYY h:mm:ss A"); ProfileImageHeading.InnerHtml = latestLogInfo.Count < 1 ? $"Newly-Uploaded Profile:<br />{dateTag}" : $"Newly-Uploaded Profile<br />({dateTag} by {latestLogInfo[0].UserName}):"; byte[] loggedBlob = null; if (latestLogInfo.Count >= 2) { loggedBlob = LatestLoggedImagePage.GetLoggedImageByDate(politicianKey, new DateTime(latestLogInfo[1].DateStamp.Ticks)); } //if (latestLogInfo.Count < 2) if (loggedBlob == null) { LoggedImage.Visible = false; LoggedImageSize.Visible = false; LoggedImageHeading.InnerHtml = "No logged profile available"; LoggedImageHeading.Style.Add(HtmlTextWriterStyle.Color, "red"); ButtonRevertToLog.Visible = false; } else { LoggedImage.Visible = true; LoggedImageSize.Visible = true; LoggedImageHeading.InnerHtml = $"Most Recent Logged Profile<br/>({LocalDate.AsString(latestLogInfo[1].DateStamp, "M/D/YYYY h:mm:ss A")}" + $" by {latestLogInfo[1].UserName}):"; LoggedImageHeading.Style.Add(HtmlTextWriterStyle.Color, "black"); ButtonRevertToLog.Visible = true; LoggedImage.ImageUrl = "/master/latestloggedimage.aspx?id=" + politicianKey + "&ticks=" + latestLogInfo[1].DateStamp.Ticks; //var loggedBlob = // LatestLoggedImagePage.GetLoggedImageByDate(politicianKey, // new DateTime(latestLogInfo[1].DateStamp.Ticks)); var loggedImage = Image.FromStream(new MemoryStream(loggedBlob)); LoggedImageSize.InnerHtml = $"{loggedImage.Width}x{loggedImage.Height}"; } OriginalImage.ImageUrl = InsertNoCacheIntoUrl(Url_Image_Politician_Original(politicianKey) + "&Def=1"); var blob = ImageManager.GetPoliticianImage(politicianKey, "ProfileOriginal", "ProfileOriginal", true); var image = Image.FromStream(new MemoryStream(blob)); OriginalImageSize.InnerHtml = $"{image.Width}x{image.Height}"; Image15.ImageUrl = InsertNoCacheIntoUrl( Url_Image_Politician(politicianKey, ImageSize15Headshot) + "&Def=1"); Image20.ImageUrl = InsertNoCacheIntoUrl( Url_Image_Politician(politicianKey, ImageSize20Headshot) + "&Def=1"); Image25.ImageUrl = InsertNoCacheIntoUrl( Url_Image_Politician(politicianKey, ImageSize25Headshot) + "&Def=1"); Image35.ImageUrl = InsertNoCacheIntoUrl( Url_Image_Politician(politicianKey, ImageSize35Headshot) + "&Def=1"); Image50.ImageUrl = InsertNoCacheIntoUrl( Url_Image_Politician(politicianKey, ImageSize50Headshot) + "&Def=1"); Image75.ImageUrl = InsertNoCacheIntoUrl( Url_Image_Politician(politicianKey, ImageSize75Headshot) + "&Def=1"); Image100.ImageUrl = InsertNoCacheIntoUrl( Url_Image_Politician(politicianKey, ImageSize100Headshot) + "&Def=1"); Image200.ImageUrl = InsertNoCacheIntoUrl( Url_Image_Politician(politicianKey, ImageSize200Profile) + "&Def=1"); Image300.ImageUrl = InsertNoCacheIntoUrl( Url_Image_Politician(politicianKey, ImageSize300Profile) + "&Def=1"); }
// ReSharper disable MemberCanBePrivate.Global // ReSharper disable MemberCanBeProtected.Global // ReSharper disable UnusedMember.Global // ReSharper disable UnusedMethodReturnValue.Global // ReSharper disable UnusedAutoPropertyAccessor.Global // ReSharper disable UnassignedField.Global #endregion ReSharper disable public static void DeleteByPoliticianKey( string politicianKey, int commandTimeout = -1) { PoliticiansImagesData.DeleteByPoliticianKey(politicianKey, commandTimeout); PoliticiansImagesBlobs.DeleteByPoliticianKey(politicianKey, commandTimeout); }
private void SetRowCountForNewOption() { LabelRows.Text = PoliticiansImagesData.CountOutOfDateHeadshots() .ToString(CultureInfo.InvariantCulture); }
private static byte[] UpdatePoliticianImages(string politicianKey, Stream imageStream, DateTime uploadTime, bool includeAllProfileImages, bool includeHeadshotOriginal, bool includeHeadshotResizedImages, bool checkForDuplicates, out Size originalSize, out byte[] originalBlob) { var memoryStream = new MemoryStream(); imageStream.Position = 0; imageStream.CopyTo(memoryStream); imageStream.Position = 0; var image = Image.FromStream(imageStream); originalSize = image.Size; var blob = memoryStream.ToArray(); if (!image.RawFormat.Equals(ImageFormat.Jpeg)) // could be transparent { // draw on a white background var b = new Bitmap(image.Width, image.Height); b.SetResolution(image.HorizontalResolution, image.VerticalResolution); using (var g = Graphics.FromImage(b)) { g.Clear(Color.White); g.DrawImageUnscaled(image, 0, 0); //b.Save(@"c:\temp\zz.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); } image = b; } // This is so all subsequent db operations can be updates PoliticiansImagesData.GuaranteePoliticianKeyExists(politicianKey); PoliticiansImagesBlobs.GuaranteePoliticianKeyExists(politicianKey); originalBlob = null; if (checkForDuplicates) { // We fetch this image to see if its a duplicate var duplicateTester = GetImageToUseForDuplicateTesting(); if (duplicateTester != null) { var duplicateTesterBlob = GetResizedImageBlobAsJpg(image, duplicateTester.MaxWidth, duplicateTester.MaxHeight); originalBlob = duplicateTesterBlob; var dbBlob = PoliticiansImagesBlobs.GetColumn(duplicateTester.BlobsColumn, politicianKey) as Byte[]; if (dbBlob != null && dbBlob.Length == duplicateTesterBlob.Length) { var isDuplicate = !dbBlob.Where((t, inx) => t != duplicateTesterBlob[inx]) .Any(); if (isDuplicate) { return(null); // signals duplicate } } } } if (includeAllProfileImages) { PoliticiansImagesData.UpdateProfileOriginalDate(uploadTime, politicianKey); //PoliticiansImagesBlobs.UpdateProfileOriginal(blob, politicianKey); foreach (var info in GetAllProfilePoliticianImageInfos()) { var resizedBlob = GetResizedImageBlobAsJpg(image, info.MaxWidth, info.MaxHeight); PoliticiansImagesBlobs.UpdateColumn(info.BlobsColumn, resizedBlob, politicianKey); } } if (includeHeadshotOriginal) { PoliticiansImagesData.UpdateHeadshotDate(uploadTime, politicianKey); } if (includeHeadshotResizedImages) { foreach (var info in GetResizedHeadshotPoliticianImageInfos()) { var resizedBlob = GetResizedImageBlobAsJpg(image, info.MaxWidth, info.MaxHeight); PoliticiansImagesBlobs.UpdateColumn(info.BlobsColumn, resizedBlob, politicianKey); } PoliticiansImagesData.UpdateHeadshotResizeDate(uploadTime, politicianKey); } // Don't do this here. It belongs as a separate call. //CommonCacheInvalidation.ScheduleInvalidation("politicianimage", politicianKey); // We return the blob for logging purposes return(blob); }
private void DoConsolidation() { try { var selectedIndex = ConsolidateSelectedIndex.Value; string selectedKey; string unselectedKey; switch (selectedIndex) { case "1": selectedKey = ConsolidateKey1.Value; unselectedKey = ConsolidateKey2.Value; break; case "2": selectedKey = ConsolidateKey2.Value; unselectedKey = ConsolidateKey1.Value; break; default: throw new VoteException("Index not 1 or 2"); } //throw new VoteException("An error"); // Politicians var selectedPolitician = Politicians.GetData(selectedKey); var unselectedPolitician = Politicians.GetData(unselectedKey); if (selectedPolitician.Count != 1) { throw new VoteException("Politician " + selectedPolitician + " not found"); } if (unselectedPolitician.Count != 1) { throw new VoteException("Politician " + unselectedKey + " not found"); } var selectedData = UpdatePoliticians(selectedIndex, selectedPolitician, unselectedPolitician); // PoliticiansImagesData and PoliticiansImagesBlobs var selectedImagesData = PoliticiansImagesData.GetData(selectedKey); var unselectedImagesData = PoliticiansImagesData.GetData(unselectedKey); var selectedImagesBlobs = PoliticiansImagesBlobs.GetData(selectedKey); var unselectedImagesBlobs = PoliticiansImagesBlobs.GetData(unselectedKey); UpdateImages(selectedIndex, selectedData, selectedKey, selectedImagesData, selectedImagesBlobs, unselectedImagesData, unselectedImagesBlobs); // Answers var selectedAnswers = Answers.GetActiveDataByPoliticianKey(selectedKey); var unselectedAnswers = Answers.GetDataByPoliticianKey(unselectedKey); UpdateAnswers(selectedKey, selectedAnswers, unselectedAnswers); // ElectionsIncumbentsRemoved var selectedIncumbentsRemoved = ElectionsIncumbentsRemoved.GetDataByPoliticianKey(selectedKey); var unselectedIncumbentsRemoved = ElectionsIncumbentsRemoved.GetDataByPoliticianKey(unselectedKey); UpdateIncumbentsRemoved(selectedKey, unselectedIncumbentsRemoved, selectedIncumbentsRemoved); // ElectionsPoliticians var selectedElectionsPoliticians = ElectionsPoliticians.GetDataByPoliticianKey(selectedKey); var unselectedElectionsPoliticians = ElectionsPoliticians.GetDataByPoliticianKey(unselectedKey); UpdateElectionsPoliticians(selectedKey, unselectedElectionsPoliticians, selectedElectionsPoliticians); // OfficesOfficials var selectedOfficesOfficials = OfficesOfficials.GetDataByPoliticianKey(selectedKey); var unselectedOfficesOfficials = OfficesOfficials.GetDataByPoliticianKey(unselectedKey); UpdateOfficesOfficials(selectedKey, unselectedOfficesOfficials, selectedOfficesOfficials); // Update everything as one transaction, politicians last PoliticiansImagesData.UpdateTable(selectedImagesData); PoliticiansImagesData.UpdateTable(unselectedImagesData); PoliticiansImagesBlobs.UpdateTable(selectedImagesBlobs); PoliticiansImagesBlobs.UpdateTable(unselectedImagesBlobs); Answers.UpdateTable(selectedAnswers); Answers.UpdateTable(unselectedAnswers); ElectionsIncumbentsRemoved.UpdateTable(unselectedIncumbentsRemoved); ElectionsPoliticians.UpdateTable(unselectedElectionsPoliticians); OfficesOfficials.UpdateTable(unselectedOfficesOfficials); Politicians.UpdateTable(selectedPolitician); Politicians.UpdateTable(unselectedPolitician); // Log LogDataChange.LogUpdate("*ConsolidatePoliticians", "*Various", unselectedKey, selectedKey, VotePage.UserName, SecurePage.UserSecurityClass, DateTime.UtcNow, selectedKey); // After the main update, refresh the LiveOfficeKey, LiveOfficeStatus and LiveElectionKey var view = PoliticiansLiveOfficeKeyView.GetData(selectedKey); if (view.Count == 1) { var keyAndStatus = PoliticianOfficeStatus.FromLiveOfficeKeyAndStatus( view[0].LiveOfficeKeyAndStatus); selectedPolitician[0].LiveOfficeKey = keyAndStatus.OfficeKey; selectedPolitician[0].LiveOfficeStatus = keyAndStatus.PoliticianStatus.ToString(); selectedPolitician[0].LiveElectionKey = keyAndStatus.ElectionKey; Politicians.UpdateTable(selectedPolitician); } ConsolidateReloaded.Value = "ok"; } catch (Exception ex) { FeedbackConsolidate.AddError("There was an unexpected error: " + ex.Message); } }
private static void InvalidatePoliticianImage(string politicianKey) { // We do this via updates to avoid synchronization problems var oldBlobs = PoliticiansImagesBlobs.GetDataByPoliticianKey(politicianKey); if (oldBlobs.Count == 1) { var newBlobs = DB.Vote.PoliticiansImagesBlobs.GetCacheDataByPoliticianKey(politicianKey); switch (newBlobs.Count) { case 1: { var oldRow = oldBlobs[0]; var newRow = newBlobs[0]; oldRow.Profile300 = newRow.Profile300; oldRow.Profile200 = newRow.Profile200; oldRow.Headshot100 = newRow.Headshot100; oldRow.Headshot75 = newRow.Headshot75; oldRow.Headshot50 = newRow.Headshot50; oldRow.Headshot35 = newRow.Headshot35; oldRow.Headshot25 = newRow.Headshot25; oldRow.Headshot20 = newRow.Headshot20; oldRow.Headshot15 = newRow.Headshot15; PoliticiansImagesBlobs.UpdateTable(oldBlobs); } break; case 0: PoliticiansImagesBlobs.DeleteByPoliticianKey(politicianKey); break; } } var oldData = PoliticiansImagesData.GetDataByPoliticianKey(politicianKey); if (oldData.Count != 1) { return; } var newData = DB.Vote.PoliticiansImagesData.GetDataByPoliticianKey(politicianKey); switch (newData.Count) { case 1: { var oldRow = oldData[0]; var newRow = newData[0]; //oldRow.ProfileOriginalContentType = newRow.ProfileOriginalContentType; oldRow.ProfileOriginalDate = newRow.ProfileOriginalDate; //oldRow.ProfileOriginalWidth = newRow.ProfileOriginalWidth; //oldRow.ProfileOriginalHeight = newRow.ProfileOriginalHeight; //oldRow.HeadshotContentType = newRow.HeadshotContentType; oldRow.HeadshotDate = newRow.HeadshotDate; //oldRow.HeadshotWidth = newRow.HeadshotWidth; //oldRow.HeadshotHeight = newRow.HeadshotHeight; oldRow.HeadshotResizeDate = newRow.HeadshotResizeDate; PoliticiansImagesData.UpdateTable(oldData); } break; case 0: PoliticiansImagesData.DeleteByPoliticianKey(politicianKey); break; } }