Ejemplo n.º 1
0
        /// <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);
                    }
                }
            });
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
            /// <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);
            }
Ejemplo n.º 4
0
            /// <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;
            }
Ejemplo n.º 5
0
 /// <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);
 }
Ejemplo n.º 6
0
 /// <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;
 }
Ejemplo n.º 7
0
 /// <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);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Handles ResourceUpdated event
 /// </summary>
 /// <param name="e">event args</param>
 private void UnitTestOnResourceUpdated(ResourceUpdatedEventArgs e) => ResourceUpdatedCalled = true;