Beispiel #1
0
 public CremaDataTableSerializerSettings(string path, string templatedPath)
 {
     if (string.IsNullOrEmpty(templatedPath) == false)
     {
         this.relativePath = UriUtility.MakeRelative(path, templatedPath);
     }
 }
        public void Write(XmlWriter writer)
        {
            var schema = new XmlSchema();

            if (this.dataSet != null)
            {
                this.WriteSchemaAttribute(schema, this.dataSet.Namespace);
                this.WriteGuidType(schema);
                this.WriteDataTypes(schema, dataSet.Types.OrderBy(item => item.Name));
                this.WriteTables(schema, dataSet.DataSetName, dataSet.Tables);
            }
            else if (this.dataTable != null)
            {
                var contentName    = this.dataTable.DataSet != null ? this.dataTable.DataSet.DataSetName : CremaDataSet.DefaultDataSetName;
                var tableNamespace = this.itemName == null ? this.dataTable.Namespace : CremaSchema.TableNamespace + this.itemName.CategoryPath + this.itemName.Name;
                this.WriteSchemaAttribute(schema, tableNamespace);
                this.WriteGuidType(schema);

                var tables = this.IsRecursive == true?EnumerableUtility.FamilyTree(dataTable, item => item.Childs) : Enumerable.Repeat(dataTable, 1);

                if (this.dataTable.DataSet != null)
                {
                    var columns = tables.SelectMany(item => item.Columns).Distinct();
                    var query   = from item in this.dataTable.DataSet.Types
                                  join column in columns on item.Path equals column.DataTypeName
                                  select item;

                    var index = 0;
                    foreach (var item in query.Distinct())
                    {
                        var typeSchema = new XmlSchema();
                        WriteSchemaAttribute(typeSchema, item.Namespace);
                        WriteDataType(typeSchema, item);

                        var import = new XmlSchemaImport()
                        {
                            Schema         = typeSchema,
                            Namespace      = item.Namespace,
                            SchemaLocation = UriUtility.MakeRelative(tableNamespace, item.Namespace) + CremaSchema.SchemaExtension
                        };
                        schema.Includes.Add(import);
                        index++;
                    }
                }

                this.WriteTables(schema, contentName, tables);
            }
            else if (this.dataType != null)
            {
                this.WriteSchemaAttribute(schema, this.dataType.Namespace);
                this.WriteDataTypes(schema, new CremaDataType[] { this.dataType });
            }

            schema.Write(writer);
        }
Beispiel #3
0
        public CremaXmlReadInfo(string xmlPath)
        {
            if (FileUtility.IsAbsolute(xmlPath) == false)
            {
                throw new ArgumentException("\"${xmlPath}\" 은(는) 절대 경로가 아닙니다.", nameof(xmlPath));
            }
            if (File.Exists(xmlPath) == false)
            {
                throw new FileNotFoundException($"\"{xmlPath}\" 경로를 찾을 수 없습니다.");
            }

            this.xmlPath = xmlPath;
            this.xsdPath = Path.ChangeExtension(xmlPath, CremaSchema.SchemaExtension);
            this.xmlSize = new FileInfo(xmlPath).Length;

            using (var reader = XmlReader.Create(this.xmlPath))
            {
                reader.MoveToContent();
                var text = reader.GetAttribute(CremaSchema.Version);
                if (string.IsNullOrEmpty(text) == false)
                {
                    Version.TryParse(text, out this.version);
                }
            }

            if (File.Exists(this.xsdPath) == false)
            {
                using (var reader = XmlReader.Create(xmlPath))
                {
                    reader.MoveToContent();
                    if (Version.TryParse(reader.GetAttribute(CremaSchema.Version), out Version version) == false)
                    {
                        version = new Version(2, 0);
                    }

                    if (version.Major == CremaSchema.MajorVersion)
                    {
                        FindSchemaLocation(reader, xmlPath, out this.xsdPath, out string tableNamespace);
                        var categoryPath = CremaDataSet.GetTableCategoryPath(CremaSchema.TableNamespace, tableNamespace);
                        var tableName    = CremaDataSet.GetTableName(CremaSchema.TableNamespace, tableNamespace);
                        this.itemName = new ItemName(categoryPath, tableName);
                    }
                    else
                    {
                        FindSchemaLocationVersion2(reader, xmlPath, out this.xsdPath, out string tableNamespace);
                        var categoryPath = CremaDataSet.GetTableCategoryPath(CremaSchemaObsolete.TableNamespaceObsolete, tableNamespace);
                        var tableName    = CremaDataSet.GetTableName(CremaSchemaObsolete.TableNamespaceObsolete, tableNamespace);
                        this.itemName = new ItemName(categoryPath, tableName);
                    }
                }
                this.isInherited = true;
            }

            this.relativeXsdPath = UriUtility.MakeRelative(this.xmlPath, this.xsdPath);
        }
Beispiel #4
0
        public void Write(XmlWriter writer)
        {
            var schema = new XmlSchema();

            if (this.dataSet != null)
            {
                this.WriteSchemaAttribute(schema, this.dataSet.Namespace);
                this.WriteGuidType(schema);
                this.WriteDataTypes(schema, dataSet.Types);
                this.WriteTables(schema, dataSet.DataSetName, dataSet.Tables.Where(item => item.Parent == null).OrderBy(item => item.TemplateNamespace));
            }
            else if (this.dataTable != null)
            {
                var contentName    = this.dataTable.DataSet != null ? this.dataTable.DataSet.DataSetName : CremaDataSet.DefaultDataSetName;
                var tableNamespace = this.itemName == null ? this.dataTable.Namespace : CremaSchema.TableNamespace + this.itemName.CategoryPath + this.itemName.Name;
                this.WriteSchemaAttribute(schema, tableNamespace);
                this.WriteGuidType(schema);

                if (this.dataTable.DataSet != null)
                {
                    var query = from item in this.dataTable.DataSet.Types
                                join c in this.dataTable.Columns on item.TypeName equals c.DataType.GetTypeName()
                                select item;

                    int index = 0;
                    foreach (var item in query.Distinct())
                    {
                        var typeSchema = new XmlSchema();
                        WriteSchemaAttribute(typeSchema, item.Namespace);
                        WriteDataType(typeSchema, item);

                        var import = new XmlSchemaImport()
                        {
                            Schema         = typeSchema,
                            Namespace      = item.Namespace,
                            SchemaLocation = UriUtility.MakeRelative(this.dataTable.Namespace, item.Namespace) + CremaSchema.SchemaExtension
                        };
                        schema.Includes.Add(import);
                        schema.Namespaces.Add("d" + index, item.Namespace);
                        index++;
                    }
                }

                this.WriteTables(schema, contentName, new CremaDataTable[] { this.dataTable });
            }
            else if (this.dataType != null)
            {
                this.WriteSchemaAttribute(schema, this.dataType.Namespace);
                this.WriteDataTypes(schema, new CremaDataType[] { this.dataType });
            }

            schema.Write(writer);
        }
Beispiel #5
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 #6
0
        private void WriteTables(XmlWriter writer, IEnumerable <CremaDataTable> tables)
        {
            writer.WriteAttribute(CremaSchema.Version, CremaSchema.VersionValue);

            if (this.dataTable != null)
            {
                if (this.dataTable.TemplateNamespace != string.Empty)
                {
                    var relativeUri = UriUtility.MakeRelative(this.dataTable.Namespace, this.dataTable.TemplateNamespace) + CremaSchema.SchemaExtension;
                    var value       = string.Format("{0} {1}", this.dataTable.Namespace, relativeUri);
                    writer.WriteAttributeString(CremaSchema.InstancePrefix, "schemaLocation", XmlSchema.InstanceNamespace, value);
                }
                else
                {
                    var value = string.Format("{0} {1}", this.dataTable.Namespace, this.dataTable.Name + CremaSchema.SchemaExtension);
                    writer.WriteAttributeString(CremaSchema.InstancePrefix, "schemaLocation", XmlSchema.InstanceNamespace, value);
                }
            }

            foreach (var item in tables)
            {
                if (item.TemplateNamespace != string.Empty)
                {
                    if (this.dataSet != null)
                    {
                        var name     = item.Name;
                        var user     = name + CremaSchema.CreatorExtension;
                        var dateTime = name + CremaSchema.CreatedDateTimeExtension;
                        writer.WriteAttribute(user, dateTime, item.CreationInfo);
                    }
                    else
                    {
                        var name     = item.TemplatedParentName;
                        var user     = name + CremaSchema.CreatorExtension;
                        var dateTime = name + CremaSchema.CreatedDateTimeExtension;
                        writer.WriteAttribute(user, dateTime, item.CreationInfo);
                    }
                }
            }

            foreach (var item in tables)
            {
                this.WriteHeaderInfo(writer, item);
            }

            foreach (var item in tables)
            {
                this.WriteRows(writer, item);
            }
        }
Beispiel #7
0
        private XmlQualifiedName GetXmlQualifiedName(XmlSchema schema, CremaDataColumn dataColumn)
        {
            if (dataColumn.CremaType != null)
            {
                var cremaType = dataColumn.CremaType;
                foreach (var item in schema.Includes)
                {
                    if (item is XmlSchemaImport == true)
                    {
                        var n = (item as XmlSchemaImport).Namespace;
                        if (cremaType.Namespace == n)
                        {
                            return(new XmlQualifiedName(cremaType.TypeName, cremaType.Namespace));
                        }
                    }
                }

                if (this.dataSet == null)
                {
                    using (var sr = new StringReader(cremaType.GetXmlSchema()))
                    {
                        var typeSchema     = XmlSchema.Read(sr, ValidationCallbackOne);
                        var schemaLocation = UriUtility.MakeRelative(dataColumn.Namespace, cremaType.Namespace) + CremaSchema.SchemaExtension;
                        schema.Includes.Add(new XmlSchemaImport()
                        {
                            Schema         = typeSchema,
                            SchemaLocation = schemaLocation,
                            Namespace      = cremaType.Namespace,
                        });
                    }

                    return(new XmlQualifiedName(cremaType.TypeName, cremaType.Namespace));
                }

                return(new XmlQualifiedName(cremaType.TypeName, schema.TargetNamespace));
            }
            else if (string.IsNullOrEmpty(dataColumn.Validation) == false)
            {
                return(new XmlQualifiedName(dataColumn.GetXmlSchemaTypeName(), schema.TargetNamespace));
            }
            else if (dataColumn.DataType == typeof(Guid))
            {
                return(new XmlQualifiedName(typeof(Guid).GetTypeName(), schema.TargetNamespace));
            }
            else
            {
                return(GetSystemQualifiedName(dataColumn.DataType));
            }
        }
 public ConsoleConfiguration([ImportMany] IEnumerable <IConfigurationPropertyProvider> propertiesProvider)
     : base(propertiesProvider)
 {
     this.xmlPath        = AppUtility.GetDocumentFilename("configs") + ".xml";
     this.xsdPath        = AppUtility.GetDocumentFilename("configs") + ".xsd";
     this.SchemaLocation = UriUtility.MakeRelative(this.xmlPath, this.xsdPath);
     if (File.Exists(this.xmlPath) == true)
     {
         try
         {
             //this.Read(this.xmlPath);
         }
         catch (Exception e)
         {
             CremaLog.Error(e);
         }
     }
 }
Beispiel #9
0
        private void WriteTable(XmlWriter writer, CremaDataTable dataTable)
        {
            writer.WriteAttribute(CremaSchema.Version, CremaSchema.VersionValue);

            if (dataTable.TemplateNamespace != string.Empty)
            {
                var relativeUri = UriUtility.MakeRelative(dataTable.Namespace, dataTable.TemplateNamespace) + CremaSchema.SchemaExtension;
                var value       = string.Format("{0} {1}", dataTable.Namespace, relativeUri);
                writer.WriteAttributeString(CremaSchema.InstancePrefix, "schemaLocation", XmlSchema.InstanceNamespace, value);
                writer.WriteAttribute(CremaSchema.Creator, CremaSchema.CreatedDateTime, dataTable.CreationInfo);
            }
            else
            {
                var value = string.Format("{0} {1}", dataTable.Namespace, dataTable.Name + CremaSchema.SchemaExtension);
                writer.WriteAttributeString(CremaSchema.InstancePrefix, "schemaLocation", XmlSchema.InstanceNamespace, value);
            }

            this.WriteHeaderInfo(writer, dataTable);

            this.WriteRows(writer, dataTable);
        }
        /// <summary>
        /// 솔루션 경로 기준으로 계산된 파일 경로
        /// </summary>
        public static string GetLocalPath(this Project project)
        {
            var solution = project.DTE.Solution;

            return(UriUtility.MakeRelative(solution.FullName, project.FullName));
        }
Beispiel #11
0
        /// <summary>
        /// 프로젝트 경로 기준으로 계산된 파일 경로
        /// </summary>
        public static string GetLocalPath(this ProjectItem projectItem)
        {
            var project = projectItem.ContainingProject;

            return(UriUtility.MakeRelative(project.FullName, projectItem.GetFullPath()));
        }