Пример #1
0
        public void DoEnumerate(Object _params)
        {
            Params myparams = (_params as Params);

            string[]  dirs       = myparams.directories.Split(',');
            string[]  extensions = myparams.extensions.Split(',');
            JobStatus status     = myparams.jobStatus;

            if (status == null)
            {
                status = new JobStatus("FileStdEnum");
            }
            Stopwatch watch = myparams.jobWatch;

            if (watch == null)
            {
                watch = new Stopwatch();
                watch.Start();
            }
            int  num_file = 0;
            bool should_close;

            myparams.fileProcessor.Start(out should_close);
            foreach (string dir in dirs)
            {
                if (status.Cancelled)
                {
                    break;
                }

                if (dir == null)
                {
                    continue;
                }
                if (dir.Trim().Length == 0)
                {
                    continue;
                }
                if (!DirectoryWalker.IsWalkable(dir))
                {
                    continue;
                }
                //IEnumerable

                //foreach (string path in enumerable)

                foreach (FileInfo fi in DirectoryWalker.GetFileInfosRecursive(dir))
                {
                    if (status.Cancelled)
                    {
                        break;
                    }
                    // fe = enumerator as DirectoryWalker.FileEnumerator;
                    string s = Path.GetExtension(fi.Name);
                    foreach (string ext in extensions)
                    {
                        if (string.Compare(s, ext, true) == 0)
                        {
                            myparams.fileProcessor.ProcessFile(fi.FullName);
                            break;
                        }
                    }
                    num_file++;
                    if ((num_file % 101) == 1)
                    {
                        status.Description = string.Format("std file enum: {0} files - {1}", num_file, watch.ElapsedMilliseconds / 1000.0);
                    }
                }
            }
            myparams.fileProcessor.End(should_close);
            if (myparams.jobStatus == null)
            {
                status.RemoveFromQueue();
                status = null;
            }
            if (myparams.jobWatch == null)
            {
                watch = null;
            }
        }