//public Func<HttpServerConfig,Task<bool>> OnSaveAndApply; private async void opbSaveApply_Click(object sender, RoutedEventArgs e) { var httpServerConfigVM = ((HttpServerConfigVM)this.DataContext); try { httpServerConfigVM.IsLoading = true; cmHttpServerConfig.ShowMessageProcess("Saving..."); HttpServerConfig model = httpServerConfigVM.ToModel(); if (await httpServerConfigVM.OnSaveAndApply?.Invoke(model)) { cmHttpServerConfig.ShowMessageSuccess("Saved!"); await Task.Delay(1000); } else { cmHttpServerConfig.ShowMessageError("Save Failed!"); } } finally { httpServerConfigVM.IsLoading = false; } //this.OnSaveAndApply?.Invoke(((HttpServerConfigVM)this.DataContext).ToModel()); }
HttpServerConfig GetConfig(string name, string password) { var config = new HttpServerConfig(_clientConfig, name, password); config.Initialize(); return(config); }
public void DefaultSettingsTest() { HttpServerConfig defaultConfig = new HttpServerConfig(); HttpServerConfig loadedConfig = XmlLoader.LoadConfig(this.sampleConfigPath); Assert.AreEqual(defaultConfig, loadedConfig); }
public void LoadTest() { HttpServerConfig expectedConfig = new HttpServerConfig { Port = 80 }; HttpServerConfig actualConfig = XmlLoader.LoadConfig(Path.Combine(this.testFilesDir, "GoodConfig.xml")); Assert.AreEqual(expectedConfig, actualConfig); }
/// <summary> /// HTTPサーバー更新 /// </summary> private void HttpServerUpdate() { System.Action <AsyncOperation> readConfig = (x) => { var u = (UnityWebRequestAsyncOperation)x; HttpServerConfigState state; if (!u.webRequest.isNetworkError && !u.webRequest.isHttpError) { var text = u.webRequest.downloadHandler.text; m_HttpServerConfig = JsonUtility.FromJson <HttpServerConfig>(text); state = HttpServerConfigState.Valid; } else { state = HttpServerConfigState.Invalid; } if (m_HttpServerConfigState == HttpServerConfigState.ConnectingAndChange) { m_HttpServerConfigState = HttpServerConfigState.Change; } else { m_HttpServerConfigState = state; } m_DisplayDirty = true; }; if (m_HttpServerConfigState == HttpServerConfigState.Invalid) { //コンフィグが無いなら m_HttpServerConfigState = HttpServerConfigState.Connecting; var port = EditorPrefs.GetInt(HttpServer.kHttpServerPortEditorPrefsKey, HttpServer.kHttpServerPortDefault); var url = GetUrl(port); var unityWebRequest = new UnityWebRequest(url, UnityWebRequest.kHttpVerbGET, new DownloadHandlerBuffer(), null); var request = unityWebRequest.SendWebRequest(); request.completed += readConfig; } else if (m_HttpServerConfigState == HttpServerConfigState.Change) { //コンフィグが変更されているなら m_HttpServerConfigState = HttpServerConfigState.Connecting; var urlSb = new StringBuilder(); var port = EditorPrefs.GetInt(HttpServer.kHttpServerPortEditorPrefsKey, HttpServer.kHttpServerPortDefault); urlSb.Append(GetUrl(port)); urlSb.Append('?'); urlSb.Append("MaxBandwidthBps="); urlSb.Append(m_HttpServerConfig.MaxBandwidthBps); var url = urlSb.ToString(); var unityWebRequest = new UnityWebRequest(url, UnityWebRequest.kHttpVerbGET, new DownloadHandlerBuffer(), null); var request = unityWebRequest.SendWebRequest(); request.completed += readConfig; } }
/// <summary> /// Creates a <see cref="IClusterManager"/> object that uses the current <see cref="ICluster"/> configuration settings. /// </summary> /// <returns>A <see cref="IClusterManager"/> instance that uses the current <see cref="ICluster"/> configuration settings. </returns> public IClusterManager CreateManager(string username, string password) { var serverConfig = new HttpServerConfig(Configuration, username, password); serverConfig.Initialize(); return(new ClusterManager(Configuration, serverConfig, new HttpClient(), new JsonDataMapper(Configuration), username, password)); }
public void EqualsTest() { HttpServerConfig config1 = new HttpServerConfig(); HttpServerConfig config2 = new HttpServerConfig(); // Null check Assert.IsFalse(config1.Equals(null)); Assert.IsFalse(config1.Equals(1)); TestHelpers.EqualsTest(config1, config2); config1.Port = (ushort)(config2.Port + 1); TestHelpers.NotEqualsTest(config1, config2); config1.Port = config2.Port; }
/// <summary> /// Instantiates a new <see cref="HttpServer"/> class. /// </summary> /// <param name="httpConfig">Http server config</param> public HttpServer(HttpServerConfig httpConfig) { // If no host is set use wildcard for all host interfaces Host = httpConfig.Host ?? "*"; Port = httpConfig.Port; _processedPokemon = new Dictionary <string, ScannedPokemon>(); _processedRaids = new Dictionary <string, ScannedRaid>(); _processedGyms = new Dictionary <string, ScannedGym>(); _processedPokestops = new Dictionary <string, ScannedPokestop>(); _processedQuests = new Dictionary <string, ScannedQuest>(); _processedWeather = new Dictionary <long, WeatherData>(); _despawnTimerMinimumMinutes = httpConfig.DespawnTimerMinimum; _clearCacheTimer = new System.Timers.Timer { Interval = 60000 * 15 }; _clearCacheTimer.Elapsed += (sender, e) => OnClearCache(); _checkForDuplicates = httpConfig.CheckForDuplicates; Initialize(); }
public void StartServer() { if (_httpServer.IsRunning) { return; } if (string.IsNullOrEmpty(WebRoot)) { MessageBox.Show("The root dir is required."); return; } if (_port <= ushort.MinValue || _port > ushort.MaxValue) { MessageBox.Show($"The port must be between 1 and {ushort.MaxValue}"); return; } _staticFileHandler.RootDir = WebRoot; _staticFileHandler.EnableGZIP = EnableGZIP; HttpServerConfig config = new HttpServerConfig(); config.TcpConfig.MaxPendingCount = 10000; config.TcpConfig.MaxClientCount = 2000; config.TcpConfig.SocketAsyncBufferSize = 100 * 1024; try { _httpServer.Start((ushort)_port, config); CanStartServer = false; WebSocketUrl = $"ws://127.0.0.1:{_port}{_websocketHandler.RelativeUrl}"; AppConfig.Singleton.HttpRootDir = _webRoot; AppConfig.Singleton.HttpListenPort = _port; AppConfig.Singleton.EnableGZIP = _enableGZIP; AppConfig.Save(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Creates a <see cref="IClusterManager"/> object that uses the current <see cref="ICluster"/> configuration settings. /// </summary> /// <returns>A <see cref="IClusterManager"/> instance that uses the current <see cref="ICluster"/> configuration settings. </returns> public IClusterManager CreateManager(string username, string password) { var serverConfig = new HttpServerConfig(Configuration, username, password); try { serverConfig.Initialize(); } catch (BootstrapException e) { //if initializing a new cluster, we won't be able to bootstrap //so Initialize will fail; you can still use the REST API methods //that do not depend upon the API exposed by the config Log.Info(e); } return(new ClusterManager(Configuration, serverConfig, new JsonDataMapper(Configuration), new CouchbaseHttpClient(username, password), username, password)); }
/// <summary> /// Creates a <see cref="IClusterManager"/> object that uses the current <see cref="ICluster"/> configuration settings. /// </summary> /// <returns>A <see cref="IClusterManager"/> instance that uses the current <see cref="ICluster"/> configuration settings. </returns> public IClusterManager CreateManager(string username, string password) { var serverConfig = new HttpServerConfig(Configuration, username, password); try { serverConfig.Initialize(); } catch (BootstrapException e) { //if initializing a new cluster, we won't be able to bootstrap //so Initialize will fail; you can still use the REST API methods //that do not depend upon the API exposed by the config Log.Info(e); } return new ClusterManager(Configuration, serverConfig, new HttpClient(), new JsonDataMapper(Configuration), username, password); }
HttpServerConfig GetConfig(string name, string password) { var config = new HttpServerConfig(_clientConfig, name, password, _loggerFactory); config.Initialize(); return config; }
/// <summary> /// コンフィグ描画 /// </summary> private void OnGUIForConfig() { var config = ((m_HttpServerConfigState != HttpServerConfigState.Invalid)? m_HttpServerConfig: new HttpServerConfig()); var isChange = false; var GuiEnabledOld = GUI.enabled; switch (m_HttpServerConfigState) { case HttpServerConfigState.Valid: case HttpServerConfigState.Connecting: case HttpServerConfigState.ConnectingAndChange: GUI.enabled = true; break; default: GUI.enabled = false; break; } var maxBandwidthKind = System.Array.IndexOf(kBandwidthBps, config.MaxBandwidthBps); if (maxBandwidthKind < 0) { maxBandwidthKind = kBandwidthKindContent.Length - 1; m_IsCustomBandwidthKind = true; } EditorGUI.BeginChangeCheck(); maxBandwidthKind = EditorGUILayout.Popup(kMaxBandwidthKindContent, maxBandwidthKind, kBandwidthKindContent); if (EditorGUI.EndChangeCheck()) { if (maxBandwidthKind < kBandwidthBps.Length) { config.MaxBandwidthBps = kBandwidthBps[maxBandwidthKind]; m_IsCustomBandwidthKind = false; isChange = true; } else { m_IsCustomBandwidthKind = true; } } var GuiEnabledOld2 = GUI.enabled; if (GUI.enabled) { GUI.enabled = m_IsCustomBandwidthKind; } EditorGUI.BeginChangeCheck(); var maxBandwidthBps = EditorGUILayout.IntField(kMaxBandwidthBpsContent, config.MaxBandwidthBps); if (EditorGUI.EndChangeCheck()) { config.MaxBandwidthBps = maxBandwidthBps; isChange = true; } GUI.enabled = GuiEnabledOld2; if (isChange) { m_HttpServerConfig = config; if (m_HttpServerConfigState == HttpServerConfigState.Connecting) { m_HttpServerConfigState = HttpServerConfigState.ConnectingAndChange; } else { m_HttpServerConfigState = HttpServerConfigState.Change; } } GUI.enabled = GuiEnabledOld; }
static void Main() { #region Console Interactive setting //Capture unhandled exception AppDomain.CurrentDomain.UnhandledException += (o, e) => { ConsoleInteractive.LogAndRestartUnHandledException(Properties.Settings.Default.UnhandledExceptionReboot, e); }; //Disable close button in control box. //使 Console 視窗關閉功能無法運作 ConsoleInteractive.DisableControlBoxCloseButton(); //Disable quick edit //使 Console 視窗輸入功能無法運作,避免誤觸導致系統停止運作 ConsoleInteractive.DisableQuickEdit(); #endregion #region Redirect Trace messages to NLogTraceListen NLogTraceListener nLogTraceListener = new NLogTraceListener(true); Trace.Listeners.Add(nLogTraceListener); Trace.AutoFlush = true; #endregion #region Display start up message //Display Program name and version while starts //顯示軟體版本 AssemblyName assemblyName = Assembly.GetExecutingAssembly().GetName(); Trace.WriteLine($"{assemblyName.Name} {assemblyName.Version} Starts"); #endregion #region Check http listen configuration and start listen 檢查並啟用 Http Web API 伺服器 HttpServerConfig hsc = new HttpServerConfig(Properties.Settings.Default.ListenPort, HttpServerConfig.HttpListenTypes.http); string webListenUrl = $"http://+:{Properties.Settings.Default.ListenPort}/"; bool isHttpSysEnabled = hsc.IsEnable; if (!isHttpSysEnabled) { if (hsc.AddUrlAcl()) { Trace.WriteLine($"Add new urlacl {webListenUrl} successfuly"); isHttpSysEnabled = true; } else { throw new UriFormatException("Http listen can not be started."); } } if (isHttpSysEnabled) { var startOptions = new StartOptions(); startOptions.Urls.Add(webListenUrl); //startOptions.Urls.Add("https://+:443"); //Enable Https //Can not listem mutiple urls WebApp.Start <Startup>(startOptions); Trace.Listeners.Remove("HostingTraceListener"); Trace.WriteLine($"Listen {webListenUrl}"); } #endregion #region Handle Console interactive command string helpContent = File.ReadAllText($"{AppContext.BaseDirectory}helpContent.txt"); while (true) { Console.Write("\r\n>"); string cmd = Console.ReadLine(); if (string.IsNullOrEmpty(cmd)) { Console.Write(helpContent); } else if (cmd == "q") { break; } else { CommandHandler(cmd); } } #endregion #region Dispose resouces before leave (add your ocde here) #endregion }
/// <summary> /// Creates a <see cref="IClusterManager"/> object that uses the current <see cref="ICluster"/> configuration settings. /// </summary> /// <returns>A <see cref="IClusterManager"/> instance that uses the current <see cref="ICluster"/> configuration settings. </returns> public IClusterManager CreateManager(string username, string password) { var serverConfig = new HttpServerConfig(Configuration, username, password); serverConfig.Initialize(); return new ClusterManager(Configuration, serverConfig, new HttpClient(), new JsonDataMapper(Configuration), username, password); }
static void Main(string[] args) { if (_captureGlobalUnhandledExceptionAndRestartProgram) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; } #region Redirect Trace messages to NLogTraceListen NLogTraceListener nLogTraceListener = new NLogTraceListener(true); Trace.Listeners.Add(nLogTraceListener); Trace.AutoFlush = true; #endregion //Display Program name and version while starts AssemblyName assemblyName = Assembly.GetExecutingAssembly().GetName(); Trace.WriteLine($"{assemblyName.Name} {assemblyName.Version} Starts"); //Disable close button in control box. Utility.ConsoleWindow.DisableCloseButton(); //Start self-host Web API string _listenUri = $"http://+:{Properties.Settings.Default.ListenPort}/"; HttpServerConfig hsc = new HttpServerConfig(_listenUri); if (hsc.IsEnable) { Trace.WriteLine($"Start selfhost web api. {_listenUri}"); WebApp.Start <Startup>(_listenUri); } else { if (hsc.AddUrlAcl()) { Trace.WriteLine($"Add new urlacl {_listenUri} successfuly"); WebApp.Start <Startup>(_listenUri); } else { throw new Exception("Http listen can not be started."); } } //Accept user console input and response List <char> commandInputBuufer = new List <char>(); while (true) { if (Console.KeyAvailable) { ConsoleKeyInfo cunKey = Console.ReadKey(); if (cunKey.Key == ConsoleKey.Enter) { string cmd = new string(commandInputBuufer.ToArray()); commandInputBuufer.Clear(); if (cmd == "q") { Console.WriteLine("Terminating..."); break; } else { CommandHandler(cmd); } } else { commandInputBuufer.Add(cunKey.KeyChar); } } } #region Dispose resouces //Add dispose resouce here before leave #endregion }