Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
 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);
         }
     }
 }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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);
        }