Example #1
0
        public async Task OpenAsync(string path1, string path2, string filterExpression)
        {
            try
            {
                this.BeginProgress("loading data");
                this.dataSet = await Task.Run(async() =>
                {
                    var filter = filterExpression == string.Empty ? null : filterExpression;
                    var tasks  = new Task <CremaDataSet>[]
                    {
                        Task.Run(() => CremaDataSet.ReadFromDirectory(path1, filter)),
                        Task.Run(() => CremaDataSet.ReadFromDirectory(path2, filter)),
                    };

                    Task.WaitAll(tasks);
                    var dataSet1 = tasks[0].Result;
                    var dataSet2 = tasks[1].Result;

                    dataSet1.ExtendedProperties["location"] = Path.GetFileNameWithoutExtension(path1);
                    dataSet2.ExtendedProperties["location"] = Path.GetFileNameWithoutExtension(path2);
                    await this.Dispatcher.InvokeAsync(() => this.ProgressMessage = "comparing data");
                    return(this.Compare(dataSet1, dataSet2));
                });

                this.EndProgress();
                this.OnLoaded(EventArgs.Empty);
            }
            catch (Exception e)
            {
                await AppMessageBox.ShowErrorAsync(e.Message);

                this.EndProgress();
                return;
            }
        }
Example #2
0
        private CremaDataSet ReadDataSet(string path)
        {
            var dataSet = CremaDataSet.ReadFromDirectory(path);

            var dirs = DirectoryUtility.GetAllDirectories(path);

            {
                var typesPath = System.IO.Path.Combine(path, CremaSchema.TypeDirectory);
                var query     = from item in dirs
                                where item.StartsWith(typesPath)
                                let localPath = item.Substring(typesPath.Length)
                                                let segments = localPath.Split(new char[] { System.IO.Path.DirectorySeparatorChar, }, StringSplitOptions.RemoveEmptyEntries)
                                                               select CategoryName.Create(segments).Path;

                dataSet.ExtendedProperties[CremaSchema.TypeDirectory] = query.ToArray();
            }
            {
                var tablesPath = System.IO.Path.Combine(path, CremaSchema.TableDirectory);
                var query      = from item in dirs
                                 where item.StartsWith(tablesPath)
                                 let localPath = item.Substring(tablesPath.Length)
                                                 let segments = localPath.Split(new char[] { System.IO.Path.DirectorySeparatorChar, }, StringSplitOptions.RemoveEmptyEntries)
                                                                select CategoryName.Create(segments).Path;

                dataSet.ExtendedProperties[CremaSchema.TableDirectory] = query.ToArray();
            }

            return(dataSet);
        }
Example #3
0
        static void Main(string[] args)
        {
            var settings = new ValidatorSettings();
            var parser   = new CommandLineParser(settings);

            try
            {
                if (parser.Parse(Environment.CommandLine) == true)
                {
                    var directoryInfo = new DirectoryInfo(settings.Path);
                    while (true)
                    {
                        CremaDataSet.ReadFromDirectory(directoryInfo.FullName);
                    }
                }
            }
            catch (Exception e)
            {
                if (settings.Details == true)
                {
                    Console.WriteLine(e);
                }
                else
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
Example #4
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);
            }
        }
Example #5
0
        public object Deserialize(string itemPath, Type type, ObjectSerializerSettings settings)
        {
            if (type == typeof(CremaDataTable))
            {
                throw new NotImplementedException();
            }
            else if (type == typeof(CremaDataType))
            {
                var extension = settings.Extension != string.Empty ? settings.Extension : CremaSchema.SchemaExtension;
                var filename  = itemPath + extension;
                var dataSet   = new CremaDataSet();
                var dataType  = CremaDataType.ReadSchema(filename);
                dataSet.Types.Add(dataType);
                return(dataType);
            }
            else if (type == typeof(CremaDataSet))
            {
                if (settings is CremaDataSetSerializerSettings props)
                {
                    var dataSet    = CremaDataSet.Create(props.SignatureDateProvider);
                    var typePaths  = props.TypePaths.Select(item => item + CremaSchema.SchemaExtension).ToArray();
                    var tablePaths = props.TablePaths.Select(item => item + CremaSchema.XmlExtension).ToArray();

                    dataSet.ReadMany(typePaths, tablePaths, props.SchemaOnly);
                    dataSet.AcceptChanges();

                    return(dataSet);
                }
                else
                {
                    return(CremaDataSet.ReadFromDirectory(itemPath));
                }
            }
            else
            {
                var extension = settings.Extension != string.Empty ? settings.Extension : CremaSchema.XmlExtension;
                var filename  = itemPath + extension;
                return(DataContractSerializerUtility.Read(filename, type));
            }
        }
Example #6
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);
            }
        }
Example #7
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);
            }
        }