Пример #1
0
 public static int GetTotalWeight(FileSearchData searchData)
 {
     return searchData.Files.Sum(file => GetFileHandler(file).Weight)+searchData.Folders.Count()*folderHandlerWeight;
 }
Пример #2
0
        public void StartAsync()
        {
            var task = new Task(() => {
                var searchData = new FileSearchData(rootFiles.Length == 0 ? string.Empty : IOUtils.FindRootPath(rootFiles));
                var rand = new Random();

                int[] entryCount = { 0 };
                int nextNotice = 0;

                Action updateNotice = () => {
                    if (--nextNotice < 0){
                        if (Refresh != null){
                            Refresh(entryCount[0]);
                        }

                        nextNotice = 100+rand.Next(50);
                    }
                };

                updateNotice();

                foreach(string rootFile in rootFiles){
                    if (cancelToken.IsCancellationRequested){
                        if (CancelFinish != null){
                            CancelFinish();
                        }

                        return;
                    }

                    bool? isDirectory = IOUtils.IsDirectory(rootFile);
                    if (!isDirectory.HasValue)continue;

                    if (isDirectory.Value){
                        foreach(IOEntry entry in EnumerateEntriesSafe(rootFile)){
                            if (cancelToken.IsCancellationRequested){
                                if (CancelFinish != null){
                                    CancelFinish();
                                }

                                return;
                            }

                            searchData.Add(entry);
                            ++entryCount[0];
                            updateNotice();
                        }
                    }
                    else{
                        searchData.Add(new IOEntry(IOEntry.Type.File, rootFile));
                        ++entryCount[0];
                        updateNotice();
                    }
                }

                if (Refresh != null){
                    Refresh(entryCount[0]);
                }

                if (Finish != null){
                    Finish(searchData);
                }
            }, cancelToken.Token);

            task.ContinueWith(originalTask => {
                if (Failure != null){
                    Failure(originalTask.Exception);
                }
            }, TaskContinuationOptions.OnlyOnFaulted);

            task.Start();
        }
Пример #3
0
        public void StartAsync()
        {
            var task = new Task(() => {
                var searchData = new FileSearchData(rootFiles.Length == 0 ? string.Empty : IOUtils.FindRootPath(rootFiles));
                var rand       = new Random();

                int[] entryCount = { 0 };
                int nextNotice   = 0;

                Action updateNotice = () => {
                    if (--nextNotice < 0)
                    {
                        if (Refresh != null)
                        {
                            Refresh(entryCount[0]);
                        }

                        nextNotice = 100 + rand.Next(50);
                    }
                };

                updateNotice();

                foreach (string rootFile in rootFiles)
                {
                    if (cancelToken.IsCancellationRequested)
                    {
                        if (CancelFinish != null)
                        {
                            CancelFinish();
                        }

                        return;
                    }

                    bool?isDirectory = IOUtils.IsDirectory(rootFile);
                    if (!isDirectory.HasValue)
                    {
                        continue;
                    }

                    if (isDirectory.Value)
                    {
                        foreach (IOEntry entry in EnumerateEntriesSafe(rootFile))
                        {
                            if (cancelToken.IsCancellationRequested)
                            {
                                if (CancelFinish != null)
                                {
                                    CancelFinish();
                                }

                                return;
                            }

                            searchData.Add(entry);
                            ++entryCount[0];
                            updateNotice();
                        }
                    }
                    else
                    {
                        searchData.Add(new IOEntry(IOEntry.Type.File, rootFile));
                        ++entryCount[0];
                        updateNotice();
                    }
                }

                if (Refresh != null)
                {
                    Refresh(entryCount[0]);
                }

                if (Finish != null)
                {
                    Finish(searchData);
                }
            }, cancelToken.Token);

            task.ContinueWith(originalTask => {
                if (Failure != null)
                {
                    Failure(originalTask.Exception);
                }
            }, TaskContinuationOptions.OnlyOnFaulted);

            task.Start();
        }
Пример #4
0
 public Project(FileSearchData searchData)
 {
     this.SearchData = searchData;
     this.cancelToken = new CancellationTokenSource();
 }