/// <summary> /// This method is used to verify the attributes of the xml file’s root element. /// </summary> /// <returns>If any of the validation described fails, return a value of false </returns> private bool processHeader() { //Define an XDocument object and populate this object with the contents of the current file (fileName) xDocDetails = XDocument.Load(fileName); //Define an XElement object and populate this object with the data found within the transfer element of the xml file XElement xeleElement = xDocDetails.Element("transfer"); try { //The XElement object must have 4 attributes if (xeleElement.Attributes().Count() != 4) { var ex = new Exception("The XElement object must have 4 attributes"); throw ex; } //Attribute XAttribute dateAttribute = xeleElement.Attribute("date"); //The date attribute of the XElement object must be equal to today’s date if (!dateAttribute.Value.Equals(System.DateTime.Today.ToString("yyyy-MM-dd"))) { var ex = new Exception("The date attribute of the XElement object must be equal to today’s date"); throw ex; } XAttribute toAttribute = xeleElement.Attribute("to"); //The to attribute must match the Bank of BIT institution number if (!toAttribute.Value.Equals(BusinessRules.BankNumber().ToString())) { var ex = new Exception("The to attribute must match the Bank of BIT institution number "); throw ex; } XAttribute fromAttribute = xeleElement.Attribute("from"); int ifromAttribute = 0; if (fromAttribute != null) { ifromAttribute = int.Parse(fromAttribute.Value); } //retrive data form institution table List <int> institutionNumbers = db.Institutions.Where(d => d.InstitutionNumber == ifromAttribute).Select(d => d.InstitutionNumber).ToList(); //The from attribute must match one of the institution number values within the Institution Entity class if (institutionNumbers.Count == 0) { var ex = new Exception("The from attribute must match one of the institution number values within the Institution Entity class"); throw ex; } XAttribute checksumAttribute = xeleElement.Attribute("checksum"); int iChecksum = 0; IEnumerable <XElement> accountNoElements = xDocDetails.Descendants().Where(d => d.Name == "account_no"); foreach (XElement xele in accountNoElements) { iChecksum += int.Parse(xele.Value); } //The checksum attribute must match the sum of all account_no elements in the file if (int.Parse(checksumAttribute.Value) != iChecksum) { var ex = new Exception("The checksum attribute must match the sum of all account_no elements in the file "); throw ex; } return(true); } catch (Exception ex) { logData += "\nError occor cause: " + ex.Message; return(false); } }