/// <summary> /// The InistialseFolder event is raised from here, for every subfolder that we perform an item count on. /// </summary> /// <param name="folderName">The name of the folder</param> /// <remarks>This event just publishes some activity to clients of this type, during the process of /// finding the total item count for all items</remarks> private void RaiseInitialScanEvent(string folderName) { if (InitialiseFolder != null) { FSScanEventArgs args = new FSScanEventArgs(); args.FolderName = folderName; InitialiseFolder(this, args); Thread.Sleep(0); } }
void m_scanFS_FileFound(object sender, FSScanEventArgs e) { lock (this) { m_filesFound++; if (0 < m_delay) { System.Threading.Thread.Sleep(m_delay); //this will slow down the scanning speed for tests } } }
void fileScan_OnFolderCountCompleted(object sender, FSScanEventArgs e) { m_fileCount = e.ItemsFound; m_eventReturned = true; }
void OnFileSystemItemFound(object sender, FSScanEventArgs e) { throw new Exception("The method or operation is not implemented."); }
int FindItemCount(DirectoryInfo directory) { int itemCount = 0; try { RaiseInitialScanEvent(directory.Name); foreach (string filter in m_searchFilters) { m_reset.WaitOne(); if (m_isCounting == false) return 0; itemCount += directory.GetFiles(filter).GetLength(0); } if (OnFolderCountProgress != null) { FSScanEventArgs args = new FSScanEventArgs(); args.FolderName = directory.Name; args.ItemsFound = itemCount; OnFolderCountProgress(this, args); } DirectoryInfo[] subs = directory.GetDirectories(); foreach (DirectoryInfo sub in subs) { itemCount += FindItemCount(sub); } } catch (UnauthorizedAccessException e) { System.Diagnostics.Trace.TraceError("Cannot access file/folder - " + e.Message); } return itemCount; }
private void FindCountAysnc(object state) { System.Globalization.CultureInfo ci = state as System.Globalization.CultureInfo; if (ci != null) { Thread.CurrentThread.CurrentCulture = ci; Thread.CurrentThread.CurrentUICulture = ci; } int itemCount = 0; m_totalItems = 0; m_isCounting = true; if (OnFolderCountStart != null) OnFolderCountStart(this, new EventArgs()); foreach (DirectoryInfo dir in m_directoriesToScan) { itemCount += FindItemCount(dir); m_reset.WaitOne(); if (m_isCounting == false) return; } m_totalItems = itemCount; if (OnFolderCountCompleted != null) { FSScanEventArgs args = new FSScanEventArgs(); args.FolderName = ""; args.ItemsFound = itemCount; OnFolderCountCompleted(this, args); } RaiseInitialScanEvent(String.Empty); m_isCounting = false; }