Exemple #1
0
        private static void StopServers()
        {
            Console.WriteLine("Stopping servers...");

            _dispatchServer.Stop();
            _notificationServer.Stop();
            _switchboardServer.Stop();

            Console.WriteLine("Save database? Y / D %filename% / N");
            String line = Console.ReadLine();

            if (line.ToUpperInvariant() == "Y")
            {
                Console.WriteLine("Saving Database...");

                User.SaveDatabase(_dbPath);
            }
            else if (line.StartsWith("D", StringComparison.OrdinalIgnoreCase))
            {
                String path = Path.Combine(Path.GetDirectoryName(_dbPath), line.Substring(2).Trim());

                Console.WriteLine("Saving Database to \"{0}\"...", path);

                User.SaveDatabase(path);
            }
            else
            {
                Console.WriteLine("Not saving changes");
            }

            Console.WriteLine("Terminating");
        }
        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);
            }
        }