コード例 #1
0
        public static DBFields GetDBFields <TEntityType>(this TEntityType entity) where TEntityType : IMvxDBEntity
        {
            if (entity == null)
            {
                return(null);
            }
            var map = MvxDBMapping.Get(entity.GetType());

            if (map == null || map.PropertiesInfos == null || map.PropertiesInfos.Count == 0)
            {
                return(null);
            }
            var fields = new DBFields();

            foreach (var property in map.PropertiesInfos)
            {
                var value = property.GetValue(entity);
                if (value == null)
                {
                    continue;
                }
                fields.SetEx(property.Name, value);
            }
            return(fields);
        }
コード例 #2
0
        public void Sync()
        {
            if (DropboxDatastore == null)
            {
                return;
            }
            var changes = DropboxDatastore.Sync();

            if (changes != null && changes.Count > 0)
            {
                var messageType = typeof(DrbxReceivedMessage <>);
                var messenger   = Mvx.Resolve <IMvxMessenger>();
                foreach (var change in changes)
                {
                    var map = MvxDBMapping.Get(change.Key);
                    if (map == null)
                    {
                        continue;
                    }
                    Type[] typeArgs = { map.Type };
                    var    makeme   = messageType.MakeGenericType(typeArgs);
                    foreach (var record in change.Value)
                    {
                        var m = Activator.CreateInstance(makeme, this, record.ToMvxDBRecord()) as MvxMessage;
                        messenger.Publish(m, makeme);
                    }
                }
            }
        }
コード例 #3
0
        public static MvxDBRecord ToMvxDBRecord(this DBRecord record)
        {
            if (record == null)
            {
                return(null);
            }
            var map = MvxDBMapping.Get(record.Table.Id);

            return(new MvxDBRecord(record));
        }
コード例 #4
0
        public static Dictionary <string, object> ToDictionary(this DBRecord record, MvxDBMapping mapping)
        {
            var dictionary = new Dictionary <string, object>();

            foreach (var fieldName in record.FieldNames())
            {
                var property = mapping.PropertiesInfos.SingleOrDefault(p => p.Name.Equals(fieldName));
                if (property != null)
                {
                    object value = null;
                    var    type  = property.PropertyType;
                    if (type.IsLong())
                    {
                        value = record.GetLong(fieldName);
                    }
                    else if (type.IsNumeric())
                    {
                        value = record.GetDouble(fieldName);
                    }
                    else if (type.IsBool())
                    {
                        value = record.GetBoolean(fieldName);
                    }
                    else if (type.IsDateTime())
                    {
                        var date = record.GetDate(fieldName);
                        value = date.ToDateTime();
                    }
                    else if (type == typeof(string))
                    {
                        value = record.GetString(fieldName);
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                    dictionary.Add(fieldName, value);
                }
            }
            return(dictionary);
        }