Пример #1
0
        public MobeelizerJsonEntity GetJsonEntity(MobeelizerModelMetadata metadata, MobeelizerDatabaseContext db)
        {
            MobeelizerJsonEntity entity = new MobeelizerJsonEntity();

            entity.Model  = metadata.Model;
            entity.Guid   = metadata.Guid;
            entity.Fields = new Dictionary <string, string>();
            var result = from MobeelizerWp7Model model in db.GetTable(this.Type) where model.Guid == metadata.Guid select model;
            MobeelizerWp7Model modelObject = result.Single();

            entity.Owner = modelObject.Owner;
            entity.Fields.Add("s_deleted", modelObject.Deleted.ToString().ToLower());
            foreach (MobeelizerField field in this.Fields)
            {
                object       value    = null;
                PropertyInfo property = modelObject.GetType().GetProperty(field.Accessor.Name);
                if (property == null)
                {
                    throw new ConfigurationException("There is no property " + field.Accessor.Name + " in " + entity.Model + " class.");
                }

                value = property.GetValue(modelObject, null);
                entity.Fields.Add(field.Name, field.FieldType.SetValueFromDatabaseToMap(value));
            }

            return(entity);
        }
Пример #2
0
        private void InsertEntity(MobeelizerDatabaseContext db, IDictionary <String, object> values)
        {
            MobeelizerModelMetadata metadate = new MobeelizerModelMetadata();

            metadate.Model = this.Name;
            var entity = Activator.CreateInstance(this.Type);

            foreach (KeyValuePair <String, object> value in values)
            {
                if (value.Key == "Guid")
                {
                    metadate.Guid = (String)value.Value;
                    PropertyInfo property = this.Type.GetProperty("Guid");
                    property.SetValue(entity, value.Value, null);
                }
                if (value.Key == "Conflicted" || value.Key == "Deleted" || value.Key == "Modified")
                {
                    PropertyInfo property = this.Type.GetProperty(value.Key);
                    property.SetValue(entity, ((Int32)value.Value == 1) ? true : false, null);
                }
                else
                {
                    PropertyInfo property = this.Type.GetProperty(value.Key);
                    property.SetValue(entity, value.Value, null);
                }
            }

            db.GetTable(this.Type).InsertOnSubmit(entity);
            db.ModelMetadata.InsertOnSubmit(metadate);
            Log.i("mobeelizermodel", "Add entity from sync " + metadate.Model + ", guid: " + metadate.Guid);
        }
Пример #3
0
 private void UpdateEntity(MobeelizerDatabaseContext db, MobeelizerModelMetadata metadate, IDictionary <String, object> values, String guid, MobeelizerWp7Model entity)
 {
     foreach (KeyValuePair <String, object> value in values)
     {
         if (value.Key == "Conflicted" || value.Key == "Deleted" || value.Key == "Modified")
         {
             PropertyInfo property = this.Type.GetProperty(value.Key);
             property.SetValue(entity, ((Int32)value.Value == 1) ? true : false, null);
         }
         else
         {
             PropertyInfo property = this.Type.GetProperty(value.Key);
             property.SetValue(entity, value.Value, null);
         }
     }
     Log.i("mobeelizermodel", "Upadate entity from sync " + metadate.Model + ", guid: " + metadate.Guid);
 }