internal void SetLazyValue(ObjectId oid, ModelProperty property, LazyValue value, bool creating) { GreenModelUpdateContext ctx = null; try { var slot = oid.Descriptor.GetSlot(property); do { ctx = this.BeginUpdate(); ctx.Updater.SetValue(this.id, oid, slot, creating, property.IsDerived ? (object)new GreenDerivedValue(value) : value); } while (!this.EndUpdate(ctx)); } finally { this.FinalizeUpdate(ctx); } }
internal void SetValue <T>(ObjectId oid, ModelProperty property, T value, bool creating) { GreenModelUpdateContext ctx = null; try { var slot = oid.Descriptor.GetSlot(property); do { ctx = this.BeginUpdate(); ctx.Updater.SetValue(this.id, oid, slot, creating, this.ToGreenValue(value)); } while (!this.EndUpdate(ctx)); } finally { this.FinalizeUpdate(ctx); } }
internal bool EndUpdate(GreenModelUpdateContext context) { if (this.group != null) { return(this.group.EndUpdate(context)); } else { if (context.NewUpdater) { this.updater.Value = null; return(Interlocked.CompareExchange(ref this.green, context.Updater.Model, context.OriginalModel) == context.OriginalModel); } else { return(true); } } }
internal ImmutableModelList <MutableObject> MChildren(ObjectId oid) { ImmutableList <ObjectId> children = ImmutableList <ObjectId> .Empty; GreenModelUpdateContext ctx = null; try { do { ctx = this.BeginUpdate(); children = ctx.Updater.GetChildren(this.id, oid); } while (!this.EndUpdate(ctx)); } finally { this.FinalizeUpdate(ctx); } return(ImmutableModelList <MutableObject> .FromObjectIdList(children, this)); }
internal bool ClearLazyItems(ObjectId oid, ModelProperty property, bool creating) { bool changed = false; GreenModelUpdateContext ctx = null; try { var slot = oid.Descriptor.GetSlot(property); do { ctx = this.BeginUpdate(); changed = ctx.Updater.ClearLazyItems(this.id, oid, slot, creating); } while (!this.EndUpdate(ctx)); } finally { this.FinalizeUpdate(ctx); } return(changed); }
internal bool ReplaceItem(ObjectId oid, ModelProperty property, int index, object value, bool creating) { bool changed = false; GreenModelUpdateContext ctx = null; try { var slot = oid.Descriptor.GetSlot(property); do { ctx = this.BeginUpdate(); changed = ctx.Updater.AddItem(this.id, oid, slot, creating, true, index, this.ToGreenValue(value)); } while (!this.EndUpdate(ctx)); } finally { this.FinalizeUpdate(ctx); } return(changed); }
internal object GetValue(ObjectId oid, ModelProperty property) { object value = null; GreenModelUpdateContext ctx = null; try { var slot = oid.Descriptor.GetSlot(property); do { ctx = this.BeginUpdate(); value = ctx.Updater.GetValue(this.id, oid, slot, true); } while (!this.EndUpdate(ctx)); value = this.ToRedValue(value, oid); } finally { this.FinalizeUpdate(ctx); } return(value); }
internal bool AddLazyItems(ObjectId oid, ModelProperty property, IEnumerable <LazyValue> values, bool creating) { bool changed = false; GreenModelUpdateContext ctx = null; try { var slot = oid.Descriptor.GetSlot(property); do { ctx = this.BeginUpdate(); foreach (var value in values) { changed = ctx.Updater.AddItem(this.id, oid, slot, creating, false, -1, value); } } while (!this.EndUpdate(ctx)); } finally { this.FinalizeUpdate(ctx); } return(changed); }
public bool RemoveObject(MutableObject obj) { if (obj == null) { return(false); } bool result = false; GreenModelUpdateContext ctx = null; try { do { ctx = this.BeginUpdate(); result = ctx.Updater.RemoveObject(this.id, ((MutableObjectBase)obj).MId); } while (!this.EndUpdate(ctx)); } finally { this.FinalizeUpdate(ctx); } return(result); }
public MutableModel CreateModel(string name = null, ModelVersion version = default) { ModelId mid = new ModelId(); MutableModel model = new MutableModel(mid, this, false, null); this.models.Add(mid, model); GreenModel greenModel; GreenModelUpdateContext ctx = null; try { do { ctx = this.BeginUpdate(); greenModel = ctx.Updater.CreateModel(mid, name, version); } while (!this.EndUpdate(ctx)); } finally { this.FinalizeUpdate(ctx); } return(model); }
internal MutableObjectBase CreateObject(ObjectId oid, bool weakReference) { Debug.Assert(oid != null); Debug.Assert(!this.ContainsObject(oid)); MutableObjectBase result = null; result = oid.CreateMutable(this, true); GreenModelUpdateContext ctx = null; try { do { ctx = this.BeginUpdate(); ctx.Updater.AddObject(this.id, oid, weakReference); } while (!this.EndUpdate(ctx)); this.RegisterObject(oid, result); } finally { this.FinalizeUpdate(ctx); } return(result); }