Esempio n. 1
0
        /// <summary>
        /// Gets the item with the given key.
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        private object GetValue(object key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            Lock.AcquireReaderLock(-1);
            try
            {
                // find it...
                if (!(InnerValues.Contains(key)))
                {
                    // mbr - 2010-01-20 - moved to method...
                    //Lock.UpgradeToWriterLock(-1);

                    //// try again...
                    //if(!(InnerValues.Contains(key)))
                    //{
                    //    // create it...
                    //    CreateLookupItemEventArgs e = new CreateLookupItemEventArgs(key);
                    //    this.OnCreateItemValue(e);

                    //    // add...
                    //    // mbr - 2010-01-20 - added wrap...
                    //    //InnerValues[key] = e.NewValue;
                    //    InnerValues[key] = Wrap(e.NewValue);
                    //}
                    LoadItem(key, false);
                }

                // return...
                // mbr - 2010-01-20 - added wrap...
                //return InnerValues[key];
                bool   expired = false;
                object value   = Unwrap(InnerValues[key], ref expired);

                // mbr - 2010-01-20 - expired...
                if (expired)
                {
                    // load and reload...
                    LoadItem(key, true);
                    value = Unwrap(InnerValues[key], ref expired);
                }

                // return...
                return(value);
            }
            finally
            {
                Lock.ReleaseLock();
            }
        }
Esempio n. 2
0
 public object[] PeekQueue()
 {
     Lock.AcquireReaderLock(-1);
     try
     {
         return(this.Queue.ToArray());
     }
     finally
     {
         Lock.ReleaseLock();
     }
 }
Esempio n. 3
0
        private static SourceState GetSourceStateFromCache(string fullyQualifiedReference)
        {
            SourceState sourceState;

            // Lock

            Lock.AcquireReaderLock(Timeout.Infinite);
            try
            {
                // Check whether the event source has been cached.

                sourceState = (SourceState)SourceStates[fullyQualifiedReference];
            }
            finally
            {
                Lock.ReleaseReaderLock();
            }

            return(sourceState);
        }
Esempio n. 4
0
 public IBar FindBar(int dt)
 {
     if (!Lock.IsWriterLockHeld)
     {
         Lock.AcquireReaderLock(1000);
     }
     try
     {
         int  alignmentDT = TimeAlignment(dt);
         IBar bar         = this.Last;
         while (bar != null)
         {
             if (alignmentDT == bar.DT)
             {
                 if (l.IsDebugEnabled)
                 {
                     l.Debug(debKey + "Найден бар " + bar.Number);
                 }
                 return(bar);
             }
             if (alignmentDT > bar.DT) // если искомое время больше времени в баре, то можно закругляться
             {
                 break;
             }
             bar = this.GetPrevious(bar);
         }
         l.Debug(debKey + "Бар не найден");
         return(null);
     }
     finally
     {
         if (!Lock.IsWriterLockHeld)
         {
             Lock.ReleaseReaderLock();
         }
     }
 }
Esempio n. 5
0
 public IBar GetNext(IBar bar)
 {
     Lock.AcquireReaderLock(1000);
     try
     {
         // Надеюсь, что с последнего GetNext bar не изменился
         if ((lastGetNextFind <= bars.Count - 1) && (bars[lastGetNextFind] == bar))
         {
             if ((++lastGetNextFind) == bars.Count)
             {
                 lastGetNextFind = 0;
                 return(null);
             }
             else
             {
                 return(bars[lastGetNextFind]);
             }
         }
         // Воспользоваться кэшем lastGetNextFind не удалось, ищу по всему массиву
         // TODO Вообще этот поиск можно ускорить, т.к. массив отсартирован
         for (int find = bars.Count - 2; find >= 0; --find)
         {
             if (bars[find] == bar)
             {
                 lastGetNextFind = find + 1;
                 return(bars[lastGetNextFind]);
             }
         }
         l.Info("GetNext бар не найден, вернул null");
         return(null);
     }
     finally
     {
         Lock.ReleaseReaderLock();
     }
 }
Esempio n. 6
0
        internal static void UpdateNamespace(string fullName)
        {
            Debug.Assert(!string.IsNullOrEmpty(fullName), "fullName != null && fullName.Length > 0");

            // Find the SourceStates for all Sources in the namespace (recursively).

            string prefix         = fullName + ".";
            var    statesToUpdate = new ArrayList();
            var    nsCount        = new Hashtable();   // Count of sources to update per namespace < string, int >

            Lock.AcquireReaderLock(Timeout.Infinite);
            try
            {
                foreach (SourceState sourceState in SourceStates.Values)
                {
                    if (sourceState.FullyQualifiedReference.StartsWith(prefix))
                    {
                        statesToUpdate.Add(sourceState);

                        // Maintain the count of states in this namespace that are being updated.

                        string nsName = CatalogueName.CreateUnchecked(sourceState.FullyQualifiedReference).Namespace;
                        object count  = nsCount[nsName];
                        nsCount[nsName] = (count == null ? 1 : (int)count + 1);
                    }
                }
            }
            finally
            {
                Lock.ReleaseReaderLock();
            }

            if (statesToUpdate.Count == 0)
            {
                return;                 // No Sources from this namespace have been created - nothing to update.
            }
            // Get the catalogue and find the namespace on which event status was changed.

            var rootNs = _catalogue.GetSearcher().GetNamespace(fullName);

            if (rootNs == null)
            {
                return;                 // The namespace must have been deleted after it was updated.
            }
            // Update each source.

            foreach (SourceState sourceState in statesToUpdate)
            {
                CatalogueName catalogueName = CatalogueName.CreateUnchecked(sourceState.FullyQualifiedReference);
                var           sourceCount   = (int)nsCount[catalogueName.Namespace];

                // To minimise access to WMI use two different ways to search for the source. If there are only
                // 1 or 2 sources that need to be updated in the namespace then find them using the searcher -
                // if the repository is WMI it will read only those sources. If there are 3 or more then just
                // use the Sources collection, which will load all the sources in the namespace in one go.

                Source source;
                if (sourceCount < 3)
                {
                    string relativeName = sourceState.FullyQualifiedReference.Substring(prefix.Length);
                    source = rootNs.GetSearcher().GetSource(relativeName);
                }
                else
                {
                    if (catalogueName.Namespace == fullName)
                    {
                        source = rootNs.Sources[catalogueName.RelativeQualifiedReference];
                    }
                    else
                    {
                        Namespace leafNs = rootNs.GetSearcher().GetNamespace(catalogueName.Namespace.Substring(prefix.Length));
                        source = leafNs == null ? null : leafNs.Sources[catalogueName.RelativeQualifiedReference];
                    }
                }

                if (source == null)
                {
                    sourceState.SetEventStatus(_defaultEventStatus);
                }
                else
                {
                    sourceState.SetEventStatus(CreateEventStatus(source.GetEffectiveEnabledEvents()));
                }
            }
        }