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()));
        }
Пример #2
0
        public HttpResponseMessage GetStat(PathStatisticRequestModel model)
        {
            if (model == null || string.IsNullOrWhiteSpace(model.FullPath))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Model is not valid"));
            }

            var result = _directoryBrowserService.GetDirStatistics(model);

            if (result.Status == RequestResultStatus.Success)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, result));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, result));
            }
        }