private Dictionary <string, object> getItemUpdates(AccountWP account, Guid identifier, List <ChangedProperty> changedProperties) { BaseItemWP item = account.Find(identifier); if (item == null) { return(null); } if (changedProperties.Any(i => i.PropertyName == BaseItemWP.PropertyNames.All)) { foreach (ChangedProperty p in changedProperties) { p.HasBeenSent = true; } return(item.SerializeToDictionary()); } Dictionary <string, object> answer = new Dictionary <string, object>(); answer["Identifier"] = identifier; answer["Updated"] = item.Updated; foreach (ChangedProperty p in changedProperties) { answer[p.PropertyName.ToString()] = item.GetPropertyValue(p.PropertyName); p.HasBeenSent = true; } return(answer); }
/// <summary> /// Returns all the updated items /// </summary> /// <param name="offset"></param> /// <returns></returns> public UpdatedItems Serialize(AccountWP account, int offset) { UpdatedItems answer = new UpdatedItems(); foreach (var pair in _changedItems) { if (pair.Value.IsUpdated) { //mark it sent pair.Value.HasBeenSent = true; //find its item BaseItemWP entity = account.AccountSection.Find(pair.Key); if (entity == null) { continue; } //add the serialized item to the list answer.Add(entity.Serialize(offset)); } } return(answer); }
/// <summary> /// As long as Json.NET is used, it'll serialize dictionaries correctly. DataContractJson formats them as Key: xx Value: xx, which is incorrect. /// </summary> /// <param name="accountWin"></param> /// <returns></returns> public IEnumerable <Dictionary <string, object> > GetUpdates(AccountWP accountWin) { List <Dictionary <string, object> > answer = new List <Dictionary <string, object> >(); foreach (var pair in Changes) { Dictionary <string, object> item = getItemUpdates(accountWin, pair.Key, pair.Value); if (item != null) { answer.Add(item); } } return(answer); }