public async void RunInitialize(CancellationToken token) { try { var traceFilename = String.Format("logs\\outputoutput{0}.txt", DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")); Trace.Listeners.Add(new TextWriterLogger(File.Create(traceFilename), _synco)); var textStream = new MemoryStream(); Trace.Listeners.Add(new TextWriterLogger(textStream, _synco)); var endPoint = new IPEndPoint(IPAddress.Loopback, 8080); var handler = new SimpleReverseProxyHandler(ConfigurationManager.AppSettings.Get("RemoteUrl")); var server = new SwitchboardServer(endPoint, handler); var lastStreamLength = -0L; server.Start(); //long lastPosition = -1; var previousPosition = textStream.Position; TestUrl = String.Format("Intercepting at http://{0}:{1}", endPoint.Address, endPoint.Port); while (true) { lock (_synco) { if (textStream.Position > previousPosition) { textStream.Position = 0L; var sr = new StreamReader(textStream); //new StreamReader(copyStream); var currentMemStream = sr.ReadToEnd(); if (currentMemStream.Length > lastStreamLength) { lastStreamLength = textStream.Position; Status = currentMemStream; CurrentTransferredBytes = lastStreamLength; //String.Format("{0}: {1}.{2}", currentMemStream, System.DateTime.Now.ToLongTimeString(), System.Environment.NewLine); } textStream.Position = previousPosition; } if (token.IsCancellationRequested) { server.Stop(); break; } } await Task.Delay(100); } } catch (Exception exception) { Status = String.Format("Failed to load. {0}", exception); } }
static void Main(string[] args) { // Dump all debug data to the console, coloring it if possible Trace.Listeners.Add(new ConsoleLogger()); var endPoint = new IPEndPoint(IPAddress.Loopback, 8080); var handler = new SimpleReverseProxyHandler("http://www.nytimes.com"); var server = new SwitchboardServer(endPoint, handler); server.Start(); Console.WriteLine("Point your browser at http://{0}", endPoint); Console.ReadLine(); }
private static bool StartServers() { Console.Write("Loading User Database..."); //String path = @"C:\Documents and Settings\David\My Documents\Visual Studio Projects\W3b.MsnpServer\Data\PinkEgoBox.sqlite"; //String path = @"D:\Users\David\My Documents\Visual Studio Projects\Solutions\W3b.MsnpServer\Data\PinkEgoBox.sqlite"; _dbPath = UtilityMethods.FindFile(new DirectoryInfo(Environment.CurrentDirectory), "PinkEgoBox.sqlite", 5); if (_dbPath == null) { Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Unable to locate database file"); Console.ResetColor(); return(false); } User.LoadDatabase(_dbPath); Console.WriteLine("Done"); Console.WriteLine("Starting Servers..."); _dispatchServer = DispatchServer.Instance; _dispatchServer.Start(); Console.ForegroundColor = _dispatchServer.ConsoleColor; Console.WriteLine("Dispatch Server started, listening on " + _dispatchServer.EndPoint.ToString2()); ////////////////////// _notificationServer = NotificationServer.Instance; _notificationServer.Start(); Console.ForegroundColor = _notificationServer.ConsoleColor; Console.WriteLine("Notification Server started, listening on " + _notificationServer.EndPoint.ToString2()); ////////////////////// _switchboardServer = SwitchboardServer.Instance; _switchboardServer.Start(); Console.ForegroundColor = _switchboardServer.ConsoleColor; Console.WriteLine("Switchboard Server started, listening on " + _switchboardServer.EndPoint.ToString2()); Console.ResetColor(); return(true); }
static void Main(string[] args) { var traceFilename = String.Format("outputoutput{0}.txt", DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")); Trace.Listeners.Add(new TextWriterLogger(File.Create(traceFilename), new object())); // Dump all debug data to the console, coloring it if possible Trace.Listeners.Add(new ConsoleLogger()); var endPoint = new IPEndPoint(IPAddress.Loopback, 8080); var handler = new SimpleReverseProxyHandler("http://www.road.is/travel-info/road-conditions-and-weather/the-entire-country/island1e.html"); var server = new SwitchboardServer(endPoint, handler); server.Start(); Console.WriteLine("Point your browser at http://{0}", endPoint); Console.ReadLine(); }