private void MigrateUsers() { this.logService.Info(nameof(MigrateUsers)); var repositoryProvider = this.repositoryMigrator.RepositoryProvider; var usersPath = Path.Combine(this.repositoryPath, CremaString.Users); var userUrl = UriUtility.Combine(this.sourceUrl, $"{CremaString.Users}.xml"); var userPath = Path.Combine(this.basePath, $"{CremaString.Users}.xml"); this.logService.Info($" - export {CremaString.Users}.xml"); this.Run($"export \"{userUrl}\" \"{this.basePath}\" --force"); var userContext = JSSoft.Library.Serialization.DataContractSerializerUtility.Read <UserContextSerializationInfo>(userPath); var tempPath = PathUtility.GetTempPath(true); try { this.logService.Info($" - write users information"); userContext.WriteToDirectory(tempPath); this.logService.Info($" - initialize users repository"); repositoryProvider.InitializeRepository(usersPath, tempPath); } finally { this.logService.Info($" - delete temp files"); FileUtility.Delete(userPath); DirectoryUtility.Delete(tempPath); } }
private void MoveTagsToBranches(string dataBasesPath) { var dataBaseUrl = new Uri(dataBasesPath); var tagsUrl = UriUtility.Combine(dataBaseUrl, SvnString.Tags); var branchesUri = UriUtility.Combine(dataBaseUrl, SvnString.Branches); var listCommand = new SvnCommand("list") { (SvnPath)tagsUrl }; var list = listCommand.ReadLines(); foreach (var item in list) { if (item.EndsWith(PathUtility.Separator) == true) { var name = item.Remove(item.Length - PathUtility.Separator.Length); var sourceUri = UriUtility.Combine(tagsUrl, name); var destUri = UriUtility.Combine(branchesUri, name); //var log = SvnLogInfo.Run(sourceUri.ToString(), null, 1).First(); var moveCommand = new SvnCommand("mv") { (SvnPath)sourceUri, (SvnPath)destUri, SvnCommandItem.FromMessage($"Migrate: move {name} from tags to branches"), SvnCommandItem.FromUsername(nameof(SvnRepositoryMigrator)), }; moveCommand.Run(); //var propText = string.Join(" ", log.Properties.Select(i => $"--with-revprop \"{i.Prefix}{i.Key}={i.Value}\"")); //SvnClientHost.Run($"mv \"{sourceUri}\" \"{destUri}\" -m \"Migrate: move {name} from tags to branches\"", propText, $"--username {nameof(SvnRepositoryMigrator)}"); } } }
public bool Contains(string name, string categoryPath) { var itemNamespace = UriUtility.Combine(this.dataSet.TableNamespace + categoryPath, name); return(this.itemsByNamespace.ContainsKey(name)); //return this.IndexOf(name, categoryPath) >= 0; }
public CremaDataType this[string name, string categoryPath] { get { Validate(); var itemNamespace = UriUtility.Combine(this.dataSet.TypeNamespace + categoryPath, name); for (var i = 0; i < this.itemList.Count; i++) { var item = this.itemList[i]; if (item.Name == name && item.Namespace == itemNamespace) { return(item.Target); } } return(null); void Validate() { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (categoryPath == null) { throw new ArgumentNullException(nameof(categoryPath)); } } } }
public IEnumerable <KeyValuePair <string, Uri> > GetRepositoryPaths(string basePath) { var uri = new Uri(basePath); var listCommand = new SvnCommand("list") { (SvnPath)uri }; var lines = listCommand.ReadLines(); foreach (var line in lines) { if (line.EndsWith(PathUtility.Separator) == true) { var name = line.Substring(0, line.Length - PathUtility.Separator.Length); if (name == SvnString.Trunk) { yield return(new KeyValuePair <string, Uri>(SvnString.Default, UriUtility.Combine(uri, name))); } else if (name == SvnString.Tags || name == SvnString.Branches) { var subPath = Path.Combine(basePath, name); foreach (var item in this.GetRepositoryPaths(subPath)) { yield return(item); } } else { yield return(new KeyValuePair <string, Uri>(name, UriUtility.Combine(uri, name))); } } } }
public IRepository CreateInstance(RepositorySettings settings) { var baseUri = new Uri(settings.RemotePath); var repositoryName = settings.RepositoryName == string.Empty ? SvnString.Default : settings.RepositoryName; var url = repositoryName == SvnString.Default ? UriUtility.Combine(baseUri, SvnString.Trunk) : UriUtility.Combine(baseUri, SvnString.Branches, settings.RepositoryName); if (Directory.Exists(settings.BasePath) == false) { var checkoutCommand = new SvnCommand("checkout") { (SvnPath)url, (SvnPath)settings.BasePath, }; checkoutCommand.Run(); } else { var updateCommand = new SvnCommand("update") { (SvnPath)settings.BasePath, }; updateCommand.Run(); } var repositoryInfo = this.GetRepositoryInfo(settings.RemotePath, repositoryName); return(new SvnRepository(settings.LogService, settings.BasePath, settings.TransactionPath, repositoryInfo)); }
public void TestCombineWithAbsoluteAndRelativeUris() { AssertEqual("http://pauthor.codeplex.com/documentation", UriUtility.Combine("http://pauthor.codeplex.com", "documentation")); AssertEqual("http://pauthor.codeplex.com/documentation/sample.html", UriUtility.Combine("http://pauthor.codeplex.com/documentation/foobar", "../sample.html")); }
public static string GetAccessInfoPath(this ITableItem tableItem) { var tableContext = GetTableContext(tableItem); var uriString = UriUtility.Combine(tableContext.BasePath, tableItem.Path.TrimStart(PathUtility.SeparatorChar) + extension); var uri = new Uri(uriString); return(uri.LocalPath); }
public static string GetAccessInfoPath(this ITypeItem typeItem, string categoryPath) { var typeContext = GetTypeContext(typeItem); var uriString = UriUtility.Combine(typeContext.BasePath, categoryPath.TrimStart(PathUtility.SeparatorChar) + typeItem.Name + extension); var uri = new Uri(uriString); return(uri.LocalPath); }
public void TestCombineWithTwoRelativeUris() { try { UriUtility.Combine("path1/path2", "foobar.html"); } catch (UriFormatException e) { AssertEqual("Invalid URI: The format of the URI could not be determined.", e.Message); } }
public CremaDataSet GetTableCategoryData(string repositoryPath, string localPath, long revision) { var tempPath = PathUtility.GetTempPath(true); try { var revisionValue = revision == -1 ? this.Revision : revision; var repoUri = this.GetUri(repositoryPath, revisionValue); var categoryUri = this.GetUri(localPath, revisionValue); var categoryPath = this.Export(categoryUri, tempPath); var baseUri = this.GetDataBaseUri($"{repoUri}", $"{categoryUri}"); var files = DirectoryUtility.GetAllFiles(categoryPath, "*" + CremaSchema.XmlExtension); foreach (var item in files) { var relativeItemUri = UriUtility.MakeRelative(categoryPath, item); var itemUri = UriUtility.Combine(UriUtility.GetDirectoryName(categoryUri), $"{relativeItemUri}@{revisionValue}"); var xmlInfo = new CremaXmlReadInfo(item); var schemaUri = UriUtility.Combine(UriUtility.GetDirectoryName(itemUri), $"{xmlInfo.RelativeSchemaPath}@{revisionValue}"); var schemaPath = new Uri(UriUtility.Combine(Path.GetDirectoryName(item), xmlInfo.RelativeSchemaPath)).LocalPath; if (File.Exists(schemaPath) == false) { this.Export(schemaUri, tempPath); } ExportTypes(schemaUri, schemaPath); } void ExportTypes(Uri schemaUri, string schemaPath) { var xsdInfo = new CremaSchemaReadInfo(schemaPath); foreach (var item in xsdInfo.RelativeTypePaths) { var typeUri = UriUtility.Combine(UriUtility.GetDirectoryName(schemaUri), $"{item}@{revisionValue}"); var typePath = new Uri(UriUtility.Combine(Path.GetDirectoryName(schemaPath), item)).LocalPath; if (File.Exists(typePath) == false) { this.Export(typeUri, tempPath); } } } var pureBaseUri = $"{baseUri}".Replace($"@{revisionValue}", string.Empty); var pureCategoryUri = $"{categoryUri}".Replace($"@{revisionValue}", string.Empty); var dataBaseRelativeUri = UriUtility.MakeRelativeOfDirectory(pureCategoryUri, pureBaseUri); var dataBasePath = UriUtility.Combine(new Uri(categoryPath), dataBaseRelativeUri).LocalPath; return(CremaDataSet.ReadFromDirectory(dataBasePath)); } finally { DirectoryUtility.Delete(tempPath); } }
private void DeleteUsers(string dataBasesPath) { var usersUrl = UriUtility.Combine(new Uri(dataBasesPath), "users.xml"); var deleteCommand = new SvnCommand("rm") { (SvnPath)usersUrl, SvnCommandItem.FromMessage("Migrate: delete users"), SvnCommandItem.FromUsername(nameof(SvnRepositoryMigrator)), }; deleteCommand.Run(); }
public CremaSchemaReadInfo(string schemaPath) { var xnm = new XmlNamespaceManager(new NameTable()); xnm.AddNamespace("xs", XmlSchema.Namespace); var doc = XDocument.Load(schemaPath); var query = from item in doc.XPathSelectElements("/xs:schema/xs:import[@schemaLocation]", xnm).ToArray() let attr = item.Attribute(XName.Get("schemaLocation", string.Empty)) select attr.Value; this.RelativeTypePaths = query.ToArray(); this.TypePaths = this.RelativeTypePaths.Select(item => UriUtility.Combine(Path.GetDirectoryName(schemaPath), item)).ToArray(); }
public int IndexOf(string name, string categoryPath) { var itemNamespace = UriUtility.Combine(this.dataSet.TypeNamespace + categoryPath, name); for (var i = 0; i < this.itemList.Count; i++) { var item = this.itemList[i]; if (item.Name == name && item.Namespace == itemNamespace) { return(i); } } return(-1); }
public string[] GetTypePaths() { var prefix = "xs"; var schemaDirectory = System.IO.Path.GetDirectoryName(this.SchemaPath); var namespaceResolver = new XmlNamespaceManager(new NameTable()); namespaceResolver.AddNamespace(prefix, XmlSchema.Namespace); var doc = XDocument.Load(this.SchemaPath); var query = from item in doc.XPathSelectElements($"/{prefix}:schema/{prefix}:import", namespaceResolver) let schemaLocation = item.Attribute(XName.Get("schemaLocation")).Value let uri = new Uri(UriUtility.Combine(schemaDirectory, schemaLocation)) select uri.LocalPath; return(query.ToArray()); }
public static InternalDataType GetType(InternalDataSet dataSet, string name, string categoryPath) { var itemNamespace = UriUtility.Combine(dataSet.TypeNamespace + categoryPath, name); foreach (var item in dataSet.Tables) { if (item is InternalDataType dataType) { if (dataType.Name == name && dataType.Namespace == itemNamespace) { return(dataType); } } } return(null); }
public CremaDataTable this[string name, string categoryPath] { get { var itemNamespace = UriUtility.Combine(this.dataSet.TableNamespace + categoryPath, name); for (var i = 0; i < this.itemList.Count; i++) { var item = this.itemList[i]; if (item.Name == name && item.Namespace == itemNamespace) { return(item.Target); } } return(null); } }
public void CreateRepository(string author, string basePath, string initPath, string comment, params LogPropertyInfo[] properties) { var repositoryName = Path.GetFileName(initPath); var uri = UriUtility.Combine(new Uri(basePath), SvnString.Branches, repositoryName); var props = GeneratePropertiesArgument(properties); var importCommand = new SvnCommand("import") { (SvnPath)initPath, (SvnPath)uri, SvnCommandItem.FromMessage(comment), SvnCommandItem.Force, props, SvnCommandItem.FromUsername(author), }; importCommand.Run(); }
public RepositoryItem[] Status(params string[] paths) { var items = GitItemStatusInfo.Run(this.BasePath, paths); var itemList = new List <RepositoryItem>(items.Length); foreach (var item in items) { var repositoryItem = new RepositoryItem() { Path = new Uri(UriUtility.Combine(this.BasePath, item.Path)).LocalPath, OldPath = new Uri(UriUtility.Combine(this.BasePath, item.OldPath)).LocalPath, Status = item.Status, }; itemList.Add(repositoryItem); } return(itemList.ToArray()); }
public string GetDataBaseUri(string repoUri, string itemUri) { var pattern = "(@\\d+)$"; var pureRepoUri = Regex.Replace(repoUri, pattern, string.Empty); var pureItemUri = Regex.Replace(itemUri, pattern, string.Empty); var relativeUri = UriUtility.MakeRelativeOfDirectory(pureRepoUri, pureItemUri); var segments = relativeUri.Split(PathUtility.SeparatorChar); if (segments[0] == "trunk") { pureRepoUri = $"{UriUtility.Combine(pureRepoUri, segments.Take(1).ToArray())}"; } else if (segments[0] == "tags") { pureRepoUri = $"{UriUtility.Combine(pureRepoUri, segments.Take(2).ToArray())}"; } return(pureRepoUri); }
public static bool ContainsType(InternalDataSet dataSet, string name, string categoryPath) { if (dataSet == null) { return(false); } var itemNamespace = UriUtility.Combine(dataSet.TypeNamespace + categoryPath, name); foreach (var item in dataSet.Tables) { if (item is InternalDataType dataType) { if (dataType.Name == name && dataType.Namespace == itemNamespace) { return(true); } } } return(false); }
private void PrepareBranches(string dataBasesPath) { var dataBaseUrl = new Uri(dataBasesPath); var listCommand = new SvnCommand("list") { (SvnPath)dataBaseUrl }; var list = listCommand.ReadLines(); if (list.Contains($"{SvnString.Branches}{PathUtility.Separator}") == false) { var branchesUrl = UriUtility.Combine(dataBaseUrl, SvnString.Branches); var mkdirCommand = new SvnCommand("mkdir") { (SvnPath)branchesUrl, SvnCommandItem.FromMessage("Migrate: create branches"), SvnCommandItem.FromUsername(nameof(SvnRepositoryMigrator)), }; mkdirCommand.Run(); } }
public void RevertRepository(string author, string basePath, string repositoryName, string revision, string comment) { var baseUri = new Uri(basePath); var url = repositoryName == SvnString.Default ? UriUtility.Combine(baseUri, SvnString.Trunk) : UriUtility.Combine(baseUri, SvnString.Branches, repositoryName); var tempPath = PathUtility.GetTempPath(false); try { var checkoutCommand = new SvnCommand("checkout") { (SvnPath)url, (SvnPath)tempPath, }; checkoutCommand.Run(); var mergeCommand = new SvnCommand("merge") { new SvnCommandItem('r', $"head:{revision}"), (SvnPath)tempPath, (SvnPath)tempPath, }; mergeCommand.Run(); var commitCommand = new SvnCommand("commit") { (SvnPath)tempPath, SvnCommandItem.FromMessage(comment), SvnCommandItem.FromEncoding(Encoding.UTF8), SvnCommandItem.FromUsername(author), }; commitCommand.Run(); } catch (Exception e) { throw e; } finally { DirectoryUtility.Delete(tempPath); } }
public CremaDataSet GetTypeCategoryData(string repositoryPath, string localPath, long revision) { var tempPath = PathUtility.GetTempPath(true); try { var revisionValue = revision == -1 ? this.Revision : revision; var repoUri = this.GetUri(repositoryPath, revisionValue); var categoryUri = this.GetUri(localPath, revisionValue); var baseUri = this.GetDataBaseUri($"{repoUri}", $"{categoryUri}"); var categoryPath = this.Export(categoryUri, tempPath); var pureBaseUri = $"{baseUri}".Replace($"@{revisionValue}", string.Empty); var pureCategoryUri = $"{categoryUri}".Replace($"@{revisionValue}", string.Empty); var dataBaseRelativeUri = UriUtility.MakeRelativeOfDirectory(pureCategoryUri, pureBaseUri); var dataBasePath = UriUtility.Combine(new Uri(categoryPath), dataBaseRelativeUri).LocalPath; return(CremaDataSet.ReadFromDirectory(dataBasePath)); } finally { DirectoryUtility.Delete(tempPath); } }
private RepositoryMigrator(LogService logService, IRepositoryMigrator repositoryMigrator, string basePath, Uri repositoryUrl) { this.logService = logService; this.repositoryMigrator = repositoryMigrator; this.basePath = basePath; this.repositoryPath = DirectoryUtility.Prepare(basePath, CremaString.Repository); if (repositoryUrl == null) { this.sourceUrl = new Uri(Path.Combine(this.basePath, nameString)); } else if (repositoryUrl.IsAbsoluteUri) { this.sourceUrl = repositoryUrl; } else { this.sourceUrl = UriUtility.Combine(new Uri(this.basePath), nameString, repositoryUrl.ToString()); } this.sourceRootUrl = new Uri(this.Run($"info \"{this.sourceUrl}\" --show-item repos-root-url").Trim()); this.sourceRelativeUrl = UriUtility.MakeRelativeString(this.sourceRootUrl, this.sourceUrl); }
public string Export(Uri uri, string exportPath) { var match = Regex.Match(uri.LocalPath, "(?<path>.+)@(?<keep>.*)(?<revision>[a-f0-9]{40})", RegexOptions.ExplicitCapture); var path = match.Groups["path"].Value; var keep = match.Groups["keep"].Value; var revision = match.Groups["revision"].Value; var tempPath = PathUtility.GetTempFileName(); try { if (Directory.Exists(exportPath) == false) { Directory.CreateDirectory(exportPath); } if (DirectoryUtility.IsEmpty(exportPath) == true) { new CremaDataSet().WriteToDirectory(exportPath); } var relativePath = UriUtility.MakeRelativeOfDirectory(this.BasePath, path); var archiveCommand = new GitCommand(this.BasePath, "archive") { new GitCommandItem($"output={(GitPath)tempPath}"), new GitCommandItem("format=zip"), revision, GitCommandItem.Separator, (GitPath)path, }; archiveCommand.Run(this.logService); ZipFile.ExtractToDirectory(tempPath, exportPath); var exportUri = new Uri(UriUtility.Combine(exportPath, relativePath)); return(exportUri.LocalPath); } finally { FileUtility.Delete(tempPath); } }
public CremaDataSet GetTableData(string repositoryPath, string tableXmlPath, string tableSchemaPath, long revision) { var tempPath = PathUtility.GetTempPath(true); try { var revisionValue = revision == -1 ? this.Revision : revision; var repoUri = this.GetUri(repositoryPath, revisionValue); var xmlUri = this.GetUri(tableXmlPath, revisionValue); var baseUri = this.GetDataBaseUri($"{repoUri}", $"{xmlUri}"); var xmlPath = this.Export(xmlUri, tempPath); var xmlInfo = new CremaXmlReadInfo(xmlPath); var schemaUri = UriUtility.Combine(UriUtility.GetDirectoryName(xmlUri), xmlInfo.RelativeSchemaPath + "@" + revisionValue); var schemaPath = this.Export(schemaUri, tempPath); var xsdInfo = new CremaSchemaReadInfo(schemaPath); foreach (var item in xsdInfo.RelativeTypePaths) { var typeUri = UriUtility.Combine(UriUtility.GetDirectoryName(schemaUri), $"{item}@{revisionValue}"); this.Export(typeUri, tempPath); } var pureBaseUri = $"{baseUri}".Replace($"@{revisionValue}", string.Empty); var pureTableXmlUri = $"{xmlUri}".Replace($"@{revisionValue}", string.Empty); var dataBaseRelativeUri = UriUtility.MakeRelativeOfDirectory(pureTableXmlUri, pureBaseUri); var dataBasePath = UriUtility.Combine(new Uri(xmlPath), dataBaseRelativeUri).LocalPath; return(CremaDataSet.ReadFromDirectory(dataBasePath)); } finally { DirectoryUtility.Delete(tempPath); } }
public void TestCombineWithTwoRelativeLocalPaths() { AssertEqual(Path.GetFullPath(@"..\..\Resources\DeepZoom"), UriUtility.Combine(@"..\..\Resources", "DeepZoom")); }
private Uri GenerateUrl(string basePath, string repositoryName) { var baseUri = new Uri(basePath); return(UriUtility.Combine(baseUri, SvnString.Branches, repositoryName)); }
public void TestCombineWithAbsoluteAndRelativeLocalPaths() { String basePath = Path.GetFullPath(@"..\..\Resources"); AssertEqual(basePath + @"\DeepZoom\sample.cxml", UriUtility.Combine(basePath, "DeepZoom/sample.cxml")); }