コード例 #1
0
        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);
        }
コード例 #2
0
        /// <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());
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
                }
            }
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        public static void Add(this TGSerializedObject _tgs, string _name, GeoPoint _geoPoint)
        {
            TGSerializedProperty tgsp = new TGSerializedProperty(_name, _geoPoint.ToGeoJson(), true);

            _tgs.Properties.Add(_name, tgsp);
        }