Esempio n. 1
0
        private static void StartLWAClient(string url, WebBrowserType browserType)
        {
            //make sure to launch LWA Client in case OC is installed
            //if (server_url.EndsWith("?sl=", StringComparison.CurrentCultureIgnoreCase) == false)
            //    server_url += "?sl=";

            Console.WriteLine("Start web browser...");
            WebBrowserLauncher browser = new WebBrowserLauncher(browserType);

            browser.StartWebBrowser(url);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler);

            string         startUrl      = string.Empty;
            WebBrowserType browser       = WebBrowserType.IE;
            bool           launchBrowser = false;

            foreach (String str in args)
            {
                string param = str.ToLower();
                if (param[0] == '-')
                {
                    param = "/" + param.Substring(1);
                }

                if (param.StartsWith("/map:"))
                {
                    string          mapEntry = str.Substring("/map:".Length).ToLower();
                    ReplaceMapEntry entry    = new ReplaceMapEntry();
                    int             delim    = mapEntry.IndexOf("@@");
                    if (delim >= 0)
                    {
                        string sourcePath = mapEntry.Substring(0, delim);
                        sourcePath = sourcePath.Replace("http://", "");
                        sourcePath = sourcePath.Replace("https://", "");
                        sourcePath = sourcePath.Replace("file://", "");

                        string destinationPath = mapEntry.Substring(delim + 2);

                        //check replaced files
                        Util.IsExisting(destinationPath);

                        //check is dest is file or folder
                        if (File.Exists(destinationPath))
                        {
                            //replacement is a file
                            if (!sourcePath.EndsWith(".js") &&
                                !sourcePath.EndsWith(".css") &&
                                !sourcePath.EndsWith(".png") &&
                                !sourcePath.EndsWith(".html") &&
                                !sourcePath.EndsWith(".htm"))
                            {
                                Usage();
                            }
                        }
                        else
                        {
                            //replacement is a folder
                            if (!sourcePath.EndsWith("/"))
                            {
                                sourcePath += "/";
                            }

                            if (!destinationPath.EndsWith("\\"))
                            {
                                destinationPath += "\\";
                            }
                        }

                        entry.sourcePath      = sourcePath;
                        entry.destinationPath = destinationPath;
                        replaceMap.Add(entry);
                    }
                }
                else if (param.StartsWith("/url:"))
                {
                    startUrl      = str.Substring("/url:".Length);
                    launchBrowser = true;
                }
                else if (param.StartsWith("/browser:"))
                {
                    browser       = WebBrowserLauncher.GetWebBrowserType(str.Substring("/browser:".Length));
                    launchBrowser = true;
                }
                else
                {
                    Usage();
                }
            }

            if (replaceMap.Count <= 0)
            {
                Usage();
            }

            CleanUpBrowserCache();

            try
            {
                InitializeFiddler();

                if (launchBrowser)
                {
                    StartLWAClient(startUrl, browser);
                }

                bool done = false;
                do
                {
                    Console.WriteLine("Enter a command [ctrl+c or q=quit]:");
                    Console.Write(">");

                    ConsoleKeyInfo cki = Console.ReadKey(true);
                    switch (cki.KeyChar)
                    {
                    case 'q':
                    case 'Q':
                        done = true;
                        DoQuit();
                        break;

                    default:
                        Console.WriteLine();
                        break;
                    }
                } while (!done);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());

                //in case an exception thrown, always do clear up work: close log, shutdown fiddler
                //FiddlerCore change IE proxy settings, make sure to revert it
                DoQuit();
            }
        }