public void Process() { foreach (var newMap in _configQueue.GetConsumingEnumerable()) { try { var isNewOrUpdate = false; var stored = _configs.AddOrUpdate(newMap.Name, key => { isNewOrUpdate = true; return(newMap); }, (key, map) => { if (newMap.Equals(map)) { return(map); } isNewOrUpdate = true; return(newMap.Rev > map.Rev ? newMap : map); }); if (isNewOrUpdate) { ConfigChanged?.Invoke(this, new BucketConfigEventArgs(stored)); } } catch (Exception e) { _logger.LogWarning(e, "Error processing new clusterOptions"); } } }
public void Process() { foreach (var newMap in _configQueue.GetConsumingEnumerable()) { try { var isUpdate = false; var stored = _configs.AddOrUpdate(newMap.Name, newMap, (key, oldMap) => { if (newMap.Equals(oldMap)) { return(oldMap); } isUpdate = true; return(newMap.Rev > oldMap.Rev ? newMap : oldMap); }); if (isUpdate) { if (stored.Rev > newMap.Rev) { ConfigChanged?.Invoke(newMap, new BucketConfigEventArgs(stored)); } } else { ConfigChanged?.Invoke(newMap, new BucketConfigEventArgs(stored)); } } catch (Exception e) { } } }
public void ToggleCheckingUpdate(bool enabled) { _config.autoCheckUpdate = enabled; Configuration.Save(_config); ConfigChanged?.Invoke(this, new EventArgs()); }
public void ToggleSecureLocalPac(bool enabled) { _config.secureLocalPac = enabled; SaveConfig(_config); ConfigChanged?.Invoke(this, new EventArgs()); }
public async Task SaveHotkeyConfig(HotkeyConfig newConfig) { _config.hotkey = newConfig; await SaveConfig(_config); ConfigChanged?.Invoke(this, new EventArgs()); }
public void SavePACUrl(string pacUrl) { _config.pacUrl = pacUrl; SaveConfig(_config); ConfigChanged?.Invoke(this, new EventArgs()); }
public void SaveHotkeyConfig(HotkeyConfig newConfig) { _config.hotkey = newConfig; SaveConfig(_config); ConfigChanged?.Invoke(this, new EventArgs()); }
public void SaveLogViewerConfig(LogViewerConfig newConfig) { _config.logViewer = newConfig; newConfig.SaveSize(); Configuration.Save(_config); ConfigChanged?.Invoke(this, new EventArgs()); }
/// <summary> /// Method called when config changes /// </summary> protected virtual void OnConfigChanged() { if (ConfigChanged != null) { ConfigChanged.Invoke(this, new EventArgs()); } }
private void RemoveSiteButton_Click(object sender, RoutedEventArgs e) { sconnDataShare.removeSite(_sitesPanel.SelectedItemId); _configManager.saveConfig(); InitSiteList(); //reload gui ConfigChanged.Invoke(this, new EventArgs()); }
public void UseOnlinePAC(bool useOnlinePac) { _config.useOnlinePac = useOnlinePac; SaveConfig(_config); ConfigChanged?.Invoke(this, new EventArgs()); }
public static void InvokeNotify(NotifyEventType eventType, INotifyEventArgs args) { switch (eventType) { case NotifyEventType.ConfigChanged: ConfigChanged? .Invoke(args as ConfigEventArgs); break; case NotifyEventType.MousePointDataBind: MousePositionDataBind? .Invoke(args as MousePointEventArgs); break; case NotifyEventType.ScreenCaptureDataBInd: ScreenCaptureDataBind? .Invoke(args as CaptureEventArgs); break; case NotifyEventType.TreeItemOrderChanged: TreeItemOrderChanged? .Invoke(args as EventTriggerOrderChangedEventArgs); break; case NotifyEventType.SelctTreeViewItemChanged: SelectTreeViewChanged? .Invoke(args as SelctTreeViewItemChangedEventArgs); break; case NotifyEventType.EventTriggerOrderChanged: EventTriggerOrderChanged? .Invoke(args as EventTriggerOrderChangedEventArgs); break; case NotifyEventType.EventTriggerInserted: EventTriggerInserted?.Invoke(args as EventTriggerEventArgs); break; case NotifyEventType.EventTriggerRemoved: EventTriggerRemoved?.Invoke(args as EventTriggerEventArgs); break; case NotifyEventType.Save: SaveEventTriggerModel?.Invoke(args as SaveEventTriggerModelArgs); break; case NotifyEventType.Delete: DeleteEventTriggerModel?.Invoke(args as DeleteEventTriggerModelArgs); break; case NotifyEventType.ComboProcessChanged: ComboProcessChanged?.Invoke(args as ComboProcessChangedEventArgs); break; case NotifyEventType.TreeGridViewFocus: TreeGridViewFocus?.Invoke(args as TreeGridViewFocusEventArgs); break; } }
public async Task ToggleCheckingUpdate(bool enabled) { _config.autoCheckUpdate = enabled; await Task.Delay(100); Configuration.Save(_config); ConfigChanged?.Invoke(this, new EventArgs()); }
public void Reload() { StopPortMap(); // some logic in configuration updated the config when saving, we need to read it again Global.GuiConfig = MergeGetConfiguration(Global.GuiConfig); Global.GuiConfig.FlushPortMapCache(); Logging.SaveToFile = Global.GuiConfig.LogEnable; Logging.OpenLogFile(); ReloadProxyRule(); if (_privoxyRunner == null) { _privoxyRunner = new HttpProxyRunner(); } ReloadPacServer(); if (_gfwListUpdater == null) { _gfwListUpdater = new GfwListUpdater(); _gfwListUpdater.UpdateCompleted += (o, args) => UpdatePACFromGFWListCompleted?.Invoke(o, args); _gfwListUpdater.Error += (o, args) => UpdatePACFromGFWListError?.Invoke(o, args); } _listener?.Stop(); _privoxyRunner.Stop(); // don't put privoxyRunner.Start() before pacServer.Stop() // or bind will fail when switching bind address from 0.0.0.0 to 127.0.0.1 // though UseShellExecute is set to true now // http://stackoverflow.com/questions/10235093/socket-doesnt-close-after-application-exits-if-a-launched-process-is-open try { _privoxyRunner.Start(Global.GuiConfig); var local = new Local(Global.GuiConfig, _transfer, _chnRangeSet); var services = new List <Listener.IService> { local, _pacServer, new HttpPortForwarder(_privoxyRunner.RunningPort, Global.GuiConfig) }; _listener = new Listener(services); _listener.Start(Global.GuiConfig, 0); } catch (Exception e) { ThrowSocketException(ref e); Logging.LogUsefulException(e); ReportError(e); } LoadPortMap(); Application.Current.Dispatcher?.InvokeAsync(() => { ConfigChanged?.Invoke(this, new EventArgs()); }); UpdateSystemProxy(); Utils.ReleaseMemory(); }
private int FireEvents(HashSet <EventType> events) { int eventsProcessed = 0; if (events.Contains(EventType.ConfigChanged)) { //Logger.Trace("ConfigChanged"); ConfigChanged?.Invoke(); eventsProcessed++; } if (events.Contains(EventType.HeadChanged)) { //Logger.Trace("HeadChanged"); HeadChanged?.Invoke(); eventsProcessed++; } if (events.Contains(EventType.LocalBranchesChanged)) { //Logger.Trace("LocalBranchesChanged"); LocalBranchesChanged?.Invoke(); eventsProcessed++; } if (events.Contains(EventType.RemoteBranchesChanged)) { //Logger.Trace("RemoteBranchesChanged"); RemoteBranchesChanged?.Invoke(); eventsProcessed++; } if (events.Contains(EventType.IndexChanged)) { if (!events.Contains(EventType.RepositoryChanged)) { //Logger.Trace("IndexChanged"); IndexChanged?.Invoke(); eventsProcessed++; } } if (events.Contains(EventType.RepositoryChanged)) { //Logger.Trace("RepositoryChanged"); RepositoryChanged?.Invoke(); eventsProcessed++; } if (events.Contains(EventType.RepositoryCommitted)) { //Logger.Trace("RepositoryCommitted"); RepositoryCommitted?.Invoke(); eventsProcessed++; } return(eventsProcessed); }
void editwnd_Closing(object sender, System.ComponentModel.CancelEventArgs e) { WndEditScheduleAction editwnd = (WndEditScheduleAction)sender; //parse schedule and update view _schedules[editwnd.ScheduleId] = editwnd.Schedule; LoadScheduleView(); ConfigChanged.Invoke(this, new EventArgs()); //invoke parent update }
private int FireEvents(Dictionary <EventType, List <EventData> > events) { int eventsProcessed = 0; if (events.ContainsKey(EventType.ConfigChanged)) { Logger.Trace("ConfigChanged"); ConfigChanged?.Invoke(); eventsProcessed++; } if (events.ContainsKey(EventType.HeadChanged)) { Logger.Trace("HeadChanged"); HeadChanged?.Invoke(); eventsProcessed++; } if (events.ContainsKey(EventType.LocalBranchesChanged)) { Logger.Trace("LocalBranchesChanged"); LocalBranchesChanged?.Invoke(); eventsProcessed++; } if (events.ContainsKey(EventType.RemoteBranchesChanged)) { Logger.Trace("RemoteBranchesChanged"); RemoteBranchesChanged?.Invoke(); eventsProcessed++; } if (events.ContainsKey(EventType.IndexChanged)) { Logger.Trace("IndexChanged"); IndexChanged?.Invoke(); eventsProcessed++; } if (events.ContainsKey(EventType.RepositoryChanged)) { Logger.Trace("RepositoryChanged"); RepositoryChanged?.Invoke(); eventsProcessed++; } if (events.ContainsKey(EventType.RepositoryCommitted)) { Logger.Trace("RepositoryCommitted"); RepositoryCommitted?.Invoke(); eventsProcessed++; } return(eventsProcessed); }
private void FileSystemWatcherOnChanged(object sender, FileSystemEventArgs e) { _fileSystemWatcher.EnableRaisingEvents = false; var configContents = File.ReadAllText(e.FullPath); var config = JsonSerializer.Deserialize <T>(configContents); ConfigChanged?.Invoke(config); _fileSystemWatcher.EnableRaisingEvents = true; }
protected void Reload() { Encryption.RNG.Reload(); // some logic in configuration updated the config when saving, we need to read it again _config = Configuration.Load(); NLogConfig.LoadConfiguration(); privoxyRunner = privoxyRunner ?? new PrivoxyRunner(); _pacDaemon = _pacDaemon ?? new PACDaemon(); _pacDaemon.PACFileChanged += PacDaemon_PACFileChanged; _pacDaemon.UserRuleFileChanged += PacDaemon_UserRuleFileChanged; _pacServer = _pacServer ?? new PACServer(_pacDaemon); _pacServer.UpdatePACURL(_config); // So PACServer works when system proxy disabled. gfwListUpdater = gfwListUpdater ?? new GFWListUpdater(); gfwListUpdater.UpdateCompleted += PacServer_PACUpdateCompleted; gfwListUpdater.Error += PacServer_PACUpdateError; // don't put PrivoxyRunner.Start() before pacServer.Stop() // or bind will fail when switching bind address from 0.0.0.0 to 127.0.0.1 // though UseShellExecute is set to true now // http://stackoverflow.com/questions/10235093/socket-doesnt-close-after-application-exits-if-a-launched-process-is-open privoxyRunner.Stop(); _pacServer.Stop(); try { privoxyRunner.Start(this, _config); _pacServer.Start(_config); } catch (Exception e) { // translate Microsoft language into human language // i.e. An attempt was made to access a socket in a way forbidden by its access permissions => Port already in use if (e is SocketException se) { if (se.SocketErrorCode == SocketError.AddressAlreadyInUse) { e = new Exception(I18N.GetString("Port {0} already in use", _config.localPort), e); } else if (se.SocketErrorCode == SocketError.AccessDenied) { e = new Exception(I18N.GetString("Port {0} is reserved by system", _config.localPort), e); } } logger.LogUsefulException(e); ReportError(e); } ConfigChanged?.Invoke(this, new EventArgs()); UpdateSystemProxy(); Utils.ReleaseMemory(true); }
public void SaveConfig(Configuration config) { Configuration.Save(config); this._config = config; if (config.isDefault) { config.isDefault = false; } if (ConfigChanged != null) { ConfigChanged.Invoke(this, new EventArgs()); } }
private int FireEvents(HashSet <EventType> events) { int eventsProcessed = 0; if (events.Contains(EventType.ConfigChanged)) { ConfigChanged?.Invoke(); eventsProcessed++; } if (events.Contains(EventType.HeadChanged)) { HeadChanged?.Invoke(); eventsProcessed++; } if (events.Contains(EventType.LocalBranchesChanged)) { LocalBranchesChanged?.Invoke(); eventsProcessed++; } if (events.Contains(EventType.RemoteBranchesChanged)) { RemoteBranchesChanged?.Invoke(); eventsProcessed++; } if (events.Contains(EventType.IndexChanged)) { if (!events.Contains(EventType.RepositoryChanged)) { IndexChanged?.Invoke(); eventsProcessed++; } } if (events.Contains(EventType.RepositoryChanged)) { RepositoryChanged?.Invoke(); eventsProcessed++; } if (events.Contains(EventType.RepositoryCommitted)) { RepositoryCommitted?.Invoke(); eventsProcessed++; } return(eventsProcessed); }
public void Reload() { StopPortMap(); // some logic in configuration updated the config when saving, we need to read it again Global.GuiConfig = MergeGetConfiguration(Global.GuiConfig); Global.GuiConfig.FlushPortMapCache(); Logging.SaveToFile = Global.GuiConfig.LogEnable; Logging.OpenLogFile(); ReloadProxyRule(); _httpProxyRunner ??= new HttpProxyRunner(); ReloadPacServer(); if (_gfwListUpdater == null) { _gfwListUpdater = new GfwListUpdater(); _gfwListUpdater.UpdateCompleted += (o, args) => UpdatePACFromGFWListCompleted?.Invoke(o, args); _gfwListUpdater.Error += (o, args) => UpdatePACFromGFWListError?.Invoke(o, args); } _listener?.Stop(); _httpProxyRunner.Stop(); try { _httpProxyRunner.Start(Global.GuiConfig); var local = new Local(Global.GuiConfig, _transfer, _chnRangeSet); var services = new List <Listener.IService> { local, _pacServer, new HttpPortForwarder(_httpProxyRunner.RunningPort, Global.GuiConfig) }; _listener = new Listener(services); _listener.Start(Global.GuiConfig, 0); } catch (Exception e) { ThrowSocketException(ref e); Logging.LogUsefulException(e); ReportError(e); } LoadPortMap(); Application.Current.Dispatcher?.InvokeAsync(() => { ConfigChanged?.Invoke(this, new EventArgs()); }); UpdateSystemProxy(); }
internal async Task UpdateConfiguration() { try { ConfigFilePath = (!File.Exists(ConfigFilePath) ? Path.Combine(AppContext.BaseDirectory, IPBanService.ConfigFileName) : ConfigFilePath); string newXml = await ConfigReaderWriter.CheckForConfigChange(); if (!string.IsNullOrWhiteSpace(newXml)) { IPBanConfig oldConfig = Config; IPBanConfig newConfig = IPBanConfig.LoadFromXml(newXml, DnsLookup); ConfigChanged?.Invoke(newConfig); whitelistChanged = (Config is null || Config.Whitelist != newConfig.Whitelist || Config.WhitelistRegex != newConfig.WhitelistRegex); Config = newConfig; LoadFirewall(oldConfig); ParseAndAddUriFirewallRules(newConfig); Logger.Info("Config file changed"); } } catch (Exception ex) { Logger.Error(ex); } if (Config is null) { throw new ApplicationException("Configuration failed to load, make sure to check for XML errors or unblock all the files."); } if (Firewall is null) { throw new ApplicationException("Firewall failed to load, check that your firewall is enabled and setup in configuration properly"); } // set or unset default banned ip address handler based on config if (Config.UseDefaultBannedIPAddressHandler && BannedIPAddressHandler is null) { BannedIPAddressHandler = new DefaultBannedIPAddressHandler(); } else if (!Config.UseDefaultBannedIPAddressHandler && BannedIPAddressHandler != null && BannedIPAddressHandler is DefaultBannedIPAddressHandler) { BannedIPAddressHandler = NullBannedIPAddressHandler.Instance; } // will only execute once UpdateBannedIPAddressesOnStart(); // will only execute once SetupWindowsEventViewer(); }
internal static void Save() { JavaScriptSerializer serializer = new JavaScriptSerializer(); var configStr = serializer.Serialize(Config); try { File.WriteAllText(Env.FullPath(CONFIG_FILE), configStr); } catch { MessageBox.Show("Config file failed to save.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } ConfigChanged?.Invoke(); }
protected async Task ReloadAsync() { _config = await Configuration.LoadAsync(); if (_config.isDefault) { return; } if (privoxyRunner == null) { privoxyRunner = new PrivoxyRunner(); } if (v2rayRunner == null) { v2rayRunner = new V2RayRunner(); } if (pacServer == null) { pacServer = new PACServer(); pacServer.PACFileChanged += pacServer_PACFileChanged; pacServer.UserRuleFileChanged += pacServer_UserRuleFileChanged; } if (gfwListUpdater == null) { gfwListUpdater = new GFWListUpdater(); gfwListUpdater.UpdateCompleted += pacServer_PACUpdateCompleted; gfwListUpdater.Error += pacServer_PACUpdateError; } pacServer.UpdatePACURL(_config); pacServer.Stop(); privoxyRunner.Stop(); v2rayRunner.Stop(); try { pacServer.Start(_config); privoxyRunner.Start(_config); v2rayRunner.Start(_config); } catch (Exception e) { Logging.LogUsefulException(e); ReportError(e); } ConfigChanged?.Invoke(this, new EventArgs()); UpdateSystemProxy(); Utils.ReleaseMemory(true); }
internal async Task UpdateConfiguration() { try { ConfigFilePath = (!File.Exists(ConfigFilePath) ? Path.Combine(AppContext.BaseDirectory, IPBanConfig.DefaultFileName) : ConfigFilePath); var configChange = await ConfigReaderWriter.CheckForConfigChange(); if (!string.IsNullOrWhiteSpace(configChange.Item1)) { IPBanConfig oldConfig = Config; IPBanConfig newConfig = IPBanConfig.LoadFromXml(configChange.Item1, DnsLookup, DnsList, RequestMaker); ConfigChanged?.Invoke(newConfig); whitelistChanged = (Config is null || Config.Whitelist != newConfig.Whitelist || Config.WhitelistRegex != newConfig.WhitelistRegex); Config = newConfig; LoadFirewall(oldConfig); ParseAndAddUriFirewallRules(newConfig); // if the config change was not a force refresh with no actual config values changed, log it if (!configChange.Item2) { Logger.Info("Config file changed"); } } } catch (Exception ex) { Logger.Error(ex); } if (Config is null) { throw new ApplicationException("Configuration failed to load, make sure to check for XML errors or unblock all the files."); } if (Firewall is null) { throw new ApplicationException("Firewall failed to load, check that your firewall is enabled and setup in configuration properly"); } // set or unset default banned ip address handler based on config if (Config.UseDefaultBannedIPAddressHandler && BannedIPAddressHandler is null) { BannedIPAddressHandler = new DefaultBannedIPAddressHandler(); } else if (!Config.UseDefaultBannedIPAddressHandler && BannedIPAddressHandler != null && BannedIPAddressHandler is DefaultBannedIPAddressHandler) { BannedIPAddressHandler = NullBannedIPAddressHandler.Instance; } }
private void ButtonOK_OnClick(object sender, RoutedEventArgs e) { if (allowCheckBox.IsChecked == null) { return; } if (allowCheckBox.IsChecked.Value) { DateTime start; DateTime end; try { start = DateTime.Parse(startTextBox.Text); } catch (Exception) { startTextBox.ShowPopUpOnControl("时间格式不正确,格式为 HH:ss(例如:12:00)", 3000); return; } try { end = DateTime.Parse(endTextBox.Text); } catch (Exception) { endTextBox.ShowPopUpOnControl("时间格式不正确,格式为 HH:ss(例如:12:00)", 3000); return; } if (ConfigHelper.Instance.Config.WorkTime == null) { ConfigHelper.Instance.Config.WorkTime = new WorkTime(); } ConfigHelper.Instance.Config.WorkTime.StartTime = start; ConfigHelper.Instance.Config.WorkTime.EndTime = end; } ConfigHelper.Instance.Config.IsShowWorkTime = allowCheckBox.IsChecked.Value; ConfigHelper.Instance.Save(); ConfigChanged?.Invoke(); Close(); }
private static IEnumerator WaitForConfigWriteCoroutine(FileSystemEventArgs e) { if (e.ChangeType == WatcherChangeTypes.Deleted) { ConfigChanged?.Invoke(null); yield break; } var configPath = e.FullPath; var configFileInfo = new FileInfo(configPath); var timeout = new Timeout(3f); yield return(new WaitUntil(() => !Util.IsFileLocked(configFileInfo) || timeout.HasTimedOut)); var config = LoadConfig(configPath); ConfigChanged?.Invoke(config); }
/// <summary> /// File watcher Changed event handler. Filter the events, reload the config and if successful invoke ConfigChanged. /// </summary> /// <param name="sender">Sender.</param> /// <param name="e">File system event args.</param> private void OnChanged(object sender, FileSystemEventArgs e) { if (e.ChangeType != WatcherChangeTypes.Changed) { return; } var logEntry = LogEntry.Create(ServiceStatus.NewConfigurationDetetected, string.Format(CultureInfo.InvariantCulture, "Settings have changed: {0}", e.FullPath)); logEntry.Log(_logger, LogLevel.Information); if (!Load()) { return; } ConfigChanged?.Invoke(this, new EventArgs()); }
private void siteEditSaveButton_Click(object sender, RoutedEventArgs e) { try { int siteId = _sitesPanel.SelectedItemId; sconnSite site = sconnDataShare.getSite(siteId); site.siteName = SiteNameInput.Text; site.serverIP = SiteHostnameInput.Text; site.serverPort = int.Parse(SitePortInput.Text); site.statusCheckInterval = int.Parse(SiteIntervalInput.Text); site.authPasswd = SitePasswordInput.Text; _configManager.saveConfig(); InitSiteList(); //reload gui ConfigChanged.Invoke(this, new EventArgs()); } catch (Exception err) { } }