public static FileContext GetFileContext([NotNull] IProject project, [NotNull] IConfiguration configuration, [NotNull] ISourceFile sourceFile) { var localFileName = "/" + PathHelper.NormalizeItemPath(PathHelper.UnmapPath(project.Options.ProjectDirectory, sourceFile.AbsoluteFileName)).TrimStart('/'); string database = null; var isExtern = false; var itemPathConfig = string.Empty; var localFileDirectory = string.Empty; var serverFileDirectory = string.Empty; var uploadMedia = true; foreach (var pair in configuration.GetSubKeys(Constants.Configuration.BuildProjectFiles)) { var key = Constants.Configuration.BuildProjectFiles + ":" + pair.Key; var localDirectory = PathHelper.NormalizeItemPath(configuration.GetString(key + ":project-directory")); if (!localFileName.StartsWith(localDirectory, StringComparison.OrdinalIgnoreCase)) { continue; } var includes = configuration.GetString(key + ":include"); var excludes = configuration.GetString(key + ":exclude"); if (!string.IsNullOrEmpty(includes) && !string.IsNullOrEmpty(localDirectory)) { includes = PathHelper.NormalizeItemPath(localDirectory).TrimEnd('/') + "/" + PathHelper.NormalizeItemPath(includes).TrimStart('/'); } if (!string.IsNullOrEmpty(excludes) && !string.IsNullOrEmpty(localDirectory)) { includes = PathHelper.NormalizeItemPath(localDirectory).TrimEnd('/') + "/" + PathHelper.NormalizeItemPath(excludes).TrimStart('/'); } if (!string.IsNullOrEmpty(includes) || !string.IsNullOrEmpty(excludes)) { var pathMatcher = new PathMatcher(includes, excludes); if (!pathMatcher.IsMatch(localFileName)) { continue; } } localFileDirectory = localDirectory; serverFileDirectory = PathHelper.NormalizeItemPath(configuration.GetString(key + ":website-directory")); itemPathConfig = configuration.GetString(key + ":item-path"); database = configuration.Get(key + ":database"); isExtern = configuration.GetBool(key + ":external-references"); uploadMedia = configuration.GetBool(key + ":upload-media", true); break; } var filePath = PathHelper.GetFilePath(project, sourceFile, localFileDirectory, serverFileDirectory); var itemName = PathHelper.GetItemName(sourceFile); var itemPath = PathHelper.GetItemPath(project, sourceFile, localFileDirectory, itemPathConfig); var databaseName = !string.IsNullOrEmpty(database) ? database : project.Options.DatabaseName; return(new FileContext(itemName, itemPath, filePath, databaseName, isExtern, uploadMedia)); }
public void SaveRenamedMappedObjectOverridesExistingEntry() { string id = "id"; string oldName = "my"; string newName = "newMy"; string path = Path.GetTempPath(); string parentId = "ParentId"; string oldToken = "oldToken"; string newToken = "newToken"; var matcher = new PathMatcher(path, "/"); var storage = new MetaDataStorage(this.engine, matcher); var rootFolder = new MappedObject("/", parentId, MappedObjectType.Folder, null, "token"); storage.SaveMappedObject(rootFolder); var folder = new MappedObject(oldName, id, MappedObjectType.Folder, parentId, oldToken); storage.SaveMappedObject(folder); var savedObject = storage.GetObjectByRemoteId(id); savedObject.Name = newName; savedObject.LastChangeToken = newToken; storage.SaveMappedObject(savedObject); Assert.That(storage.GetObjectByLocalPath(Mock.Of <IDirectoryInfo>(d => d.FullName == Path.Combine(path, oldName))), Is.Null); Assert.That(storage.GetObjectByLocalPath(Mock.Of <IDirectoryInfo>(d => d.FullName == Path.Combine(path, newName))), Is.EqualTo(savedObject)); }
public void ConstructorTakesLocalAndRemotePath() { var matcher = new PathMatcher(this.localpath, this.remotepath); Assert.AreEqual(this.localpath, matcher.LocalTargetRootPath); this.AssertPathEqual(this.remotepath, matcher.RemoteTargetRootPath); }
public ProjectDirectoryToWebsiteItemPathMapper([NotNull] string projectDirectory, [NotNull] string databaseName, [NotNull] string itemPath, [NotNull] string include, [NotNull] string exclude, bool isImport, bool uploadMedia) { ProjectDirectory = '\\' + PathHelper.NormalizeFilePath(projectDirectory).Trim('\\'); ItemPath = '/' + PathHelper.NormalizeItemPath(itemPath).Trim('/'); DatabaseName = databaseName; Include = include; Exclude = exclude; IsImport = isImport; UploadMedia = uploadMedia; if (string.IsNullOrEmpty(Include) && string.IsNullOrEmpty(Exclude)) { return; } if (!string.IsNullOrEmpty(include)) { include = ProjectDirectory.TrimEnd('\\') + '\\' + PathHelper.NormalizeFilePath(include).Trim('\\'); } if (!string.IsNullOrEmpty(exclude)) { exclude = ProjectDirectory.TrimEnd('\\') + '\\' + PathHelper.NormalizeFilePath(exclude).Trim('\\'); } PathMatcher = new PathMatcher(include, exclude); }
private static bool TryFindShortestReplacementPath(string path, PathMatcher matcher, out string result) { if (matcher(path, out result)) { return(true); } int num = 100; int num2 = path.Length - 1; while (true) { if (num2 > 0 && path[num2] != '.') { num2--; continue; } if (path[num2] == '.') { string path2 = path.Substring(0, num2); if (matcher(path2, out result)) { result += path.Substring(num2); return(true); } } num2--; num--; if (num2 <= 0 || num <= 0) { break; } } result = null; return(false); }
public void GetRelativePath() { var matcher = new PathMatcher(this.localpath, this.remotepath); string folderName = "new"; string newLocalPath = Path.Combine(this.localpath, folderName); Assert.That(matcher.GetRelativeLocalPath(newLocalPath), Is.EqualTo(folderName)); }
public void GetRelativePathDoesNotStartWithSlash() { this.localpath = this.localpath.EndsWith(Path.DirectorySeparatorChar.ToString()) ? this.localpath.Substring(0, this.localpath.Length - 1) : this.localpath; var matcher = new PathMatcher(this.localpath, "/"); string folderName = "new"; Assert.That(matcher.GetRelativeLocalPath(Path.Combine(this.localpath, folderName)).StartsWith(Path.DirectorySeparatorChar.ToString()), Is.False); }
public void LastCommonChunk_NoMatch() { var pathA = new PathInfo(@"C:\Users\Alice\Documents\Codes\OpenSource\Project\README.md"); var pathB = new PathInfo(@"https://filestore.cloud.example/#!/AJones/Files/"); string expected = ""; string actual = PathMatcher.LastCommonChunk(pathA, pathB); Assert.AreEqual(expected, actual); }
public void Resituate_OneMatchingChunk_Normal() { string filePathA = @"C:\Users\Alice\Documents\Codes\OpenSource\Project\README.md"; string filePathB = @"https://filestore.cloud.example/Alice/"; var actual = PathMatcher.Resituate(filePathA, filePathB); var expected = @"https://filestore.cloud.example/Alice/Documents/Codes/OpenSource/Project/README.md"; Assert.AreEqual(expected, actual); }
public void Resituate_NoMatchesJustPutSourceFileInDestDir() { string filePathA = @"C:\Users\Alice\Documents\Codes\OpenSource\Project\README.md"; string filePathB = @"https://filestore.cloud.example/#!/AJones/Files/"; var actual = PathMatcher.Resituate(filePathA, filePathB); var expected = @"https://filestore.cloud.example/#!/AJones/Files/README.md"; Assert.AreEqual(expected, actual); }
public void Resituate_UseLastOfMultipleMatches() { string filePathA = @"C:\Users\Alice\Documents\Codes\OpenSource\Project\README.md"; string filePathB = @"https://filestore.cloud.example/#!/Alice/OpenSource/"; var actual = PathMatcher.Resituate(filePathA, filePathB); var expected = @"https://filestore.cloud.example/#!/Alice/OpenSource/Project/README.md"; Assert.AreEqual(expected, actual); }
public void Resituate_MatchesInSkewedOrder() { string filePathA = @"C:\Users\Alice\Documents\OpenSource\Codes\Project\README.md"; string filePathB = @"https://filestore.cloud.example/Alice/Codes/OpenSource/"; //The correct behaviour is, in fact, to match on the 'OpenSource' chunk // and then copy the directory tree after that from the source var expected = @"https://filestore.cloud.example/Alice/Codes/OpenSource/Codes/Project/README.md"; var actual = PathMatcher.Resituate(filePathA, filePathB); Assert.AreEqual(expected, actual); }
public void ConstructorTest() { var matcher = new PathMatcher(this.localpath, this.remotepath); Assert.AreEqual(this.localpath, matcher.LocalTargetRootPath); AssertPathEqual(this.remotepath, matcher.RemoteTargetRootPath); try { new PathMatcher(null, this.remotepath); Assert.Fail(); } catch (ArgumentException) { } try { new PathMatcher(null, null); Assert.Fail(); } catch (ArgumentException) { } try { new PathMatcher(this.localpath, null); Assert.Fail(); } catch (ArgumentException) { } try { new PathMatcher(string.Empty, this.remotepath); Assert.Fail(); } catch (ArgumentException) { } try { new PathMatcher(this.localpath, string.Empty); Assert.Fail(); } catch (ArgumentException) { } }
public void FindRootFolder() { string id = "id"; string path = Path.GetTempPath(); var fsInfo = new DirectoryInfoWrapper(new DirectoryInfo(path)); var matcher = new PathMatcher(path, "/"); var storage = new MetaDataStorage(this.engine, matcher); var rootFolder = new MappedObject("/", id, MappedObjectType.Folder, null, "token"); storage.SaveMappedObject(rootFolder); Assert.That(storage.GetObjectByRemoteId(id), Is.Not.Null, "Not findable by ID"); Assert.That(storage.GetObjectByLocalPath(fsInfo), Is.Not.Null, "Not findable by path"); }
public void SetUp() { _repository = new MockRepository(MockBehavior.Strict); _config = _repository.Create <Configuration>(); _matcher = new DefaultPathMatcher(); _combiner = new DefaultPathCombiner(); Target = new ClientResourcesPathBuilder ( _config.Object, _matcher, _combiner ); }
public void CanCreateRemotePathTest() { string local = Path.Combine(this.localpath, "test"); string wrong = Path.Combine("wrong", "path", "on", "client", "test"); var matcher = new PathMatcher(this.localpath, this.remotepath); Assert.IsTrue(matcher.CanCreateRemotePath(this.localpath)); Assert.IsTrue(matcher.CanCreateRemotePath(local)); Assert.IsFalse(matcher.CanCreateRemotePath(wrong)); var localFolder = new DirectoryInfo(Path.Combine(this.localpath, "test2")); Assert.IsTrue(matcher.CanCreateRemotePath(localFolder)); var wrongFolder = new DirectoryInfo(wrong); Assert.IsFalse(matcher.CanCreateRemotePath(wrongFolder)); }
public void MatchesTest() { var matcher = new PathMatcher(this.localpath, this.remotepath); Assert.IsTrue(matcher.Matches(this.localpath, this.remotepath)); string sameSubfolder = "bla"; Assert.IsTrue(matcher.Matches(Path.Combine(this.localpath, sameSubfolder), this.remotepath + "/" + sameSubfolder)); sameSubfolder = Path.Combine("sub", "folder"); Assert.IsTrue(matcher.Matches(Path.Combine(this.localpath, sameSubfolder), this.remotepath + "/" + sameSubfolder)); string anotherFolder = "another"; Assert.IsFalse(matcher.Matches(Path.Combine(this.localpath, sameSubfolder), this.remotepath + "/" + anotherFolder)); string subfolderOfSame = Path.Combine(sameSubfolder, "sub"); Assert.IsFalse(matcher.Matches(Path.Combine(this.localpath, sameSubfolder), this.remotepath + "/" + subfolderOfSame)); Assert.IsFalse(matcher.Matches(Path.Combine(this.localpath, subfolderOfSame), this.remotepath + "/" + sameSubfolder)); string wrongStartingFolder = "wrong"; try { matcher.Matches(Path.Combine(this.localpath, wrongStartingFolder), wrongStartingFolder); Assert.Fail("Should throw exception on wrong path start"); } catch (ArgumentOutOfRangeException) { } try { matcher.Matches(wrongStartingFolder, wrongStartingFolder); Assert.Fail("Should throw exception on wrong path start"); } catch (ArgumentOutOfRangeException) { } try { matcher.Matches(wrongStartingFolder, this.remotepath + "/" + wrongStartingFolder); Assert.Fail("Should throw exception on wrong path start"); } catch (ArgumentOutOfRangeException) { } }
public void CrossPathCreatingTest() { var matcher = new PathMatcher(this.localpath, this.remotepath); string result = matcher.CreateRemotePath(this.localpath); AssertPathEqual(this.remotepath, result); result = matcher.CreateLocalPath(result); AssertPathEqual(this.localpath, result); result = matcher.CreateRemotePath(Path.Combine(this.localpath, "sub")); result = matcher.CreateLocalPath(result); AssertPathEqual(Path.Combine(this.localpath, "sub"), result); result = matcher.CreateLocalPath(this.remotepath + "/sub"); result = matcher.CreateRemotePath(result); AssertPathEqual(this.remotepath + "/sub", result); }
public void CreationViaARegexFilterConfigurerPrependsApplicationFullPathToRegex() { IApplication application = new Application(Path.GetFullPath(".")); FileSystemApplicationWatcher w = (FileSystemApplicationWatcher)DefaultApplicationWatcherFactory.Instance.CreateApplicationWatcher(application); Assert.AreEqual(1, w.DisallowFilters.Count); Assert.AreEqual(1, w.AllowFilters.Count); RegularExpressionFilter filter1 = w.AllowFilters[0] as RegularExpressionFilter; Assert.AreEqual( PathMatcher.ForwardifySlashes(application.FullPath + "/bin/**/*.*"), filter1.Patterns[0]); RegularExpressionFilter filter2 = w.DisallowFilters[0] as RegularExpressionFilter; Assert.AreEqual( PathMatcher.ForwardifySlashes(application.FullPath + "/**/*.log"), filter2.Patterns[0]); }
public void CanCreateLocalPathTest() { string remote = this.remotepath + "/test"; string wrong = "/wrong/path/on/server/test"; var matcher = new PathMatcher(this.localpath, this.remotepath); Assert.IsTrue(matcher.CanCreateLocalPath(this.remotepath)); Assert.IsTrue(matcher.CanCreateLocalPath(remote)); Assert.IsFalse(matcher.CanCreateLocalPath(wrong)); var remoteFolder = new Mock <IFolder>(); remoteFolder.Setup(f => f.Path).Returns(this.remotepath + "/test2"); Assert.IsTrue(matcher.CanCreateLocalPath(remoteFolder.Object)); var wrongFolder = new Mock <IFolder>(); wrongFolder.Setup(f => f.Path).Returns(wrong + "/test2"); Assert.IsFalse(matcher.CanCreateLocalPath(wrongFolder.Object)); }
public WebsiteItemPathToProjectDirectoryMapper([NotNull] string databaseName, [NotNull] string itemPath, [NotNull] string projectDirectory, [NotNull] string format, [NotNull] string itemNameInclude, [NotNull] string itemNameExclude, [NotNull] string templateNameInclude, [NotNull] string templateNameExclude) { ItemPath = '/' + PathHelper.NormalizeItemPath(itemPath).Trim('/'); ProjectDirectory = '\\' + PathHelper.NormalizeFilePath(projectDirectory).Trim('\\'); DatabaseName = databaseName; Format = format; ItemNameInclude = itemNameInclude; ItemNameExclude = itemNameExclude; TemplateNameInclude = templateNameInclude; TemplateNameExclude = templateNameExclude; if (!string.IsNullOrEmpty(ItemNameInclude) || !string.IsNullOrEmpty(ItemNameExclude)) { if (!string.IsNullOrEmpty(itemNameInclude)) { itemNameInclude = ItemPath.TrimEnd('/') + '/' + PathHelper.NormalizeItemPath(itemNameInclude).Trim('/'); } if (!string.IsNullOrEmpty(itemNameExclude)) { itemNameExclude = ItemPath.TrimEnd('/') + '/' + PathHelper.NormalizeItemPath(itemNameExclude).Trim('/'); } ItemNamePathMatcher = new PathMatcher(itemNameInclude, itemNameExclude); } if (!string.IsNullOrEmpty(TemplateNameInclude) || !string.IsNullOrEmpty(TemplateNameExclude)) { if (!string.IsNullOrEmpty(templateNameInclude)) { templateNameInclude = ItemPath.TrimEnd('/') + '/' + PathHelper.NormalizeItemPath(templateNameInclude).Trim('/'); } if (!string.IsNullOrEmpty(templateNameExclude)) { templateNameExclude = ItemPath.TrimEnd('/') + '/' + PathHelper.NormalizeItemPath(templateNameExclude).Trim('/'); } TemplateNamePathMatcher = new PathMatcher(templateNameInclude, templateNameExclude); } }
public void ExampleUsageForReadme() { string myPath = @"C:\Users\Coder\Documents\Code\Project\File.cs"; var pathInfo = new PathInfo(myPath); pathInfo.ConformSeparatorTo('/'); //Remove the filename (strip it back to directory only) pathInfo.SetFileName(""); pathInfo.AddChunks(true, "src", "Controllers"); pathInfo.SetFileName("FileNameController.cs"); Assert.AreEqual(@"C:\Users\Coder\Documents\Code\Project\src\Controllers\FileNameController.cs", pathInfo.FilePath); string remotePath = "https://files.example/Coder/Documents/"; string newPath = PathMatcher.Resituate(pathInfo.FilePath, remotePath); string expected = "https://files.example/Coder/Documents/Code/Project/src/Controllers/FileNameController.cs"; Assert.AreEqual(expected, newPath); }
public void GetObjectByPathWithHierarchie() { var matcher = new PathMatcher(Path.GetTempPath(), "/"); var storage = new MetaDataStorage(this.engine, matcher); var root = Mock.Of <IDirectoryInfo>(f => f.FullName == Path.GetTempPath()); var folder = Mock.Of <IDirectoryInfo>(f => f.FullName == Path.Combine(Path.GetTempPath(), "a")); var mappedRoot = new MappedObject("/", "rootId", MappedObjectType.Folder, null, null); var mappedFolder = new MappedObject("a", "remoteId", MappedObjectType.Folder, "rootId", null) { Guid = Guid.NewGuid(), }; storage.SaveMappedObject(mappedRoot); storage.SaveMappedObject(mappedFolder); var obj = storage.GetObjectByLocalPath(folder); Assert.That(storage.GetObjectByLocalPath(root), Is.EqualTo(mappedRoot)); Assert.That(obj, Is.EqualTo(mappedFolder)); }
public void CreateRemotePathTest() { var matcher = new PathMatcher(this.localpath, this.remotepath); string result = matcher.CreateRemotePath(this.localpath); AssertPathEqual(this.remotepath, result); string subfolder = "sub"; result = matcher.CreateRemotePath(Path.Combine(this.localpath, subfolder)); Assert.AreEqual(this.remotepath + "/" + subfolder, result); subfolder = "sub/sub"; result = matcher.CreateRemotePath(Path.Combine(this.localpath, "sub", "sub")); Assert.AreEqual(this.remotepath + "/" + subfolder, result); try { matcher.CreateRemotePath(Path.Combine("wrong", "folder")); Assert.Fail(); } catch (ArgumentOutOfRangeException) { } }
public WebsiteDirectoryToProjectDirectoryMapper([NotNull] string websiteDirectory, [NotNull] string projectDirectory, [NotNull] string include, [NotNull] string exclude) { WebsiteDirectory = '\\' + PathHelper.NormalizeFilePath(websiteDirectory).Trim('\\'); ProjectDirectory = '\\' + PathHelper.NormalizeFilePath(projectDirectory).Trim('\\'); Include = include; Exclude = exclude; if (string.IsNullOrEmpty(Include) && string.IsNullOrEmpty(Exclude)) { return; } if (!string.IsNullOrEmpty(include)) { include = WebsiteDirectory.TrimEnd('\\') + '\\' + PathHelper.NormalizeFilePath(include).Trim('\\'); } if (!string.IsNullOrEmpty(exclude)) { exclude = WebsiteDirectory.TrimEnd('\\') + '\\' + PathHelper.NormalizeFilePath(exclude).Trim('\\'); } PathMatcher = new PathMatcher(include, exclude); }
public AddTableOfContents(PathMatcher matcher, bool anyIfNotFound, params string[] patterns) : base(new LoadRawToc(patterns), new BakeTocModels(), new BakeTocIntoDocuments(matcher, anyIfNotFound)) { }
public void GetRootFolderRelativePathWithoutTrailingDenominator() { var matcher = new PathMatcher(Path.GetTempPath(), "/tmp"); Assert.That(matcher.GetRelativeLocalPath(Path.GetTempPath().TrimEnd(Path.DirectorySeparatorChar)), Is.EqualTo(".")); }
public void RootFolderMatchesItselfWithoutTrailingDenominator() { var matcher = new PathMatcher(Path.GetTempPath().TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar.ToString(), "/"); Assert.That(matcher.CanCreateRemotePath(Path.GetTempPath().TrimEnd(Path.DirectorySeparatorChar)), Is.True); }
public override bool CanParse(IParseContext context) { var fileName = context.Snapshot.SourceFile.AbsoluteFileName; return(context.Snapshot is ITextSnapshot && PathMatcher.IsMatch(fileName)); }
private IMetaDataStorage GetInitializedStorage() { IPathMatcher matcher = new PathMatcher(this.localRoot, this.remoteRoot); return(new MetaDataStorage(this.engine, matcher)); }
public ClientResourcesPathBuilder(Configuration configuration, PathMatcher matcher, PathCombiner combiner) { _configuration = configuration; _matcher = matcher; _combiner = combiner; }