Esempio n. 1
0
        /// <summary>
        /// Insert the data that was fected onto the remote server.
        /// </summary>
        /// <param name="server">The address of the server.</param>
        /// <param name="port">The port of the server.</param>
        /// <param name="user">The username.</param>
        /// <param name="password">The password.</param>
        public void InsertData(string server, string port, string user, string password)
        {
            foreach (var municipality in this.Municipalities)
            {
                municipality.ResetAssociations();
            }
            foreach (var pollingStation in this.PollingStations)
            {
                pollingStation.ResetAssociations();
            }
            foreach (var voter in this.Voters)
            {
                voter.ResetAssociations();
            }

            var context = DigitalVoterList.GetInstance(user, password, server, port);

            mDAO = new MunicipalityDAO(context);
            pDAO = new PollingStationDAO(context);
            vDAO = new VoterDAO(context);

            mDAO.Create(this.Municipalities);
            pDAO.Create(this.PollingStations);
            vDAO.Create(this.Voters);
        }
Esempio n. 2
0
        /// <summary>
        /// (To be called when a group has finished being generated)
        /// Prepares for and starts the generation of the next group, if any remain.
        /// If no groups remain; the voters are updated in the database.
        /// </summary>
        /// <param name="sender">BackgroundWorker that just completed a generation process.</param>
        /// <param name="e">Worker event completion parameters (currently not used).</param>
        private void GroupGenerated(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                return;
            }
            var worker = sender as BackgroundWorker;

            this.GroupDoneCount++;

            // Prepare and start generation of next group, if any remain.
            if (this.groupsEnumerator.MoveNext())
            {
                this.currentGroup     = this.groupsEnumerator.Current;
                this.CurrentGroupName = this.currentGroup.Key;
                this.voterCount       = this.currentGroup.Count();
                this.voterDoneCount   = 0;
                this.VoterDonePerc    = 0;

                worker.RunWorkerAsync();
            }
            // ..Otherwise update voters in db and declare completed.
            else
            {
                this.CurrentGroupName = "Updating Database..";

                var voterDAO  = new VoterDAO();
                var template  = new VoterDO(null, null, null, null, null, true, null);
                var predicate = filter != null?filter.ToPredicate() : v => true;

                voterDAO.Update(predicate, template);

                GenerationEnded("Completed");
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Fetch data from the db based on the current filter.
        /// </summary>
        public void FetchData()
        {
            pDAO = new PollingStationDAO(DigitalVoterList.GetDefaultInstance());
            mDAO = new MunicipalityDAO(DigitalVoterList.GetDefaultInstance());
            vDAO = new VoterDAO(DigitalVoterList.GetDefaultInstance());

            VoterFilter f = this.Filter;

            if (f.CPRNO != 0)
            {
                this.Voters = vDAO.Read(v => v.PrimaryKey == f.CPRNO);
                VoterDO voter = this.Voters.First();
                this.PollingStations = pDAO.Read(ps => ps.PrimaryKey == voter.PollingStationId);
                PollingStationDO pollingStation = this.PollingStations.First();
                this.Municipalities = mDAO.Read(m => m.PrimaryKey == pollingStation.MunicipalityId);
            }
            else if (f.PollingStation != null)
            {
                this.PollingStations = pDAO.Read(ps => ps.PrimaryKey == f.PollingStation.PrimaryKey);
                this.Voters = vDAO.Read(v => v.PollingStationId == f.PollingStation.PrimaryKey);
                this.Municipalities = mDAO.Read(m => m.PrimaryKey == f.PollingStation.MunicipalityId);
            }
            else if (f.Municipality != null)
            {
                this.Municipalities = mDAO.Read(m => m.PrimaryKey == f.Municipality.PrimaryKey);
                this.PollingStations = pDAO.Read(p => p.MunicipalityId == f.Municipality.PrimaryKey);

                this.Voters = Enumerable.Empty<VoterDO>();
                foreach (var ps in this.PollingStations)
                {
                    PollingStationDO ps1 = ps;
                    this.Voters = this.Voters.Concat(vDAO.Read(v => v.PollingStationId == ps1.PrimaryKey));
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Fetch data from the db based on the current filter.
        /// </summary>
        public void FetchData()
        {
            pDAO = new PollingStationDAO(DigitalVoterList.GetDefaultInstance());
            mDAO = new MunicipalityDAO(DigitalVoterList.GetDefaultInstance());
            vDAO = new VoterDAO(DigitalVoterList.GetDefaultInstance());

            VoterFilter f = this.Filter;

            if (f.CPRNO != 0)
            {
                this.Voters = vDAO.Read(v => v.PrimaryKey == f.CPRNO);
                VoterDO voter = this.Voters.First();
                this.PollingStations = pDAO.Read(ps => ps.PrimaryKey == voter.PollingStationId);
                PollingStationDO pollingStation = this.PollingStations.First();
                this.Municipalities = mDAO.Read(m => m.PrimaryKey == pollingStation.MunicipalityId);
            }
            else if (f.PollingStation != null)
            {
                this.PollingStations = pDAO.Read(ps => ps.PrimaryKey == f.PollingStation.PrimaryKey);
                this.Voters = vDAO.Read(v => v.PollingStationId == f.PollingStation.PrimaryKey);
                this.Municipalities = mDAO.Read(m => m.PrimaryKey == f.PollingStation.MunicipalityId);
            }
            else if (f.Municipality != null)
            {
                this.Municipalities = mDAO.Read(m => m.PrimaryKey == f.Municipality.PrimaryKey);
                this.PollingStations = pDAO.Read(p => p.MunicipalityId == f.Municipality.PrimaryKey);

                this.Voters = Enumerable.Empty<VoterDO>();
                foreach (var ps in this.PollingStations)
                {
                    PollingStationDO ps1 = ps;
                    this.Voters = this.Voters.Concat(vDAO.Read(v => v.PollingStationId == ps1.PrimaryKey));
                }
            }
        }
Esempio n. 5
0
        public void SetUp()
        {
            if (!Directory.Exists(destination))
            {
                Directory.CreateDirectory(destination);
            }

            // Create a municipality
            var mDAO = new MunicipalityDAO();

            mDAO.Create(new MunicipalityDO(9998, "Teststreet 42", "4242 Testcity", "Municipality of Test"));
            IEnumerator <MunicipalityDO> muns =
                mDAO.Read(m => m.Name.StartsWith("Municipality of Test")).GetEnumerator();

            muns.MoveNext();
            this.mun = muns.Current;

            // Create 3 polling stations.
            var pDAO = new PollingStationDAO();

            pDAO.Create(new PollingStationDO(this.mun.PrimaryKey, 10000, "Test Polling Station 1", "Teststreet 44"));
            pDAO.Create(new PollingStationDO(this.mun.PrimaryKey, 10001, "Test Polling Station 2", "Teststreet 45"));
            pDAO.Create(new PollingStationDO(this.mun.PrimaryKey, 10002, "Test Polling Station 3", "Teststreet 46"));
            IEnumerator <PollingStationDO> pss =
                pDAO.Read(po => po.Name.StartsWith("Test Polling Station")).GetEnumerator();
            int pi = 0;

            while (pss.MoveNext())
            {
                this.ps[pi++] = pss.Current;
            }

            // Create 10 voters.
            var vDAO = new VoterDAO();

            vDAO.Create(new VoterDO(this.ps[0].PrimaryKey, 101264242, "Test Testson 1", "Teststreet 47", "4242 Testcity", false, false));
            vDAO.Create(new VoterDO(this.ps[1].PrimaryKey, 101264243, "Test Testson 2", "Teststreet 47", "4242 Testcity", false, false));
            vDAO.Create(new VoterDO(this.ps[2].PrimaryKey, 101264244, "Test Testson 3", "Teststreet 47", "4242 Testcity", false, false));
            vDAO.Create(new VoterDO(this.ps[0].PrimaryKey, 101264245, "Test Testson 4", "Teststreet 47", "4242 Testcity", false, false));
            vDAO.Create(new VoterDO(this.ps[0].PrimaryKey, 101264246, "Test Testson 5", "Teststreet 47", "4242 Testcity", false, false));
            vDAO.Create(new VoterDO(this.ps[1].PrimaryKey, 101264247, "Test Testson 6", "Teststreet 47", "4242 Testcity", false, false));
            vDAO.Create(new VoterDO(this.ps[1].PrimaryKey, 101264248, "Test Testson 7", "Teststreet 47", "4242 Testcity", false, false));
            vDAO.Create(new VoterDO(this.ps[2].PrimaryKey, 101264249, "Test Testson 8", "Teststreet 47", "4242 Testcity", false, false));
            vDAO.Create(new VoterDO(this.ps[2].PrimaryKey, 101264250, "Test Testson 9", "Teststreet 47", "4242 Testcity", false, false));
            vDAO.Create(new VoterDO(this.ps[2].PrimaryKey, 101264251, "Test Testson 10", "Teststreet 47", "4242 Testcity", false, false));
            IEnumerator <VoterDO> voters = vDAO.Read(vo => vo.Name.StartsWith("Test Testson")).GetEnumerator();
            int vi = 0;

            while (voters.MoveNext())
            {
                this.v[vi++] = voters.Current;
            }

            // Setup Voter Card Generator sub-system.
            this.filter        = new VoterFilter(mun);
            this.vcg           = new VoterCardGenerator(filter);
            this.vcgView       = new VoterCardGeneratorWindow(this.vcg);
            this.vcgController = new VoterCardGeneratorController(this.vcg, this.vcgView);
        }
Esempio n. 6
0
        public void DeleteOperation1()
        {
            // Arrange
            var dao = new VoterDAO();

            // Assert (contained in contracts)
            dao.Delete(v => v.Name.StartsWith("K"));
        }
Esempio n. 7
0
        public void DeleteOperation1()
        {
            // Arrange
            var dao = new VoterDAO();

            // Assert (contained in contracts)
            dao.Delete(v => v.Name.StartsWith("K"));
        }
Esempio n. 8
0
        public void DeleteOperation2()
        {
            // Arrange
            var dao = new VoterDAO();
            dao.Update(v => v.Name.StartsWith("B"), new VoterDO(null, null, null, null, null, null, true));
            // Change some voters to have status voted = true;

            // Assert (contained in contracts)
            dao.Delete(v => v.Voted == true);
        }
Esempio n. 9
0
        public void DeleteOperation2()
        {
            // Arrange
            var dao = new VoterDAO();

            dao.Update(v => v.Name.StartsWith("B"), new VoterDO(null, null, null, null, null, null, true));
            // Change some voters to have status voted = true;

            // Assert (contained in contracts)
            dao.Delete(v => v.Voted == true);
        }
Esempio n. 10
0
        public void TearDown()
        {
            var vDAO = new VoterDAO();

            vDAO.Delete(vo => vo.Name.StartsWith("Test Testson"));
            var pDAO = new PollingStationDAO();

            pDAO.Delete(po => po.Name.StartsWith("Test Polling Station"));
            var mDAO = new MunicipalityDAO();

            mDAO.Delete(m => m.Name.StartsWith("Municipality of T"));
        }
Esempio n. 11
0
        /// <summary>
        /// Create a new model that fetches data from the specified server.
        /// </summary>
        /// <param name="password">The password to the server</param>
        /// <param name="server">The address of the server.</param>
        public LogModel(string password, string server)
        {
            this.password = password;
            this.server   = server;

            var conn = DigitalVoterList.GetInstance("groupCJN", this.password, this.server);

            this.logs = new BindingList <LogDO>();
            this.lDAO = new LogDAO(conn);

            this.vDAO = new VoterDAO(conn);

            this.Update();

            this.filter = new LogFilter();
        }
Esempio n. 12
0
        public void GenerateVoters(int voters, int pollingstations)
        {
            var v = new HashSet <VoterDO>();

            for (uint i = 0; i < voters; i++)
            {
                uint cpr = data.GetCPR();

                var voter = new VoterDO((uint)this.r.Next(pollingstations), cpr, data.GetFirstName(cpr) + " " + data.GetLastname(), data.GetRoadname() + " " + r.Next(1000), data.GetCityname(), false, false);

                v.Add(voter);
            }
            var dao = new VoterDAO(dvl);

            dao.Create(v);
        }
Esempio n. 13
0
        /// <summary>
        /// Create a new model that fetches data from the specified server.
        /// </summary>
        /// <param name="password">The password to the server</param>
        /// <param name="server">The address of the server.</param>
        public LogModel(string password, string server)
        {
            this.password = password;
            this.server = server;

            var conn = DigitalVoterList.GetInstance("groupCJN", this.password, this.server);

            this.logs = new BindingList<LogDO>();
            this.lDAO = new LogDAO(conn);

            this.vDAO = new VoterDAO(conn);

            this.Update();

            this.filter = new LogFilter();
        }
Esempio n. 14
0
        public void Setup()
        {
            this.daos = new List <PessimisticVoterDAO>();

            var connection = new MySqlConnection(
                "server=localhost;" + "port=3306;" + "uid=groupCJN;" + "password=abc123;" + "Sql Server Mode=true;"
                + "database=groupcjn;");

            var creator = new DBCreator(connection);

            var generator = new Generator(DigitalVoterList.GetDefaultInstance());

            generator.Generate(1, 1, 3);

            VoterDAO voterDAO = new VoterDAO();

            this.voters = voterDAO.Read(v => true);
        }
Esempio n. 15
0
        /// <summary>
        /// How many of these voters have already had their voter cards generated?
        /// </summary>
        /// <returns>The number of given voters who has already had their voter cards generated.</returns>
        public int ValidateSelection()
        {
            var predicate = filter != null?filter.ToPredicate() : v => true;

            int count = 0;

            try
            {
                IEnumerable <VoterDO> voters = new VoterDAO().Read(predicate);
                count = voters.Where(v => v.CardPrinted.Equals(true)).Count();
            } catch (MySqlException e)
            {
                UnableToConnectEvent();
                count = -1;
            }

            return(count);
        }
Esempio n. 16
0
 private void btnRegister_Click(object sender, EventArgs e)
 {
     try
     {
         var voterDAO = new VoterDAO();
         foreach (var voter in _voters)
         {
             voterDAO.Add(voter);
         }
         MessageBox.Show("Voters Registered!");
         dtgVoters.Rows.Clear();
     }
     catch (Exception ex)
     {
         lblError.Visible = true;
         lblError.Text    = ex.Message;
     }
 }
Esempio n. 17
0
        public void ReadOperation1()
        {
            // Arrange
            var dao = new VoterDAO();

            // Act
            Expression<Func<VoterDO, bool>> f = v => v.Name.StartsWith("A");
            Func<VoterDO, bool> func = f.Compile();
            var result = dao.Read(f);
            Debug.Assert(result.Count() > 0, "No voters matched the arranged query, please generate some new data!");
            // The above is very unlikely to fail since we are generating 5000 voters, and the generator only has 50 names to choose from, but we still have to check it.

            // Assert
            foreach (VoterDO voter in result)
            {
                Debug.Assert(func.Invoke(voter), "The predicate did not hold for some voter.");
            }
        }
Esempio n. 18
0
        public void FetchVoterTest()
        {
            VoterDAO vdao = new VoterDAO(DigitalVoterList.GetInstance(user, password, server));

            vdao.Create(voter);

            Model     model = new Model();
            SetupInfo si    = new SetupInfo(server, 0);

            model.SetupInfo = si;
            model.AdminPass = password;

            model.initializeStaticDAO();
            VoterDO v = model.FetchVoter((uint)this.voter.PrimaryKey);

            Assert.AreEqual(voter.PrimaryKey, v.PrimaryKey);
            Model.cleanUpDAO();
            vdao.Delete(x => x.PrimaryKey == voter.PrimaryKey);
        }
Esempio n. 19
0
        /// <summary>
        /// Attempt to fetch the voters from the database
        /// Make event call to notify user in case of failure.
        /// </summary>
        /// <returns>The resulting voters.</returns>
        private IEnumerable <VoterDO> fetchVoters()
        {
            var voterDAO  = new VoterDAO();
            var predicate = filter != null?filter.ToPredicate() : v => true;

            IEnumerable <VoterDO> voters = null;

            try
            {
                voters = voterDAO.Read(predicate).ToList();
            }
            catch (MySqlException e)
            {
                UnableToConnectEvent();
                this.Abort();
            }

            return(voters);
        }
Esempio n. 20
0
        public void ReadOperation1()
        {
            // Arrange
            var dao = new VoterDAO();

            // Act
            Expression <Func <VoterDO, bool> > f = v => v.Name.StartsWith("A");
            Func <VoterDO, bool> func            = f.Compile();
            var result = dao.Read(f);

            Debug.Assert(result.Count() > 0, "No voters matched the arranged query, please generate some new data!");
            // The above is very unlikely to fail since we are generating 5000 voters, and the generator only has 50 names to choose from, but we still have to check it.

            // Assert
            foreach (VoterDO voter in result)
            {
                Debug.Assert(func.Invoke(voter), "The predicate did not hold for some voter.");
            }
        }
Esempio n. 21
0
        /// <summary> Initializes a new instance of the <see cref="VoterSelection"/> class with proper values for the default selection. </summary>
        public VoterSelection()
        {
            pDAO = new PollingStationDAO(DigitalVoterList.GetDefaultInstance());
            mDAO = new MunicipalityDAO(DigitalVoterList.GetDefaultInstance());
            vDAO = new VoterDAO(DigitalVoterList.GetDefaultInstance());

            // Call database to get initial values (no selection, ie. entire DB)
            try
            {
                Municipalities = mDAO.Read(o => true);
                PollingStations = pDAO.Read(o => true);
                voterCount = vDAO.Read(o => true).Count();
                currentFilter = null;
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(
                    string.Format("The system was not able to connect to the server. The system said: {0}", e.Message));
                Environment.Exit(-1);
            }
        }
Esempio n. 22
0
        public void CreateOperation1()
        {
            // Arrange
            var dao = new VoterDAO();

            uint cpr = 0;
            while (true)
            {
                // Continue to generate CPRs until nothing is returned from the db, i.e. the key is not contained so we can safely create it.
                Data data = new Data();
                cpr = data.GetCPR();

                if (dao.Read(v => v.PrimaryKey == cpr).Count() == 0)
                {
                    break;
                }
            }

            // Assert (contained in contracts)
            dao.Create(new VoterDO(1, cpr, "Tester", "TestRoad", "TestCity", false, false));
        }
Esempio n. 23
0
        /// <summary> Initializes a new instance of the <see cref="VoterSelection"/> class with proper values for the default selection. </summary>
        public VoterSelection()
        {
            pDAO = new PollingStationDAO(DigitalVoterList.GetDefaultInstance());
            mDAO = new MunicipalityDAO(DigitalVoterList.GetDefaultInstance());
            vDAO = new VoterDAO(DigitalVoterList.GetDefaultInstance());

            // Call database to get initial values (no selection, ie. entire DB)
            try
            {
                Municipalities  = mDAO.Read(o => true);
                PollingStations = pDAO.Read(o => true);
                voterCount      = vDAO.Read(o => true).Count();
                currentFilter   = null;
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(
                    string.Format("The system was not able to connect to the server. The system said: {0}", e.Message));
                Environment.Exit(-1);
            }
        }
Esempio n. 24
0
        public void CreateOperation1()
        {
            // Arrange
            var dao = new VoterDAO();

            uint cpr = 0;

            while (true)
            {
                // Continue to generate CPRs until nothing is returned from the db, i.e. the key is not contained so we can safely create it.
                Data data = new Data();
                cpr = data.GetCPR();

                if (dao.Read(v => v.PrimaryKey == cpr).Count() == 0)
                {
                    break;
                }
            }

            // Assert (contained in contracts)
            dao.Create(new VoterDO(1, cpr, "Tester", "TestRoad", "TestCity", false, false));
        }
Esempio n. 25
0
        public void ReadOperation3()
        {
            // Arrange
            var pdao = new PollingStationDAO();
            PollingStationDO pollingStation = pdao.Read(p => true).First();
            // Pick a random polling station.

            var dao = new VoterDAO();

            // Act
            Expression <Func <VoterDO, bool> > f = v => v.PollingStationId == pollingStation.PrimaryKey;
            Func <VoterDO, bool> func            = f.Compile();
            var result = dao.Read(f);

            Debug.Assert(result.Count() > 0, "No voters matched the arranged query, please generate some new data!");
            // The above is very unlikely to fail since we are generating 5000 voters, and the generator only has 50 names to choose from, but we still have to check it.

            // Assert
            foreach (VoterDO voter in result)
            {
                Debug.Assert(func.Invoke(voter));
            }
        }
Esempio n. 26
0
        public void FindVoterTest()
        {
            VoterDAO vdao = new VoterDAO(DigitalVoterList.GetInstance(user, password, server));

            vdao.Create(voter);

            Model     model = new Model();
            SetupInfo si    = new SetupInfo(server, 0);

            model.SetupInfo = si;
            model.AdminPass = password;
            model.initializeStaticDAO();

            //string msg;
            //model.ConnectionError += (x => msg = x);

            model.ConnectionError += this.DummyMethod;

            model.FindVoter((uint)voter.PrimaryKey);
            Assert.AreEqual(model.currentVoter, voter);
            Model.cleanUpDAO();

            vdao.Delete(x => x.PrimaryKey == voter.PrimaryKey);
        }
Esempio n. 27
0
        /// <summary>
        /// How many of these voters have already had their voter cards generated?
        /// </summary>
        /// <returns>The number of given voters who has already had their voter cards generated.</returns>
        public int ValidateSelection()
        {
            var predicate = filter != null ? filter.ToPredicate() : v => true;
            int count = 0;

            try
            {
                IEnumerable<VoterDO> voters = new VoterDAO().Read(predicate);
                count = voters.Where(v => v.CardPrinted.Equals(true)).Count();
            } catch (MySqlException e)
            {
                UnableToConnectEvent();
                count = -1;
            }

            return count;
        }
Esempio n. 28
0
        public void ReadOperation3()
        {
            // Arrange
            var pdao = new PollingStationDAO();
            PollingStationDO pollingStation = pdao.Read(p => true).First();
            // Pick a random polling station.

            var dao = new VoterDAO();

            // Act
            Expression<Func<VoterDO, bool>> f = v => v.PollingStationId == pollingStation.PrimaryKey;
            Func<VoterDO, bool> func = f.Compile();
            var result = dao.Read(f);
            Debug.Assert(result.Count() > 0, "No voters matched the arranged query, please generate some new data!");
            // The above is very unlikely to fail since we are generating 5000 voters, and the generator only has 50 names to choose from, but we still have to check it.

            // Assert
            foreach (VoterDO voter in result)
            {
                Debug.Assert(func.Invoke(voter));
            }
        }
Esempio n. 29
0
        public void GenerateVoters(int voters, int pollingstations)
        {
            var v = new HashSet<VoterDO>();

            for (uint i = 0; i < voters; i++)
            {
                uint cpr = data.GetCPR();

                var voter = new VoterDO((uint)this.r.Next(pollingstations), cpr, data.GetFirstName(cpr) + " " + data.GetLastname(), data.GetRoadname() + " " + r.Next(1000), data.GetCityname(), false, false);

                v.Add(voter);
            }
            var dao = new VoterDAO(dvl);
            dao.Create(v);
        }
Esempio n. 30
0
 public UserInterface()
 {
     dao = new VoterDAO(connectionString);
 }
Esempio n. 31
0
        /// <summary>
        /// Insert the data that was fected onto the remote server.
        /// </summary>
        /// <param name="server">The address of the server.</param>
        /// <param name="port">The port of the server.</param>
        /// <param name="user">The username.</param>
        /// <param name="password">The password.</param>
        public void InsertData(string server, string port, string user, string password)
        {
            foreach (var municipality in this.Municipalities)
            {
                municipality.ResetAssociations();
            }
            foreach (var pollingStation in this.PollingStations)
            {
                pollingStation.ResetAssociations();
            }
            foreach (var voter in this.Voters)
            {
                voter.ResetAssociations();
            }

            var context = DigitalVoterList.GetInstance(user, password, server, port);

            mDAO = new MunicipalityDAO(context);
            pDAO = new PollingStationDAO(context);
            vDAO = new VoterDAO(context);

            mDAO.Create(this.Municipalities);
            pDAO.Create(this.PollingStations);
            vDAO.Create(this.Voters);
        }
Esempio n. 32
0
        /// <summary>
        /// (To be called when a group has finished being generated)
        /// Prepares for and starts the generation of the next group, if any remain.
        /// If no groups remain; the voters are updated in the database.
        /// </summary>
        /// <param name="sender">BackgroundWorker that just completed a generation process.</param>
        /// <param name="e">Worker event completion parameters (currently not used).</param>
        private void GroupGenerated(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled) return;
            var worker = sender as BackgroundWorker;
            this.GroupDoneCount++;

            // Prepare and start generation of next group, if any remain.
            if (this.groupsEnumerator.MoveNext())
            {
                this.currentGroup = this.groupsEnumerator.Current;
                this.CurrentGroupName = this.currentGroup.Key;
                this.voterCount = this.currentGroup.Count();
                this.voterDoneCount = 0;
                this.VoterDonePerc = 0;

                worker.RunWorkerAsync();
            }
            // ..Otherwise update voters in db and declare completed.
            else
            {
                this.CurrentGroupName = "Updating Database..";

                var voterDAO = new VoterDAO();
                var template = new VoterDO(null, null, null, null, null, true, null);
                var predicate = filter != null ? filter.ToPredicate() : v => true;
                voterDAO.Update(predicate, template);

                GenerationEnded("Completed");
            }
        }
Esempio n. 33
0
        /// <summary>
        /// Attempt to fetch the voters from the database
        /// Make event call to notify user in case of failure.
        /// </summary>
        /// <returns>The resulting voters.</returns>
        private IEnumerable<VoterDO> fetchVoters()
        {
            var voterDAO = new VoterDAO();
            var predicate = filter != null ? filter.ToPredicate() : v => true;
            IEnumerable<VoterDO> voters = null;

            try
            {
                voters = voterDAO.Read(predicate).ToList();
            }
            catch (MySqlException e)
            {
                UnableToConnectEvent();
                this.Abort();
            }

            return voters;
        }
Esempio n. 34
0
        public void Setup()
        {
            this.daos = new List<PessimisticVoterDAO>();

            var connection = new MySqlConnection(
                    "server=localhost;" + "port=3306;" + "uid=groupCJN;" + "password=abc123;" + "Sql Server Mode=true;"
                    + "database=groupcjn;");

            var creator = new DBCreator(connection);

            var generator = new Generator(DigitalVoterList.GetDefaultInstance());

            generator.Generate(1, 1, 3);

            VoterDAO voterDAO = new VoterDAO();
            this.voters = voterDAO.Read(v => true);
        }