示例#1
0
 public BalanceHistoryRepository(StateCache state, AccountsCache accounts, QuotesCache quotes, TimeCache time, IConfiguration config) : base(config)
 {
     State    = state;
     Accounts = accounts;
     Quotes   = quotes;
     Time     = time;
 }
示例#2
0
 public BakingRightsRepository(AccountsCache accounts, ProtocolsCache protocols, TimeCache time, StateCache state, IConfiguration config) : base(config)
 {
     Accounts  = accounts;
     Protocols = protocols;
     Time      = time;
     State     = state;
 }
示例#3
0
        private static string GetElectionDescriptionFromTemplate(string template,
                                                                 string stateCode, DateTime electionDate)
        {
            switch (stateCode)
            {
            case "U1":
                return(electionDate.ToString("MMMM d, yyyy") +
                       " General Election of U.S. President State-By-State");

            case "U2":
                return(electionDate.ToString("MMMM d, yyyy") +
                       " General Election of U.S. Senate State-By-State");

            case "U3":
                return(electionDate.ToString("MMMM d, yyyy") +
                       " General Election of U.S. House of Representatives State-By-State");

            case "U4":
                return(electionDate.ToString("MMMM d, yyyy") +
                       " General Election of Governors State-By-State");

            default:
                return(template.Replace("{StateName}", StateCache.GetStateName(stateCode)));
            }
        }
示例#4
0
 private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     try
     {
         var ldsStateCode = LdsStateTextBox.Text.Trim();
         var stateCode    = StateCache.StateCodeFromLdsStateCode(ldsStateCode);
         if (string.IsNullOrEmpty(stateCode))
         {
             throw new VoteException("Invalid LDS State");
         }
         if (MessageBox.Show(
                 $"OK to delete LDS State {ldsStateCode} ({stateCode}) from USZDNew table?",
                 "Delete State",
                 MessageBoxButtons.OKCancel, MessageBoxIcon.Question,
                 MessageBoxDefaultButton.Button2) == DialogResult.OK)
         {
             DeleteState(ldsStateCode);
             ProcessDataFile();
         }
     }
     catch (VoteException ex)
     {
         AppendStatusText(ex.Message);
         AppendStatusText("Terminated.");
     }
     catch (Exception ex)
     {
         AppendStatusText(ex.ToString());
         AppendStatusText("Terminated.");
     }
 }
示例#5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.IncludeCss("~/css/MainBanner.css");

            if (!IsPostBack)
            {
                MainBannerImageTag.Src = DomainDesign.GetImageUri("lgbanner.png")
                                         .ToString();
                MainBannerHomeLink.HRef = UrlManager.CurrentSiteUri.ToString();

                if (DomainData.IsValidStateCode)
                {
                    var stateCode = DomainData.FromQueryStringOrDomain;
                    var stateName = StateCache.GetStateName(stateCode);
                    MainBannerStateName.Src = DomainDesign.GetImageUri("name.png")
                                              .ToString();
                    MainBannerStateName.Alt = stateName;
                    var title = "Click to go to the Official " + stateName +
                                " Election Authority Website";
                    //MainBannerStateSiteLink.Title = title;
                    MainBannerStateSiteLink.InnerText = title + " →";
                    MainBannerStateSiteLink.HRef      = StateCache.GetUri(stateCode)
                                                        .ToString();
                }
                else
                {
                    MainBannerStateBanner.Visible = false;
                }
            }
        }
示例#6
0
        public static string GetEnquotedNicknameForState(string nickname,
                                                         string stateCode)
        {
            string quote1;
            string quote2 = null;

            switch (StateCache.GetEncloseNicknameCode(stateCode))
            {
            case "D":
            case null:
                quote1 = "\"";
                break;

            case "S":
                quote1 = "'";
                break;

            case "P":
                quote1 = "(";
                quote2 = ")";
                break;

            default:
                quote1 = string.Empty;
                break;
            }

            return(GetEnquotedNickname(nickname, quote1, quote2));
        }
示例#7
0
 protected override string GetCategoryTitle()
 {
     return(VotePage.GetPageCache()
            .LocalDistricts.GetLocalDistrict(StateCode, CountyCode, LocalCode) + ", " +
            CountyCache.GetCountyName(StateCode, CountyCode) + ", " +
            StateCache.GetStateName(StateCode) + " Offices");
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                const string title = "VoteSmart Import";
                Page.Title   = title;
                H1.InnerHtml = title;

                SetSubHeading();
                SetCredentialMessage();
                ClientStateCode.Value = StateCode;
                ClientStateName.Value = StateCache.GetStateName(StateCode);

                if (AdminPageLevel == AdminPageLevel.Unknown)
                {
                    UpdateControls.Visible = false;
                    NoJurisdiction.CreateStateLinks("/admin/VoteSmartImport.aspx?state={StateCode}");
                    NoJurisdiction.Visible = true;
                }

                RefreshElectionsButton.Disabled = true;
                if (StateCodeExists)
                {
                    RefreshElectionsButton.Value = $"Refresh VoteSmart Elections for {ClientStateName.Value}";
                }
            }
        }
示例#9
0
        private static void AddMasterOfficesMenu(Control parent)
        {
            // Masters only see it if they are on an Admin page
            if (!SecurePage.IsMasterUser)
            {
                return;
            }
            string stateCode = null;

            if (SecurePage.IsAdminPage)
            {
                stateCode = SecurePage.FindStateCode();
            }
            if (StateCache.IsValidStateCode(stateCode))
            {
                var ul         = CreateDropdownMenu();
                var countyCode = SecurePage.FindCountyCode();
                var localKey   = SecurePage.FindLocalKey();
                AddMenuItem(ul, "Manage Offices, Office Templates and Incumbents",
                            SecureAdminPage.GetUpdateOfficesPageUrl(stateCode, countyCode, localKey));
                AddMenuItem(ul, "Offices Report",
                            SecureAdminPage.GetOfficesPageUrl(stateCode, countyCode, localKey));
                AddMenuItem(ul, "Incumbents Report",
                            SecureAdminPage.GetOfficialsPageUrl(stateCode, countyCode, localKey));
                AddMenuItem(ul, "Download County or Local Offices CSV",
                            SecureAdminPage.GetAdminFolderPageUrl("DownloadOfficesCsv", "state", stateCode));
                AddMenuItem(parent, "Offices", ul);
            }
        }
示例#10
0
        private void AddCountiesMenu(Control ul)
        {
            // State Admins always see a counties menu
            // Masters see it if they are on a page with a state code
            var stateCode = SecurePage.FindStateCode();

            if (!StateCache.IsValidStateCode(stateCode))
            {
                return;
            }
            var template = Empty;

            if (SecurePage.IsMasterUser && !IsNullOrWhiteSpace(stateCode))
            {
                template = "/admin/{page}?state={StateCode}&county={CountyCode}";
            }
            else if (SecurePage.IsStateAdminUser)
            {
                template = "/admin/{page}?county={CountyCode}";
            }
            if (!IsNullOrWhiteSpace(template))
            {
                template = GetMenuPage(template);
                AddMenuItem(ul, " Counties", GetCountiesMenu(template, stateCode));
            }
        }
        protected static string Subsitutions_Politician_Find(string politicianKey,
                                                             string strToApplySubsitutions)
        {
            var newStr = strToApplySubsitutions;

            newStr = Regex.Replace(newStr, @"\[\[USERNAME\]\]",
                                   Politicians_Str(politicianKey, "PoliticianKey"), RegexOptions.IgnoreCase);

            newStr = Regex.Replace(newStr, @"\[\[PASSWORD\]\]", Politicians_Str(politicianKey, "Password"),
                                   RegexOptions.IgnoreCase);

            var stateCode = Politicians.GetStateCodeFromKey(politicianKey).ToUpper();

            newStr = Regex.Replace(newStr, @"\[\[STATE\]\]", StateCache.GetStateName(stateCode),
                                   RegexOptions.IgnoreCase);

            newStr = Regex.Replace(newStr, @"\[\[VOTEXXANCHOR\]\]"
                                   //, db.Anchor(@"http://Vote-" + StateCode + ".org/")
                                   , Anchor(UrlManager.GetDefaultPageUri(stateCode)), RegexOptions.IgnoreCase);

            newStr = Regex.Replace(newStr, @"\[\[MGREMAIL\]\]", Anchor_Mailto_Email("*****@*****.**"),
                                   RegexOptions.IgnoreCase);

            newStr = Regex.Replace(newStr, @"\[\[INTROANCHOR\]\]"
                                   //, db.Anchor(@"http://Vote-" + StateCode + ".org/Intro.aspx?Id=" + db.Politicians_Str(PoliticianKey, "PoliticianKey"))
                                   , Anchor(UrlManager.GetIntroPageUri(politicianKey)), RegexOptions.IgnoreCase);

            newStr = Regex.Replace(newStr, @"\[\[POLITICIANENTRY\]\]"
                                   //, db.Anchor(@"http://Vote-" + StateCode + ".org/Politician")
                                   , Anchor(UrlManager.GetStateUri(stateCode) + "Politician"), RegexOptions.IgnoreCase);
            return(newStr);
        }
示例#12
0
 public VotingRepository(StateCache state, TimeCache time, AccountsCache accounts, ProposalMetadataService proposalMetadata, IConfiguration config) : base(config)
 {
     State            = state;
     Time             = time;
     Accounts         = accounts;
     ProposalMetadata = proposalMetadata;
 }
        private bool LdsInfoMatches(string zip5, string zip4, AddressFinderResult result)
        {
            var table = DB.VoteZipNew.Uszd.GetDataByZip5Zip4(zip5, zip4);

            if (table.Count == 0)
            {
                return(false);
            }
            var row = table[0];

            if (StateCache.StateCodeFromLdsStateCode(row.LdsStateCode) != result.State)
            {
                return(false);
            }
            if (row.Congress.ZeroPad(3) != result.Congress)
            {
                return(false);
            }
            if (row.StateSenate.ZeroPad(3) != result.StateSenate)
            {
                return(false);
            }
            if (row.StateHouse.ZeroPad(3) != result.StateHouse)
            {
                return(false);
            }
            if (row.County.ZeroPad(3) != result.County)
            {
                return(false);
            }
            return(true);
        }
示例#14
0
        private static void CreateBallotData(string stateCode, string electionKey,
                                             string congressionalDistrict, string stateSenateCode, string stateHouseCode,
                                             string countyCode)
        {
            StringBuilder     sb       = new StringBuilder();
            XmlWriterSettings settings = new XmlWriterSettings();

            using (XmlWriter writer = XmlWriter.Create(sb, settings))
            {
                writer.WriteStartElement("ballot");

                string stateName = StateCache.GetStateName(stateCode);
                if (stateName == null)
                {
                    stateName = string.Empty;
                }
                string countyName = db.Name_County(stateCode, countyCode);

                writer.WriteAttributeString("stateCode", stateCode);
                writer.WriteAttributeString("stateName", stateName);
                writer.WriteAttributeString("countyCode", countyCode);
                writer.WriteAttributeString("countyName", countyName);
                writer.WriteAttributeString("congressionalDistrict", congressionalDistrict);
                writer.WriteAttributeString("stateSenateCode", stateSenateCode);
                writer.WriteAttributeString("stateHouseCode", stateHouseCode);

                WriteElectionData(writer, electionKey);
                writer.WriteEndElement();
                writer.Flush();
            }
        }
示例#15
0
        private void ThePageTitle()
        {
            var title = $"{StateCache.GetStateName(StateCode)} Political Parties Emails, Websites and Information";

            Page.Title   = title;
            H1.InnerHtml = title;
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         Title = H1.InnerText = $"Download Offices CSV for {StateCache.GetStateName(QueryState)}";
     }
 }
示例#17
0
        public static string FormatElectionKey(DateTime electionDate,
                                               string electionTypeCode, string nationalPartyCode, string stateCode)
        {
            if (electionDate.Year < MinimumElectionYear ||
                electionDate.Year > MaximumElectionYear)
            {
                throw new VoteException("FormatElectionKey: invalid electionDate");
            }
            if (electionTypeCode.SafeString().Length != 1)
            {
                throw new VoteException("FormatElectionKey: invalid electionTypeCode");
            }
            if (nationalPartyCode.SafeString().Length != 1)
            {
                throw new VoteException("FormatElectionKey: invalid nationalPartyCode");
            }
            var isState = StateCache.IsValidStateCode(stateCode);

            if (!isState && !StateCache.IsValidFederalCode(stateCode) &&
                !stateCode.IsEqIgnoreCase("PP"))
            {
                throw new VoteException("FormatElectionKey: invalid stateCode");
            }
            return
                ((stateCode + electionDate.ToString("yyyyMMdd") + electionTypeCode +
                  nationalPartyCode).ToUpperInvariant());
        }
示例#18
0
        public static List <StateProvince> GetCacheStates(int countryId)
        {
            StateCache           cache = new StateCache(HttpContext.Current);
            List <StateProvince> list  = (List <StateProvince>)cache.Value;

            return(list.FindAll(x => x.CountryId == countryId));
        }
示例#19
0
        private void PopulateStateDropDown(bool includeSelectMessage = false)
        {
            if (includeSelectMessage)
            {
                StateCache.Populate(StateDropDownList, "<select a state>", Empty);
            }
            else
            {
                StateCache.Populate(StateDropDownList, _SecureAdminPage.StateCode);
            }

            var nonStateCodesAllowed = _SecureAdminPage.NonStateCodesAllowed;

            if (nonStateCodesAllowed == null)
            {
                return;
            }
            if (!SecurePage.IsSuperUser)
            {
                var nonStateCodesRequireSuperUser = _SecureAdminPage.NonStateCodesRequireSuperUser;
                if (nonStateCodesRequireSuperUser != null)
                {
                    nonStateCodesAllowed =
                        nonStateCodesAllowed.Where(
                            s => !nonStateCodesRequireSuperUser.Contains(s));
                }
            }
            foreach (var nonState in nonStateCodesAllowed)
            {
                StateDropDownList.AddItem(GetNonStateCodeName(nonState), nonState,
                                          nonState == _SecureAdminPage.StateCode);
            }
        }
示例#20
0
 public static IEnumerable <KeyValuePair <string, string> > GetElectionTypes(
     string stateCode)
 {
     if (StateCache.IsValidStateCode(stateCode))
     {
         foreach (var info in ElectionTypeInfos.Where(info => info.IsValidForState))
         {
             yield return
                 (new KeyValuePair <string, string>(info.ElectionTypeCode,
                                                    info.Description));
         }
     }
     else if (StateCache.IsValidFederalCode(stateCode, includeUS: false))
     {
         yield return
             (new KeyValuePair <string, string>(ElectionTypeGeneralElection,
                                                GetElectionTypeDescription(ElectionTypeGeneralElection)));
     }
     else // US or PP
     {
         yield return
             (new KeyValuePair <string, string>(ElectionTypeUSPresidentialPrimary,
                                                GetElectionTypeDescription(ElectionTypeUSPresidentialPrimary, stateCode)));
     }
 }
示例#21
0
 public BGMPlayer(AudioSource source)
 {
     audio        = new AudioDataContainer(source);
     stateCache   = new StateCache <PlayState>();
     stateMachine = new StateMachine <PlayState>();
     stateMachine.SetState(getCahceState <Stop>(PlayState.Stop));
 }
示例#22
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Page.Title   = "Setup Ballot Page Banner Ad";
                H1.InnerHtml = "Setup Ballot Page Banner Ad";
                _SetupAdDialogInfo.LoadControls();
                FeedbackSetupAd.AddInfo("Ad information loaded.");
                SetupSampleAd();
            }

            var body = Master.FindControl("body") as HtmlGenericControl;

            Debug.Assert(body != null, "body != null");
            body.Attributes.Add("data-state", StateCode);

            AdRate.InnerText =
                DB.Vote.Master.GetBallotAdRate(0)
                .ToString("C", CultureInfo.CreateSpecificCulture("en-US"));
            State.InnerText = StateCache.GetStateName(StateCode.SafeString());

            if (AdminPageLevel == AdminPageLevel.Unknown)
            {
                UpdateControls.Visible = false;
                NoJurisdiction.CreateStateLinks("/admin/SetupBallotPageBannerAd.aspx?state={StateCode}");
                NoJurisdiction.Visible = true;
            }
        }
示例#23
0
        /// <summary>
        /// Configures the P# runtime.
        /// </summary>
        /// <param name="configuration">Configuration</param>
        internal static void Configure(BugFindingConfiguration configuration)
        {
            PSharpRuntime.Configuration = configuration;

            PSharpRuntime.RootTaskId = Task.CurrentId;

            PSharpRuntime.MachineTasks = new List <Task>();
            PSharpRuntime.MachineMap   = new Dictionary <int, Machine>();
            PSharpRuntime.TaskMap      = new Dictionary <int, Machine>();
            PSharpRuntime.Monitors     = new List <Monitor>();

            if (PSharpRuntime.Configuration.ScheduleIntraMachineConcurrency)
            {
                PSharpRuntime.TaskScheduler         = new TaskWrapperScheduler(PSharpRuntime.MachineTasks);
                TaskMachineExtensions.TaskScheduler = PSharpRuntime.TaskScheduler as TaskWrapperScheduler;
            }

            MachineId.ResetMachineIDCounter();

            BugFindingDispatcher dispatcher = new BugFindingDispatcher();

            Machine.Dispatcher        = dispatcher;
            PSharp.Monitor.Dispatcher = dispatcher;

            PSharpRuntime.ProgramTrace    = new Trace();
            PSharpRuntime.StateCache      = new StateCache();
            PSharpRuntime.LivenessChecker = new LivenessChecker();

            PSharpRuntime.IsRunning = true;
        }
 protected override string GetCategoryTitle()
 {
     return(Elections.GetElectionTypeFromKey(ElectionKey) ==
            Elections.ElectionTypeUSPresidentialPrimary
 ? "US Presidential Candidates"
 : "US President & Vice President (" + StateCache.GetStateName(StateCode) + ")");
 }
示例#25
0
 public AccountsController(AccountRepository accounts, BalanceHistoryRepository history, ReportRepository reports, StateCache state)
 {
     Accounts = accounts;
     History  = history;
     Reports  = reports;
     State    = state;
 }
        //private Control GenerateReportByOfficeKey(string officeKey, string electionKey)
        //{
        //  _DataManager.GetDataByOfficeKey(officeKey, electionKey);

        //  var issueGroups = _DataManager.GetDataSubset()
        //    .GroupBy(row => row.IssueKey())
        //    .ToList();

        //  OneReportSection(issueGroups, "Questions");

        //  return ReportContainer.AddCssClasses("issue-list-report");
        //}

        //private Control GenerateReportByPoliticianKey(string politicianKey,
        //  string electionKey)
        //{
        //  _DataManager.GetDataByPoliticianKey(politicianKey, electionKey);

        //  var issueGroups = _DataManager.GetDataSubset()
        //    .GroupBy(row => row.IssueKey())
        //    .ToList();

        //  OneReportSection(issueGroups, "Questions");

        //  return ReportContainer.AddCssClasses("issue-list-report");
        //}

        private Control GenerateReportByStateCode(string stateCode)
        {
            _DataManager.GetDataByStateCode(stateCode);

            var issueLevelGroups = _DataManager.GetDataSubset()
                                   .GroupBy(row => row.IssueKey())
                                   .ToList()
                                   .GroupBy(g => g.First()
                                            .SortIssueLevel())
                                   .ToList();

            foreach (var issueLevelGroup in issueLevelGroups)
            {
                switch (issueLevelGroup.Key)
                {
                case "A":
                    OneReportSection(issueLevelGroup,
                                     "Questions Available to All Candidates");
                    break;

                case "B":
                    OneReportSection(issueLevelGroup,
                                     "Questions Available Only to U.S. President, U.S. House and U.S. Senate Candidates");
                    break;

                case "C":
                    OneReportSection(issueLevelGroup,
                                     "Questions Available Only to " + StateCache.GetStateName(stateCode) +
                                     " Statewide, House and Senate Candidates");
                    break;
                }
            }

            return(ReportContainer.AddCssClasses("issue-list-report"));
        }
示例#27
0
        public static DataTable GetSearchCandidates(string lastname,
                                                    IList <string> keysToSkip, string stateCode = null,
                                                    bool fullAlphaNameOnly = false, int commandTimeout = -1)
        {
            // if stateCode is not supplied, do not search on VowelStrippedName --
            // these are presidential candidates (or if it is a single character)
            var haveStateCode = StateCache.IsValidStateCode(stateCode);
            var alphaName     = lastname.StripAccents();

            if (!fullAlphaNameOnly)
            {
                alphaName += "%";
            }
            var vowelStrippedName = lastname.StripVowels() + "%";

            var stateCodeClause = haveStateCode
        ? "p.StateCode=@StateCode AND"
        : string.Empty;
            var excludeClause = (keysToSkip == null) || (keysToSkip.Count == 0)
        ? string.Empty
        : "p.PoliticianKey NOT IN ('" + string.Join("','", keysToSkip) + "') AND";
            var vowelStrippedClause = haveStateCode && (vowelStrippedName.Length > 2) &&
                                      !fullAlphaNameOnly
          ? "OR p.VowelStrippedName LIKE @VowelStrippedName"
          : string.Empty;

            var cmdText =
                "SELECT p.Address,p.CityStateZip,p.FName AS FirstName," +
                "p.MName as MiddleName,p.LiveOfficeKey," +
                "p.LiveOfficeStatus,p.LName AS LName,p.Nickname,p.PoliticianKey," +
                "p.StateAddress,p.StateCityStateZip,p.Suffix,p.AlphaName," +
                "p.VowelStrippedName,pt.PartyCode,o.OfficeLine1," +
                "o.OfficeLine2,o.OfficeLevel,l.LocalDistrict FROM Politicians p" +
                " LEFT JOIN Parties pt ON pt.PartyKey=p.PartyKey" +
                " LEFT JOIN Offices o ON o.OfficeKey=p.LiveOfficeKey" +
                " LEFT JOIN LocalDistricts l ON l.StateCode=o.StateCode" +
                "  AND l.CountyCode=o.CountyCode AND l.LocalCode=o.LocalCode" +
                $" WHERE {stateCodeClause} {excludeClause} (p.AlphaName LIKE @AlphaName {vowelStrippedClause})";

            var cmd = VoteDb.GetCommand(cmdText, commandTimeout);

            VoteDb.AddCommandParameter(cmd, "AlphaName", alphaName);
            if (haveStateCode)
            {
                VoteDb.AddCommandParameter(cmd, "StateCode", stateCode);
                if (vowelStrippedName.Length > 1)
                {
                    VoteDb.AddCommandParameter(cmd, "VowelStrippedName", vowelStrippedName);
                }
            }
            using (var cn = VoteDb.GetOpenConnection())
            {
                cmd.Connection = cn;
                var           table   = new DataTable();
                DbDataAdapter adapter = new MySqlDataAdapter(cmd as MySqlCommand);
                adapter.Fill(table);
                return(table);
            }
        }
            protected override string GetCategoryTitle()
            {
                var pageCache = VotePage.GetPageCache();

                return(pageCache.LocalDistricts.GetLocalDistrict(StateCode, LocalKey) + ", " +
                       CountyCache.GetCountyDescription(StateCode, CountyCode, LocalKey) + ", " +
                       StateCache.GetStateName(StateCode) + " - Local Offices");
            }
   protected override string GetCategoryTitle()
   {
       return(IsForAllStatesReport
 ? StateCache.GetStateName(StateCode)
 : StateCode == "DC"
   ? "Mayor District of Columbia"
   : "Governor and Lieutenant Governor");
   }
 protected override string GetCategoryTitle()
 {
     if (IsForAllStatesReport)
     {
         return(StateCache.GetStateName(StateCode));
     }
     return("US House of Representatives");
 }