public static Dictionary <string, AttributeValue> GetDictionary(TGSerializedObject _tgs) { Dictionary <string, AttributeValue> dictionary = new Dictionary <string, AttributeValue>(); foreach (string key in _tgs.Properties.Keys) { TGSerializedProperty property = _tgs.Properties[key]; if (!string.IsNullOrEmpty(property.SerializedValue)) { AttributeValue av = new AttributeValue() { S = property.SerializedValue }; dictionary.Add(property.PropertyName, av); } } dictionary.Add("TGObjectType", new AttributeValue { S = _tgs.TGObjectType }); return(dictionary); }
/// <summary> /// /// </summary> /// <param name="_tg"></param> /// <returns></returns> private string GetRow(TGSerializedObject _tg) { StringBuilder sb = new StringBuilder(); foreach (string key in _tg.Properties.Keys) { TGSerializedProperty property = _tg.Properties[key]; if (EncloseValuesInQuotes) { sb.AppendFormat(@"""{0}""", property.SerializedValue); } else { sb.AppendFormat(@"{0}", property.SerializedValue); } sb.Append(Delimiter); } //Remove the final delimiter if (sb.Length > 0) { sb.Remove(sb.Length - Delimiter.Length, Delimiter.Length); } return(sb.ToString()); }
public static BsonDocument Get <T>(T _obj) where T : AbstractTGObject { BsonDocument doc = new BsonDocument(); TGSerializedObject bcn = _obj.GetTGSerializedObject(); foreach (KeyValuePair <string, TGSerializedProperty> kvp in bcn.Properties) { TGSerializedProperty prop = kvp.Value; if (prop.PropertyName.Equals("guid", StringComparison.InvariantCultureIgnoreCase)) { Guid temp = new Guid(prop.SerializedValue); doc.Add("_id", new BsonBinaryData(temp.ToByteArray())); doc.Add("Guid", new BsonString(prop.SerializedValue)); } else if (prop.IsChildObject) { string temp = prop.SerializedValue; BsonDocument subDoc = BsonDocument.Parse(temp); doc.Add(prop.PropertyName, subDoc); } else { doc.Add(prop.PropertyName, prop.SerializedValue); } } return(doc); }
public static void PopulateTGSerializedObject(TGSerializedObject _tgs, Dictionary <string, AttributeValue> _values) { foreach (string key in _values.Keys) { AttributeValue av = _values[key]; if (key == "TGObjectType") { _tgs.TGObjectType = av.S; } else { TGSerializedProperty tgp = new TGSerializedProperty(av.S); _tgs.Properties.Add(key, tgp); } } }
public static T Get <T>(BsonDocument _document) where T : AbstractTGObject, new() { if (_document != null) { TGSerializedObject tso = new TGSerializedObject(); foreach (string name in _document.Names) { if (!name.Equals("_id")) { BsonValue val = _document[name]; TGSerializedProperty serializedProperty = new TGSerializedProperty(name, val.ToString()); tso.Properties.Add(name, serializedProperty); } } return(TGSerializedObject.GetTGSerializable <T>(tso)); } return(default(T)); }
public static void Add(this TGSerializedObject _tgs, string _name, GeoPoint _geoPoint) { TGSerializedProperty tgsp = new TGSerializedProperty(_name, _geoPoint.ToGeoJson(), true); _tgs.Properties.Add(_name, tgsp); }