/// <summary> /// The constructor. /// </summary> /// <param name="random">Specifies the CryptoRandom to use for random selection.</param> /// <param name="log">Specifies the output log.</param> /// <param name="src">Specifies the data source that holds the data on the database.</param> /// <param name="factory">Specifies the data factory used to access the database data.</param> /// <param name="rgAbort">Specifies the cancel handles.</param> /// <param name="nMaxLoadCount">Optionally, specifies to automaticall start the image refresh which only applies when the number of images loaded into memory is less than the actual number of images (default = false).</param> public MasterList(CryptoRandom random, Log log, SourceDescriptor src, DatasetFactory factory, List <WaitHandle> rgAbort, int nMaxLoadCount = 0) { m_random = random; m_log = log; m_src = src; m_factory = factory; m_rgAbort.Add(m_evtCancel); if (rgAbort.Count > 0) { m_rgAbort.AddRange(rgAbort); } m_imgMean = m_factory.LoadImageMean(m_src.ID); m_nLoadCount = nMaxLoadCount; if (m_nLoadCount == 0 || m_nLoadCount > m_src.ImageCount) { m_nLoadCount = m_src.ImageCount; } m_rgImages = new SimpleDatum[m_nLoadCount]; m_nLoadedCount = 0; if (m_nLoadCount < m_src.ImageCount) { m_refreshManager = new RefreshManager(random, m_src, m_factory); } }
public LoadSequence(CryptoRandom random, int nCount, int nImageCount, RefreshManager refresh) { // When using load limit (count < image count), load item indexes in such // a way that balances the number of items per label. if (nCount < nImageCount) { Dictionary <int, List <DbItem> > rgItemsByLabel = refresh.GetItemsByLabel(); List <int> rgLabel = rgItemsByLabel.Where(p => p.Value.Count > 0).Select(p => p.Key).ToList(); for (int i = 0; i < nCount; i++) { int nLabelIdx = random.Next(rgLabel.Count); int nLabel = rgLabel[nLabelIdx]; List <DbItem> rgItems = rgItemsByLabel[nLabel]; int nItemIdx = random.Next(rgItems.Count); DbItem item = rgItems[nItemIdx]; m_rgLoadSequence.Add(item.Index); rgLabel.Remove(nLabel); if (rgLabel.Count == 0) { rgLabel = rgItemsByLabel.Where(p => p.Value.Count > 0).Select(p => p.Key).ToList(); } } refresh.Reset(); } // Otherwise just load all item indexes. else { for (int i = 0; i < nCount; i++) { m_rgLoadSequence.Add(i); } } }