static void Main(string[] args) { var dg = new DataGenerator.DataGenerator(); dg.NumberOfMunicipalities = 20; dg.NumberOfPollingVenues = 20; dg.NumberOfVoters = 2000; dg.FileDestination = "XmlTest.xml"; dg.Generate(); int server = int.Parse(args[0]); if (server == 0) { Console.Out.WriteLine(System.Net.Dns.GetHostName() + " = name"); VoterServer voterServer = new VoterServer(System.Net.Dns.GetHostName()); DateTime time = DateTime.Now; int unix = (int)TimeConverter.ConvertToUnixTimestamp(time.ToUniversalTime()); voterServer.CprToPersonRequest = ((name,cpr) => new Person(){Cpr = cpr.ToString(), FirstName = "Ole", DbId = 42, LastName = "Henriksen", VotedPollingTable = "2", VotedTime = unix, Voted = false, Exists = true}); voterServer.VoterIdToPersonRequest = ((name,id) => new Person() { Cpr = "42", FirstName = "Kim", DbId = id, LastName = "Larsen", VotedPollingTable = "3", VotedTime = unix, Voted = true, Exists = false}); voterServer.RegisterVoteRequest = ((name,person) => !person.Voted); voterServer.UnregisterVoteRequest = ((name,person) => !person.Voted); voterServer.ValidTableRequest = ((name) => new string[]{"Table 1", "Table 2", "Table 3"}); voterServer.ListenForCalls(0); } }
public static VoterServer Create() { int unixTime = (int)TimeConverter.ConvertToUnixTimestamp(DateTime.Now.ToUniversalTime()); Person person1 = new Person() { Cpr = "1", FirstName = "TestCprFirst", DbId = 11, LastName = "TestCprLast", VotedPollingTable = "Table 1", VotedTime = unixTime, Voted = false, Exists = true }; Person person2 = new Person() { Cpr = "2", FirstName = "TestIdFirst", DbId = 22, LastName = "TestIdFirst", VotedPollingTable = "Table 2", VotedTime = unixTime, Voted = true, Exists = true }; Person emptyPerson = new Person(); string[] tables = new string[] { "Table 1", "Table 2", "Table 3" }; VoterServer voterServer = new VoterServer("Client"); voterServer.SetUnregisterVoteRequest((name, person) => !person.Voted); voterServer.SetValidTableRequest(name => tables); voterServer.SetCprToPersonRequest((name, cpr) => cpr == "1" ? person1 : emptyPerson); voterServer.SetVoterIdToPersonRequest((name, id) => id == 2 ? person2 : emptyPerson); voterServer.SetRegisterVoteRequest((name, person) => !person.Voted); return voterServer; // TODO: Edit factory method of VoterServer // This method should be able to configure the object in all possible ways. // Add as many parameters as needed, // and assign their values to each field by using the API. }
/// <summary> /// Construct a new server and instantiate and instance /// of the VoterNetworkServer identified as "primary". /// </summary> public Server() { this.voterServer = new VoterServer(System.Net.Dns.GetHostName()); this.serverData = new ServerData(); }
/// <summary> /// A server that will listen for 10 seconds /// </summary> private void SetupServer() { VoterServer voterServer = new VoterServer(System.Net.Dns.GetHostName()); voterServer.CprToPersonRequest = ((name, cpr) => cpr == "1" ? person1 : emptyPerson); voterServer.VoterIdToPersonRequest = ((name, id) => id == 2 ? person2 : emptyPerson); voterServer.RegisterVoteRequest = ((name, person) => !person.Voted); voterServer.UnregisterVoteRequest = ((name, person) => !person.Voted); voterServer.ValidTableRequest = ((name) => tables); voterServer.ListenForCalls(10000); }