Beispiel #1
0
 internal MutableModelGroup(GreenModelGroup green, ImmutableModelGroup immutableModelGroup)
 {
     this.green               = green;
     this.updater             = new ThreadLocal <GreenModelUpdater>();
     this.immutableModelGroup = new WeakReference <ImmutableModelGroup>(immutableModelGroup);
     this.models              = new ConditionalWeakTable <ModelId, MutableModel>();
     this.objects             = new ConditionalWeakTable <ObjectId, MutableObject>();
 }
Beispiel #2
0
 internal ImmutableModel(GreenModel green, MutableModel mutableModel)
 {
     this.id           = green.Id;
     this.group        = null;
     this.green        = green;
     this.readOnly     = false;
     this.objects      = new ConditionalWeakTable <ObjectId, ImmutableObject>();
     this.mutableModel = new WeakReference <MutableModel>(mutableModel);
 }
Beispiel #3
0
 internal ImmutableModel(ModelId id, ImmutableModelGroup group, GreenModel green, bool readOnly, MutableModel mutableModel)
 {
     this.id           = id;
     this.group        = group;
     this.green        = green;
     this.readOnly     = readOnly;
     this.objects      = null;
     this.mutableModel = new WeakReference <MutableModel>(mutableModel);
 }
Beispiel #4
0
        public void AddReference(ImmutableModelGroup reference)
        {
            GreenModelGroup gmg = reference.Green;

            foreach (var greenReference in gmg.References)
            {
                this.AddReference(greenReference.Value);
            }
            foreach (var greenModel in gmg.Models)
            {
                this.AddReference(greenModel.Value);
            }
        }
Beispiel #5
0
        public ImmutableModelGroup ToImmutable(bool evaluateLazyValues = true, CancellationToken cancellationToken = default)
        {
            ImmutableModelGroup result;

            if (this.immutableModelGroup.TryGetTarget(out result) && result != null && result.Green == this.Green)
            {
                return(result);
            }
            else
            {
                if (evaluateLazyValues)
                {
                    this.EvaluateLazyValues(cancellationToken);
                }
                result = new ImmutableModelGroup(this.Green, this);
                Interlocked.Exchange(ref this.immutableModelGroup, new WeakReference <ImmutableModelGroup>(result));
                return(result);
            }
        }
Beispiel #6
0
        public ImmutableModel ToImmutable(bool evaluateLazyValues = true, CancellationToken cancellationToken = default)
        {
            ImmutableModel result;

            if (this.group != null)
            {
                ImmutableModelGroup immutableGroup = this.group.ToImmutable(evaluateLazyValues, cancellationToken);
                if (immutableGroup != null)
                {
                    if (this.readOnly)
                    {
                        result = immutableGroup.GetReference(this.id);
                    }
                    else
                    {
                        result = immutableGroup.GetModel(this.id);
                    }
                    return(result);
                }
            }
            else
            {
                if (evaluateLazyValues)
                {
                    this.EvaluateLazyValues(cancellationToken);
                }
                GreenModel currentGreen = this.Green;
                if (this.immutableModel.TryGetTarget(out result) && result != null && result.Green == currentGreen)
                {
                    return(result);
                }
                else
                {
                    result = new ImmutableModel(currentGreen, this);
                    Interlocked.Exchange(ref this.immutableModel, new WeakReference <ImmutableModel>(result));
                    return(result);
                }
            }
            return(null);
        }