public void Configuration(IAppBuilder appBuilder) { HttpConfiguration config = new HttpConfiguration(); WebApiConfig.Register(config); IdleTimeoutHandler.Register(config); appBuilder.UseWebApi(config); appBuilder.UseErrorPage(); appBuilder.UseWelcomePage("/"); }
// Starts the Bridge locally if it is not already running. private static void StartBridge(CommandLineArguments commandLineArgs) { string errorMessage = null; Dictionary <string, string> properties; if (PingBridge(commandLineArgs.BridgeConfiguration.BridgeHost, commandLineArgs.BridgeConfiguration.BridgePort, out errorMessage, out properties)) { Console.WriteLine("The Bridge is already running."); Environment.Exit(Bridge_ExitCode_Success); } // 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(Bridge_ExitCode_Failure); } 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(Bridge_ExitCode_Failure); } resourceFolder = Path.GetFullPath(resourceFolder); if (!Directory.Exists(resourceFolder)) { Console.WriteLine("The specified BridgeResourceFolder '{0}' does not exist."); Environment.Exit(Bridge_ExitCode_Failure); } 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, out properties)) { 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(); } // Key presses to the Bridge restart the idle timeout IdleTimeoutHandler.RestartTimer(); } BridgeController.StopBridgeProcess(0); }