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
        public void Do_WithNoAction_ThrowsArgumentNullException()
        {
            FailOnErrors = false;

            RunExclusiveAction action = new RunExclusiveAction();

            action.Do();

            Assert.False(action.HasRun);
        }
Ejemplo n.º 3
0
        public void Do_WithNullAction_DoesNotThrow()
        {
            FailOnErrors = false;

            RunExclusiveAction action = new RunExclusiveAction();

            action.Do(null);

            Assert.False(action.HasRun);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ResourceMonitor"/> class.
        /// </summary>
        /// <param name="retryPolicy">retry policy</param>
        /// <param name="loadDelay">load delay</param>
        protected ResourceMonitor(RetryPolicy retryPolicy, TimeSpan loadDelay)
        {
            RetryPolicy = retryPolicy ?? RetryPolicy.None;
            LoadDelay   = loadDelay;

            m_monitoredResources     = new ConcurrentDictionary <IResource, bool>();
            m_resourceDetails        = new ConcurrentDictionary <IResource, IResourceDetails>();
            m_resourceMonitoringData = new ConcurrentDictionary <ResourceUpdatedHandler, ResourceMonitoringData>();
            m_exclusiveAction        = new RunExclusiveAction();
        }
Ejemplo n.º 5
0
        public void DoViaConstructor_WithException_Throws()
        {
            RunExclusiveAction action = new RunExclusiveAction(
                () =>
            {
                throw new NotImplementedException();
            });

            Assert.Throws <NotImplementedException>(() => action.Do());
            Assert.True(action.HasRun);
        }
Ejemplo n.º 6
0
        public void DoViaConstructor_WithoutRunOnlyOnce_RunsEachTime()
        {
            int value = 0;
            RunExclusiveAction action = new RunExclusiveAction(
                () => Interlocked.Increment(ref value));

            for (int i = 0; i < 10; i++)
            {
                action.Do();
            }

            Assert.Equal(10, value);
            Assert.True(action.HasRun);
        }