/// <summary> /// Performs parsing operations and constructs a list of Coordinate objects as the result. /// </summary> /// <param name="fileName">The path to the file containing the XML information to parse.</param> /// <param name="crimes">The list of Crime objects to serialise the XML information into.</param> protected override void OnParse(string fileName, List <Crime> crimes) { OutputStreams.WriteLine($"Parsing {SA} data..."); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(fileName); State state = DataProvider.StateRepository.GetStateByAbbreviatedName(SA); List <LocalGovernmentArea> localGovernmentAreas = DataProvider.LocalGovernmentAreaRepository.GetLocalGovernmentAreasByStateID(state.ID); Dictionary <string, Offence> offences = new Dictionary <string, Offence>(); DataProvider.OffenceRepository.GetOffences().ForEach(m => offences.Add(m.Name.ToUpper(), m)); XmlNodeList workSheetXmlNodeList = xmlDocument.SelectNodes("/Workbook/Worksheet"); foreach (XmlNode workSheetXmlNode in workSheetXmlNodeList) { string localGovernmentAreaName = workSheetXmlNode.Attributes["Name"].Value; if (localGovernmentAreaName.Contains("(") == true) { localGovernmentAreaName = localGovernmentAreaName.Substring(0, localGovernmentAreaName.IndexOf("(")).Trim(); } LocalGovernmentArea localGovernmentArea = localGovernmentAreas.Where(m => (m.Name.EqualsIgnoreCase(localGovernmentAreaName) == true)).FirstOrDefault(); XmlNodeList xmlNodeList = workSheetXmlNode.SelectNodes("Table/Row[count(Cell) = 6]"); foreach (XmlNode xmlNode in xmlNodeList) { string offenceName = xmlNode.ChildNodes[0].InnerText.ToUpper(); if ((String.IsNullOrEmpty(offenceName) == false) && (offenceName.StartsWith("-") == true)) { offenceName = offenceName.Substring(offenceName.IndexOf("-") + 1).Trim(); Offence offence = null; if ((String.IsNullOrEmpty(offenceName) == false) && (offences.ContainsKey(offenceName) == true)) { offence = offences[offenceName]; } for (int i = 1, j = 2009; i < 6; i++, j++) { int count = Convert.ToInt32(xmlNode.ChildNodes[i].InnerText); crimes.Add(new Crime(count, localGovernmentArea.ID, 1, offence.ID, j)); } } } } base.OnParse(fileName, crimes); }
/// <summary> /// Selects local government area information from the underlying data source. /// </summary> /// <param name="id">The ID of the associated local government area.</param> /// <returns>Returns a LocalGovernmentArea object representing the result of the operation.</returns> public LocalGovernmentArea GetLocalGovernmentAreaByID(int id) { LocalGovernmentArea localGovernmentArea = null; using (SqlConnection sqlConnection = SqlConnectionFactory.NewSqlConnetion()) { localGovernmentArea = SqlMapper .Query(sqlConnection, LocationSpGetLocalGovernmentAreaByID, new { ID = id }, commandType: CommandType.StoredProcedure) .Select(m => new LocalGovernmentArea(m.DateCreatedUtc, m.DateUpdatedUtc, m.ID, m.IsDeleted, m.IsVisible, m.Name, m.StateID)) .FirstOrDefault(); } return(localGovernmentArea); }
/// <summary> /// Performs parsing operations and constructs a list of Coordinate objects as the result. /// </summary> /// <param name="fileName">The path to the file containing the XML information to parse.</param> /// <param name="crimes">The list of Crime objects to serialise the XML information into.</param> protected override void OnParse(string fileName, List <Crime> crimes) { OutputStreams.WriteLine($"Parsing {NSW} data..."); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(fileName); XmlNodeList xmlNodeList = xmlDocument.SelectNodes("/Workbook/Worksheet/Table/Row[position() > 1]"); int year = 1995; State state = DataProvider.StateRepository.GetStateByAbbreviatedName(NSW); List <LocalGovernmentArea> localGovernmentAreas = DataProvider.LocalGovernmentAreaRepository.GetLocalGovernmentAreasByStateID(state.ID); Dictionary <string, Offence> offences = new Dictionary <string, Offence>(); DataProvider.OffenceRepository.GetOffences().ForEach(m => offences.Add(m.Name.ToUpper(), m)); foreach (XmlNode xmlNode in xmlNodeList) { string localGovernmentAreaName = xmlNode.ChildNodes[0].InnerText.Trim(); string offenceName = xmlNode.ChildNodes[1].InnerText.Trim().ToUpper(); string suboffenceName = xmlNode.ChildNodes[2].InnerText.Trim().ToUpper(); Offence offence = null; LocalGovernmentArea localGovernmentArea = localGovernmentAreas.Where(m => (m.Name.EqualsIgnoreCase(localGovernmentAreaName) == true)).FirstOrDefault(); if ((String.IsNullOrEmpty(offenceName) == false) && (offences.ContainsKey(offenceName) == true)) { offence = offences[offenceName]; } if ((String.IsNullOrEmpty(suboffenceName) == false) && (offences.ContainsKey(offenceName) == true)) { offence = offences[suboffenceName]; } DateTime dateTime = new DateTime(year, 1, 1); for (int i = 3; i < xmlNode.ChildNodes.Count; i++) { int count = Convert.ToInt32(xmlNode.ChildNodes[i].InnerText); crimes.Add(new Crime(count, localGovernmentArea.ID, dateTime.Month, offence.ID, dateTime.Year)); dateTime = dateTime.AddMonths(1); } } base.OnParse(fileName, crimes); }
/// <summary> /// Performs parsing operations and constructs a list of Coordinate objects as the result. /// </summary> /// <param name="fileName">The path to the file containing the XML information to parse.</param> /// <param name="crimes">The list of Crime objects to serialise the XML information into.</param> protected override void OnParse(string fileName, List <Crime> crimes) { OutputStreams.WriteLine($"Parsing {ACT} data..."); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(fileName); XmlNodeList xmlNodeList = xmlDocument.SelectNodes("/Workbook/Worksheet/Table"); State state = DataProvider.StateRepository.GetStateByAbbreviatedName(ACT); List <LocalGovernmentArea> localGovernmentAreas = DataProvider.LocalGovernmentAreaRepository.GetLocalGovernmentAreasByStateID(state.ID); Dictionary <string, Offence> offences = new Dictionary <string, Offence>(); DataProvider.OffenceRepository.GetOffences().ForEach(m => offences.Add(m.Name.ToUpper(), m)); foreach (XmlNode xmlNode in xmlNodeList) { XmlNode localGovermentAreaXmlNode = xmlNode.SelectSingleNode("Row[position() = 1]"); string localGovernmentAreaName = localGovermentAreaXmlNode.InnerText.Trim(); LocalGovernmentArea localGovernmentArea = localGovernmentAreas.Where(m => (m.Name.EqualsIgnoreCase(localGovernmentAreaName) == true)).FirstOrDefault(); List <DateTime> dateTimeList = new List <DateTime>(); XmlNodeList datesXmlNodeList = xmlNode.SelectNodes("Row[position() = 3]/Cell"); datesXmlNodeList.OfType <XmlNode>().ToList().ForEach(m => dateTimeList.Add(DateTime.Parse(m.InnerText))); XmlNodeList offenceXmlNodeList = xmlNode.SelectNodes("Row[position() > 3]"); foreach (XmlNode offenceXmlNode in offenceXmlNodeList) { Offence offence = null; string offenceName = offenceXmlNode.ChildNodes[0].InnerText.Trim().ToUpper(); if ((String.IsNullOrEmpty(offenceName) == false) && (offences.ContainsKey(offenceName) == true)) { offence = offences[offenceName]; } for (int i = 0, j = 1; j < offenceXmlNode.ChildNodes.Count; i++, j++) { int count = Convert.ToInt32(offenceXmlNode.ChildNodes[j].InnerText); DateTime dateTime = dateTimeList[i]; crimes.Add(new Crime(count, localGovernmentArea.ID, dateTime.Month, offence.ID, dateTime.Year)); } } } base.OnParse(fileName, crimes); }
/// <summary> /// Performs parsing operations and constructs a list of Coordinate objects as the result. /// </summary> /// <param name="fileName">The path to the file containing the XML information to parse.</param> /// <param name="crimes">The list of Crime objects to serialise the XML information into.</param> protected override void OnParse(string fileName, List <Crime> crimes) { OutputStreams.WriteLine($"Parsing {VIC} data..."); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(fileName); XmlNodeList xmlNodeList = xmlDocument.SelectNodes("/Workbook/Worksheet/Table/Row[position() > 1]"); // The dataset I'm working with has a single year - 2014 int year = 2014; State state = DataProvider.StateRepository.GetStateByAbbreviatedName(VIC); List <LocalGovernmentArea> localGovernmentAreas = DataProvider.LocalGovernmentAreaRepository.GetLocalGovernmentAreasByStateID(state.ID); Dictionary <string, Offence> offences = new Dictionary <string, Offence>(); DataProvider.OffenceRepository.GetOffences().ForEach(m => offences.Add(m.Name.ToUpper(), m)); foreach (XmlNode xmlNode in xmlNodeList) { string localGovernmentAreaName = xmlNode.ChildNodes[2].InnerText.Trim(); string offenceName = xmlNode.ChildNodes[3].InnerText.Trim().ToUpper(); string suboffenceName = xmlNode.ChildNodes[4].InnerText.Trim().ToUpper(); int count = Convert.ToInt32(xmlNode.ChildNodes[5].InnerText); LocalGovernmentArea localGovernmentArea = localGovernmentAreas.Where(m => (m.Name.EqualsIgnoreCase(localGovernmentAreaName) == true)).FirstOrDefault(); Offence offence = null; if ((String.IsNullOrEmpty(offenceName) == false) && (offences.ContainsKey(offenceName) == true)) { offence = offences[offenceName]; } if ((String.IsNullOrEmpty(suboffenceName) == false) && (offences.ContainsKey(offenceName) == true)) { offence = offences[suboffenceName]; } // We only have crime data per year, so it will always be added in on 01/01/YYYY crimes.Add(new Crime(count, localGovernmentArea.ID, 1, offence.ID, year)); } base.OnParse(fileName, crimes); }
/// <summary> /// Checks the database for LocalGovernmentAreas records based on a specified ID value. /// </summary> /// <param name="value">The ID value for the LocalGovernmentArea record.</param> /// <returns>true if the LocalGovernmentArea exists; otherwise false.</returns> public override bool IsValid(object value) { bool isValid = false; if (value != null) { int id = 0; if (Int32.TryParse(value.ToString(), out id) == true) { LocalGovernmentArea localGovernmentArea = DataProvider.LocalGovernmentAreaRepository.GetLocalGovernmentAreaByID(id); isValid = (localGovernmentArea != null); } } return(isValid); }
public ActionResult LocalGovernmentArea(uint id) { LocalGovernmentAreaModel localGovernmentAreaModel = null; LocalGovernmentArea localGovernmentArea = DataProvider.LocalGovernmentAreaRepository.GetLocalGovernmentAreaByID((int)(id)); if (localGovernmentArea != null) { localGovernmentAreaModel = new LocalGovernmentAreaModel ( localGovernmentArea.DateCreatedUtc, localGovernmentArea.DateUpdatedUtc, localGovernmentArea.ID, localGovernmentArea.IsDeleted, localGovernmentArea.IsVisible, localGovernmentArea.Name, localGovernmentArea.StateID ); } return(View(localGovernmentAreaModel)); }
/// <summary> /// Performs parsing operations and constructs a list of Coordinate objects as the result. /// </summary> /// <param name="fileName">The path to the file containing the XML information to parse.</param> /// <param name="crimes">The list of Crime objects to serialise the XML information into.</param> protected override void OnParse(string fileName, List <Crime> crimes) { OutputStreams.WriteLine($"Parsing {QLD} data..."); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(fileName); XmlNode qldXmlNode = xmlDocument.SelectSingleNode("/Workbook/Worksheet/Table/Row[position() = 1]"); State state = DataProvider.StateRepository.GetStateByAbbreviatedName(QLD); List <LocalGovernmentArea> localGovernmentAreas = DataProvider.LocalGovernmentAreaRepository.GetLocalGovernmentAreasByStateID(state.ID); Dictionary <string, Offence> offences = new Dictionary <string, Offence>(); DataProvider.OffenceRepository.GetOffences().ForEach(m => offences.Add(m.Name.ToUpper(), m)); List <string> offenceNames = new List <string>(); qldXmlNode.ChildNodes.OfType <XmlNode>().Skip(2).ToList().ForEach(m => offenceNames.Add(m.InnerText)); XmlNodeList xmlNodeList = xmlDocument.SelectNodes("/Workbook/Worksheet/Table/Row[position() > 1]"); foreach (XmlNode xmlNode in xmlNodeList) { string localGovernmentAreaName = xmlNode.ChildNodes[0].InnerText.Trim(); string dateTimeValue = xmlNode.ChildNodes[1].InnerText.Trim(); DateTime dateTime = DateTime.MinValue; if (DateTime.TryParse(dateTimeValue, out dateTime) == false) { // Can't really use this, but should the whole thing fall over because of it? throw new Exception($"Date time parse choked: {dateTimeValue}"); } for (int i = 0, j = 2; i < offenceNames.Count; i++, j++) { string offenceName = offenceNames[i].ToUpper(); double countDouble = 0; int count = 0; // These must be some kind of averaged data - you can't have half a crime for example. if (Double.TryParse(xmlNode.ChildNodes[j].InnerText, out countDouble) == true) { count = Convert.ToInt32(countDouble); } LocalGovernmentArea localGovernmentArea = localGovernmentAreas.Where(m => (m.Name.EqualsIgnoreCase(localGovernmentAreaName) == true)).FirstOrDefault(); Offence offence = null; if ((String.IsNullOrEmpty(offenceName) == false) && (offences.ContainsKey(offenceName) == true)) { offence = offences[offenceName]; } crimes.Add(new Crime(count, localGovernmentArea.ID, dateTime.Month, offence.ID, dateTime.Year)); } } base.OnParse(fileName, crimes); }