Пример #1
0
        /// <summary>
        /// Excludes a mapped path, optionally based on the given HTTP method. If HTTP method is not specified, every request to this path will not be used by <see cref="HttpSignatureMiddleware"/>.
        /// </summary>
        /// <param name="pathString">The path to exclude.</param>
        /// <param name="httpMethods">The HTTP methods to exclude for the given path.</param>
        public HttpSignatureOptions IgnorePath(PathString pathString, params string[] httpMethods)
        {
            if (pathString == null)
            {
                throw new ArgumentNullException(nameof(pathString), "Cannot ignore a null path.");
            }
            var path = pathString.Value.EnsureLeadingSlash().ToTemplatedDynamicPath();

            // No HTTP methods specified, so exclude just the path (implies that all HTTP methods will be excluded for this path).
            if (httpMethods?.Length == 0)
            {
                IgnoredPaths.Add(path, "*");
                return(this);
            }
            // Validate HTTP method.
            // There are more of course, but this seems enough for our needs.
            foreach (var method in httpMethods)
            {
                var isValidHttpMethod = HttpMethods.IsGet(method) || HttpMethods.IsPost(method) || HttpMethods.IsPut(method) || HttpMethods.IsDelete(method) || HttpMethods.IsPatch(method);
                if (!isValidHttpMethod)
                {
                    throw new ArgumentException($"HTTP method {method} is not valid.");
                }
            }
            if (!IgnoredPaths.ContainsKey(path))
            {
                IgnoredPaths.Add(path, string.Join('|', httpMethods));
            }
            else
            {
                var methods = IgnoredPaths[path].Split('|').Union(httpMethods);
                IgnoredPaths[path] = string.Join('|', methods);
            }
            return(this);
        }
Пример #2
0
        internal void OnDeserialized(StreamingContext context)
        {
            if (null == IgnoredPaths)
            {
                //  https://www.microsoft.com/en-us/wdsi/help/folder-variables
                IgnoredPaths = new List <string>
                {
                    "%temp%",
                    "%tmp%",
                    "%ProgramFiles%",
                    "%ProgramFiles(x86)%",
                    "%ProgramW6432%",
                    "%windir%",
                    "%SystemRoot%"
                };
            }

            // Recycle Bins
            if (IgnoreCurrentPath)
            {
                //  ignore the current path
                IgnoredPaths.Add(Directory.GetCurrentDirectory());
            }

            // Recycle Bins
            if (IgnoreRecycleBins)
            {
                // Add the recycle bins as well.
                var drvs = DriveInfo.GetDrives();
                foreach (var drv in drvs.Where(d => d.DriveType == DriveType.Fixed))
                {
                    IgnoredPaths.Add(Path.Combine(drv.Name, "$recycle.bin"));
                }
            }

            // internet cache
            if (IgnoreInternetCache)
            {
                IgnoredPaths.Add(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));
            }

            if (!ComponentsPaths.Any())
            {
                throw new ArgumentException("You must have at least one valid component path!");
            }
        }
Пример #3
0
        /// <summary>
        /// Adds a new CheckBox with the given <paramref name="folder"/> to the list.
        /// </summary>
        /// <param name="folder">Folder to add.</param>
        private void AddCheckBox(string folder)
        {
            SenpaiDirectory dir = new SenpaiDirectory(folder, this);

            if (IgnoredPaths.Contains(folder))
            {
                dir.Opacity    = 0.5;
                dir.Visibility = Visibility.Collapsed;
            }

            if (FavoritePaths.Contains(folder))
            {
                dir.BackgroundColor = new SolidColorBrush(Colors.Yellow);
            }

            _directoryList.Add(dir);
            NotifyOfPropertyChange(() => CanInvertCheckBoxes);
        }
Пример #4
0
        /// <summary>
        /// Adds/removes the right clicked CheckBox path to/from the <see cref="IgnoredPaths"/>
        /// </summary>
        public void IgnorePath()
        {
            if (_currentRightClickedDirectory.Opacity == 1.0)
            {
                File.AppendAllText("IgnoredPaths.txt", _currentRightClickedDirectory.FullPath + "\r\n");
                IgnoredPaths.Add(_currentRightClickedDirectory.FullPath);
                _currentRightClickedDirectory.Opacity = 0.5;

                if (!ShowIgnoredFolders)
                {
                    _currentRightClickedDirectory.Visibility = Visibility.Collapsed;
                }

                Logging.LogInfo("Manually added " + _currentRightClickedDirectory.FullPath + " to IgnoredPaths.txt");
            }
            else
            {
                List <string> ignoredPaths = File.ReadAllLines("IgnoredPaths.txt").ToList();
                ignoredPaths.Remove(_currentRightClickedDirectory.FullPath);
                File.WriteAllLines("IgnoredPaths.txt", ignoredPaths.ToArray());
                _currentRightClickedDirectory.Opacity = 1.0;
                Logging.LogInfo("Manually removed " + _currentRightClickedDirectory.FullPath + " from FavoritePaths.txt");
            }
        }