public static int AsInt32(this XProperty node) { int result = 0; if (node != null) { int.TryParse(node.Value, out result); } return(result); }
public static bool AsBool(this XProperty node) { bool result = false; if (node != null) { bool.TryParse(node.Value, out result); } return(result); }
private static Gateway DetermineGateway(XProperty gateway, XProperty serverUri, XProperty serverPort) { Gateway[] gateways = new Gateway[] { Gateway.Asia, Gateway.Europe, Gateway.USEast, Gateway.USWest }; if (gateway == null) { string server = serverUri.Value; int port = serverUri.AsInt32(); var realGateway = gateways.Where(g => g.ServerHost.Equals(server, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (realGateway != null) { return(realGateway); } else { return(new Gateway(server, "", "", server, port)); } } else { XElement element = gateway.AsElement; if (element.HasElements) { return(new Gateway( element.Property("Name").Value, element.Property("OldClientSuffix").Value, element.Property("Warcraft3ClientSuffix").Value, element.Property("ServerHost").Value, element.Property("ServerPort").AsInt32() )); } else { var realGateway = gateways.Where(g => g.Name.Equals(gateway.Value, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (realGateway != null) { return(realGateway); } return(new Gateway(gateway.Value, "", "", gateway.Value, 6112)); } } }
private static Gateway DetermineGateway(XProperty gateway, XProperty serverUri, XProperty serverPort) { Gateway[] gateways = new Gateway[] { Gateway.Asia, Gateway.Europe, Gateway.USEast, Gateway.USWest }; if (gateway == null) { string server = serverUri.Value; int port = serverUri.AsInt32(); var realGateway = gateways.Where(g => g.ServerHost.Equals(server, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (realGateway != null) { return realGateway; } else { return new Gateway(server, "", "", server, port); } } else { XElement element = gateway.AsElement; if (element.HasElements) { return new Gateway( element.Property("Name").Value, element.Property("OldClientSuffix").Value, element.Property("Warcraft3ClientSuffix").Value, element.Property("ServerHost").Value, element.Property("ServerPort").AsInt32() ); } else { var realGateway = gateways.Where(g => g.Name.Equals(gateway.Value, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (realGateway != null) return realGateway; return new Gateway(gateway.Value, "", "", gateway.Value, 6112); } } }