Esempio n. 1
0
        public IndexingPolicyViewModel(IndexingPolicy policy)
        {
            _isCreating = true;

            // deep clone the indexing policy
            var json = JsonConvert.SerializeObject(policy);

            Policy = JsonConvert.DeserializeObject <IndexingPolicy>(json);

            _isCreating = false;

            IncludedPaths.ListChanged += (s, e) =>
            {
                if (IncludedPaths.All(ip => !ip.HasErrors))
                {
                    RaisePropertyChanged(nameof(IncludedPaths));
                }
            };

            ExcludedPaths.ListChanged += (s, e) =>
            {
                if (ExcludedPaths.All(ep => !ep.HasErrors))
                {
                    RaisePropertyChanged(nameof(ExcludedPaths));
                }
            };

            PropertyChanged += (s, e) =>
            {
                if (e.PropertyName != nameof(IsValid))
                {
                    RaisePropertyChanged(nameof(IsValid));
                }
            };
        }
Esempio n. 2
0
        bool IsExcludedFromIndex(string fullPath, bool isDirectory)
        {
            var excluded = ExcludedPaths.Any(u => fullPath.ToUpperInvariant().Contains(u)) ||
                           !isDirectory && ContainsExcludedExtension(fullPath);

            if (excluded)
            {
                Log.LogDebug($"{IndexConfig.IndexName}: {fullPath} is excluded from index, {(!isDirectory ? "check extension" : "not check extension")}");
            }

            return(excluded);
        }
Esempio n. 3
0
        private void findResourcesInFolder(string folder, string baseFolder)
        {
            List <string> files = new List <string>();

            FileFilter.Split(';').ToList().ForEach(filter => { files = files.Concat(Directory.GetFiles(folder, filter)).ToList(); });

            files.AsParallel().ForAll(f =>
            {
                using (StreamReader stream = new StreamReader(f))
                {
                    int lineCount = 1;
                    int resCount  = 0;

                    string line = stream.ReadLine();

                    while (line != null)
                    {
                        if (line.Length < 250 && line.Length > 15)
                        {
                            patterns.ToList().ForEach(r =>
                            {
                                var matchCol = r.Matches(line);
                                for (int i = 0; i < matchCol.Count; i++)
                                {
                                    var m = matchCol[i];
                                    if (m.Groups["key"] != null)
                                    {
                                        addMatch(f, line, lineCount, m);
                                        ++resCount;
                                    }
                                }
                            });
                        }
                        ++lineCount;
                        line = stream.ReadLine();
                    }

                    Console.Out.WriteLine("*** " + f.Substring(baseFolder.Length) + " " + resCount);
                }
            });
            if (RecursiveSearchEnabled)
            {
                string[] directories = Directory.GetDirectories(folder);
                if (directories != null)
                {
                    directories
                    .Where(d => !ExcludedPaths.Any(p => p.Equals(Path.GetFileName(d), StringComparison.CurrentCultureIgnoreCase)) && !ExcludedPaths.Any(p => p.Equals(d, StringComparison.CurrentCultureIgnoreCase))).ToList()
                    .ForEach(d => findResourcesInFolder(d, baseFolder));
                }
            }
        }
Esempio n. 4
0
        public void Export()
        {
            sLastSaveTime = CTL_Tools.ThreadSafeTimeStamp();
            sShouldSave   = false;

            if (DEBUG_MODE)
            {
                Debug.Log("export");
            }

            StreamWriter _sw = null;

            try
            {
                string _filePath = GetFilePath();
                if (File.Exists(_filePath))
                {
                    File.Delete(_filePath);
                }

                _sw = File.CreateText(_filePath);
                WriteDataToStreamWriter("a", mAutoRefresh.ToString(), _sw);
                WriteDataToStreamWriter("b", mKeywordsList.Export(), _sw);
                WriteDataToStreamWriter("c", mCaseSensitive.ToString(), _sw);
                WriteDataToStreamWriter("d", ((int)mDisplayContainerType).ToString(), _sw);
                WriteDataToStreamWriter("e", mEnableHelpTooltips.ToString(), _sw);
                WriteDataToStreamWriter("f", ExcludedPaths.Export(), _sw);
                WriteDataToStreamWriter("g", ColumnSortIndex.ToString(), _sw);
                WriteDataToStreamWriter("h", mColumnSortAscending.ToString(), _sw);
                WriteDataToStreamWriter("i", GetColumnVisibilityExportString(), _sw);
                WriteDataToStreamWriter("j", mEnableCommentTooltip.ToString(), _sw);
                WriteDataToStreamWriter("k", mDisplayKeywordInCommentTooltip.ToString(), _sw);
                WriteDataToStreamWriter("l", mDisplayFilenameAndLineInCommentTooltip.ToString(), _sw);
                WriteDataToStreamWriter("m", ((int)mDisplayTooltipModifier).ToString(), _sw);
                WriteDataToStreamWriter("n", GetColumnSizeExportString(), _sw);
                WriteDataToStreamWriter("o", mSearchFieldContent, _sw);
                WriteDataToStreamWriter("p", ((int)mCommentClickModifier_OpenFile).ToString(), _sw);
                WriteDataToStreamWriter("q", ParseCSFiles.ToString(), _sw);
                WriteDataToStreamWriter("r", ParseJSFiles.ToString(), _sw);
                WriteDataToStreamWriter("s", ((int)KeywordSortOrder).ToString(), _sw);
                WriteDataToStreamWriter("t", TrimCommentOnParse.ToString(), _sw);
            }
            catch (Exception e) { Debug.LogError("Fail during prefs export:" + e.ToString()); }
            finally { if (_sw != null)
                      {
                          _sw.Dispose();
                      }
            }
        }
Esempio n. 5
0
        protected void OnPolicyChanged()
        {
            IncludedPaths.Clear();
            foreach (var vm in Policy.IncludedPaths.Select(ip => new IncludedPathViewModel(ip)))
            {
                IncludedPaths.Add(vm);
            }

            ExcludedPaths.Clear();
            foreach (var vm in Policy.ExcludedPaths.Select(ep => new ExcludedPathViewModel(ep)))
            {
                ExcludedPaths.Add(vm);
            }

            if (_isCreating)
            {
                IsChanged = false;
            }
        }
Esempio n. 6
0
        bool IsExcludedFromIndex(string fullPath, WatcherChangeTypes changeType)
        {
            if (changeType == WatcherChangeTypes.Deleted) // Unable to determine path is folder or file under deleted scenario
            {
                var excluded  = ExcludedPaths.Any(u => fullPath.ToUpperInvariant().Contains(u));
                var extension = Path.GetExtension(fullPath).ToUpperInvariant();

                if (extension != string.Empty)
                {
                    excluded = excluded || ExcludedExtensions.Contains(extension) || IncludedExtensions.Length > 0 && !IncludedExtensions.Contains(extension);
                }

                if (excluded)
                {
                    Log.LogDebug($"{IndexConfig.IndexName}: {fullPath} is excluded from index, change type: {WatcherChangeTypes.Deleted}");
                }

                return(excluded);
            }

            return(IsExcludedFromIndex(fullPath, IsDirectory(fullPath)));
        }
Esempio n. 7
0
 public MockEnvironment Exclude(Regex path)
 {
     ExcludedPaths.Add(path);
     return(this);
 }
Esempio n. 8
0
        /// <summary>
        ///     Gets the file system infos.
        /// </summary>
        /// <param name="directory">The directory.</param>
        /// <param name="currentLevel">The current level.</param>
        /// TODO Edit XML Comment Template for GetFileSystemInfos
        private void GetFileSystemInfos(
            DirectoryInfo directory,
            int currentLevel)
        {
            try
            {
                if (!ExcludedPaths.IsNullOrEmpty() &&
                    ExcludedPaths.ContainsIgnoreCase(directory.FullName))
                {
                    return;
                }

                try
                {
                    var directorySizeInfo = new FileSystemSizeInfo(directory);

                    if (MinFolderSize != null &&
                        directorySizeInfo.Size < MinFolderSize.Value ||
                        MaxFolderSize != null &&
                        directorySizeInfo.Size > MaxFolderSize.Value ||
                        MinFolderContents != null &&
                        directorySizeInfo.ContentsCount
                        < MinFolderContents.Value ||
                        MaxFolderContents != null &&
                        directorySizeInfo.ContentsCount
                        > MaxFolderContents.Value)
                    {
                        return;
                    }

                    if (directorySizeInfo.PathLevels > MaxPathLevels)
                    {
                        MaxPathLevels = directorySizeInfo.PathLevels;
                    }

                    FileSystemSizeInfos.Add(directorySizeInfo);
                }
                catch (UnauthorizedAccessException)
                {
                }

                foreach (var fileSystemInfo in directory.GetFileSystemInfos())
                {
                    CancellationToken.ThrowIfCancellationRequested();

                    var fileInfo = fileSystemInfo as FileInfo;

                    if (fileInfo != null)
                    {
                        if (MinFileSize != null &&
                            fileInfo.Length < MinFileSize.Value ||
                            MaxFileSize != null &&
                            fileInfo.Length > MaxFileSize.Value ||
                            ShouldExcludeExtensions &&
                            Extensions.ContainsIgnoreCase(fileInfo.Extension) ||
                            !ShouldExcludeExtensions &&
                            !Extensions.ContainsIgnoreCase(
                                fileInfo.Extension))
                        {
                            continue;
                        }

                        var fileSizeInfo = new FileSystemSizeInfo(fileInfo);

                        if (fileSizeInfo.PathLevels > MaxPathLevels)
                        {
                            MaxPathLevels = fileSizeInfo.PathLevels;
                        }

                        FileSystemSizeInfos.Add(fileSizeInfo);
                    }

                    var directoryInfo = fileSystemInfo as DirectoryInfo;

                    if (directoryInfo == null ||
                        Scope == Scope.NoChildren ||
                        Scope == Scope.ImmediateChildren && currentLevel > 0)
                    {
                        continue;
                    }

                    GetFileSystemInfos(directoryInfo, currentLevel + 1);
                }
            }
            catch (UnauthorizedAccessException)
            {
            }
        }
    /// <summary>
    /// Checks if the file should be excluded from the deletion.
    /// </summary>
    /// <param name="path">Full path to the file.</param>
    private bool IsFileExcluded(string path)
    {
        var relativePath = path.Substring(DirsToSearch.Where(path.StartsWith).First().Length + 1);

        return(ExcludedPaths.Any(relativePath.StartsWith));
    }