예제 #1
0
파일: Program.cs 프로젝트: darthdeus/boxxy
        private static void Main(string[] args)
        {
            if (args.Length < 3) {
                Console.WriteLine("Usage: boxxy.exe \"Port\" \"Sync directory\" \"Destination host\"");
                return;
            }

            bool interactive = args.Length == 4 && args[3] == "i";

            if (interactive) {
                Console.WriteLine("Starting in INTERACTIVE mode, all requests are automatically PAUSED.");
            } else {
                Console.WriteLine("Starting in NON-INTERACTIVE mode, all requests are automatically FORWARDED.");
            }

            Console.WriteLine("Press ENTER to continue.");
            Console.ReadLine();

            string listeningPort = args[0];
            string syncPath = args[1];
            string destination = args[2];

            if (!Directory.Exists(syncPath)) {
                Console.WriteLine("Invalid sync directory, exiting.");
                return;
            }

            string[] files = Directory.GetFiles(syncPath, "*.json");

            var requests = new List<IncomingHttpRequest>();

            foreach (var file in files) {
                try {
                    using (var reader = new StreamReader(file)) {
                        string str = reader.ReadToEnd();

                        requests.Add(IncomingHttpRequest.FromString(str));
                        Debug.WriteLine("Deserialized request from file {0}", str);
                    }
                } catch (SecurityException e) {
                    ReadFailed(file, e);
                } catch (UnauthorizedAccessException e) {
                    ReadFailed(file, e);
                } catch (IOException e) {
                    ReadFailed(file, e);
                }
            }

            var store = new ProxyStore(syncPath, requests);
            var proxy = new HttpProxy(store, interactive);

            proxy.Start(string.Format("http://localhost:{0}/", listeningPort), destination);

            try {
                new MainScreen(store).Run();
            } catch (QuitMenu) {
                // Intentionally ignored, the exception is only used for control flow.
            }
        }
예제 #2
0
 public ListRequestsScreen(ProxyStore store)
 {
     _store = store;
 }
예제 #3
0
 public RequestDetailScreen(ProxyStore store, int index)
 {
     _store = store;
     _index = index;
 }
예제 #4
0
 public HttpProxy(ProxyStore proxyStore, bool interactive)
 {
     _proxyStore  = proxyStore;
     _interactive = interactive;
 }
예제 #5
0
 public MainScreen(ProxyStore store)
 {
     _store = store;
 }
예제 #6
0
 public HttpProxy(ProxyStore proxyStore, bool interactive) {
     _proxyStore = proxyStore;
     _interactive = interactive;
 }