Ejemplo n.º 1
0
        public static int UpdateSitemapVirtualPage()
        {
            string message;
            var    pages = 0;

            try
            {
                VotePage.LogInfo("UpdateSitemapVirtualPage", "Started");

                //var table = Sitemap.GetAllKeyData(0);
                //foreach (var row in table)
                //  new SitemapManager().UpdateVirtualPage(row.DomainDataCode);

                pages = new SitemapManager().UpdateVirtualPage();

                message = "Completed";
            }
            catch (Exception ex)
            {
                VotePage.LogException("UpdateSitemapVirtualPage", ex);
                message = $"Exception: {ex.Message} [see exception log for details]";
            }

            VotePage.LogInfo("UpdateSitemapVirtualPage", message);
            return(pages);
        }
        public static void Update()
        {
            string message;

            try
            {
                VotePage.LogInfo("UpdateOfficesAlternateOfficeLevel", "Started");

                var alternateOfficeLevelsUpdated = 0;

                foreach (var row in Offices.GetAllAlternateOfficeLevelUpdateData())
                {
                    var newAlternateOfficeLevel = ComputeAlternateOfficeClass(row)
                                                  .ToInt();

                    if (newAlternateOfficeLevel == row.AlternateOfficeLevel)
                    {
                        continue;
                    }

                    Offices.UpdateAlternateOfficeLevel(newAlternateOfficeLevel, row.OfficeKey);
                    alternateOfficeLevelsUpdated++;
                }

                message = $"{alternateOfficeLevelsUpdated} AlternateOfficeLevels updated";
            }
            catch (Exception ex)
            {
                VotePage.LogException("UpdateOfficesAlternateOfficeLevel", ex);
                message = $"Exception: {ex.Message} [see exception log for details]";
            }

            VotePage.LogInfo("UpdateOfficesAlternateOfficeLevel", message);
        }
Ejemplo n.º 3
0
        // This method is only used by the CommonCacheCleanup which is run via the
        // Windows task scheduler
        public static void CleanUpCacheInvalidation()
        {
            string message;

            try
            {
                VotePage.LogInfo("CleanUpCacheInvalidation", "Started");

                // Get the number of days to retain, default to 7
                var daysString =
                    ConfigurationManager.AppSettings["VoteCommonCacheInvalidationRetentionDays"];
                if (!int.TryParse(daysString, out var days))
                {
                    days = 7;
                }

                // Convert to a past DateTime
                var expiration = DateTime.UtcNow - new TimeSpan(days, 0, 0, 0);

                // Do it
                var deleted = CacheInvalidation.DeleteExpiredTransactions(expiration);

                message =
                    $"{deleted} CacheInvalidation rows deleted";
            }
            catch (Exception ex)
            {
                VotePage.LogException("CleanUpCacheInvalidation", ex);
                message = $"Exception: {ex.Message} [see exception log for details]";
            }

            VotePage.LogInfo("CleanUpCacheInvalidation", message);
        }
        public static void Update()
        {
            string message;

            try
            {
                VotePage.LogInfo("UpdatePoliticianSearchKeys", "Started");

                var alphaNamesUpdated         = 0;
                var vowelStrippedNamesUpdated = 0;

                var table = Politicians.GetAllSearchKeyUpdateData(0);
                foreach (var row in table)
                {
                    var newAlphaName = row.LastName.StripAccents();

                    if (newAlphaName != row.AlphaName)
                    {
                        row.AlphaName = newAlphaName;
                        alphaNamesUpdated++;
                    }

                    var newVowelStrippedName = row.LastName.StripVowels();

                    if (newVowelStrippedName != row.VowelStrippedName)
                    {
                        row.VowelStrippedName = newVowelStrippedName;
                        vowelStrippedNamesUpdated++;
                    }
                }

                Politicians.UpdateTable(table, PoliticiansTable.ColumnSet.SearchKeyUpdate, 0);

                message =
                    $"{alphaNamesUpdated} AlphaNames updated, {vowelStrippedNamesUpdated} VowelStrippedNames updated";
            }
            catch (Exception ex)
            {
                VotePage.LogException("UpdatePoliticianSearchKeys", ex);
                message = $"Exception: {ex.Message} [see exception log for details]";
            }

            VotePage.LogInfo("UpdatePoliticianSearchKeys", message);
        }
        public static void Update()
        {
            string message;

            try
            {
                VotePage.LogInfo("UpdateSingleCandidateContestWinners", "Started");

                message =
                    $"{ElectionsPoliticians.MarkWinnersForSingleCandidatePastContests(0)} winners updated";
            }
            catch (Exception ex)
            {
                VotePage.LogException("UpdateSingleCandidateContestWinners", ex);
                message = $"Exception: {ex.Message} [see exception log for details]";
            }

            VotePage.LogInfo("UpdateSingleCandidateContestWinners", message);
        }
Ejemplo n.º 6
0
        // This method is only used by the CommonCacheInvalidation which is run via the
        // Windows task scheduler
        public static void ProcessPendingTransactions()
        {
            string message;

            try
            {
                VotePage.LogInfo("CommonCacheInvalidation", "Started");

                var table = CacheInvalidation.GetUnprocessedData();
                var count = table.Sum(ProcessTransaction);

                message =
                    $"{table.Count()} CacheInvalidation rows processed, {count} Page rows deleted";
            }
            catch (Exception ex)
            {
                VotePage.LogException("CommonCacheInvalidation", ex);
                message = $"Exception: {ex.Message} [see exception log for details]";
            }
            VotePage.LogInfo("CommonCacheInvalidation", message);
        }
Ejemplo n.º 7
0
        public static void UpdateAllSitemapVirtualPages()
        {
            string message;

            try
            {
                VotePage.LogInfo("UpdateAllSitemapVirtualPages", "Started");

                var table = Sitemap.GetAllKeyData(0);
                foreach (var row in table)
                {
                    new SitemapManager().UpdateVirtualPage(row.DomainDataCode);
                }

                message = "Completed";
            }
            catch (Exception ex)
            {
                VotePage.LogException("UpdateAllSitemapVirtualPages", ex);
                message = $"Exception: {ex.Message} [see exception log for details]";
            }

            VotePage.LogInfo("UpdateAllSitemapVirtualPages", message);
        }
        public static void Update()
        {
            string message;

            try
            {
                VotePage.LogInfo("UpdatePoliticiansLiveOfficeKey", "Started");

                var officeKeysUpdated     = 0;
                var officeStatusesUpdated = 0;
                var electionKeysUpdated   = 0;

                var dictionary = PoliticiansLiveOfficeKeyView.GetAllData(commandTimeout: 3600)
                                 .ToDictionary(row => row.PoliticianKey, row => row);
                var politiciansTable = Politicians.GetAllLiveOfficeData();

                foreach (var politiciansRow in politiciansTable)
                {
                    if (!dictionary.TryGetValue(politiciansRow.PoliticianKey, out var viewRow))
                    {
                        continue;
                    }
                    var keyAndStatus =
                        PoliticianOfficeStatus.FromLiveOfficeKeyAndStatus(
                            viewRow.LiveOfficeKeyAndStatus);
                    if (keyAndStatus.OfficeKey != politiciansRow.LiveOfficeKey)
                    {
                        Politicians.UpdateLiveOfficeKey(keyAndStatus.OfficeKey,
                                                        politiciansRow.PoliticianKey);
                        officeKeysUpdated++;
                    }
                    if (keyAndStatus.PoliticianStatus.ToString() !=
                        politiciansRow.LiveOfficeStatus)
                    {
                        Politicians.UpdateLiveOfficeStatus(
                            keyAndStatus.PoliticianStatus.ToString(), politiciansRow.PoliticianKey);
                        officeStatusesUpdated++;
                    }
                    // ReSharper disable InvertIf
                    if (keyAndStatus.ElectionKey != politiciansRow.LiveElectionKey)
                    // ReSharper restore InvertIf
                    {
                        Politicians.UpdateLiveElectionKey(
                            keyAndStatus.ElectionKey, politiciansRow.PoliticianKey);
                        electionKeysUpdated++;
                    }
                }

                message =
                    $"{officeKeysUpdated} LiveOfficeKeys updated," +
                    $" {officeStatusesUpdated} LiveOfficeStatuses updated," +
                    $" {electionKeysUpdated} LiveElectionKeys updated";
            }
            catch (Exception ex)
            {
                VotePage.LogException("UpdatePoliticiansLiveOfficeKey", ex);
                message = $"Exception: {ex.Message} [see exception log for details]";
            }

            VotePage.LogInfo("UpdatePoliticiansLiveOfficeKey", message);
        }
Ejemplo n.º 9
0
        public static void RefreshYouTubePoliticians()
        {
            // this is so we only do it every three days
            if (DateTime.UtcNow.Day % 3 != 0)
            {
                return;
            }

            string message;

            try
            {
                VotePage.LogInfo("RefreshYouTubePoliticians", "Started");

                var politiciansUpdated = 0;
                var table = Politicians.GetYouTubeRefreshData();

                foreach (var row in table)
                {
                    YouTubeInfo info      = null;
                    var         url       = row.YouTubeWebAddress;
                    var         videoType = string.Empty;
                    if (url.IsValidYouTubeVideoUrl())
                    {
                        var id = url.GetYouTubeVideoId();
                        info      = GetVideoInfo(id, false, 1);
                        videoType = "video";
                    }
                    else if (url.IsValidYouTubePlaylistUrl())
                    {
                        var id = url.GetYouTubePlaylistId();
                        info      = GetPlaylistInfo(id, false, 1);
                        videoType = "playlist";
                    }
                    else if (url.IsValidYouTubeChannelUrl() || url.IsValidYouTubeCustomChannelUrl() ||
                             url.IsValidYouTubeUserChannelUrl())
                    {
                        var id = LookupChannelId(url, 1);
                        if (!string.IsNullOrWhiteSpace(id))
                        {
                            info = GetChannelInfo(id, false, 1);
                        }
                        videoType = "channel";
                    }

                    var error = string.Empty;
                    if (info == null || !info.IsValid)
                    {
                        switch (videoType)
                        {
                        case "video":
                            error = YouTubeInfo.VideoIdNotFoundMessage;
                            break;

                        case "playlist":
                            error = YouTubeInfo.PlaylistIdNotFoundMessage;
                            break;

                        case "channel":
                            error = YouTubeInfo.ChannelIdNotFoundMessage;
                            break;

                        default:
                            error = YouTubeInfo.InvalidVideoUrlMessage;
                            break;
                        }

                        if (row.YouTubeAutoDisable != error)
                        {
                            row.YouTubeAutoDisable = error;
                            politiciansUpdated++;
                        }
                        continue;
                    }

                    if (!info.IsPublic)
                    {
                        switch (videoType)
                        {
                        case "video":
                            error = YouTubeInfo.VideoNotPublicMessage;
                            break;

                        case "playlist":
                            error = YouTubeInfo.PlaylistNotPublicMessage;
                            break;

                        case "channel":
                            error = YouTubeInfo.ChannelNotPublicMessage;
                            break;
                        }
                        if (row.YouTubeAutoDisable != error)
                        {
                            row.YouTubeAutoDisable = error;
                            politiciansUpdated++;
                        }
                        continue;
                    }

                    if (info.ShortDescription != row.YouTubeDescription ||
                        info.Duration != row.YouTubeRunningTime ||
                        info.PublishedAt != row.YouTubeDate ||
                        row.YouTubeAutoDisable != null)
                    {
                        row.YouTubeDescription = info.ShortDescription;
                        row.YouTubeRunningTime = info.Duration;
                        row.YouTubeAutoDisable = null;
                        row.YouTubeDate        = info.PublishedAt;
                        politiciansUpdated++;
                    }
                }

                Politicians.UpdateTable(table, PoliticiansTable.ColumnSet.YouTubeRefresh);

                message =
                    $"{table.Count} Expired YouTube Politicians found, {politiciansUpdated} YouTube Politicians updated";
            }
            catch (Exception ex)
            {
                VotePage.LogException("RefreshYouTubePoliticians", ex);
                message = $"Exception: {ex.Message} [see exception log for details]";
            }

            VotePage.LogInfo("RefreshYouTubePoliticians", message);
        }
Ejemplo n.º 10
0
        public static void RefreshYouTubeAnswers()
        {
            string message;
            var    expiration = new TimeSpan(3, 0, 0, 0); // 3 days
            // fudge is to account for small differences in run time
            var fudge = new TimeSpan(1, 0, 0);            // 1 hour
            var now   = DateTime.UtcNow;

            try
            {
                VotePage.LogInfo("UpdatePoliticiansLiveOfficeKey", "Started");

                var answersUpdated = 0;
                var table          = Answers.GetDataForYouTubeRefresh(now - expiration + fudge);

                foreach (var row in table)
                {
                    row.YouTubeRefreshTime = now;

                    var youTubeId = row.YouTubeUrl.GetYouTubeVideoId();
                    if (string.IsNullOrWhiteSpace(youTubeId))
                    {
                        if (row.YouTubeAutoDisable != YouTubeInfo.InvalidVideoUrlMessage)
                        {
                            row.YouTubeAutoDisable = YouTubeInfo.InvalidVideoUrlMessage;
                            answersUpdated++;
                        }
                        continue;
                    }

                    var videoInfo = GetVideoInfo(youTubeId, false, 1);
                    if (!videoInfo.IsValid)
                    {
                        if (row.YouTubeAutoDisable != YouTubeInfo.VideoIdNotFoundMessage)
                        {
                            row.YouTubeAutoDisable = YouTubeInfo.VideoIdNotFoundMessage;
                            answersUpdated++;
                        }
                        continue;
                    }

                    if (!videoInfo.IsPublic)
                    {
                        if (row.YouTubeAutoDisable != YouTubeInfo.VideoNotPublicMessage)
                        {
                            row.YouTubeAutoDisable = YouTubeInfo.VideoNotPublicMessage;
                            answersUpdated++;
                        }
                        continue;
                    }

                    var description = videoInfo.Description.Trim();
                    if (string.IsNullOrWhiteSpace(description) || description.Length > YouTubeInfo.MaxVideoDescriptionLength)
                    {
                        description = videoInfo.Title.Trim();
                    }

                    if (description != row.YouTubeDescription ||
                        videoInfo.Duration != row.YouTubeRunningTime ||
                        row.YouTubeAutoDisable != null ||
                        row.YouTubeSource == YouTubeInfo.VideoUploadedByCandidateMessage &&
                        videoInfo.PublishedAt != row.YouTubeDate)
                    {
                        row.YouTubeDescription = description;
                        row.YouTubeRunningTime = videoInfo.Duration;
                        row.YouTubeAutoDisable = null;
                        if (row.YouTubeSource == YouTubeInfo.VideoUploadedByCandidateMessage)
                        {
                            row.YouTubeDate = videoInfo.PublishedAt;
                        }
                        answersUpdated++;
                    }
                }

                Answers.UpdateTable(table);

                message =
                    $"{table.Count} Expired YouTube answers found, {answersUpdated} YouTube Answers updated";
            }
            catch (Exception ex)
            {
                VotePage.LogException("RefreshYouTubeAnswers", ex);
                message = $"Exception: {ex.Message} [see exception log for details]";
            }

            VotePage.LogInfo("RefreshYouTubeAnswers", message);
        }