コード例 #1
0
        public ModelReader(XDocument doc, Action <string> write, bool isStage = true)
        {
            Schema = doc.Descendants("schema").Select(x => new SchemaInfo
            {
                ConnectionStringName = RootUtil.GetAttribute <string>(x, "connectionStringName", true),
                ClassName            = RootUtil.GetAttribute <string>(x, "class", true),
                NamespaceName        = RootUtil.GetAttribute <string>(x, "namespace", true),
                SiteName             = RootUtil.GetAttribute <string>(x, "siteName", true),
                UseLongUrls          = RootUtil.GetAttribute <bool>(x, "useLongUrls"),
                ReplaceUrls          = RootUtil.GetAttribute <bool>(x, "replaceUrls"),
                IsStageMode          = isStage,
            }).First();

            Contents = doc.Descendants("schema").First().Descendants("content").Select(x => new ContentInfo
            {
                Id                   = RootUtil.GetAttribute <int>(x, "id", true),
                Name                 = RootUtil.GetAttribute <string>(x, "name", true),
                MappedName           = RootUtil.GetAttribute <string>(x, "mapped_name", true),
                PluralMappedName     = RootUtil.GetAttribute <string>(x, "plural_mapped_name", true),
                UseDefaultFiltration = bool.Parse(x.Attribute("use_default_filtration").Value),
                IsVirtual            = RootUtil.GetAttribute <bool>(x, "virtual"),
                SplitArticles        = RootUtil.GetAttribute <bool>(x, "split_articles", fallbackValue: true),
                IsStageMode          = Schema.IsStageMode,
                Attributes           = x.Descendants("attribute").Select(a => new AttributeInfo
                {
                    Id                 = RootUtil.GetAttribute <int>(a, "id", true),
                    Name               = RootUtil.GetAttribute <string>(a, "name", true),
                    MappedName         = RootUtil.GetAttribute <string>(a, "mapped_name", true),
                    MappedBackName     = RootUtil.GetAttribute <string>(a, "mapped_back_name"),
                    Type               = RootUtil.GetAttribute <string>(a, "type", true),
                    Size               = RootUtil.GetAttribute <int>(a, "size"),
                    IsLong             = RootUtil.GetAttribute <bool>(a, "is_long"),
                    RelatedContentId   = RootUtil.GetAttribute <int>(a, "related_content_id"),
                    RelatedAttributeId = RootUtil.GetAttribute <int>(a, "related_attribute_id"),
                    LinkId             = RootUtil.GetAttribute <int>(a, "link_id"),
                    ContentId          = int.Parse(x.Attribute("id").Value),
                    HasM2O             = RootUtil.GetAttribute <bool>(a, "has_m2o")
                }).ToList()
            }).ToList();

            Links = doc.Descendants("schema").First().Descendants("link").Select(x => new LinkInfo
            {
                Id               = RootUtil.GetAttribute <int>(x, "id"),
                MappedName       = RootUtil.GetAttribute <string>(x, "mapped_name"),
                PluralMappedName = RootUtil.GetAttribute <string>(x, "plural_mapped_name"),
                ContentId        = RootUtil.GetAttribute <int>(x, "content_id"),
                LinkedContentId  = RootUtil.GetAttribute <int>(x, "linked_content_id"),
                IsSelf           = RootUtil.GetAttribute <bool>(x, "self"),
            }).ToList();

            Build(write);
        }
コード例 #2
0
        public static EDMXSettings Parse(string path)
        {
            var doc = System.Xml.Linq.XDocument.Load(path);

            var result = doc.Descendants("settings").Select(x => new EDMXSettings
            {
                QPContextMappingResultPath = RootUtil.GetElementValue <string>(x, "QPContextMappingResultPath"),
                GenerateModel                    = RootUtil.GetElementValue <bool>(x, "GenerateModel"),
                GenerateMappings                 = RootUtil.GetElementValue <bool>(x, "GenerateMappings"),
                GenerateMappingInterface         = RootUtil.GetElementValue <bool>(x, "GenerateMappingInterface"),
                GenerateClasses                  = RootUtil.GetElementValue <bool>(x, "GenerateClasses"),
                LazyLoadingEnabled               = RootUtil.GetElementValue <bool>(x, "LazyLoadingEnabled"),
                ProxyCreationEnabled             = RootUtil.GetElementValue <bool>(x, "ProxyCreationEnabled"),
                GenerateStage                    = RootUtil.GetElementValue <bool>(x, "GenerateStage"),
                GenerateLive                     = RootUtil.GetElementValue <bool>(x, "GenerateLive"),
                GenerateUnion                    = RootUtil.GetElementValue <bool>(x, "GenerateUnion"),
                UseContextNameAsConnectionString = RootUtil.GetElementValue <bool>(x, "UseContextNameAsConnectionString"),
                Usings = RootUtil.GetElementValue <string>(x, "Usings") ?? "",
                InheritTableExtensions       = RootUtil.GetElementValue <bool>(x, "InheritTableExtensions"),
                GenerateExtensions           = RootUtil.GetElementValue <bool>(x, "GenerateExtensions"),
                GenerateInterface            = RootUtil.GetElementValue <bool>(x, "GenerateInterface"),
                PlaceContentsInSeparateFiles = RootUtil.GetElementValue <bool>(x, "PlaceContentsInSeparateFiles"),
                UseReversedAssociations      = RootUtil.GetElementValue <bool>(x, "UseReversedAssociations"),
                Localization = x.Descendants("Localization").Select(
                    l => new Localization
                {
                    CaseSensitive           = RootUtil.GetElementValue <bool>(l, "CaseSensitive"),
                    GenerateMappingsRuntime = RootUtil.GetElementValue <bool>(l, "GenerateMappingsRuntime"),
                    UseSelectiveMappings    = RootUtil.GetElementValue <bool>(l, "UseSelectiveMappings"),
                    Pattern         = RootUtil.GetElementValue <string>(l, "Pattern"),
                    CultureMappings = x.Descendants("CultureMappings").Select(
                        cm => new Map
                    {
                        CultureAlias = RootUtil.GetAttribute <string>(cm, "cultureAlias"),
                        To           = RootUtil.GetAttribute <string>(cm, "to")
                    }).ToArray()
                }).FirstOrDefault()
            }).First();

            return(result);
        }