public Notification(string ruleIdentifier, Guid ruleRunGuid, DateTime ruleRunTimeUtc, DateTime creationTimeUtc, DateTime eventTimeUtc, string bucket, Severity severity, MonitorEnvironment environment, string stamp, string message, string?summary = null) { RuleIdentifier = ruleIdentifier; RuleRunGuid = ruleRunGuid; RuleRunTimeUtc = ruleRunTimeUtc; CreationTimeUtc = creationTimeUtc; EventTimeUtc = eventTimeUtc; Bucket = bucket; Severity = severity; Environment = environment; Stamp = stamp; Message = message; Summary = summary; }
public MultiStampRuleConfiguration( IClock clock, ILogger logger, INotifier <Notification> notifier, IKustoClient kustoClient, IIcmClient icmClient, string kustoDatabaseName, string cacheTableName, MonitorEnvironment environment, Watchlist watchlist) : base(clock, logger, notifier, kustoClient, kustoDatabaseName, cacheTableName, icmClient) { Environment = environment; WatchList = watchlist; }
/// <summary> /// The add services. /// </summary> /// <param name="env"> /// The env. /// </param> internal void AddServices(MonitorEnvironment env) { LiveUpdateService liveUpdateService = null; OnlineCurrencyProvider currencyProvider = null; var activeServices = env.BackgroundServices.GetAll(); foreach (var svc in activeServices) { if (svc is LiveUpdateService) { liveUpdateService = (LiveUpdateService)svc; } else if (svc is OnlineCurrencyProvider) { currencyProvider = (OnlineCurrencyProvider)svc; } } if (liveUpdateService == null) { this._logger.Debug("Adding Live Update Service..."); liveUpdateService = new LiveUpdateService(); liveUpdateService.Configuration = liveUpdateService.DefaultConfig; env.BackgroundServices.Add(liveUpdateService, false); } liveUpdateService.ProductLogo = Resources.FareLiz; if (currencyProvider == null) { this._logger.Debug("Adding Currency Provider..."); env.CurrencyProvider = currencyProvider = new OnlineCurrencyProvider(); currencyProvider.Configuration = currencyProvider.DefaultConfig; env.BackgroundServices.Add(currencyProvider, false); } this._logger.Info("Total loaded services: " + env.BackgroundServices.Count); }
public StampId(MonitorEnvironment environment, string name) { Environment = environment; Name = name; }
/// <summary> /// The get environment. /// </summary> /// <param name="executionParam"> /// The execution param. /// </param> /// <param name="globalContext"> /// The global context. /// </param> /// <returns> /// The <see cref="MonitorEnvironment"/>. /// </returns> private MonitorEnvironment GetEnvironment(ExecutionParam executionParam, WinFormGlobalContext globalContext) { var pluginResolver = new AssemblyPluginResolver(this.Logger); pluginResolver.LoadPlugins(); var configStore = new FileConfigStore(AppUtil.GetLocalDataPath(this.ENV_CONFIG_FILENAME), pluginResolver, this.Logger); MonitorEnvironment env = configStore.LoadEnv(); if (env == null || env.ArchiveManager == null || env.FareDatabase == null || env.FareDataProvider == null) { env = new MonitorEnvironment(configStore, pluginResolver, new BackgroundServiceManager(this.Logger), this.Logger); globalContext.AddServices(env); using (var configDialog = new EnvConfiguratorDialog(env, executionParam)) { if (configDialog.ShowDialog() == DialogResult.OK) { env = configDialog.ResultEnvironment; } else { env.Close(); env = null; } } } return env; }
/// <summary> /// The btn import config_ click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void btnImportConfig_Click(object sender, EventArgs e) { using (var selectFileDlg = new OpenFileDialog()) { selectFileDlg.Title = "Import " + AppUtil.ProductName + " Configuration"; selectFileDlg.Filter = AppUtil.ProductName + " Configuration File (*.bin)|*.bin"; var result = selectFileDlg.ShowDialog(this); if (result == DialogResult.OK) { MonitorEnvironment newEnv = null; try { newEnv = this._env.ConfigStore.LoadEnv(selectFileDlg.FileName); } catch (Exception ex) { Console.Error.WriteLine(ex.ToString()); } if (newEnv == null) { MessageBox.Show( this, "The selected configuration file is corrupted or does not have a valid file format", "Invalid configuration file", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { newEnv.ConfigStore = this._env.ConfigStore; this._env = newEnv; this.InitializeData(); } } } }
/// <summary> /// The bind currencies. /// </summary> /// <param name="env"> /// The env. /// </param> /// <exception cref="ArgumentException"> /// </exception> private void BindCurrencies(MonitorEnvironment env) { ICurrencyProvider provider = env.CurrencyProvider; if (provider == null) { throw new ArgumentException("Missing Currency Provider"); } var allCurrencies = provider.GetCurrencies(); if (provider.Configuration == null) { provider.Configuration = provider.DefaultConfig; } int index = 0; var sel = provider.AllowedCurrencies; this.lstCurrency.Items.Clear(); // Clear the list of items before repopulating the default currency list foreach (var item in allCurrencies) { this.lstCurrency.Items.Add(item); bool isSelected = sel != null && sel.Contains(item.Key); this.lstCurrency.SetItemChecked(index, isSelected); index++; } }
/// <summary> /// Initializes a new instance of the <see cref="EnvConfiguratorDialog"/> class. /// </summary> /// <param name="environment"> /// The environment. /// </param> /// <param name="executionParam"> /// The execution param. /// </param> /// <exception cref="ArgumentException"> /// </exception> internal EnvConfiguratorDialog(MonitorEnvironment environment, ExecutionParam executionParam) : this() { if (environment == null) { throw new ArgumentException("Environment cannot be null"); } if (environment.Logger == null) { throw new ArgumentException("Environment logger cannot be null"); } if (environment.ConfigStore == null) { throw new ArgumentException("Environment config store cannot be null"); } if (executionParam.ConfigHandler == null) { throw new ArgumentException("Execution param config store cannot be null"); } this._logger = environment.Logger; this._typeResolver = new TypeResolver(this._logger); this._executionParam = executionParam.ReflectionDeepClone(this._logger); this.Height -= this.pnlTop.Height; this._env = environment.ReflectionDeepClone(this._logger); #if DEBUG this._env.Id = Guid.NewGuid().ToString(); #endif this.InitializeData(); }
public static string Abbreviation(this MonitorEnvironment environment) => environment switch {
/// <summary> /// The set environment. /// </summary> /// <param name="env"> /// The env. /// </param> internal void SetEnvironment(MonitorEnvironment env) { this._err = null; if (env != null) { this._logger.Debug("Closing global environment..."); env.Close(); } this._logger.Info("Setting new global environment..."); this.AddServices(env); // Add needed services to this environment instance this._env = env; if (this._env != null) { this._logger.Debug("Initializing global environment..."); var result = this._env.Initialize(); if (!result.Succeeded) { this._err = result.ErrorMessage; this._logger.Warn("Error initializing environment: " + this._err); } } }
/// <summary> /// The save env. /// </summary> /// <param name="env"> /// The env. /// </param> /// <param name="filePath"> /// The file path. /// </param> public void SaveEnv(MonitorEnvironment env, string filePath) { var data = new List<KeyValue<Type, ConfigInfo>>(); if (env.ArchiveManager != null) { data.Add(new KeyValue<Type, ConfigInfo>(typeof(IArchiveManager), new ConfigInfo(env.ArchiveManager))); } if (env.FareDataProvider != null) { data.Add(new KeyValue<Type, ConfigInfo>(typeof(IFareDataProvider), new ConfigInfo(env.FareDataProvider))); } if (env.FareDatabase != null) { data.Add(new KeyValue<Type, ConfigInfo>(typeof(IFareDatabase), new ConfigInfo(env.FareDatabase))); } var syncDb = env.FareDatabase as ISyncableDatabase; if (syncDb != null && syncDb.DataSynchronizer != null) { data.Add(new KeyValue<Type, ConfigInfo>(typeof(IDatabaseSyncer<>), new ConfigInfo(syncDb.DataSynchronizer))); } if (env.CurrencyProvider != null) { data.Add(new KeyValue<Type, ConfigInfo>(typeof(ICurrencyProvider), new ConfigInfo(env.CurrencyProvider))); } if (env.BackgroundServices != null) { var allServices = env.BackgroundServices.GetAll(); foreach (var s in allServices) { if (s != env.CurrencyProvider) { data.Add(new KeyValue<Type, ConfigInfo>(s.GetType(), new ConfigInfo(s))); } } } var rawData = new byte[data.Count][]; var formatter = new TolerantBinaryFormatter(this.Logger); using (var ms = new MemoryStream()) { for (int i = 0; i < data.Count; i++) { formatter.Serialize(ms, data[i]); rawData[i] = ms.ToArray(); ms.SetLength(0); } } using (var stream = File.Open(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) { using (var writer = new BinaryWriter(stream)) { writer.Write(AppUtil.ProductName); writer.Write(AppUtil.ProductVersion); formatter.Serialize(stream, rawData); } } }
/// <summary> /// The save env. /// </summary> /// <param name="env"> /// The env. /// </param> public void SaveEnv(MonitorEnvironment env) { this.SaveEnv(env, this.ConfigFile); }