public void CheckExecTime(string path, DirectoryStat ds) { //remove directory from ThreadExecPoint's because it is ready (again) to enum if (CurrentThreadExecPoint != null) { CurrentThreadExecPoint.Points.Remove(path); } if (!ds.isComplete) { return; } if ((DateTime.Now - StartOfRecursion).Seconds >= 1) { // other task threads wait to change UncompletedRecursions lock (locker) { ds.isComplete = false; if (CurrentThreadExecPoint == null) { CurrentThreadExecPoint = new StatisticTaskExecPoint(); CurrentThreadExecPoint.DirectoryStat = ds; ds.ContinueCursor = UncompletedRecursions.Count; CurrentThreadExecPoint.Id = ds.ContinueCursor; UncompletedRecursions.Add(CurrentThreadExecPoint); } } } }
public RequestResult <DirectoryStat> GetDirStatistics(PathStatisticRequestModel model) { string path = model.FullPath; if (!_worker.PathExists(path)) { return(new RequestResult <DirectoryStat>(RequestResultStatus.Error, null, "Such directory does not exist")); } path = path.TrimEnd(((char)92)); currentPath = path; if (path.EndsWith(":")) { path += @"\"; } StartOfRecursion = DateTime.Now; DirectoryStat ds = new DirectoryStat(); ds.isComplete = true; ds.FullPath = path; if (!string.IsNullOrWhiteSpace(model.Cursor)) { int tmp; if (int.TryParse(model.Cursor, out tmp) && UncompletedRecursions.Count > tmp) { CurrentThreadExecPoint = UncompletedRecursions[tmp]; // previous results will be considered in further enum ds = CurrentThreadExecPoint.DirectoryStat; ds.isComplete = true; } //continue enumeration if (CurrentThreadExecPoint != null && CurrentThreadExecPoint.Id == tmp && ds.FullPath == path) { //points collection will change(remove processed items), //so we fix initial collection in array string[] arr = CurrentThreadExecPoint.Points.ToArray(); foreach (string pth in arr) { GetDirStatistics(pth, ds); } } else { return(new RequestResult <DirectoryStat>(RequestResultStatus.Error, null, "Can not find proper cursor state object ")); } } else { GetDirStatistics(path, ds); } return(new RequestResult <DirectoryStat>(RequestResultStatus.Success, ds, "worker instance " + _worker.instanceIdx.ToString())); }