Ejemplo n.º 1
0
        private string GenerateFieldCreateSql(IFieldType field)
        {
            // There is probably a better way to do this but this is how things are currently
            switch (field)
            {
            case BooleanField _:
                return($"{field.Name} boolean {(!field.Nullable ? "not null" : "")}");

            case NumberField _:
                return($"{field.Name} integer" + (!field.Nullable ? "NOT NULL" : ""));

            case PrimaryField _:
                return($"{field.Name} uuid Not Null Primary Key");

            case TextField _:
                TextField castedTextField = (TextField)field;
                return($"{castedTextField.Name} varchar({castedTextField.Length})" + (!castedTextField.Nullable ? "NOT NULL" : ""));

            case LookupField _:
                LookupField castedLookupField = (LookupField)field;
                return($"{field.Name} uuid references {castedLookupField.Target}({castedLookupField.Target}id) {(!field.Nullable ? "not null" : "")}");

            default:
                throw new NotSupportedException($"Field type {field.GetType().Name} is unsupported by this backend");
            }
        }
Ejemplo n.º 2
0
        public static string DecodeAttributeValue(this IFieldType fieldType, AttributeCache attribute, string value)
        {
            var fieldTypeName = fieldType.GetType().FullName;

            if (FieldTypeConverters.ContainsKey(fieldTypeName))
            {
                return(FieldTypeConverters[fieldTypeName].DecodeValue(fieldType, attribute, value));
            }
            return("");
        }
Ejemplo n.º 3
0
        public static FormElementItem GetMobileElement(this IFieldType fieldType, AttributeCache attribute)
        {
            var fieldTypeName = fieldType.GetType().FullName;

            if (FieldTypeConverters.ContainsKey(fieldTypeName))
            {
                return(FieldTypeConverters[fieldTypeName].Convert(fieldType, attribute));
            }

            return(new FormElementItem()
            {
                Type = FormElementType.Entry,
                Keyboard = Keyboard.Text,
            });
        }
Ejemplo n.º 4
0
        private RecordFieldMetadata SerializeFieldMetadata(IFieldType field)
        {
            List <string> ignoredFields = new List <string>()
            {
                "Name", "FieldType"
            };
            var type = field.GetType();
            Dictionary <string, string> metadata = new Dictionary <string, string>();

            foreach (var f in type.GetFields())
            {
                if (!ignoredFields.Contains(f.Name))
                {
                    metadata.Add(f.Name, f.GetValue(field).ToString());
                }
            }
            return(new RecordFieldMetadata()
            {
                Type = type.Name,
                Nullable = field.Nullable,
                Metadata = metadata,
            });
        }