public static string GetIdBackingField(Type type) { if (!idBackingFields.ContainsKey(type)) { PropertyInfo pi = GetIdProperty(type); idBackingFields[type] = ExternalMetaHelper.GetBackingField(pi); } return(idBackingFields[type]); }
internal async Task SaveObjectPartiallyAsync(object obj, SqoTypeInfo ti, string[] properties) { foreach (string path in properties) { string[] arrayPath = path.Split('.'); PropertyInfo property; Type type = ti.Type; object objOfProp = obj; SqoTypeInfo tiOfProp = ti; int oid = -1; string backingField = null; foreach (var include in arrayPath) { if ((property = type.GetProperty(include)) == null) { throw new Sqo.Exceptions.SiaqodbException("Property:" + include + " does not belong to Type:" + type.FullName); } backingField = ExternalMetaHelper.GetBackingField(property); tiOfProp = this.GetSqoTypeInfoSoft(type); ATuple <int, object> val = MetaExtractor.GetPartialObjectInfo(objOfProp, tiOfProp, backingField, metaCache); objOfProp = val.Value; oid = val.Name; if (oid == 0) { throw new Sqo.Exceptions.SiaqodbException("Only updates are allowed through this method."); } type = property.PropertyType; } object oldPropVal = await indexManager.GetValueForFutureUpdateIndexAsync(oid, backingField, tiOfProp); await this.SaveValueAsync(oid, backingField, tiOfProp, objOfProp).ConfigureAwait(false); await indexManager.UpdateIndexesAsync(oid, backingField, tiOfProp, oldPropVal, objOfProp); } }
private async Task DownloadChanges() { this.OnSyncProgress(new SyncProgressEventArgs("Downloading changes from server...")); foreach (Type t in SyncedTypes.Keys) { IMobileServiceTable table = MobileService.GetTable(SyncedTypes[t]); table.SystemProperties |= MobileServiceSystemProperties.All; Anchor anchor = siaqodbMobile.Query <Anchor>().Where(anc => anc.EntityType == ReflectionHelper.GetDiscoveringTypeName(t)).FirstOrDefault(); string filter = ""; string anchorJSON = ""; if (anchor != null) { string dateTimeString = new DateTime(anchor.TimeStamp.Ticks, DateTimeKind.Utc).ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffK", CultureInfo.InvariantCulture); filter = "$filter=(__updatedAt gt " + string.Format(CultureInfo.InvariantCulture, "datetime'{0}'", dateTimeString) + ")"; anchorJSON = dateTimeString;//JsonConvert.SerializeObject(anchor.TimeStamp); } Dictionary <string, string> paramAMS = GetParamsAMS(); paramAMS.Add("Anchor", anchorJSON); var token = await table.ReadAsync(filter, paramAMS); //Type typeIList = typeof(List<>).MakeGenericType(t); //ConstructorInfo ctor = typeIList.GetConstructor(new Type[] { }); //IList list = (IList)ctor.Invoke(new object[]{}); this.OnSyncProgress(new SyncProgressEventArgs("Items downloaded,start store locally...")); DownloadedBatch serverEntities = JsonConvert.DeserializeObject(token.ToString(), typeof(DownloadedBatch)) as DownloadedBatch; if (serverEntities != null) { siaqodbMobile.StartBulkInsert(t); try { if (serverEntities.ItemsList != null) { syncStatistics.TotalDownloads = (uint)serverEntities.ItemsList.Count; foreach (var entity in serverEntities.ItemsList) { object objEn = JsonConvert.DeserializeObject(((JObject)entity).ToString(), t); siaqodbMobile.StoreDownloadedEntity(objEn); } } if (serverEntities.TombstoneList != null) { syncStatistics.TotalDownloads += (uint)serverEntities.TombstoneList.Count; foreach (var delEntity in serverEntities.TombstoneList) { var delEnJ = (JObject)delEntity; JToken ENId = delEnJ.GetValue("enid"); Dictionary <string, object> criteria = new Dictionary <string, object>(); criteria.Add(ExternalMetaHelper.GetBackingField(ReflectionHelper.GetIdProperty(t)), ENId.ToString()); int nrDeleted = siaqodbMobile.DeleteObjectByBase(t, criteria); } } } finally { siaqodbMobile.EndBulkInsert(t); } if (anchor != null) { anchor.TimeStamp = serverEntities.TimeStamp; } else { anchor = new Anchor() { EntityType = ReflectionHelper.GetDiscoveringTypeName(t), TimeStamp = serverEntities.TimeStamp }; } siaqodbMobile.StoreObjectBase(anchor); } } siaqodbMobile.Flush(); this.OnSyncProgress(new SyncProgressEventArgs("Download and store locally finished...")); }