static void Main(string[] args) { ServicePointManager.CertificatePolicy = new Program(); DateTime _start = DateTime.Now; if (args.Length != 1) { Console.WriteLine("Usage: this.exe free|global|disconnectall"); return; } PKUGW GatewayLogin = new PKUGW(); string result = string.Empty; string username = "******"; string password = "******"; switch (args[0].ToLower()) { case "global": result = GatewayLogin.Login(username, password, PKUGW.LoginType.fee); break; case "free": result = GatewayLogin.Login(username, password, PKUGW.LoginType.free); break; case "disconnectall": result = GatewayLogin.Login(username, password, PKUGW.LoginType.DisconnectAll); break; default: Console.WriteLine("Usage: this.exe free|global|disconnectall"); return; } if (result.IndexOf(@"<!--IPGWCLIENT_START") < 0) { Console.WriteLine("Error! Maybe wrong password or else"); } else { string info = result.Substring(result.IndexOf(@"<!--IPGWCLIENT_START") + ("<!--IPGWCLIENT_START").Length, result.IndexOf("IPGWCLIENT_END-->") - (result.IndexOf(@"<!--IPGWCLIENT_START") + ("<!--IPGWCLIENT_START").Length)); string[] infos = info.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (string str in infos) { Console.WriteLine(str); } } Console.WriteLine("Connect consume:" + (DateTime.Now - _start).TotalMilliseconds.ToString() + " ms"); }
static void Main(string[] args) { ServicePointManager.CertificatePolicy = new Program(); DateTime _start = DateTime.Now; if (args.Length > 2 || args.Length < 1) { Usage(); return; } PKUGW GatewayLogin = new PKUGW(); string result = string.Empty; string username = "******"; string password = "******"; PKUGW.LoginType lt = PKUGW.LoginType.noopen; string settings = string.Empty; bool forceLogin = false; if (args.Length == 1) { settings = args[0].ToLower(); forceLogin = false; } else if (args.Length == 2) { if (args[0].ToLower() == "force") { settings = args[1].ToLower(); forceLogin = true; } else if (args[1].ToLower() == "force") { settings = args[0].ToLower(); forceLogin = true; } else { settings = string.Empty; // indicates error } } else { throw new Exception("How can you run here? It is illogic!"); } switch (settings) { case "openall": case "global": lt = PKUGW.LoginType.fee; break; case "open": case "login": case "free": lt = PKUGW.LoginType.free; break; case "disconnectall": lt = PKUGW.LoginType.DisconnectAll; break; default: Usage(); return; } while (true) { if (forceLogin) { result = GatewayLogin.Login(username, password, PKUGW.LoginType.DisconnectAll); } else { result = GatewayLogin.Login(username, password, lt); } ParseStrings(result); Console.WriteLine("Connect consume:" + (DateTime.Now - _start).TotalMilliseconds.ToString() + " ms"); forceLogin = !forceLogin; if (forceLogin) { break; } } }