Beispiel #1
0
 public static SchemaEntity JsonToSchema(string JsonStr, string SchemaName)
 {
     dynamic obj = JsonConvert.DeserializeObject<ExpandoObject>(JsonStr, new ExpandoObjectConverter());
     var node = new SchemaEntity();
     node.SchemaName = SchemaName;
     node.JsonStructure = JsonStr;
     node.XmlStructure = ExpandoToXML(obj, SchemaName);
     node.Fields = GenerateFieldsFromExpando(obj);
     return node;
 }
Beispiel #2
0
 public static SchemaEntity ExpandoToSchema(dynamic obj, string SchemaName)
 {
     var node = new SchemaEntity();
     node.SchemaName = SchemaName;
     node.JsonStructure = JsonConvert.SerializeObject(obj);
     XElement el = ExpandoToXML(obj, SchemaName);
     node.XmlStructure = el.ToString();
     node.Fields = GenerateFieldsFromExpando(obj);
     return node;
 }
Beispiel #3
0
 public static SchemaEntity XmlToSchema(string XmlStr, string SchemaName)
 {
     dynamic obj = XMLtoExpando(null, XElement.Parse(XmlStr));
     var node = new SchemaEntity();
     node.SchemaName = SchemaName;
     node.JsonStructure = JsonConvert.SerializeObject(obj); ;
     node.XmlStructure = XmlStr;
     node.Fields = GenerateFieldsFromExpando(obj);
     return node;
 }
Beispiel #4
0
 public static string SchemaToXml(SchemaEntity entity)
 {
     return entity.XmlStructure;
 }
Beispiel #5
0
 public static string SchemaToJson(SchemaEntity entity)
 {
     return entity.JsonStructure;
 }
Beispiel #6
0
 public static SchemaEntity DesignToSchema(List<IDField> fields, string SchemaName)
 {
     var node = new SchemaEntity();
     var NewFields = new Dictionary<string, IDField>();
     dynamic newObj = new ExpandoObject();
     foreach (var item in fields)
     {
         (newObj as IDictionary<string, object>).Add(item.Name.Replace(" ", "_"), GetSample(item.NativeType));
         NewFields.Add(item.Name.Replace(" ", "_"),item);
     }
     
     node.SchemaName = SchemaName;
     node.JsonStructure = JsonConvert.SerializeObject(newObj);
     XElement el = ExpandoToXML(newObj, SchemaName);
     node.XmlStructure = el.ToString();
     node.Fields = NewFields;
     return node;
 }