Esempio n. 1
0
        public override void Execute(ProjectState project, List <ActionParameter> parameters)
        {
            var schemaName        = GetStringParameterValue(parameters, SchemaNameParameter).ToWordPascalCase();
            var name              = GetStringParameterValue(parameters, NameParameter).ToWordPascalCase();
            var type              = GetStringParameterValue(parameters, TypeParameter);
            var length            = GetIntParameterValue(parameters, LengthParameter);
            var isPrimaryKey      = GetBoolParameterValue(parameters, IsPrimaryKeyParameter);
            var isNullable        = GetBoolParameterValue(parameters, IsNullableParameter);
            var isUnique          = GetBoolParameterValue(parameters, IsUniqueParameter);
            var isAutoincremental = GetBoolParameterValue(parameters, IsAutoIncrementalParameter);

            var schema = project.GetSchema(schemaName);

            if (schema == null)
            {
                throw new Exception($"Can't find any schema named '{schemaName}'");
            }

            var typedType = SchemaProperty.StringToType(type);
            var property  = new SchemaProperty(name, typedType, true)
            {
                IsAutoIncremental = isAutoincremental,
                IsNullable        = isNullable,
                IsPrimaryKey      = isPrimaryKey,
                IsUnique          = isUnique,
                Length            = length
            };

            schema.AddProperty(property);
            OverrideOutputParameter(SchemaNameParameter.Name, schemaName);
            OverrideOutputParameter(NameParameter.Name, name);
        }
 public void AddProperty(string name,string displayName,string description, string trueType,SoType k2Type)
 {
     SchemaProperty prop = new SchemaProperty();
     prop.Name=name;
     prop.DisplayName = displayName;
     prop.Description = description;
     prop.TrueType = trueType;
     prop.K2Type = k2Type;
     SchemaProperties.Add(prop);
 }
        public string ResolveSchemaProperty(SchemaProperty property)
        {
            var resolvedType = ResolveSchemaPropertyType(property.Type);

            var required     = property.IsRequired ? RequiredSymbol : string.Empty;
            var defaultValue = property.DefaultValue != null && !string.IsNullOrEmpty(property.DefaultValue.ToString()) ? $" default({property.DefaultValue})" : string.Empty;
            var unique       = property.IsUnique ? $" {UniqueKeyword}" : string.Empty;

            return($"{property.Name}: {resolvedType}{required}{defaultValue}{unique}");
        }
Esempio n. 4
0
        public void AddProperty(string name, string displayName, string description, string trueType, SoType k2Type)
        {
            SchemaProperty prop = new SchemaProperty();

            prop.Name        = name;
            prop.DisplayName = displayName;
            prop.Description = description;
            prop.TrueType    = trueType;
            prop.K2Type      = k2Type;
            SchemaProperties.Add(prop);
        }
Esempio n. 5
0
        public async Task <IActionResult> AddSchema()
        {
            var schema = new Schema {
                Name = "Customer"
            };
            var property = new SchemaProperty {
                Name = "Name", Type = "string", IsRequired = true
            };

            schema.Properties.Add(property);

            await _writer.SaveAsync(schema);

            return(Ok(schema));
        }
Esempio n. 6
0
        private async Task SaveSchemaAsync(string controller, object model)
        {
            var schema = new Schema
            {
                Name = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(controller)
            };
            var type = model.GetType();

            foreach (var p in type.GetProperties())
            {
                var property = new SchemaProperty {
                    Type = p.PropertyType.Name, Name = p.Name, IsRequired = false
                };
                schema.Properties.Add(property);
            }

            await _writer.SaveAsync(schema);
        }
Esempio n. 7
0
 private static SchemaProperty GetSchemaProperty(string propertyName)
 {
     if (!schemaPropertyCache.TryGetValue(propertyName, out SchemaProperty schemaProperty))
     {
         using (ActiveDirectorySchema schema = ActiveDirectorySchema.GetCurrentSchema())
         {
             ActiveDirectorySchemaProperty           result         = schema.FindProperty(propertyName);
             System.DirectoryServices.DirectoryEntry directoryEntry = result.GetDirectoryEntry();
             schemaProperty = new SchemaProperty()
             {
                 LdapDisplayName = result.Name,
                 SchemaGuid      = result.SchemaGuid,
                 IsConfidential  = (((int)directoryEntry.Properties["searchFlags"][0] & 128) == 128)
             };
             schemaPropertyCache.Add(result.Name, schemaProperty);
         }
     }
     return(schemaProperty);
 }
Esempio n. 8
0
        public AddSchemaProperty() : base(ActionName)
        {
            SchemaNameParameter = new ActionParameterDefinition(
                "schemaname", ActionParameterDefinition.TypeValue.String, "Schema name", "s", string.Empty)
            {
                IsSchemaSuggestion = true
            };
            NameParameter = new ActionParameterDefinition(
                "name", ActionParameterDefinition.TypeValue.String, "Name. Use PascalCase or the name will be converted to PascalCase automatically", "n", string.Empty);
            TypeParameter = new ActionParameterDefinition(
                "type", ActionParameterDefinition.TypeValue.String, "Type. Possible values: Guid = 1, Boolean = 2, Integer = 3, Decimal = 4,  Float = 5, Time = 6, DateTime = 7, String = 8, LongString = 9, Password = 99, ",
                "t", string.Empty)
            {
                InputSuggestions = SchemaProperty.GetUseCaseTypesList()
            };

            LengthParameter = new ActionParameterDefinition(
                "length", ActionParameterDefinition.TypeValue.Integer, "Length. Use only for String types", "l", 0);
            IsPrimaryKeyParameter = new ActionParameterDefinition(
                "primarykey", ActionParameterDefinition.TypeValue.Boolean, "Is primary key", "pk", false);
            IsNullableParameter = new ActionParameterDefinition(
                "nullable", ActionParameterDefinition.TypeValue.Boolean, "Is nullable", "nl", false);
            IsUniqueParameter = new ActionParameterDefinition(
                "unique", ActionParameterDefinition.TypeValue.Boolean, "Is unique key", "un", false);
            IsAutoIncrementalParameter = new ActionParameterDefinition(
                "autoincrement", ActionParameterDefinition.TypeValue.Boolean, "Is autoincrement. Only valid for Integer types", "ai", false);

            ActionParametersDefinition.Add(SchemaNameParameter);
            ActionParametersDefinition.Add(NameParameter);
            ActionParametersDefinition.Add(TypeParameter);
            ActionParametersDefinition.Add(LengthParameter);
            ActionParametersDefinition.Add(IsPrimaryKeyParameter);
            ActionParametersDefinition.Add(IsNullableParameter);
            ActionParametersDefinition.Add(IsUniqueParameter);
            ActionParametersDefinition.Add(IsAutoIncrementalParameter);
        }
        private static SchemaObject Read(JToken token)
        {
            var commentToken = token["rdfs:comment"];

            if (commentToken == null)
            {
                return(null);
            }

            var supercededByToken = token["http://schema.org/supersededBy"];

            if (supercededByToken != null)
            {
                // Ignore deprecated properties.
                return(null);
            }

            var id             = new Uri(token["@id"].Value <string>());
            var types          = GetTokenValues(token["@type"]).ToList();
            var comment        = token["rdfs:comment"].Value <string>();
            var label          = GetLabel(token);
            var domainIncludes = GetTokenValues(token["http://schema.org/domainIncludes"], "@id").ToList();
            var rangeIncludes  = GetTokenValues(token["http://schema.org/rangeIncludes"], "@id").ToList();
            var subClassOf     = GetTokenValues(token["rdfs:subClassOf"], "@id").ToList();
            var isPartOf       = GetTokenValues(token["http://schema.org/isPartOf"]).FirstOrDefault();
            var layer          = isPartOf == null ?
                                 LayerName.Core :
                                 isPartOf.Replace("http://", string.Empty, StringComparison.Ordinal).Replace(".schema.org", string.Empty, StringComparison.Ordinal);

            if (types.Any(type => string.Equals(type, "rdfs:Class", StringComparison.OrdinalIgnoreCase)))
            {
                var schemaClass = new SchemaClass()
                {
                    Comment = comment,
                    Id      = id,
                    Label   = label,
                    Layer   = layer,
                };
                schemaClass.SubClassOfIds.AddRange(subClassOf);
                schemaClass.Types.AddRange(types);
                return(schemaClass);
            }
            else if (types.Any(type => string.Equals(type, "rdf:Property", StringComparison.OrdinalIgnoreCase)))
            {
                var schemaProperty = new SchemaProperty()
                {
                    Comment = comment,
                    Id      = id,
                    Label   = label,
                    Layer   = layer,
                };
                schemaProperty.DomainIncludes.AddRange(domainIncludes);
                schemaProperty.RangeIncludes.AddRange(rangeIncludes);
                schemaProperty.Types.AddRange(types);
                return(schemaProperty);
            }
            else
            {
                var schemaEnumerationValue = new SchemaEnumerationValue()
                {
                    Comment = comment,
                    Id      = id,
                    Label   = label,
                    Layer   = layer,
                };
                schemaEnumerationValue.Types.AddRange(types);
                return(schemaEnumerationValue);
            }
        }
Esempio n. 10
0
        public static Guid GetAttributeSchemaGuid(string attribute)
        {
            SchemaProperty schemaProperty = GetSchemaProperty(attribute);

            return(schemaProperty.SchemaGuid);
        }
Esempio n. 11
0
        public static bool IsAttributeConfidential(string attribute)
        {
            SchemaProperty schemaProperty = GetSchemaProperty(attribute);

            return(schemaProperty.IsConfidential);
        }
Esempio n. 12
0
 set => SetValue(SchemaProperty, value);
 public string ResolvePropertyAsParameter(SchemaProperty property)
 {
     return($"{ResolveAsParameterName(property.Name)}: {ResolveSchemaPropertyType(property.Type)}{(property.IsRequired || property.IsKey ? RequiredSymbol : string.Empty)}");
 }
 public string ResolveSchemaIdProperty(SchemaProperty property)
 {
     return($"{property.Name}: ID! {UniqueKeyword}");
 }