Esempio n. 1
0
        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}");
            }
        }
        private Graft CreateGraftInternal(LocalRoot parent, string relativePath, LocalRoot child)
        {
            var segments  = PathUtils.GetRelativePathSegments(relativePath);
            var graftPath = fileSystemApi.GetCanonicalRelativePath(parent.RootUri.LocalPath, segments).AsContainer();

            return(new Graft(new QualifiedPath(parent, graftPath), child));
        }
 private bool TryAddLocalRoot(LocalRoot node, LocalRoot validEnclosingParent, out ConfigurationRuleViolation violation)
 {
     if (nodes.Contains(node))
     {
         violation = new DuplicateLocalRootDeclaration(node);
         return(false);
     }
     if (nodePaths.Contains(node))
     {
         violation = new DuplicateLocalRootDeclaration(node);
         return(false);
     }
     foreach (var existing in nodes)
     {
         if (node.RootUri.IsBaseOf(existing.RootUri))
         {
             violation = new OverlappingLocalRootDeclaration(node, existing);
             return(false);
         }
         if (existing == validEnclosingParent)
         {
             continue;
         }
         if (existing.RootUri.IsBaseOf(node.RootUri))
         {
             violation = new OverlappingLocalRootDeclaration(existing, node);
             return(false);
         }
     }
     nodes.Add(node);
     nodePaths.Add(node);
     violation = null;
     return(true);
 }
Esempio n. 4
0
 public ExcludedByFilterEvent(LocalRoot localRoot, RelativePath relativePath, RelativePathMatcher matcher) : base(localRoot, relativePath)
 {
     if (matcher.Rule != FilterRule.Exclude)
     {
         throw new ArgumentException("Matcher is not an exclude rule.");
     }
     this.matcher = matcher;
 }
Esempio n. 5
0
 private void AssertLocalRootExistsInModel(LocalRoot root)
 {
     if (rootsLongestToShortest.Contains(root))
     {
         return;
     }
     throw new InvalidOperationException($"Unrecognised LocalRoot: {root}");
 }
Esempio n. 6
0
 public Graft(QualifiedPath graftPoint, LocalRoot childRoot)
 {
     if (!graftPoint.RelativePath.IsContainer())
     {
         throw new ArgumentException($"Graft point must be a container: {graftPoint}", nameof(graftPoint));
     }
     GraftPoint = graftPoint;
     ChildRoot  = childRoot ?? throw new ArgumentNullException(nameof(childRoot));
 }
Esempio n. 7
0
 public NamedRoot(string name, LocalRoot localRoot)
 {
     if (string.IsNullOrWhiteSpace(name))
     {
         throw new ArgumentException("Name cannot be null or whitespace.", nameof(name));
     }
     Name      = name;
     LocalRoot = localRoot ?? throw new ArgumentNullException(nameof(localRoot));
 }
        public ConfigurationRuleViolation AddGraftPoint(LocalRoot parent, string relativePath, LocalRoot child)
        {
            if (!nodes.Contains(parent))
            {
                throw new InvalidOperationException($"Parent is not yet declared: {parent}");
            }
            var graft = CreateGraftInternal(parent, relativePath, child);

            return(AddGraftInternal(graft));
        }
        public ConfigurationRuleViolation AddLocation(LocalRoot parent, string relativePath, out LocalRoot child)
        {
            if (!nodes.Contains(parent))
            {
                throw new InvalidOperationException($"Parent is not yet declared: {parent}");
            }
            var childRootPath = new Uri(parent.RootUri, relativePath).LocalPath;

            child = fileSystemApi.CreateStorageRoot(childRootPath.AsDirectoryPath(), parent.Casing);
            var graft = CreateGraftInternal(parent, relativePath, child);

            return(AddGraftInternal(graft, parent));
        }
        public ConfigurationRuleViolation AddNamedRoot(string name, LocalRoot node)
        {
            var namedRoot = new NamedRoot(name, node);

            if (namedRoots.TryGetValue(namedRoot.Name, out var conflict))
            {
                return(errors.Record(new DuplicateNamedRootDeclaration(namedRoot, conflict)));
            }
            if (!TryAddLocalRoot(node, null, out var violation))
            {
                return(errors.Record(violation));
            }
            namedRoots.Add(namedRoot.Name, namedRoot);
            return(null);
        }
        public ConfigurationRuleViolation AddFilter(LocalRoot owner, RelativePathMatcher filterRule)
        {
            if (!nodes.Contains(owner))
            {
                throw new InvalidOperationException($"Owner is not yet declared: {owner}");
            }

            if (!filters.TryGetValue(owner, out var list))
            {
                list = new List <RelativePathMatcher>();
                filters.Add(owner, list);
            }
            list.Add(filterRule);
            return(null);
        }
 private ConfigurationRuleViolation AddGraftInternal(Graft graft, LocalRoot validEnclosingParent = null)
 {
     if (grafts.TryGetValue(graft.GraftPoint, out var conflict))
     {
         return(errors.Record(new DuplicateGraftDeclaration(graft, conflict)));
     }
     if (graft.ChildRoot.Casing != graft.GraftPoint.Root.Casing)
     {
         return(errors.Record(new FileSystemCasingConflict(graft)));
     }
     if (!TryAddLocalRoot(graft.ChildRoot, validEnclosingParent, out var violation))
     {
         return(errors.Record(violation));
     }
     grafts.Add(graft.GraftPoint, graft);
     return(null);
 }
Esempio n. 13
0
 public RelativePathFilter GetFilterFor(LocalRoot root)
 {
     AssertLocalRootExistsInModel(root);
     filtersByRoot.TryGetValue(root, out var filter);
     return(filter);
 }
Esempio n. 14
0
 protected FilterEvent(LocalRoot localRoot, RelativePath relativePath)
 {
     this.localRoot    = localRoot;
     this.relativePath = relativePath;
 }
Esempio n. 15
0
 public QualifiedPath(LocalRoot root, RelativePath relativePath)
 {
     Root         = root ?? throw new ArgumentNullException(nameof(root));
     RelativePath = relativePath ?? throw new ArgumentNullException(nameof(relativePath));
 }