/// <summary> /// Attempts to load a new dataset and replaces the old one if load was successful /// </summary> /// <param name="arguments">The arguments for the update event.</param> protected virtual void UpdateLoadedDataSet(ResourceUpdatedEventArgs arguments) { RunExclusiveAction action = AllowMultipleThreadsLoadingDataSet ? m_action : s_action; action.Do(() => { if (arguments.IsInitialLoad) { ULSLogging.LogTraceTag(0x23821004 /* tag_967ae */, Categories.ConfigurationDataSet, Levels.Verbose, "Adding data set type '{0}' to cache.", typeof(T).Name); if (Cache.GetOrAdd(typeof(IConfigurationDataSetLoader <T>), () => CreateCachedConfigurationDataSet(new CachedConfigurationDataSet <T>(DataSetOverride), arguments), out bool wasAdded) is CachedConfigurationDataSet <T> result && wasAdded) { OnLoad(result.LoadDetails); } } else { ULSLogging.LogTraceTag(0x23850399 /* tag_97qoz */, Categories.ConfigurationDataSet, Levels.Verbose, "Updating data set type '{0}' in cache.", typeof(T).Name); CachedConfigurationDataSet <T> dataSets = DataSets; IList <ConfigurationDataSetLoadDetails> loadDetails = dataSets.LoadDetails; if (Cache.AddOrUpdate(typeof(IConfigurationDataSetLoader <T>), () => CreateCachedConfigurationDataSet(dataSets, arguments), out bool wasUpdated) is CachedConfigurationDataSet <T> result && wasUpdated) { OnReload(loadDetails, result.LoadDetails); } } }); }
/// <summary> /// Updates DataSet on resources change event /// </summary> /// <param name="arguments">event arguments</param> /// <remarks>Since this may be called on a background thread without a current correlation, /// start a new correlation if one does not already exist</remarks> protected virtual void OnResourceUpdated(ResourceUpdatedEventArgs arguments) { ULSLogging.LogTraceTag(0x23821005 /* tag_967af */, Categories.ConfigurationDataSet, Levels.Verbose, "'{0}' loader encountered an event for resources '{1}'.", typeof(T).Name, string.Join(";", arguments.Details.Select(d => d.Key))); UpdateLoadedDataSet(arguments); DataSetLoaded?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Loads DataSet /// </summary> /// <param name="arguments">The arguments for the update event.</param> /// <returns>Loaded DataSet</returns> private TDataSet LoadDataSet(ResourceUpdatedEventArgs arguments) { ULSLogging.LogTraceTag(0x2382100c /* tag_967am */, Categories.ConfigurationDataSet, Levels.Verbose, "Loading data set for '{0}'.", typeof(TDataSet).Name); TDataSet dataSet = m_dataSetDefault ?? new TDataSet(); try { dataSet.Load(arguments.Details); } catch (Exception exception) { ULSLogging.ReportExceptionTag(0x2382100d /* tag_967an */, Categories.ConfigurationDataSet, exception, "Exception encountered while loading '{0}'", typeof(TDataSet).Name); } return(dataSet); }
/// <summary> /// Attempts to load a new dataset and replaces the old one if load was successful /// </summary> /// <param name="arguments">The arguments for the update event.</param> public void UpdateLoadedDataSet(ResourceUpdatedEventArgs arguments) { if (!Code.ValidateArgument(arguments, nameof(arguments), TaggingUtilities.ReserveTag(0x23821007 /* tag_967ah */))) { return; } TDataSet dataSet = LoadDataSet(arguments); if (dataSet != null && dataSet.IsHealthy) { ULSLogging.LogTraceTag(0x23821008 /* tag_967ai */, Categories.ConfigurationDataSet, Levels.Verbose, "Successfully loaded {0} with status 'Healthy'", typeof(TDataSet).Name); } else { ULSLogging.LogTraceTag(0x23821009 /* tag_967aj */, Categories.ConfigurationDataSet, Levels.Error, "Loaded {0} with status '{1}'", typeof(TDataSet).Name, dataSet != null ? dataSet.IsHealthy ? "Healthy" : "Not healthy" : "DataSet is null"); } if (LoadedDataSet == null) { LoadedDataSet = dataSet; } else if ((!LoadedDataSet.IsHealthy && dataSet != null) || (dataSet != null && dataSet.IsHealthy)) { ULSLogging.LogTraceTag(0x2382100a /* tag_967ak */, Categories.ConfigurationDataSet, Levels.Verbose, "Replacing old {0} loaded at {1} with data loaded with status '{2}'", typeof(TDataSet).Name, LoadedDataSet.LastReload, dataSet.IsHealthy ? "Healthy" : "Not healthy"); LoadedDataSet = dataSet; } else { ULSLogging.LogTraceTag(0x2382100b /* tag_967al */, Categories.ConfigurationDataSet, Levels.Error, "Not replacing old {0} with data loaded with status '{1}'", typeof(TDataSet).Name, dataSet != null ? dataSet.IsHealthy ? "Healthy" : "Not healthy" : "DataSet is null"); FailedToLoadDataSet = dataSet; } LoadDetails = dataSet?.LoadDetails; }
/// <summary> /// Creates the cached configuration data set. /// </summary> /// <param name="initialValue">The initial data set value.</param> /// <param name="arguments">The arguments for the update event.</param> /// <returns>The cached configuration data set.</returns> private CachedConfigurationDataSet <T> CreateCachedConfigurationDataSet(CachedConfigurationDataSet <T> initialValue, ResourceUpdatedEventArgs arguments) { initialValue.UpdateLoadedDataSet(arguments); return(initialValue); }
/// <summary> /// Performs the event. /// </summary> /// <param name="e">The <see cref="ResourceUpdatedEventArgs"/> instance containing the event data.</param> private void PerformEvent(ResourceUpdatedEventArgs e) { m_handlerCalledIndicator = true; }
/// <summary> /// Handler called when resource monitor notices that the resource has changed /// </summary> /// <param name="arguments">ResourceUpdated event arguments</param> protected override void OnResourceUpdated(ResourceUpdatedEventArgs arguments) { UpdateLoadedDataSet(arguments); m_resourceUpdatedHandler?.Invoke(arguments); }
/// <summary> /// Handles ResourceUpdated event /// </summary> /// <param name="e">event args</param> private void UnitTestOnResourceUpdated(ResourceUpdatedEventArgs e) => ResourceUpdatedCalled = true;