Example #1
0
        private static Enumeration TranslateEnumeration(
            Models.SchemaClass schemaClass,
            List <Models.SchemaEnumerationValue> schemaValues)
        {
            var values = schemaValues
                         .Where(x => x.Types.Contains(schemaClass.Id.ToString()))
                         .Select(x => new EnumerationValue()
            {
                Description = x.Comment,
                Name        = x.Label,
                Uri         = x.Id
            })
                         .OrderBy(x => x.Name, new EnumerationValueComparer())
                         .ToList();

            return(new Enumeration()
            {
                Description = schemaClass.Comment,
                Layer = $"{schemaClass.Layer}{Path.DirectorySeparatorChar}enumerations",
                Name = schemaClass.Label,
                Values = values
            });
        }
Example #2
0
        private static Class TranslateClass(
            Models.SchemaClass schemaClass,
            List <Models.SchemaClass> schemaClasses,
            List <Models.SchemaProperty> schemaProperties)
        {
            var @class = new Class()
            {
                Description = schemaClass.Comment,
                Id          = schemaClass.Id,
                Layer       = schemaClass.Layer,
                Name        = schemaClass.Label,
                Parents     = schemaClasses
                              .Where(x => schemaClass.SubClassOfIds.Contains(x.Id))
                              .Select(x => new Class()
                {
                    Id = x.Id
                })
                              .ToList()
            };

            var properties = schemaProperties
                             .Where(x => x.DomainIncludes.Contains(schemaClass.Id) && !x.IsArchived && !x.IsMeta && !x.IsPending)
                             .Select(x =>
            {
                var propertyName = GetPropertyName(x.Label);
                return(new Property()
                {
                    Class = @class,
                    Description = x.Comment,
                    JsonName = CamelCase(propertyName),
                    Name = propertyName,
                    Types = x.RangeIncludes
                            .Where(y =>
                    {
                        var propertyTypeName = y.ToString().Replace("http://schema.org/", string.Empty);
                        var propertyTypeClass = schemaClasses
                                                .FirstOrDefault(z => string.Equals(z.Label, propertyTypeName, StringComparison.OrdinalIgnoreCase));
                        return propertyTypeClass == null || (!propertyTypeClass.IsArchived && !propertyTypeClass.IsMeta && !propertyTypeClass.IsPending);
                    })
                            .Select(y =>
                    {
                        var propertyTypeName = y.ToString().Replace("http://schema.org/", string.Empty);
                        var isPropertyTypeEnum = schemaClasses
                                                 .Any(z => z.IsEnum && string.Equals(z.Label, propertyTypeName, StringComparison.OrdinalIgnoreCase));
                        var csharpTypeString = GetCSharpTypeString(
                            propertyName,
                            propertyTypeName,
                            isPropertyTypeEnum);
                        var propertyType = new PropertyType()
                        {
                            CSharpTypeString = csharpTypeString,
                            Name = propertyTypeName,
                        };
                        return propertyType;
                    })
                            .Where(y => !string.Equals(y.Name, "Enumeration", StringComparison.OrdinalIgnoreCase) &&
                                   !string.Equals(y.Name, "QualitativeValue", StringComparison.OrdinalIgnoreCase))
                            .GroupBy(y => y.CSharpTypeString)
                            .Select(y => y.First())
                            .OrderBy(y => y.Name)
                            .ToList(),
                });
            })
                             .Where(x => x.Types.Count > 0)
                             .OrderBy(x => x.Name, new PropertyNameComparer())
                             .GroupBy(x => x.Name) // Remove duplicates.
                             .Select(x => x.First())
                             .ToList();

            @class.Properties.AddRange(properties);
            return(@class);
        }