/// <summary> /// Parses the xml file into a list of polling venues /// </summary> /// <param name="xDocument">The xml file</param> /// <param name="notifier">Event subscriber if validation of the xml file fails</param> /// <returns>A list of polling venues</returns> private List<PollingVenue> LoadVenues(XDocument xDocument, ValidationEventHandler notifier) { if (!this.ValidateXmlFile(xDocument, notifier)){ var pollingVenuesElements = from n in xDocument.Descendants("PollingVenue") select n; List<PollingVenue> pollingVenues = new List<PollingVenue>(); foreach (var xElement in pollingVenuesElements){ Address pollingVenueAddress = new Address{ Name = xElement.Element("Name").Value, Street = xElement.Element("Street").Value, City = xElement.Element("City").Value }; Address municipalityAddress = new Address{ Name = xElement.Parent.Parent.Element("Name").Value, Street = xElement.Parent.Parent.Element("Street").Value, City = xElement.Parent.Parent.Element("City").Value }; PollingVenue pollingVenue = new PollingVenue{ Persons = this.LoadPersons(xElement), PollingVenueAddress = pollingVenueAddress, MunicipalityAddress = municipalityAddress }; pollingVenues.Add(pollingVenue); } return pollingVenues; } return null; }
public void TestPollingCards() { PollingCards pollingCards = new PollingCards("test election", "01-01-01-2011", "09.00 - 20.00"); Person person = new Person{ FirstName = "Hans", LastName = "Sørensen", Street = "Hovedgaden 10", City = "2300 København S", PollingTable = "1", }; Address pollingVenue = new Address { Name = "Byskolen", Street = "Lærervej 8", City = "2300 København S" }; Address sender = new Address { Name = "Rådhuset", Street = "Ministervej 8", City = "2100 København Ø" }; pollingCards.CreatePollingCard(person, sender, pollingVenue); Assert.False(File.Exists("testpollingcard.pdf")); pollingCards.SaveToDisk("testpollingcard.pdf"); Assert.True(File.Exists("testpollingcard.pdf")); File.Delete("testpollingcard.pdf"); }
/// <summary> /// Create a polling card for this person! /// </summary> /// <param name="person">The voter</param> /// <param name="sender">Address of the sender</param> /// <param name="pollingVenue">Address of the polling venue</param> public void CreatePollingCard(Person person, Address sender, Address pollingVenue) { Contract.Requires(person != null); //Add a new page to the document PdfPage page = document.AddPage(); page.Width = XUnit.FromMillimeter(Width); page.Height = XUnit.FromMillimeter(Height); XGraphics gfx = XGraphics.FromPdfPage(page); //Draw the template gfx.DrawImage(template, 0, 0); //Draw the voter specific information on the polling card FromField(gfx, sender.Name, sender.Street, sender.City); ToField(gfx, person.FirstName + " " + person.LastName, person.Street, person.City); PollingTable(gfx, person.PollingTable); VotingNumber(gfx, person.VoterId.ToString()); PollingVenue(gfx, pollingVenue.Name, pollingVenue.Street, pollingVenue.City); //Release the XGraphics object gfx.Dispose(); }