Represents a lookup cache for adapter data source data.
Пример #1
0
        /// <summary>
        /// Gets/Creates the lookup cache for the provided dataset.
        /// </summary>
        /// <param name="dataSet">The non-null dataset provided by the time-series framework</param>
        /// <returns>Lookup cache for the provided dataset.</returns>
        public static DataSourceLookupCache GetLookupCache(DataSet dataSet)
        {
            if ((object)dataSet == null)
            {
                throw new ArgumentNullException(nameof(dataSet));
            }

            //Since adding datasets will be rare, the penalty associated with a lock on the entire
            //set will be minor.
            lock (s_dataSetLookups)
            {
                DataSourceLookupCache target;

                for (int index = 0; index < s_dataSetLookups.Count; index++)
                {
                    WeakReference <DataSourceLookupCache> item = s_dataSetLookups[index];

                    if (item.TryGetTarget(out target) && target.DataSet != null)
                    {
                        if (ReferenceEquals(target.DataSet, dataSet))
                        {
                            return(target);
                        }
                    }
                    else
                    {
                        s_log.Publish(MessageLevel.Info, "A DataSet object has been disposed or garbage collected. It will be removed from the list.");
                        s_dataSetLookups.RemoveAt(index);
                        index--;
                    }
                }

                s_log.Publish(MessageLevel.Info, "Creating a lookup cache for a dataset");
                target = new DataSourceLookupCache(dataSet);

                s_dataSetLookups.Add(new WeakReference <DataSourceLookupCache>(target));

                return(target);
            }
        }
        /// <summary>
        /// Gets/Creates the lookup cache for the provided dataset.
        /// </summary>
        /// <param name="dataSet">The non-null dataset provided by the time-series framework</param>
        /// <returns>Lookup cache for the provided dataset.</returns>
        public static DataSourceLookupCache GetLookupCache(DataSet dataSet)
        {
            if ((object)dataSet == null)
                throw new ArgumentNullException(nameof(dataSet));

            //Since adding datasets will be rare, the penalty associated with a lock on the entire
            //set will be minor.
            lock (s_dataSetLookups)
            {
                DataSourceLookupCache target;

                for (int index = 0; index < s_dataSetLookups.Count; index++)
                {
                    WeakReference<DataSourceLookupCache> item = s_dataSetLookups[index];

                    if (item.TryGetTarget(out target) && target.DataSet != null)
                    {
                        if (ReferenceEquals(target.DataSet, dataSet))
                        {
                            return target;
                        }
                    }
                    else
                    {
                        s_log.Publish(MessageLevel.Info, "A DataSet object has been disposed or garbage collected. It will be removed from the list.");
                        s_dataSetLookups.RemoveAt(index);
                        index--;
                    }
                }

                s_log.Publish(MessageLevel.Info, "Creating a lookup cache for a dataset");
                target = new DataSourceLookupCache(dataSet);

                s_dataSetLookups.Add(new WeakReference<DataSourceLookupCache>(target));

                return target;
            }
        }