Пример #1
0
        static void Main(string[] args)
        {
            bool help = false;
            bool screens = false;
            string user = null, pass = null;
            string chatUrl = null, scriptUrl = null;
            string sessionPath = null;
            // http://geekswithblogs.net/robz/archive/2009/11/22/command-line-parsing-with-mono.options.aspx
            OptionSet options = new OptionSet()
                .Add("?|h|help", "Print this message", option => help = option != null)
                .Add("u=|user=|username="******"Required: StackExchange username or email", option => user = option)
                .Add("p=|pass=|password="******"Required: StackExchange password", option => pass = option)
                .Add("c=|chat-url=", "Required: Chatroom URL", option => chatUrl = option)
                .Add("b=|bot-script=|script-url=", "Required: The URL of a bot script", option => scriptUrl = option)
                .Add("s|screens|screenshot", "Display screenshots at checkpoints", option => screens = option != null)
                .Add("session-path=", "Path to browser session (profile), where settings are saved", option => sessionPath = option);

            #if DEBUG
            string[] lines = File.ReadAllLines("account.txt");
            user = lines[0];
            pass = lines[1];
            chatUrl = "http://chat.stackexchange.com/rooms/118/root-access";
            scriptUrl = "https://raw.github.com/allquixotic/SO-ChatBot/master/master.js";
            screens = true;
            sessionPath = "session";
            #else
            try
            {
                options.Parse(args);
            }
            catch (OptionException)
            {
                ShowHelp(options, "Error - usage is:");
            }

            if (help)
            {
                ShowHelp(options, "Usage:");
            }

            if (user == null)
            {
                ShowHelp(options, "Error: A username is required");
            }

            if (pass == null)
            {
                ShowHelp(options, "Error: A password is required");
            }

            if (chatUrl == null)
            {
                ShowHelp(options, "Error: A chat URL is required");
            }

            if (scriptUrl == null)
            {
                ShowHelp(options, "Error: A bot script is required");
            }

            if (sessionPath == null)
            {
                sessionPath = "session";
            }
            #endif

            try
            {
                WebConfig config = new WebConfig();
                WebCore.Initialize(config);

                WebPreferences prefs = new WebPreferences();
                prefs.LoadImagesAutomatically = true;
                prefs.RemoteFonts = false;
                prefs.WebAudio = false;
                prefs.Dart = false;
                prefs.CanScriptsCloseWindows = false;
                prefs.CanScriptsOpenWindows = false;
                prefs.WebSecurity = false;
                prefs.Javascript = true;
                prefs.LocalStorage = true;
                prefs.Databases = false;            // ?

                aweSession = WebCore.CreateWebSession(sessionPath, prefs);
                aweSession.ClearCookies();
                aweView = WebCore.CreateWebView(1024, 768, aweSession);
                aweView.ResponsiveChanged += aweView_ResponsiveChanged;
                aweView.Crashed += aweView_Crashed;
                aweView.ConsoleMessage += aweView_ConsoleMessage;
                eView.WebView = aweView;
                eView.AutoScreenshot = true;
                eView.ScreenshotsEnabled = screens;

                go(user, pass, scriptUrl, chatUrl);
            }
            finally
            {
                if (aweView != null && aweView.IsResponsive)
                    aweView.Dispose();
                WebCore.Shutdown();
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            bool   help = false;
            bool   screens = false;
            string user = null, pass = null;
            string chatUrl = null, scriptUrl = null;
            string sessionPath = null;
            // http://geekswithblogs.net/robz/archive/2009/11/22/command-line-parsing-with-mono.options.aspx
            OptionSet options = new OptionSet()
                                .Add("?|h|help", "Print this message", option => help = option != null)
                                .Add("u=|user=|username="******"Required: StackExchange username or email", option => user = option)
                                .Add("p=|pass=|password="******"Required: StackExchange password", option => pass          = option)
                                .Add("c=|chat-url=", "Required: Chatroom URL", option => chatUrl = option)
                                .Add("b=|bot-script=|script-url=", "Required: The URL of a bot script", option => scriptUrl = option)
                                .Add("s|screens|screenshot", "Display screenshots at checkpoints", option => screens        = option != null)
                                .Add("session-path=", "Path to browser session (profile), where settings are saved", option => sessionPath = option);

#if DEBUG
            string[] lines = File.ReadAllLines("account.txt");
            user        = lines[0];
            pass        = lines[1];
            chatUrl     = "http://chat.stackexchange.com/rooms/118/root-access";
            scriptUrl   = "https://raw.github.com/allquixotic/SO-ChatBot/master/master.js";
            screens     = true;
            sessionPath = "session";
#else
            try
            {
                options.Parse(args);
            }
            catch (OptionException)
            {
                ShowHelp(options, "Error - usage is:");
            }

            if (help)
            {
                ShowHelp(options, "Usage:");
            }

            if (user == null)
            {
                ShowHelp(options, "Error: A username is required");
            }

            if (pass == null)
            {
                ShowHelp(options, "Error: A password is required");
            }

            if (chatUrl == null)
            {
                ShowHelp(options, "Error: A chat URL is required");
            }

            if (scriptUrl == null)
            {
                ShowHelp(options, "Error: A bot script is required");
            }

            if (sessionPath == null)
            {
                sessionPath = "session";
            }
#endif

            try
            {
                WebConfig config = new WebConfig();
                WebCore.Initialize(config);

                WebPreferences prefs = new WebPreferences();
                prefs.LoadImagesAutomatically = true;
                prefs.RemoteFonts             = false;
                prefs.WebAudio = false;
                prefs.Dart     = false;
                prefs.CanScriptsCloseWindows = false;
                prefs.CanScriptsOpenWindows  = false;
                prefs.WebSecurity            = false;
                prefs.Javascript             = true;
                prefs.LocalStorage           = true;
                prefs.Databases = false;            // ?

                aweSession = WebCore.CreateWebSession(sessionPath, prefs);
                aweSession.ClearCookies();
                aweView = WebCore.CreateWebView(1024, 768, aweSession);
                aweView.ResponsiveChanged += aweView_ResponsiveChanged;
                aweView.Crashed           += aweView_Crashed;
                aweView.ConsoleMessage    += aweView_ConsoleMessage;
                eView.WebView              = aweView;
                eView.AutoScreenshot       = true;
                eView.ScreenshotsEnabled   = screens;

                go(user, pass, scriptUrl, chatUrl);
            }
            finally
            {
                if (aweView != null && aweView.IsResponsive)
                {
                    aweView.Dispose();
                }
                WebCore.Shutdown();
            }
        }