示例#1
0
    static public void Main(string[] args)
    {
        if (args.Length < 2 || (args.Length == 1 && (args[0] == "?" || args[0] == "/?" || args[0] == "-?" || args[0].ToLower() == "help")))
        {
            Console.WriteLine(usage);
        }
        else
        {
            try
            {
                string user = null, pw = null;
                if (args.Length > 2 && args[2].StartsWith("/p"))
                {
                    string[] credentials = args[2].Split(":".ToCharArray(), 3);
                    if (credentials.Length > 1)
                    {
                        user = credentials[1];
                    }
                    if (credentials.Length > 2)
                    {
                        pw = credentials[2];
                    }

                    if (user == null || pw == null)
                    {
                        if (!AuthenticationForm.GetCredentials(ref user, ref pw, "Proxy Authentication"))
                        {
                            return;
                        }
                    }
                }

                string htmlStr = GetHTML(args[0], user, pw);

                using (StreamWriter sw = new StreamWriter(args[1]))
                {
                    StringReader strReader = new StringReader(htmlStr);
                    string       line;
                    while ((line = strReader.ReadLine()) != null)
                    {
                        //this works better that sw.Write(htmlStr) because of nicer text layout
                        sw.WriteLine(line);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
    }
示例#2
0
    static public void Main(string[] args)
    {
        if (args.Length < 1 || (args.Length == 1 && (args[0] == "?" || args[0] == "/?" || args[0] == "-?" || args[0].ToLower() == "help")))
        {
            Console.WriteLine(usage);
        }
        else
        {
            try
            {
                string user = null, pw = null;
                string userPxy = null, pwPxy = null;

                //prepare http credentials
                string[] credentials = args[0].Split(":".ToCharArray(), 2);
                user = credentials[0];

                if (credentials.Length > 1)
                {
                    pw = credentials[1];
                }

                if (pw == null)
                {
                    if (!AuthenticationForm.GetCredentials(ref user, ref pw, "Account login"))
                    {
                        return;
                    }
                }
                //prepare proxy credentials
                if (args.Length > 1 && args[1].StartsWith("/p"))
                {
                    string[] credentialsPxy = args[1].Split(":".ToCharArray(), 3);
                    if (credentialsPxy.Length > 1)
                    {
                        userPxy = credentialsPxy[1];
                    }
                    if (credentialsPxy.Length > 2)
                    {
                        pwPxy = credentialsPxy[2];
                    }

                    if (userPxy == null || pwPxy == null)
                    {
                        if (!AuthenticationForm.GetCredentials(ref userPxy, ref pwPxy, "Proxy Authentication"))
                        {
                            return;
                        }
                    }
                }

                string htmlStr = GetHTML(String.Format(urlTemplate, user, pw), userPxy, pwPxy);

                string msg   = "";
                string title = "";
                using (StringReader strReader = new StringReader(htmlStr))
                {
                    string line;
                    while ((line = strReader.ReadLine()) != null)
                    {
                        if (line.StartsWith("plan_limit"))
                        {
                            msg += "Limit: " + line.Split("=".ToCharArray(), 2)[1] + "\n";
                        }
                        if (line.StartsWith("usage"))
                        {
                            msg += "Usage: " + line.Split("=".ToCharArray(), 2)[1] + "\n";
                        }
                        if (line.StartsWith("username"))
                        {
                            msg += "User: "******"=".ToCharArray(), 2)[1] + "\n";
                        }
                        if (line.StartsWith("plan_name"))
                        {
                            title = line.Split("=".ToCharArray(), 2)[1] + " Plan";
                        }
                    }
                }

                MessageBox.Show(msg, title);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
    }