コード例 #1
0
        private static TreeNode CreatePropertyNode(TreeNode parent, string name, SchemaDataType type)
        {
            var propertyNode = parent.Nodes.Add(name, name, type.ToString(), type.ToString());

            propertyNode.Tag = type;
            return(propertyNode);
        }
コード例 #2
0
 private static void EditPropertyNode(TreeNode propertyNode, string name, SchemaDataType type)
 {
     propertyNode.Name             = name;
     propertyNode.Text             = name;
     propertyNode.ImageKey         = type.ToString();
     propertyNode.SelectedImageKey = type.ToString();
     propertyNode.Tag = type;
 }
コード例 #3
0
ファイル: PrimitiveFieldImpl.cs プロジェクト: ahives/Butter
 public PrimitiveFieldImpl(string id, int index, SchemaDataType dataType = SchemaDataType.Primitive,
                           bool isNullable = false)
 {
     Id         = id;
     Index      = index;
     IsNullable = isNullable;
     DataType   = dataType;
     HasValue   = !string.IsNullOrWhiteSpace(id);
 }
コード例 #4
0
ファイル: SchemaObject.cs プロジェクト: grarup/SharpE
        private void Load()
        {
            lock (this)
              {
            if (m_isLoaded)
              return;
            JsonNode jsonNode = m_jsonObject as JsonNode;
            if (jsonNode != null)
            {
              string refPath = jsonNode.GetObjectOrDefault<string>("$ref", null);
              if (refPath != null)
              {
            m_ref = m_schema.GetSchemaObjectByRef(refPath);
            return;
              }
              m_id = jsonNode.GetObjectOrDefault("id", "undefined");
              m_type = jsonNode.GetObjectOrDefault("type", SchemaDataType.Undefined);
              JsonNode definitions = jsonNode.GetObjectOrDefault<JsonNode>("definitions", null);
              InitDictionary(out m_definitions, definitions);
              JsonNode properties = jsonNode.GetObjectOrDefault<JsonNode>("properties", null);
              InitDictionary(out m_properties, properties);
              if (m_properties != null && m_type == SchemaDataType.Undefined)
            m_type = SchemaDataType.Object;

              JsonObject items = jsonNode.GetObjectOrDefault<JsonObject>("items", null);
              InitArray(out m_items, items);
              JsonArray enums = jsonNode.GetObjectOrDefault<JsonArray>("enum", null);
              if (enums != null)
              {
            m_enums = new List<object>();
            foreach (object obj in enums)
              m_enums.Add(obj);
              }
              JsonNode additionalProperties = jsonNode.GetObjectOrDefault<JsonNode>("additionalProperties", null);
              if (additionalProperties != null)
              {
            m_additionalProperties = new SchemaObject(additionalProperties, m_schema);
              }
              JsonArray allOf = jsonNode.GetObjectOrDefault<JsonObject>("allOf", null) as JsonArray;
              InitArray(out m_allOf, allOf);
              m_anyOfArray = jsonNode.GetObjectOrDefault<JsonObject>("anyOf", null) as JsonArray;
              InitArray(out m_anyOf, m_anyOfArray);
              m_oneOfArray = jsonNode.GetObjectOrDefault<JsonObject>("oneOf", null) as JsonArray;
              InitArray(out m_oneOf, m_oneOfArray);
              m_description = jsonNode.GetObjectOrDefault("description", default(string));
              JsonNode autoCompleteNode = jsonNode.GetObjectOrDefault<JsonNode>("AutoComplet", null);
              if (autoCompleteNode != null)
              {
            m_schemaAutoCompletType = autoCompleteNode.GetObjectOrDefault("type", SchemaAutoCompletType.Undefined);
            m_prefix = autoCompleteNode.GetObjectOrDefault("prefix", "");
            m_suffix = autoCompleteNode.GetObjectOrDefault("suffix", "");
            string filter = autoCompleteNode.GetObjectOrDefault<string>("filter", null);
            if (filter != null)
              m_autoCompleteFilter = new Regex(filter);
            m_autoCompleteTargetKey = autoCompleteNode.GetObjectOrDefault<string>("targetkey", null);
            m_autoCompleteSourceKey = autoCompleteNode.GetObjectOrDefault<string>("sourcekey", null);
            m_autoCompletePathSeperator = autoCompleteNode.GetObjectOrDefault("pathseperator", "\\")[0];
              }
              object mulipleOfObject = jsonNode.GetObjectOrDefault<object>("multipleOf", null);
              if (mulipleOfObject != null)
              {
            if (mulipleOfObject is int)
              m_multipleOf = (int)mulipleOfObject;
            else if (mulipleOfObject is double)
              m_multipleOf = (double)mulipleOfObject;
              }
              JsonNode patternPropertiesNode = jsonNode.GetObjectOrDefault<object>("patternProperties", null) as JsonNode;
              Dictionary<string, SchemaObject> patternProperties;
              InitDictionary(out patternProperties, patternPropertiesNode);
              if (patternProperties != null)
              {
            m_patternProperties = new Dictionary<Regex, SchemaObject>();
            foreach (KeyValuePair<string, SchemaObject> patternProperty in patternProperties)
              m_patternProperties.Add(new Regex(patternProperty.Key), patternProperty.Value);
              }
              if (m_type == SchemaDataType.Undefined)
              {
            if (jsonNode.ContainsKey("minLength") || jsonNode.ContainsKey("maxLength") || jsonNode.ContainsKey("pattern"))
              m_type = SchemaDataType.String;
            if (jsonNode.ContainsKey("minimum") || jsonNode.ContainsKey("maximun") || jsonNode.ContainsKey("exclusiveMinimum") || jsonNode.ContainsKey("exclusiveMaximum") || jsonNode.ContainsKey("multipleOf"))
              m_type = SchemaDataType.Number;
            if (jsonNode.ContainsKey("minItems") || jsonNode.ContainsKey("maxItems") || jsonNode.ContainsKey("uniqueItems"))
              m_type = SchemaDataType.Array;
            if (jsonNode.ContainsKey("minProperties") || jsonNode.ContainsKey("maxProperties") || jsonNode.ContainsKey("required"))
              m_type = SchemaDataType.Object;

              }

              switch (m_type)
              {
            case SchemaDataType.String:
              m_min = jsonNode.GetObjectOrDefault("minLength", 0);
              m_max = jsonNode.GetObjectOrDefault("maxLength", int.MaxValue);
              string pattern = jsonNode.GetObjectOrDefault<string>("pattern", null);
              if (pattern != null)
                m_pattern = new Regex(pattern);
              break;
            case SchemaDataType.Integer:
              m_min = jsonNode.GetObjectOrDefault("minimum", int.MinValue);
              m_max = jsonNode.GetObjectOrDefault("maximum", int.MaxValue);
              m_exclusiveMin = jsonNode.GetObjectOrDefault("exclusiveMinimum", false);
              m_exclusiveMax = jsonNode.GetObjectOrDefault("exclusiveMaximum", false);
              break;
            case SchemaDataType.Number:
              object minJsonValue = jsonNode.GetObjectOrDefault<object>("minimum", null);
              if (minJsonValue != null)
              {
                if (minJsonValue is int)
                  m_min = (int)minJsonValue;
                else if (minJsonValue is double)
                  m_min = (double)minJsonValue;
                else
                  m_min = double.MinValue;
              }
              else
              {
                m_min = double.MinValue;
              }
              object maxJsonValue = jsonNode.GetObjectOrDefault<object>("maximum", null);
              if (maxJsonValue != null)
              {
                if (maxJsonValue is int)
                  m_max = (int)maxJsonValue;
                else if (maxJsonValue is double)
                  m_max = (double)maxJsonValue;
                else
                  m_max = double.MaxValue;
              }
              else
              {
                m_max = double.MaxValue;
              }
              m_exclusiveMin = jsonNode.GetObjectOrDefault("exclusiveMinimum", false);
              m_exclusiveMax = jsonNode.GetObjectOrDefault("exclusiveMaximum", false);
              break;
            case SchemaDataType.Array:
              m_min = jsonNode.GetObjectOrDefault("minItems", 0);
              m_max = jsonNode.GetObjectOrDefault("maxItems", int.MaxValue);
              m_uniqueItems = jsonNode.GetObjectOrDefault("uniqueItems", false);
              break;
            case SchemaDataType.Object:
              m_min = jsonNode.GetObjectOrDefault("minProperties", 0);
              m_max = jsonNode.GetObjectOrDefault("maxProperties", int.MaxValue);
              JsonArray jsonArray = jsonNode.GetObjectOrDefault<JsonArray>("required", null);
              if (jsonArray != null)
              {
                m_requiredProperties = new List<string>();
                foreach (JsonValue jsonValue in jsonArray)
                  m_requiredProperties.Add((string)jsonValue.Value);
              }
              break;
            case SchemaDataType.Undefined:
              break;
              }
            }
            m_isLoaded = true;
              }
        }
コード例 #5
0
        public Primitive DataType(SchemaDataType dataType)
        {
            _dataType = dataType;

            return(this);
        }
コード例 #6
0
 private static string GetValueFormat(SchemaDataType dataType)
 {
     return((dataType == SchemaDataType.DateTime) ? "dd.MM.yyyy" : string.Empty);
 }
コード例 #7
0
 public EditorBase CreateArrayEditor(SchemaDataType dataType)
 {
     return(new ArrayEditor(dataType.ToClrType(), GetValueFormat(dataType)));
 }
コード例 #8
0
 public EditorBase CreateSimpleEditor(SchemaDataType dataType)
 {
     return(FactoryMethods[dataType](GetValueFormat(dataType)));
 }