private void SetValue(Guid _uid) { if (m_current.Equals(_uid)) { return; } m_current = _uid; m_object = m_client.GetInternal <T>(_uid, m_factory); OnChanged(); }
public override void ApplyChanges(AbstractXReportItem _reportItem, bool _firstTime) { var rl = (XReportList)_reportItem; var toAdd = new List <Guid>(); var toDel = new List <Guid>(); switch (rl.State) { case XReportItemState.ORIGINAL: m_original.Clear(); foreach (var item in rl.Items.Select(GetChild)) { m_original.Add(item); } if (_firstTime) { toAdd.AddRange(rl.Items.Select(_item => _item.Uid)); } break; case XReportItemState.CHANGE: var current = m_dict.Values.ToArray(); foreach (var item in current) { if (!m_original.Contains(item)) { toDel.Add(item.Uid); //((IXCollection<TKind>) this).RemoveSilently(item.Uid); //item.Changed -= ItemChanged; //m_client.Release(item); } } foreach (var item in m_original) { if (!current.Contains(item)) { toAdd.Add(item.Uid); //((IXCollection<TKind>) this).AddSilently(item); } } foreach (var item in rl.Items) { switch (item.State) { case EReportListItemState.ADDED: toAdd.Add(item.Uid); toDel.Remove(item.Uid); //var add = GetChild(item); //((IXCollection<TKind>) this).AddSilently(add);) break; case EReportListItemState.REMOVED: toDel.Add(item.Uid); toAdd.Remove(item.Uid); //((IXCollection<TKind>) this).RemoveSilently(item.Uid); break; default: throw new ArgumentOutOfRangeException(); } } break; default: throw new ArgumentOutOfRangeException(); } var changed = false; foreach (var uid in toAdd) { changed = true; var add = m_client.GetInternal <T>(uid, m_factory, m_ownerUid); add.Changed += ItemChanged; ((IXCollection <TKind>) this).AddSilently(add); } foreach (var uid in toDel) { T del; if (m_dict.TryGetValue(uid, out del)) { changed = true; del.Changed -= ItemChanged; m_client.Release(del); ((IXCollection <TKind>) this).RemoveSilently(uid); } } if (changed) { OnChanged(); } UpdateIsDirty(); }