Beispiel #1
0
        private static void Main(string[] args)
        {
            CommandLineArguments commandLineArgs = new CommandLineArguments(args);

            string hostFormatString = "http://{0}:{1}";
            string owinAddress      = String.Format(hostFormatString, commandLineArgs.AllowRemote ? "+" : "localhost", commandLineArgs.Port);
            string visibleHost      = (commandLineArgs.AllowRemote) ? Environment.MachineName : "localhost";
            string visibleAddress   = String.Format(hostFormatString, visibleHost, commandLineArgs.Port);

            PortManager.OpenPortInFirewall(commandLineArgs.Port);

            OwinSelfhostStartup.Startup(owinAddress);

            Console.WriteLine("The Bridge is listening at {0} with remote access {1}", visibleAddress, commandLineArgs.AllowRemote ? "enabled" : "disabled");

            Test(visibleHost, commandLineArgs.Port);

            while (true)
            {
                Console.WriteLine("Type \"exit\" to stop the Bridge.");
                string answer = Console.ReadLine();
                if (String.Equals(answer, "exit", StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }
            }

            Environment.Exit(0);
        }
Beispiel #2
0
        private static void Main(string[] args)
        {
            CommandLineArguments commandLineArgs = new CommandLineArguments(args);

            string hostFormatString = "http://{0}:{1}";
            string owinAddress      = String.Format(hostFormatString, commandLineArgs.AllowRemote ? "+" : "localhost", commandLineArgs.Port);
            string visibleHost      = (commandLineArgs.AllowRemote) ? Environment.MachineName : "localhost";
            string visibleAddress   = String.Format(hostFormatString, visibleHost, commandLineArgs.Port);

            // Configure the remote addresses the firewall rules will accept.
            // If remote access is not allowed, specifically disallow remote addresses
            PortManager.RemoteAddresses = commandLineArgs.AllowRemote ? commandLineArgs.RemoteAddresses : String.Empty;

            // Initialize the BridgeConfiguration from command line.
            // The first POST to the ConfigController will supply the rest.
            ConfigController.BridgeConfiguration.BridgeHost = visibleHost;
            ConfigController.BridgeConfiguration.BridgePort = commandLineArgs.Port;

            // Remove any pre-existing firewall rules the Bridge may have added
            // in past runs.  We normally cleanup on exit but could have been
            // aborted.
            PortManager.RemoveAllBridgeFirewallRules();

            // Open the port used to communicate with the Bridge itself
            PortManager.OpenPortInFirewall(commandLineArgs.Port);

            Console.WriteLine("Starting the Bridge at {0}", visibleAddress);
            OwinSelfhostStartup.Startup(owinAddress);

            Test(visibleHost, commandLineArgs.Port);

            while (true)
            {
                Console.WriteLine("The Bridge is listening at {0}", visibleAddress);
                if (commandLineArgs.AllowRemote)
                {
                    Console.WriteLine("Remote access is allowed from '{0}'", commandLineArgs.RemoteAddresses);
                }
                else
                {
                    Console.WriteLine("Remote access is disabled.");
                }

                Console.WriteLine("Current configuration is:{0}{1}", Environment.NewLine, ConfigController.BridgeConfiguration.ToString());

                Console.WriteLine("Type \"exit\" to stop the Bridge.");
                string answer = Console.ReadLine();
                if (String.Equals(answer, "exit", StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }
            }

            Environment.Exit(0);
        }
Beispiel #3
0
        // Starts the Bridge locally if it is not already running.
        private static void StartBridge(CommandLineArguments commandLineArgs)
        {
            string errorMessage = null;

            if (PingBridge(commandLineArgs.BridgeConfiguration.BridgeHost,
                           commandLineArgs.BridgeConfiguration.BridgePort,
                           out errorMessage))
            {
                Console.WriteLine("The Bridge is already running.");
                Environment.Exit(0);
            }

            // The host is not local so we cannot start the Bridge
            if (!IsBridgeHostLocal(commandLineArgs.BridgeConfiguration))
            {
                Console.WriteLine("The Bridge cannot be started from this machine on {0}",
                                  commandLineArgs.BridgeConfiguration.BridgeHost);
                Environment.Exit(1);
            }

            string resourceFolder = commandLineArgs.BridgeConfiguration.BridgeResourceFolder;

            if (String.IsNullOrWhiteSpace(resourceFolder))
            {
                Console.WriteLine("Starting the Bridge requires the BridgeResourceFolder to be specified.");
                Console.WriteLine("Use either -BridgeResourceFolder:folderName or set it as an environment variable.");
                Environment.Exit(1);
            }

            resourceFolder = Path.GetFullPath(resourceFolder);
            if (!Directory.Exists(resourceFolder))
            {
                Console.WriteLine("The specified BridgeResourceFolder '{0}' does not exist.");
                Environment.Exit(1);
            }
            commandLineArgs.BridgeConfiguration.BridgeResourceFolder = resourceFolder;

            int port = commandLineArgs.BridgeConfiguration.BridgePort;

            string hostFormatString = "http://{0}:{1}";
            string owinAddress      = String.Format(hostFormatString, commandLineArgs.AllowRemote ? "+" : "localhost", port);
            string visibleHost      = (commandLineArgs.AllowRemote) ? Environment.MachineName : "localhost";
            string visibleAddress   = String.Format(hostFormatString, visibleHost, port);

            // Configure the remote addresses the firewall rules will accept.
            // If remote access is not allowed, specifically disallow remote addresses
            PortManager.RemoteAddresses = commandLineArgs.AllowRemote ? commandLineArgs.RemoteAddresses : String.Empty;

            // Initialize the BridgeConfiguration from command line.
            ConfigController.BridgeConfiguration            = commandLineArgs.BridgeConfiguration;
            ConfigController.BridgeConfiguration.BridgeHost = visibleHost;

            // Remove any pre-existing firewall rules or certificates the Bridge
            // may have added in past runs.  We normally clean them up on exit but
            // it is possible a prior Bridge process was terminated prematurely.
            BridgeController.ReleaseAllResources(force: false);

            Console.WriteLine("Starting the Bridge at {0}", visibleAddress);
            OwinSelfhostStartup.Startup(owinAddress);

            // Now test whether the Bridge is running.  Failure cleans up
            // all resources and terminates the process.
            if (!PingBridge(visibleHost, port, out errorMessage))
            {
                Console.WriteLine("The Bridge failed to start or is not responding: {0}", errorMessage);
                BridgeController.StopBridgeProcess(1);
            }

            while (true)
            {
                Console.WriteLine();
                Console.WriteLine("The Bridge is running");
                Console.WriteLine("    Listening at {0}/{1}",
                                  visibleAddress, BridgeControllerEndpoint);

                if (commandLineArgs.AllowRemote)
                {
                    Console.WriteLine("    Remote access is allowed from '{0}'", commandLineArgs.RemoteAddresses);
                }
                else
                {
                    Console.WriteLine("    Remote access is disabled.");
                }

                Console.WriteLine("    Commands:");
                Console.WriteLine("    \"cls\" to clear the screen");
                Console.WriteLine("    \"exit\" to stop the Bridge");
                Console.WriteLine();
                Console.Write("Bridge> ");

                string answer = Console.ReadLine();
                if (string.Equals(answer, "exit", StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }
                else if (string.Equals(answer, "cls", StringComparison.OrdinalIgnoreCase))
                {
                    Console.Clear();
                }
            }

            BridgeController.StopBridgeProcess(0);
        }
Beispiel #4
0
        // Starts the Bridge locally if it is not already running.
        private static void StartBridge(CommandLineArguments commandLineArgs)
        {
            string errorMessage = null;

            if (PingBridge(commandLineArgs.BridgeConfiguration.BridgeHost,
                           commandLineArgs.BridgeConfiguration.BridgePort,
                           out errorMessage))
            {
                Console.WriteLine("The Bridge is already running.");
                Environment.Exit(0);
            }

            // The host is not local so we cannot start the Bridge
            if (!IsBridgeHostLocal(commandLineArgs.BridgeConfiguration))
            {
                Console.WriteLine("The Bridge cannot be started from this machine on {0}",
                                  commandLineArgs.BridgeConfiguration.BridgeHost);
                Environment.Exit(1);
            }

            int port = commandLineArgs.BridgeConfiguration.BridgePort;

            string hostFormatString = "http://{0}:{1}";
            string owinAddress      = String.Format(hostFormatString, commandLineArgs.AllowRemote ? "+" : "localhost", port);
            string visibleHost      = (commandLineArgs.AllowRemote) ? Environment.MachineName : "localhost";
            string visibleAddress   = String.Format(hostFormatString, visibleHost, port);

            // Configure the remote addresses the firewall rules will accept.
            // If remote access is not allowed, specifically disallow remote addresses
            PortManager.RemoteAddresses = commandLineArgs.AllowRemote ? commandLineArgs.RemoteAddresses : String.Empty;

            // Initialize the BridgeConfiguration from command line.
            // The first POST to the ConfigController will supply the rest.
            ConfigController.BridgeConfiguration            = commandLineArgs.BridgeConfiguration;
            ConfigController.BridgeConfiguration.BridgeHost = visibleHost;

            // Remove any pre-existing firewall rules or certificates the Bridge
            // may have added in past runs.  We normally clean them up on exit but
            // it is possible a prior Bridge process was terminated prematurely.
            BridgeController.ReleaseAllResources();

            // Open the port used to communicate with the Bridge itself
            PortManager.OpenPortInFirewall(port);

            Console.WriteLine("Starting the Bridge at {0}", visibleAddress);
            OwinSelfhostStartup.Startup(owinAddress);

            // Now test whether the Bridge is running.  Failure cleans up
            // all resources and terminates the process.
            if (!PingBridge(visibleHost, port, out errorMessage))
            {
                Console.WriteLine("The Bridge failed to start or is not responding: {0}", errorMessage);
                BridgeController.StopBridgeProcess(1);
            }

            while (true)
            {
                Console.WriteLine("The Bridge is running and listening at {0}", visibleAddress);
                if (commandLineArgs.AllowRemote)
                {
                    Console.WriteLine("Remote access is allowed from '{0}'", commandLineArgs.RemoteAddresses);
                }
                else
                {
                    Console.WriteLine("Remote access is disabled.");
                }

                Console.WriteLine("Type \"exit\" to stop the Bridge.");
                string answer = Console.ReadLine();
                if (String.Equals(answer, "exit", StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }
            }

            BridgeController.StopBridgeProcess(0);
        }