protected virtual TNode FindNearestItem(string path, Func <string, string> transform) { var pr = RepositoryPath.IsValidPath(path); if (pr != RepositoryPath.PathResult.Correct) { throw RepositoryPath.GetInvalidPathException(pr, path); } var p = path.ToLowerInvariant(); TNode tnode; while (true) { if (Items.TryGetValue(transform(p), out tnode)) { return(tnode); } if (p == "/root" || p == "/" || p == string.Empty) { break; } p = RepositoryPath.GetParentPath(p); } return(null); }
protected virtual TNode[] FindNearestItems(string path, Func <string, string> transform) { var pr = RepositoryPath.IsValidPath(path); if (pr != RepositoryPath.PathResult.Correct) { throw RepositoryPath.GetInvalidPathException(pr, path); } var p = path.ToLowerInvariant(); while (true) { // find all items in the same folder var items = Items.Where(kv => string.Compare(RepositoryPath.GetParentPath(kv.Key), transform(p), StringComparison.InvariantCultureIgnoreCase) == 0) .Select(kv => kv.Value).ToArray(); if (items.Length > 0) { return(items); } if (p == "/root" || p == "/" || p == string.Empty) { break; } p = RepositoryPath.GetParentPath(p); } return(null); }
public override void Execute(ExecutionContext context) { context.AssertRepositoryStarted(); var sourcePath = ResolvePackagePath(Source, context); if (!IO.Directory.Exists(sourcePath) && !IO.File.Exists(sourcePath)) { throw new PackagingException(SR.Errors.Import.SourceNotFound); } var checkResult = RepositoryPath.IsValidPath(Target); if (checkResult != RepositoryPath.PathResult.Correct) { if (!Target.StartsWith("/root", StringComparison.OrdinalIgnoreCase)) { throw new PackagingException(SR.Errors.Import.InvalidTarget, RepositoryPath.GetInvalidPathException(checkResult, Target)); } } if (!Node.Exists(Target)) { throw new PackagingException(SR.Errors.Import.TargetNotFound); } base.DoImport(null, sourcePath, Target); }
/// <summary> /// Default implementation of the checking name during saving a content. /// Checks whether the given name does not match with the configured InvalidNameCharsPattern. /// If the pattern matches, an InvalidPathException will be thrown. /// </summary> protected virtual void AssertNameIsValid(string name) { var pattern = ContentNaming.InvalidNameCharsPattern; if (!String.IsNullOrEmpty(pattern)) { var match = Regex.Match(name, pattern); if (match.Length != 0) { throw RepositoryPath.GetInvalidPathException(RepositoryPath.PathResult.InvalidNameChar, name); } } }
public override void Execute(ExecutionContext context) { context.AssertRepositoryStarted(); try { string sourcePath; if (SourceIsRelativeTo == PathRelativeTo.Package) { sourcePath = ResolvePackagePath(Source, context); } else { sourcePath = ResolveTargetPath(Source, context);// ResolveAllTargets(Source, context); } if (!IO.Directory.Exists(sourcePath) && !IO.File.Exists(sourcePath)) { throw new PackagingException(SR.Errors.Import.SourceNotFound + "\nSource value:" + sourcePath); } var checkResult = RepositoryPath.IsValidPath(Target); if (checkResult != RepositoryPath.PathResult.Correct) { if (!Target.StartsWith("/root", StringComparison.OrdinalIgnoreCase)) { throw new PackagingException(SR.Errors.Import.InvalidTarget, RepositoryPath.GetInvalidPathException(checkResult, Target)); } } if (!Node.Exists(Target)) { throw new PackagingException(SR.Errors.Import.TargetNotFound); } DoImport(null, sourcePath, Target); } catch (InvalidStepParameterException) { Logger.LogMessage("Import step can work with valid paths only."); throw; } }