/// <summary> /// 创建 /// /// 往Bmob云数据库中添加一条数据记录 /// </summary> /// <param name="data">需要添加的数据</param> /// <param name="callback">添加之后的结果回调</param> public void Create(String tablename, IBmobWritable data, BmobCallback <CreateCallbackData> callback) { var bia = BmobInteractObject.Create; bia.Data = data; bia.Table = tablename; submit(bia, callback); }
/// <summary> /// 更新Bmob云数据库中的某一条记录信息 /// </summary> /// <param name="tablename">数据表名称</param> /// <param name="objectId">这个记录对应的objectId</param> /// <param name="data">需要更新的记录信息</param> /// <param name="callback">更新之后的回调</param> public void Update(String tablename, String objectId, IBmobWritable data, BmobCallback <UpdateCallbackData> callback) { var bia = BmobInteractObject.Update; bia.Data = data; bia.Table = tablename; bia.ObjectId = objectId; submit(bia, callback); }
// obj to IDictionary<String, Object> public override bool TrySerializeNonPrimitiveObject(object input, out object output) { try { Type objectType = input.GetType(); if (/*typeof(IBmobWritable).IsAssignableFrom(objectType)*/ input is IBmobWritable) { IBmobWritable obj = (IBmobWritable)input; BmobOutput tOutput = new BmobOutput(); obj.write(tOutput, isPrint); output = tOutput.getData(); return(true); } else if (objectType == typeof(BmobInt) || objectType == typeof(BmobLong) || objectType == typeof(BmobDouble) || objectType == typeof(BmobBoolean) || objectType == typeof(BmobACL)) { object value = 0; if (input is BmobInt) { value = (input as BmobInt).Get(); } else if (input is BmobLong) { value = (input as BmobLong).Get(); } else if (input is BmobDouble) { value = (input as BmobDouble).Get(); } else if (input is BmobBoolean) { value = (input as BmobBoolean).Get(); } else if (input is BmobACL) { value = (input as BmobACL).Get(); } output = value; return(true); } } catch (Exception e) { BmobDebug.Log(e); } return(base.TrySerializeNonPrimitiveObject(input, out output)); }
public Task <CreateCallbackData> CreateTaskAsync(String tablename, IBmobWritable data) { return(ExecuteTaskAsync <CreateCallbackData>(callback => { Create(tablename, data, callback); }, CancellationToken.None)); }
public Task <UpdateCallbackData> UpdateTaskAsync(String tablename, String objectId, IBmobWritable data) { return(ExecuteTaskAsync <UpdateCallbackData>(callback => { Update(tablename, objectId, data, callback); }, CancellationToken.None)); }
/// <summary> /// 输出对象的JSON字符串 /// </summary> /// <param name="ele">需要转换为JSON字符串的对象</param> /// <returns>字符串</returns> public static string ToString(IBmobWritable ele) { return JsonAdapter.JSON.ToDebugJsonString(ele); }
public String toJson(IBmobWritable data) { return(ToString(data)); }
/// <summary> /// 输出对象的JSON字符串 /// </summary> /// <param name="ele">需要转换为JSON字符串的对象</param> /// <returns>字符串</returns> public static string ToString(IBmobWritable ele) { return(JsonAdapter.JSON.ToDebugJsonString(ele)); }
// covert dispatch private static object convert(Type type, Object data) { if (data.GetType() == type || type == typeof(Object)) { return(data); } // 基本类型 if (type == typeof(int)) { return(toInt(data)); } else if (type == typeof(long)) { return(toLong(data)); } else if (type == typeof(double)) { return(toDouble(data)); } else if (type == typeof(bool)) { return(toBoolean(data)); } else if (type == typeof(string)) { return(toString(data)); } // Bmob包装类型 if (type == typeof(BmobInt)) { return(new BmobInt(toInt(data))); } else if (type == typeof(BmobLong)) { return(new BmobLong(toLong(data))); } else if (type == typeof(BmobDouble)) { return(new BmobDouble(toDouble(data))); } else if (type == typeof(BmobBoolean)) { return(new BmobBoolean(toBoolean(data))); } // 复杂类型 if (typeof(IBmobWritable).IsAssignableFrom(type)) { IDictionary <String, Object> raw = (IDictionary <String, Object>)data; IBmobWritable result = (IBmobWritable)Activator.CreateInstance(type); result.readFields(new BmobInput(raw)); return(result); } else if (typeof(IBmobValue).IsAssignableFrom(type)) { IDictionary <String, Object> raw = (IDictionary <String, Object>)data; IBmobValue result = (IBmobValue)Activator.CreateInstance(type); result.Set(result); return(result); } if (typeof(IList).IsAssignableFrom(type)) { IList raw = (IList)data; IList result = (IList)Activator.CreateInstance(type); foreach (var element in raw) { var isGeneric = type.IsGenericType(); var dataType = isGeneric ? type.GetGenericArguments()[0] : null; isGeneric = isGeneric && dataType != typeof(Object); result.Add(isGeneric ? convert(dataType, element) : element); } return(result); } else if (typeof(IDictionary).IsAssignableFrom(type)) { IDictionary <String, Object> raw = (IDictionary <String, Object>)data; IDictionary result = (IDictionary)Activator.CreateInstance(type); var isGeneric = type.IsGenericType(); var vt = isGeneric ? type.GetGenericArguments()[1] : null; foreach (var entry in raw) { isGeneric = isGeneric && type != typeof(Object); result.Add(entry.Key, isGeneric ? convert(vt, entry.Value) : entry.Value); } return(result); } throw new ArgumentException("UnExcept type: " + type + ". Use Generic Type List<T>/Dictionary<K,V> instead!"); }
public BmobBatch Create(String tablename, IBmobWritable data) { BmobWrapper.Create(tablename, data, NonCallback); return(this); }
public BmobBatch Update(String tablename, String objectId, IBmobWritable data) { BmobWrapper.Update(tablename, objectId, data, NonCallback); return(this); }
/// <summary> /// 添加键值对。加入已经存在的键时,会覆盖原有的值!不同与Hashtable#Add方法抛出异常的方式。 /// </summary> /// <param name="key"></param> /// <param name="value"></param> public void Put(string key, IBmobWritable value) { Save(real, key, value); }