public AppSettings() { uiSettings = new UISettings(); httpServerSettings = new HttpServerSettings(); NFSWorldExecutables = new ObservableCollection <String>(); System.Windows.Data.BindingOperations.EnableCollectionSynchronization(NFSWorldExecutables, threadSafeDummy); }
private static void Main(string[] args) { var options = (from arg in args where arg.StartsWith("--") let pair = arg.Substring(2).Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries) where pair.Length == 2 let key = pair[0].Trim() let val = pair[1].Trim() select new KeyValuePair <string, string>(key, val)) .ToDictionary(x => x.Key, x => x.Value, StringComparer.InvariantCultureIgnoreCase); var app = new ExpressApplication(); Func <double, double> square = x => x * x; app.Get("", req => req.Text("Hi!")) .Get( "text/{x}/{y}", req => req.Text( string.Format("x={0}, y={1}", req.RouteData.Values["x"], req.RouteData.Values["y"])) ) .Get( "json/{x}/{y}", req => req.Json( new { x = req.RouteData.Values["x"], y = req.RouteData.Values["y"] }) ) .Get("math/square/{x}", square) .WebService <MathService>("math.svc"); var port = options.Get("port", 1111); var mode = options.Get("mode", "tcp"); var settings = new HttpServerSettings { Port = port }; switch (mode.ToLowerInvariant()) { case "http": settings.Mode = HttpServerMode.HttpListener; break; default: settings.Mode = HttpServerMode.TcpListener; break; } using (new HttpServer(app, settings)) { Console.WriteLine("Listening port {0}. Press enter to stop the server.", port); Console.ReadLine(); } }
public AssemblyOperationFactory(Logger logger, HttpServerSettings settings, IAuthenticationManager authManager) { this.logger = logger; this.settings = settings; this.authManager = authManager; this.operations = new SortedSet <Tuple <int, Operation> >(new OperationPriorityComparer()); }
public HttpServerTests(HttpServerMode mode) { _settings = new HttpServerSettings {Port = 1111, Mode = mode}; _createClient = () => new WebClient { BaseAddress = string.Format("http://localhost:{0}", _settings.Port), Encoding = Encoding.UTF8 }; }
public bool ApplySettings(HttpServerSettings settings) { this.logger?.Log(EventType.ServerSetup, "Attempting to update server settings."); if (settings == null) { this.logger?.Log(EventType.ServerSetup, "Provided settings are null, skip update."); return(false); } bool startStopServer = this.IsRunning; this.settings = settings; if (startStopServer) { this.logger?.Log(EventType.ServerSetup, "HttpServer is running, attempting to stop the gateway for the settings update."); if (!this.Stop()) { this.logger?.Log(EventType.ServerSetup, "HttpServer is still running, applying settings failed."); return(false); } } try { // call update method of child this.ApplySettingsInternal(settings); this.correctConfigured = true; } catch (Exception ex) { this.logger?.Log(EventType.SystemError, ex.ToString()); this.logger?.Log(EventType.SystemError, "Error occured while applying settings, please check logs for more information."); this.correctConfigured = false; } if (this.correctConfigured && startStopServer) { this.logger?.Log(EventType.ServerSetup, "HttpServer was running before, attempting to start the gateway after the settings update."); if (!this.Start()) { this.logger?.Log(EventType.ServerSetup, "Unable sto start server, applying settings failed."); return(false); } } else { this.logger?.Log(EventType.ServerSetup, "HttpServer is in stopped state."); } return(true); }
public HttpServerTests(HttpServerMode mode) { _settings = new HttpServerSettings { Port = 1111, Mode = mode }; _createClient = () => new WebClient { BaseAddress = string.Format("http://localhost:{0}", _settings.Port), Encoding = Encoding.UTF8 }; }
private void ApplyLimits(HttpServerSettings settings) { /* IdleTimeout */ this.listener.TimeoutManager.IdleConnection = new TimeSpan(0, 0, 0, 0, settings.Core.IdleTimeout); this.logger?.Log(EventType.ServerSetup, "Set idle timeout to {0}s.", settings.Core.IdleTimeout); /* ConnectionLimit */ /* (server got stopped before settings update, save to reinitialize the semaphore.) */ this.semaphore = new Semaphore(settings.Core.ConnectionLimit, settings.Core.ConnectionLimit); this.logger?.Log(EventType.ServerSetup, "Set ConnectionLimit to '{0}'.", settings.Core.ConnectionLimit); }
public AuthenticationManager(HttpServerSettings settings) { this.users = new ConcurrentBag <User>(); this.userIdMapping = new ConcurrentDictionary <string, User>(StringComparer.InvariantCultureIgnoreCase); this.accessTokenMapping = new ConcurrentDictionary <string, User>(StringComparer.InvariantCultureIgnoreCase); this.sessionValidityInMinutes = settings.Authentication.SessionDuration; this.SessionRefreshAllowed = settings.Authentication.SessionRefresh; if (settings.Authentication.Users != null) { foreach (User user in settings.Authentication.Users) { this.AddUser(user.Id); } } }
private void ApplyEndpoints(HttpServerSettings settings) { this.logger?.Log(EventType.ServerSetup, "Set endpoints passed in settings."); this.listener.Prefixes.Clear(); foreach (Core.Settings.EndPoint ep in settings.Core.EndPoints) { this.logger?.Log(EventType.ServerSetup, "Try to add endpoint '{0}'.", JsonConvert.SerializeObject(ep, Formatting.Indented)); if (Uri.CheckHostName(ep.HostName) == UriHostNameType.Dns || HttpClientServer.AlternateHostNames.Contains(ep.HostName)) { if (ep.Protocol == Protocol.HTTPS) { string bindingHost = HttpClientServer.AlternateHostNames.Contains(ep.HostName) ? this.sslBindingHelper.DefaultEndpointHost : ep.HostName; if (!this.sslBindingHelper.TryAddOrUpdateCertBinding(ep.CertificateThumbPrint, HttpClientServer.GetApplicationId(), ep.Port.ToString(), bindingHost)) { this.logger?.Log(EventType.SettingInvalid, "Skipping endpoint, unable to bind certificate '{0}'.", ep.CertificateThumbPrint); continue; } } string prefix = string.Format( "{0}://{1}:{2}/", ep.Protocol.ToString().ToLower(), ep.HostName, ep.Port); this.listener.Prefixes.Add(prefix); this.logger?.Log(EventType.ServerSetup, "Added prefix '{0}'.", prefix); } else { this.logger?.Log(EventType.SettingInvalid, "Skipping endpoint, invalid host '{0}'.", ep.HostName); } } if (this.listener.Prefixes.Count == 0) { this.logger?.Log(EventType.SettingInvalid, "Settings file did not contain any valid endpoints!"); throw new ArgumentException("Settings file did not contain any valid endpoints!"); } }
public static SettingsProvider CreateHttpServerSettingsProvider() { // First parameter is the path in the Settings window. // Second parameter is the scope of this setting: it only appears in the Preferences Settings window. var provider = new SettingsProvider("Preferences/Http Server", SettingsScope.User) { // Create the SettingsProvider and initialize its drawing (IMGUI) function in place: guiHandler = (searchContext) => { var settings = HttpServerSettings.GetSerializedSettings(); EditorGUILayout.PropertyField(settings.FindProperty("IsEnable"), new GUIContent("Is Enable")); EditorGUILayout.PropertyField(settings.FindProperty("Address"), new GUIContent("Address")); EditorGUILayout.PropertyField(settings.FindProperty("Port"), new GUIContent("Port")); settings.ApplyModifiedProperties(); }, // Populate the search keywords to enable smart search filtering and label highlighting: keywords = new HashSet <string>(new[] { "Address", "Port" }) }; return(provider); }
static void Main(string[] args) { var options = (from arg in args where arg.StartsWith("--") let pair = arg.Substring(2).Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries) where pair.Length == 2 let key = pair[0].Trim() let val = pair[1].Trim() select new KeyValuePair <string, string>(key, val)) .ToDictionary(x => x.Key, x => x.Value, StringComparer.InvariantCultureIgnoreCase); var port = options.Get("port", 1111); var settings = new HttpServerSettings { Port = port, AspNetHost = true }; using (new HttpServer(new MyHandler(), settings)) { Console.WriteLine("Listening port {0}. Press enter to stop the server.", port); Console.ReadLine(); } }
private byte[] CustomizeLoader(ref string filepath) { if (HttpServerSettings.GetOrCreateSettings().IsEnable) { var sceneName = filepath.Substring(0, filepath.IndexOf("/")).ToLower(); var abName = filepath.Substring(0, filepath.LastIndexOf("/")).ToLower() + ".ab"; var assetName = filepath.Substring(filepath.LastIndexOf("/") + 1) + ".lua.txt"; var textAsset = AssetBundleManager.GetInstance().LoadAsset(sceneName, abName, assetName, false) as TextAsset; return(textAsset.bytes); } else { filepath = Application.dataPath + "/UnityLua/AB_Resources/" + filepath + ".lua.txt"; if (File.Exists(filepath)) { return(File.ReadAllBytes(filepath)); } else { return(null); } } }
public HttpClientServer(Logger logger, IOperationFactory operationFactory, IAuthenticationManager authManager, HttpServerSettings settings, ISSLBindingHelper sslBindingHelper) : base(logger, operationFactory, authManager) { this.listener = new HttpListener(); this.sslBindingHelper = sslBindingHelper; this.semaphore = new Semaphore(HttpClientServer.InitialConcurrentConnections, HttpClientServer.InitialConcurrentConnections); this.ApplySettings(settings); }
protected abstract void ApplySettingsInternal(HttpServerSettings settings);
public AppSettings() { uiSettings = new UISettings(); httpServerSettings = new HttpServerSettings(); }
protected override void ApplySettingsInternal(HttpServerSettings settings) { this.ApplyEndpoints(settings); this.ApplyLimits(settings); }