private DataExtracted Save(string xml_name, string value, DataExtracted current) { if (xml_name == Constants.TOTAL) { current.total = value; } if (xml_name == Constants.COST_CENTRE) { current.cost_centre = value; } if (xml_name == Constants.PAYMENT_METHOD) { current.payment_method = value; } if (xml_name == Constants.VENDOR) { current.vendor = value; } if (xml_name == Constants.DESCRIPTION) { current.description = value; } if (xml_name == Constants.DATE) { current.date = value; } return(current); }
private SummaryOutput Validate(IList <XMLElement> list) { SummaryOutput output = new SummaryOutput(); DataExtracted data = new DataExtracted(); IList <string> messages = new List <string>(); foreach (XMLElement xml in list) { if (xml.Name == Constants.TOTAL && xml.Value == Constants.UNKNOWN) { output.results = Constants.FAILED; messages.Add("The whole data import is rejected because of a missing <" + xml.Name + "> element."); break; } else if (xml.Value == Constants.OPENING_TAG_NOT_FOUND) { output.results = Constants.FAILED; messages.Add("The whole data import is rejected because a closing tag </" + xml.Name + "> has no corresponding opening tag."); break; } else if (xml.Value == Constants.CLOSING_TAG_NOT_FOUND) { output.results = Constants.FAILED; messages.Add("The whole data import is rejected because an opening tag <" + xml.Name + "> has no corresponding closing tag."); break; } else if (xml.Name == Constants.COST_CENTRE && xml.Value == Constants.UNKNOWN) { messages.Add("The whole data import is succesful eventhough <" + xml.Name + "> is missing. the value is set to unknown."); } if (string.IsNullOrEmpty(output.results)) { data = Save(xml.Name, (xml.Value == Constants.UNKNOWN && xml.Name != Constants.COST_CENTRE) ? null : xml.Value, data); } } if (output.results == Constants.FAILED) { if (messages.Count == 0) { messages.Add("The whole data import is rejected."); } } else { output.data = new DataOutput { extracted = data, calculated = Calculate(data.total) }; if (string.IsNullOrEmpty(output.results)) { output.results = Constants.SUCCESS; } if (messages.Count == 0) { messages.Add("The whole data import is succesful."); } } output.message = messages; return(output); }