/*loads a special contract*/ public static void LoadSpecialContract(string file) { var doc = new XmlDocument(); doc.Load(file); XmlElement root = doc.DocumentElement; XmlNodeList contractsList = root?.SelectNodes("//contract"); if (contractsList != null) foreach (XmlElement element in contractsList) { string name = element.Attributes["name"].Value; string text = element.Attributes["text"].Value; var infoElement = (XmlElement) element.SelectSingleNode("information"); if (infoElement != null) { long payment = Convert.ToInt64(infoElement.Attributes["payment"].Value); bool asbonus = Convert.ToBoolean(infoElement.Attributes["bonus"].Value); long penalty = Convert.ToInt64(infoElement.Attributes["penalty"].Value); bool isfixeddate = !infoElement.HasAttribute("frequency"); var scType = new SpecialContractType(name, text, payment, asbonus, penalty, isfixeddate); if (isfixeddate) { DateTime fromdate = Convert.ToDateTime( infoElement.Attributes["from"].Value, new CultureInfo("en-US", false)); DateTime todate = Convert.ToDateTime( infoElement.Attributes["to"].Value, new CultureInfo("en-US", false)); scType.Period = new Period<DateTime>(fromdate, todate); } else { int frequency = Convert.ToInt32(infoElement.Attributes["frequency"].Value); scType.Frequency = frequency; } XmlNodeList routesList = element.SelectNodes("routes/route"); if (routesList != null) foreach (XmlElement routeElement in routesList) { // public SpecialContractRoute(Airport destination1, Airport destination2, long passengers,Boolean bothways) Airport departure = Airports.GetAirport(routeElement.Attributes["departure"].Value); Airport destination = Airports.GetAirport(routeElement.Attributes["destination"].Value); bool bothways = Convert.ToBoolean(routeElement.Attributes["bothways"].Value); long passengers = Convert.ToInt64(routeElement.Attributes["passengers"].Value); var routetype = Route.RouteType.Passenger; if (routeElement.HasAttribute("type")) routetype = (Route.RouteType) Enum.Parse(typeof (Route.RouteType), routeElement.Attributes["type"].Value); var scRoute = new SpecialContractRoute(departure, destination, passengers, routetype, bothways); scType.Routes.Add(scRoute); } XmlNodeList parametersList = element.SelectNodes("parameters/parameter"); if (parametersList != null) foreach (XmlElement parameterElement in parametersList) { if (parameterElement.HasAttribute("departure")) { var parameter = new ContractRequirement(ContractRequirement.RequirementType.Destination); Airport departure = Airports.GetAirport(parameterElement.Attributes["departure"].Value); parameter.Departure = departure; string destinationText = parameterElement.Attributes["destination"].Value; if (destinationText == "any") { foreach (SpecialContractRoute scroute in scType.Routes.Where(r => r.Departure == departure)) { var tparameter = new ContractRequirement(ContractRequirement.RequirementType.Destination) {Departure = departure, Destination = scroute.Destination}; scType.Requirements.Add(tparameter); } } else { parameter.Destination = Airports.GetAirport(destinationText); scType.Requirements.Add(parameter); } } else { var parameter = new ContractRequirement(ContractRequirement.RequirementType.ClassType); var type = (AirlinerClass.ClassType) Enum.Parse(typeof (AirlinerClass.ClassType), parameterElement.Attributes["classtype"].Value); int seats = Convert.ToInt32(parameterElement.Attributes["minseats"].Value); parameter.ClassType = type; parameter.MinSeats = seats; scType.Requirements.Add(parameter); } } SpecialContractTypes.AddType(scType); } } }
public RequirementMVVM(ContractRequirement.RequirementType type, string text, string requirement) { this.Text = text; this.Requirement = requirement; this.Type = type; }