コード例 #1
0
 private static bool IsValidElectionKey(string electionKey)
 {
     if (MemCache.IsValidElection(electionKey))
     {
         if (Electoral_Class_Election(electionKey) == ElectoralClass.State ||
             Electoral_Class_Election(electionKey) == ElectoralClass.County ||
             Electoral_Class_Election(electionKey) == ElectoralClass.Local)
         {
             return(true);
         }
         else if (Electoral_Class_Election(electionKey) == ElectoralClass.County &&
                  Elections.GetCountyCodeFromKey(electionKey) == "000")
         {
             //Report of County Links to County Elections
             return(true);
         }
         else if (Electoral_Class_Election(electionKey) == ElectoralClass.Local &&
                  Elections.GetLocalCodeFromKey(electionKey) == "00")
         {
             //Report of Local Links to Local Elections
             return(true);
         }
         else
         {
             return(false);
         }
     }
     return(false);
 }
コード例 #2
0
        private void HandleElectionPage()
        {
            var electionKey = MemCache.IsValidElection(GetQueryParm("Election"))
        ? GetQueryParm("Election")
        : FixElectionKeyFromQueryString();

            var forIFrame = OriginalUri.AbsolutePath.ToLower() == "/electionforiframe.aspx";

            if (!string.IsNullOrEmpty(electionKey))
            {
                var stateCode = Elections.GetValidatedStateCodeFromKey(electionKey);
                if (string.IsNullOrEmpty(stateCode))
                {
                    // Build normalized uri without state
                    NormalizedUri   = UrlManager.GetElectionPageUri(electionKey, false, forIFrame);
                    _IsCanonicalUsa = true;
                }
                else if (StateCache.IsValidStateCode(stateCode))
                {
                    // Build normalized uri with state
                    NormalizedUri = UrlManager.GetElectionPageUri(stateCode, electionKey, false, forIFrame);
                }
                else
                {
                    ErrorMessage = "Invalid_StateCode";
                }
            }
            else
            {
                ErrorMessage = "Invalid_ElectionKey|StateCode";
            }
        }
コード例 #3
0
        private void HandleCompareCandidatesPage()
        {
            var officeKey = string.Empty;

            var electionKey = MemCache.IsValidElection(GetQueryParm("Election"))
        ? GetQueryParm("Election")
        : FixElectionKeyFromQueryString();

            if (!string.IsNullOrEmpty(electionKey))
            {
                if (Offices.IsInElection(GetQueryParm("Office"), electionKey))
                {
                    officeKey = GetQueryParm("Office");
                }
            }

            var stateCode = Elections.GetStateCodeFromKey(electionKey);

            if (!string.IsNullOrEmpty(electionKey) && !string.IsNullOrEmpty(officeKey))
            {
                NormalizedUri = UrlManager.GetCompareCandidatesPageUri(stateCode, electionKey,
                                                                       officeKey);
            }
            else
            {
                ErrorMessage =
                    "Cannot find this combination of State, Election and Office";
            }
        }
コード例 #4
0
        //public static void ServePoliticianImage(string politicianKey, string column)
        //{
        //  ServePoliticianImage(politicianKey, column, null);
        //}

        public static void ServePoliticianImage(string politicianKey, string column,
                                                string defaultColumn, bool noCache)
        {
            if (SecurePage.IsSignedIn)
            {
                noCache = true;
            }
            var request = HttpContext.Current.Request;

            // Get the appropriate modification date
            DateTime lastModDate;

            if (noCache)
            {
                lastModDate = IsColumnNameProfileImage(column)
          ? GetProfileOriginalDate(politicianKey, true)
          : GetHeadshotResizeDate(politicianKey, true);
            }
            else
            {
                // This triggers a copy to local is it's not there
                var modDates = MemCache.GetImageModDates(politicianKey);
                lastModDate = IsColumnNameProfileImage(column)
          ? modDates.ProfileDate
          : modDates.HeadshotDate;
            }
            lastModDate = new DateTime(lastModDate.Ticks, DateTimeKind.Utc);

            // To force all images older than this date to refresh
            var minimumModDate = new DateTime(2013, 05, 21, 14, 0, 0, DateTimeKind.Utc);

            if (minimumModDate > lastModDate)
            {
                lastModDate = minimumModDate;
            }

            // First check if the image has been modified
            var      ifModifiedSinceHeader = request.Headers["If-Modified-Since"];
            DateTime ifModifiedSince;

            var isModified = true; // assume modified unless we prove otherwise

            if (!string.IsNullOrWhiteSpace(ifModifiedSinceHeader) &&
                DateTime.TryParse(ifModifiedSinceHeader, null,
                                  DateTimeStyles.AdjustToUniversal, out ifModifiedSince))
            {
                isModified = false; // change our assumption
                // If mod date is greater, we need to check for insignificant (< 1 sec)
                // difference, because of lossy date conversions.
                if (lastModDate > ifModifiedSince)
                {
                    isModified = (lastModDate - ifModifiedSince) > TimeSpan.FromSeconds(1);
                }
            }

            ServeImageContent(politicianKey, column, defaultColumn, lastModDate,
                              isModified, noCache);
        }
コード例 #5
0
        private void HandleIssuePage()
        {
            var officeKey = string.Empty;
            var issueKey  = string.Empty;

            var electionKey = MemCache.IsValidElection(GetQueryParm("Election"))
        ? GetQueryParm("Election")
        : FixElectionKeyFromQueryString();

            if (!string.IsNullOrEmpty(electionKey))
            {
                if (Offices.IsInElection(GetQueryParm("Office"), electionKey))
                {
                    officeKey = GetQueryParm("Office");
                }

                if (!string.IsNullOrEmpty(officeKey))
                {
                    if (IsValidIssue(GetQueryParm("Issue"),
                                     Elections.GetStateCodeFromKey(electionKey)))
                    {
                        issueKey = GetQueryParm("Issue");
                    }
                }
            }

            var stateCode = Elections.GetStateCodeFromKey(electionKey);

            if (!string.IsNullOrEmpty(electionKey) && !string.IsNullOrEmpty(officeKey) &&
                !string.IsNullOrEmpty(issueKey))
            {
                if (OriginalUri.AbsolutePath.ToLower() == "/issue2.aspx")
                {
                    NormalizedUri = UrlManager.GetIssue2PageUri(stateCode, electionKey,
                                                                officeKey, issueKey);
                }
                else
                {
                    NormalizedUri = UrlManager.GetIssuePageUri(stateCode, electionKey,
                                                               officeKey, issueKey);
                }
            }
            else
            {
                ErrorMessage =
                    "Cannot find this combination of State, Election, Office and Issue";
            }
        }
コード例 #6
0
        private void HandleReferendumPage()
        {
            var electionKey = MemCache.IsValidElection(GetQueryParm("Election"))
        ? GetQueryParm("Election")
        : FixElectionKeyFromQueryString();
            var stateCode     = Elections.GetStateCodeFromKey(electionKey);
            var referendumKey = GetQueryParm("Referendum");

            if (!string.IsNullOrEmpty(electionKey) && !string.IsNullOrEmpty(stateCode))
            {
                NormalizedUri = UrlManager.GetReferendumPageUri(stateCode, electionKey,
                                                                referendumKey);
            }
            else
            {
                ErrorMessage = "Invalid_ElectionKey|ReferendumKey|StateCode";
            }
        }
コード例 #7
0
        private void HandleIssue2Page()
        {
            var electionKey = MemCache.IsValidElection(GetQueryParm("Election"))
        ? GetQueryParm("Election")
        : FixElectionKeyFromQueryString();

            var stateCode = Elections.GetStateCodeFromKey(electionKey);

            if (StateCache.IsValidStateCode(stateCode) && !string.IsNullOrEmpty(electionKey))
            {
                NormalizedUri = UrlManager.GetIssue2PageUri(stateCode, electionKey,
                                                            GetQueryParm("Congress"), GetQueryParm("StateSenate"),
                                                            GetQueryParm("StateHouse"), GetQueryParm("County"), GetQueryParm("Office"));
            }
            else
            {
                ErrorMessage =
                    "Invalid_ElectionKey|State|Congress|StateSenate|StateHouse|County";
            }
        }
コード例 #8
0
        private static Uri CheckForPresidentialPrimary(Uri uri)
        {
            var path = uri.AbsolutePath.ToLower();

            if (path == "/election.aspx" || path == "/electionforiframe.aspx" || path == "/issue.aspx" || path == "/issue2.aspx")
            {
                var qsc            = QueryStringCollection.Parse(uri.Query);
                var newElectionKey = MemCache.GetCanonicalElectionKey(qsc["election"]);
                // if we have a canonical key, substitute it
                // and switch to the non-state domain
                if (!string.IsNullOrWhiteSpace(newElectionKey))
                {
                    qsc["election"] = newElectionKey;
                    // Remove state from query string
                    qsc.Remove("state");
                    uri = UrlManager.GetSiteUri(path, qsc);
                }
            }
            return(uri);
        }