Beispiel #1
0
        private static void FindSchemaLocationVersion2(XmlReader reader, string xmlPath, out string xsdPath, out string tableNamespace)
        {
            var targetNamespace   = reader.NamespaceURI;
            var relativeNamespace = UriUtility.MakeRelativeOfDirectory(CremaSchemaObsolete.TableNamespaceObsolete, targetNamespace);
            var relativeXsdPath   = PathUtility.ConvertFromUri(relativeNamespace + CremaSchema.SchemaExtension);
            var path  = xmlPath;
            var index = 0;

            xsdPath = null;
            while ((index = path.LastIndexOf(Path.DirectorySeparatorChar + CremaSchemaObsolete.TableDirectoryObsolete + Path.DirectorySeparatorChar)) >= 0)
            {
                var targetPath  = Path.Combine(xmlPath.Remove(index), CremaSchemaObsolete.TableDirectoryObsolete);
                var xsdFilename = Path.GetFileName(relativeXsdPath);
                var found       = Directory.GetFiles(targetPath, xsdFilename, SearchOption.AllDirectories).Where(item => item.EndsWith(relativeXsdPath)).FirstOrDefault();
                if (File.Exists(found) == true)
                {
                    xsdPath = found;
                    break;
                }
                path = path.Remove(index);
            }

            if (xsdPath == null)
            {
                throw new Exception();
            }

            var basePath = xsdPath.Replace(relativeXsdPath, string.Empty);
            var relative = FileUtility.RemoveExtension(xmlPath.Replace(basePath, string.Empty));
            var uri      = new Uri(new Uri(CremaSchemaObsolete.TableNamespaceObsolete + Path.AltDirectorySeparatorChar), relative);

            tableNamespace = uri.ToString();
        }
Beispiel #2
0
        public async Task InitializeAsync()
        {
            await this.Dispatcher.InvokeAsync(() =>
            {
                this.CremaHost.Debug("Load user data...");

                var directories = DirectoryUtility.GetAllDirectories(this.BasePath, "*", true);
                foreach (var item in directories)
                {
                    var relativeUri  = UriUtility.MakeRelativeOfDirectory(this.BasePath, item);
                    var segments     = StringUtility.Split(relativeUri, PathUtility.SeparatorChar, true);
                    var categoryName = CategoryName.Create(relativeUri);
                    var category     = this.Categories.Prepare(categoryName);
                    category.Guid    = Guid.NewGuid();
                }

                var settings  = ObjectSerializerSettings.Empty;
                var itemPaths = this.Serializer.GetItemPaths(this.BasePath, typeof(UserSerializationInfo), settings);
                foreach (var item in itemPaths)
                {
                    var userInfo    = (UserSerializationInfo)this.Serializer.Deserialize(item, typeof(UserSerializationInfo), settings);
                    var directory   = Path.GetDirectoryName(item);
                    var relativeUri = UriUtility.MakeRelativeOfDirectory(this.BasePath, item);
                    var segments    = StringUtility.Split(relativeUri, PathUtility.SeparatorChar, true);
                    var itemName    = ItemName.Create(segments);
                    var user        = this.Users.AddNew(userInfo.ID, itemName.CategoryPath);
                    user.Initialize((UserInfo)userInfo, (BanInfo)userInfo.BanInfo);
                    user.Password = UserContext.StringToSecureString(userInfo.Password);
                    user.Guid     = Guid.NewGuid();
                }

                this.CremaHost.Info($"{nameof(UserContext)} Initialized");
            });
        }
Beispiel #3
0
        /// <summary>
        /// DataSet의 모든 타입과 테이블을 경로에 단위별로 저장합니다.
        /// </summary>
        /// <param name="path"></param>
        public void WriteToDirectory(string path)
        {
            DirectoryUtility.Prepare(path);
            DirectoryUtility.Prepare(path, CremaSchema.TypeDirectory);
            DirectoryUtility.Prepare(path, CremaSchema.TableDirectory);

            foreach (var item in this.Types)
            {
                var    relativePath = UriUtility.MakeRelativeOfDirectory(this.dataSet.Namespace, item.Namespace);
                string filename     = Path.Combine(path, relativePath + CremaSchema.SchemaExtension);
                FileUtility.Prepare(filename);
                item.Write(filename);
            }

            foreach (var item in this.Tables.Where(item => item.Parent == null))
            {
                if (item.TemplateNamespace != string.Empty)
                {
                    continue;
                }

                var    relativePath = UriUtility.MakeRelativeOfDirectory(this.dataSet.Namespace, item.Namespace);
                string filename     = Path.Combine(path, relativePath + CremaSchema.SchemaExtension);
                FileUtility.Prepare(filename);
                item.WriteXmlSchema(filename);
            }

            foreach (var item in this.Tables.Where(item => item.Parent == null))
            {
                var    relativePath = UriUtility.MakeRelativeOfDirectory(this.dataSet.Namespace, item.Namespace);
                string filename     = Path.Combine(path, relativePath + CremaSchema.XmlExtension);
                FileUtility.Prepare(filename);
                item.WriteXml(filename);
            }
        }
Beispiel #4
0
        private void Initialize(IEnumerable <TypeInfo> typeInfos)
        {
            this.CremaHost.Debug("Load Types");
            var directories = DirectoryUtility.GetAllDirectories(this.BasePath);

            foreach (var item in directories)
            {
                var categoryName = CategoryName.Create(UriUtility.MakeRelativeOfDirectory(this.BasePath, item));
                this.Categories.Prepare(categoryName.Path);
            }

            foreach (var item in typeInfos)
            {
                var type = this.Types.AddNew(Authentication.System, item.Name, item.CategoryPath);
                type.Initialize(item);
            }

            var itemPaths = this.Serializer.GetItemPaths(this.BasePath, typeof(AccessSerializationInfo), AccessSerializationInfo.Settings);

            foreach (var item in itemPaths)
            {
                var accessInfo = (AccessSerializationInfo)this.Serializer.Deserialize(item, typeof(AccessSerializationInfo), AccessSerializationInfo.Settings);
                var tableItem  = this.GetTypeItemByItemPath(item);
                if (tableItem is Type type)
                {
                    type.SetAccessInfo((AccessInfo)accessInfo);
                }
                else if (tableItem is TypeCategory category)
                {
                    category.SetAccessInfo((AccessInfo)accessInfo);
                }
            }
            this.CremaHost.Debug("TypeLoadingCompleted.");
        }
Beispiel #5
0
        private void Initialize(IEnumerable <TypeInfo> typeInfos)
        {
            this.CremaHost.Debug("Load Types");
            var directories = DirectoryUtility.GetAllDirectories(this.basePath);

            foreach (var item in directories)
            {
                var categoryName = CategoryName.Create(UriUtility.MakeRelativeOfDirectory(this.basePath, item));
                this.Categories.Prepare(categoryName.Path);
            }
            foreach (var item in typeInfos)
            {
                var type = this.Types.AddNew(Authentication.System, item.Name, item.CategoryPath);
                type.Initialize(item);
            }
            foreach (ITypeItem item in this)
            {
                var accessInfoPath = item.GetAccessInfoPath();
                try
                {
                    item.ReadAccessInfo(accessInfoPath);
                }
                catch (Exception e)
                {
                    this.CremaHost.Error(e);
                }
            }
            this.CremaHost.Debug("TypeLoadingCompleted.");
        }
Beispiel #6
0
        private ITypeItem GetTypeItemByItemPath(string itemPath)
        {
            var isCategory  = itemPath.EndsWith($"{Path.DirectorySeparatorChar}");
            var directory   = Path.GetDirectoryName(itemPath);
            var relativeUri = UriUtility.MakeRelativeOfDirectory(this.BasePath, itemPath);
            var segments    = StringUtility.Split(relativeUri, PathUtility.SeparatorChar, true);
            var path        = isCategory == true ? (string)CategoryName.Create(segments) : ItemName.Create(segments);

            return(this[path] as ITypeItem);
        }
Beispiel #7
0
        public CodeGenerationInfo(string outputPath, GenerationSet metaData, CodeGenerationSettings settings)
        {
            this.metaData = metaData;
            this.settings = settings;

            if (this.settings.BasePath != string.Empty)
            {
                var relativePath = UriUtility.MakeRelativeOfDirectory(new DirectoryInfo(outputPath).FullName, DirectoryUtility.GetAbsolutePath(outputPath, settings.BasePath));
                this.RelativePath = relativePath + Path.DirectorySeparatorChar;
            }
        }
Beispiel #8
0
        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);
            }
        }
Beispiel #9
0
        public static SvnLogInfo GetFirstLog(string path)
        {
            var info      = SvnInfo.Run(path);
            var revision  = info.LastChangedRevision;
            var localPath = PathUtility.Separator + UriUtility.MakeRelativeOfDirectory(info.RepositoryRoot, info.Uri);

            while (revision != "1")
            {
                var logs = SvnLogInfo.Run(info.Uri.ToString(), "1", revision, 100);
                foreach (var item in logs)
                {
                    var renamed = false;
                    foreach (var changedPath in item.ChangedPaths)
                    {
                        if (changedPath.Action == "A" && changedPath.Path == localPath)
                        {
                            localPath = changedPath.CopyFromPath;
                            renamed   = true;
                            break;
                        }
                    }

                    var deleted = false;
                    if (renamed == true)
                    {
                        foreach (var changedPath in item.ChangedPaths)
                        {
                            if (changedPath.Action == "D" && changedPath.Path == localPath)
                            {
                                deleted = true;
                                break;
                            }
                        }

                        if (deleted == false)
                        {
                            return(item);
                        }
                    }
                }
                if (logs.Count() == 1)
                {
                    return(logs.First());
                }
                else
                {
                    revision = logs.Last().Revision;
                }
            }

            return(SvnLogInfo.GetLogs(info.Uri.ToString(), "1").First());
        }
Beispiel #10
0
        public string Export(Uri uri, string exportPath)
        {
            var pureUri       = new Uri(Regex.Replace($"{uri}", "@\\d+$", string.Empty));
            var relativeUri   = UriUtility.MakeRelativeOfDirectory(this.repositoryUri, pureUri);
            var uriTarget     = uri.LocalPath;
            var filename      = FileUtility.Prepare(exportPath, $"{relativeUri}");
            var exportCommand = new SvnCommand("export")
            {
                (SvnPath)uri, (SvnPath)filename
            };
            var result = exportCommand.Run(this.logService);

            return(new FileInfo(Path.Combine(exportPath, $"{relativeUri}")).FullName);
        }
Beispiel #11
0
        public void Generate(string outputPath, GenerationSet metaData, CodeGenerationSettings settings)
        {
            var generationInfo = new CodeGenerationInfo(metaData, settings)
            {
                RelativePath = string.Empty,
            };

            if (settings.BasePath != string.Empty)
            {
                var relativePath = UriUtility.MakeRelativeOfDirectory(new DirectoryInfo(outputPath).FullName, DirectoryUtility.GetAbsolutePath(outputPath, settings.BasePath));
                generationInfo.RelativePath = relativePath + "/";
            }

            {
                var codes    = this.Generate(generationInfo);
                var dirInfo  = new DirectoryInfo(outputPath);
                var rootPath = generationInfo.Namespace.Replace('.', Path.DirectorySeparatorChar);
                foreach (var item in codes)
                {
                    var ext      = Path.GetExtension(item.Key);
                    var filename = FileUtility.RemoveExtension(item.Key).Replace('.', Path.DirectorySeparatorChar) + ext;
                    filename = Path.Combine(dirInfo.FullName, filename);
                    FileUtility.Prepare(filename);

                    using (StreamWriter sw = new StreamWriter(filename, false, Encoding.UTF8))
                    {
                        sw.WriteLine(item.Value);
                        this.PrintResult(filename);
                    }
                }
            }

            if (settings.Options.HasFlag(CodeGenerationOptions.OmitBaseCode) == false)
            {
                var codes     = this.GenerateBases(generationInfo);
                var codesPath = DirectoryUtility.GetAbsolutePath(outputPath, settings.BasePath);
                foreach (var item in codes)
                {
                    var codePath = FileUtility.Prepare(codesPath, item.Key);
                    using (var writer = new StreamWriter(codePath, false, Encoding.UTF8))
                    {
                        writer.WriteLine(item.Value);
                        this.PrintResult(codePath);
                    }
                }
            }
        }
Beispiel #12
0
        private void Initialize(IEnumerable <TableInfo> tableInfos)
        {
            this.CremaHost.Debug(Resources.Message_LoadTables);
            var directories = DirectoryUtility.GetAllDirectories(this.BasePath);

            foreach (var item in directories)
            {
                var categoryName = CategoryName.Create(UriUtility.MakeRelativeOfDirectory(this.BasePath, item));
                this.Categories.Prepare(categoryName.Path);
            }

            foreach (var item in tableInfos.OrderBy(i => i.Name))
            {
                var table = this.Tables.AddNew(Authentication.System, item.Name, item.CategoryPath);
                table.Initialize(item);
            }

            foreach (var item in tableInfos.Where(i => i.TemplatedParent != string.Empty))
            {
                var table = this.Tables[item.Name];
                table.TemplatedParent = this.Tables[item.TemplatedParent];
                if (table.TemplatedParent == null)
                {
                    throw new Exception();
                }
            }

            var itemPaths = this.Serializer.GetItemPaths(this.BasePath, typeof(AccessSerializationInfo), AccessSerializationInfo.Settings);

            foreach (var item in itemPaths)
            {
                var accessInfo = (AccessSerializationInfo)this.Serializer.Deserialize(item, typeof(AccessSerializationInfo), AccessSerializationInfo.Settings);
                var tableItem  = this.GetTableItemByItemPath(item);
                if (tableItem is Table table)
                {
                    table.SetAccessInfo((AccessInfo)accessInfo);
                }
                else if (tableItem is TableCategory category)
                {
                    category.SetAccessInfo((AccessInfo)accessInfo);
                }
            }
            this.CremaHost.Debug(Resources.Message_TableLoadingIsCompleted);
        }
Beispiel #13
0
        /// <summary>
        /// DataSet의 모든 타입과 테이블을 경로에 단위별로 저장합니다.
        /// </summary>
        /// <param name="path"></param>
        public void WriteToDirectory(string path)
        {
            path = PathUtility.GetFullPath(path);
            DirectoryUtility.Prepare(path);
            DirectoryUtility.Prepare(path, CremaSchema.TypeDirectory);
            DirectoryUtility.Prepare(path, CremaSchema.TableDirectory);

            foreach (var item in this.Types)
            {
                var relativePath = UriUtility.MakeRelativeOfDirectory(this.InternalObject.Namespace, item.Namespace);
                var filename     = Path.Combine(path, relativePath + CremaSchema.SchemaExtension);
                FileUtility.Prepare(filename);
                item.Write(filename);
            }

            foreach (var item in this.Tables)
            {
                if (item.TemplateNamespace != string.Empty)
                {
                    if (item.TemplatedParent == null)
                    {
                        var relativePath = UriUtility.MakeRelativeOfDirectory(this.InternalObject.Namespace, item.TemplateNamespace);
                        var filename     = Path.Combine(path, relativePath + CremaSchema.SchemaExtension);
                        FileUtility.Prepare(filename);
                        item.WriteXmlSchema(filename);
                    }
                }
                else
                {
                    var relativePath = UriUtility.MakeRelativeOfDirectory(this.InternalObject.Namespace, item.Namespace);
                    var filename     = Path.Combine(path, relativePath + CremaSchema.SchemaExtension);
                    FileUtility.Prepare(filename);
                    item.WriteXmlSchema(filename);
                }
            }

            foreach (var item in this.Tables)
            {
                var relativePath = UriUtility.MakeRelativeOfDirectory(this.InternalObject.Namespace, item.Namespace);
                var filename     = Path.Combine(path, relativePath + CremaSchema.XmlExtension);
                FileUtility.Prepare(filename);
                item.WriteXml(filename);
            }
        }
Beispiel #14
0
        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);
        }
Beispiel #15
0
        private void GetSerializableData(IDictionary <string, string> items)
        {
            var relativeType = UriUtility.MakeRelativeOfDirectory(this.dataSet.Namespace, this.TypeNamespace);
            var lockobj      = new object();

            Parallel.ForEach(this.Types, item =>
            {
                var schema = item.GetXmlSchema().Compress();
                lock (lockobj)
                {
                    items.Add(item.Namespace + CremaSchema.SchemaExtension, schema);
                }
            });

            Parallel.ForEach(this.Tables.Where(item => item.Parent == null), item =>
            {
                var schema = string.Empty;
                if (item.TemplateNamespace == string.Empty)
                {
                    schema = item.GetXmlSchema().Compress();
                }
                else
                {
                    schema = item.TemplateNamespace.Compress();
                }
                lock (lockobj)
                {
                    items.Add(item.Namespace + CremaSchema.SchemaExtension, schema);
                }
            });

            Parallel.ForEach(this.Tables.Where(item => item.Parent == null), item =>
            {
                var xml = item.GetXml().Compress();
                lock (lockobj)
                {
                    items.Add(item.Namespace + CremaSchema.XmlExtension, xml);
                }
            });
        }
Beispiel #16
0
        private void Initialize(IEnumerable <TableInfo> tableInfos)
        {
            this.CremaHost.Debug(Resources.Message_LoadTables);
            var directories = DirectoryUtility.GetAllDirectories(this.basePath);

            foreach (var item in directories)
            {
                var categoryName = CategoryName.Create(UriUtility.MakeRelativeOfDirectory(this.basePath, item));
                this.Categories.Prepare(categoryName.Path);
            }
            foreach (var item in tableInfos.OrderBy(i => i.Name))
            {
                var table = this.Tables.AddNew(Authentication.System, item.Name, item.CategoryPath);
                table.Initialize(item);
            }

            foreach (var item in tableInfos.Where(i => i.TemplatedParent != string.Empty))
            {
                var table = this.Tables[item.Name];
                table.TemplatedParent = this.Tables[item.TemplatedParent];
                if (table.TemplatedParent == null)
                {
                    throw new Exception();
                }
            }
            foreach (ITableItem item in this)
            {
                var accessInfoPath = item.GetAccessInfoPath();
                try
                {
                    item.ReadAccessInfo(accessInfoPath);
                }
                catch (Exception e)
                {
                    this.CremaHost.Error(e);
                }
            }
            this.CremaHost.Debug(Resources.Message_TableLoadingIsCompleted);
        }
Beispiel #17
0
        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);
            }
        }
        public IRepository CreateInstance(RepositorySettings settings)
        {
            var remoteUri      = new Uri(settings.RemotePath);
            var baseUri        = new Uri(settings.BasePath);
            var originUri      = UriUtility.MakeRelativeOfDirectory(baseUri, remoteUri);
            var repositoryName = settings.RepositoryName == string.Empty ? "master" : settings.RepositoryName;

            if (Directory.Exists(settings.BasePath) == false)
            {
                var cloneCommand = new GitCommand(null, "clone")
                {
                    (GitPath)remoteUri,
                    new GitCommandItem('b'),
                    repositoryName,
                    (GitPath)settings.BasePath,
                    new GitCommandItem("single-branch")
                };
                cloneCommand.Run();

                var fetchCommand = new GitCommand(settings.BasePath, "fetch")
                {
                    "origin",
                    "refs/notes/commits:refs/notes/commits",
                };
                fetchCommand.Run();

                var id = this.GetID(settings.RemotePath, repositoryName);
                this.SetID(settings.BasePath, repositoryName, id);
                GitConfig.SetValue(settings.BasePath, "remote.origin.url", originUri);
                var repositoryInfo = this.GetRepositoryInfo(settings.RemotePath, repositoryName);
                return(new GitRepository(this, settings, repositoryInfo));
            }
            else
            {
                var repositoryInfo = this.GetRepositoryInfo(settings.BasePath, repositoryName);
                return(new GitRepository(this, settings, repositoryInfo));
            }
        }
Beispiel #19
0
        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);
            }
        }
Beispiel #20
0
        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);
            }
        }