private bool PassesFilter(LocalRoot root, IEnumerable <RelativePath> paths, IDiagnosticsLog log = null)
        {
            var filter = GetFilterFor(root);

            if (!filter.Exists)
            {
                return(true);
            }
            var relativePath = RelativePath.Combine(paths);
            var match        = filter.Evaluate(relativePath);

            switch (match.Rule)
            {
            case FilterRule.Exclude:
                log?.Debug(new ExcludedByFilterEvent(root, relativePath, match));
                return(false);

            case FilterRule.Include:
                if (default(RelativePathMatcher).Equals(match))
                {
                    log?.Debug(new ExcludedByFilterEvent(root, relativePath, match));
                }
                return(true);

            default:
                throw new ArgumentOutOfRangeException($"Not a valid rule type: {match.Rule}");
            }
        }
Beispiel #2
0
        public LocalFilesystemStore(string rootPath, IStateSerialiserProvider serialiser, IDiagnosticsLog diagnosticsLog = null)
        {
            if (!PathUtils.IsNormalisedAbsolutePath(rootPath))
            {
                throw new ArgumentException($"Not a valid absolute path: {rootPath}", nameof(rootPath));
            }

            this.rootPath       = rootPath;
            this.serialiser     = serialiser;
            this.diagnosticsLog = diagnosticsLog;
        }
Beispiel #3
0
 public AtomicFile(string path, IStateSerialiser <T> serialiser, IDiagnosticsLog diagnosticsLog = null)
 {
     if (path == null)
     {
         throw new ArgumentNullException(nameof(path));
     }
     if (!PathUtils.IsNormalisedAbsolutePath(path))
     {
         throw new ArgumentException($"Not a valid absolute path: {path}", nameof(path));
     }
     this.path           = path;
     this.serialiser     = serialiser;
     this.diagnosticsLog = diagnosticsLog;
     backupPath          = path + ".backup";
     lockPath            = path + ".lock";
     directoryPath       = Path.GetDirectoryName(lockPath);
 }
        public AbstractPath MapToAbstractPath(QualifiedPath qualifiedPath, IDiagnosticsLog log = null)
        {
            var currentNode = qualifiedPath.Root;

            AssertLocalRootExistsInModel(currentNode);
            var traversed = new HashSet <LocalRoot> {
                currentNode
            };
            var paths = new Stack <RelativePath>();

            paths.Push(qualifiedPath.RelativePath);
            if (!PassesFilter(currentNode, paths, log))
            {
                return(null);
            }
            while (graftsByChild.TryGetValue(currentNode, out var graft))
            {
                currentNode = graft.GraftPoint.Root;
                paths.Push(graft.GraftPoint.RelativePath);
                // Sanity check. Should be impossible to configure such a situation.
                if (!traversed.Add(currentNode))
                {
                    throw new InvalidOperationException("Cycle detected in graph.");
                }
                if (!PassesFilter(currentNode, paths, log))
                {
                    return(null);
                }
            }
            foreach (var namedRoot in namedRoots)
            {
                if (namedRoot.LocalRoot != currentNode)
                {
                    continue;
                }
                return(new AbstractPath(namedRoot, RelativePath.Combine(paths)));
            }
            return(null);
        }
Beispiel #5
0
 public DiagnosticMiddleware(RequestDelegate next, IHostingEnvironment env, IDiagnosticsLog log)
 {
     _next = next;
     _env  = env;
     _log  = log;
 }