Beispiel #1
0
        // ---------------------------------------------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Gets and possibly initializes, for the supplied Entity-Instance, its Edit-Engine based on the specified Current.
        /// </summary>
        public static EntityEditEngine ObtainEditEngine(IModelEntity EntityInstance, EntityEditEngine Current)
        {
            // IMPORTANT: Do not read Entity.AssignedEditEngine. An infinite-loop may occur.
            //            Instead use the Current parameter.

            // PENDING: Solve mismatch crash for:
            // Change of document and immediate copy of objects.

            if (Current == null && ActiveEntityEditor != null &&
                (ActiveEntityEditor.ExecutionStatus == EExecutionStatus.Running ||
                 ActiveEntityEditor.ExecutionStatus == EExecutionStatus.Created))
            {
                EntityInstance.EditEngine = Current = ActiveEntityEditor;

                // Centralizes store-boxes references
                // IMPORTANT: The EntityEditor is used because exists while calling Constructors. So, do not use MainEditedEntity (Composition).
                if (Current != null)
                {
                    foreach (var PropDef in EntityInstance.ClassDefinition.Properties.Where(prop => prop.IsStoreBoxBased))
                    {
                        PropDef.GetStoreBoxContainer(EntityInstance).CentralizeReferencesIn(Current.GlobalId);
                    }
                }
            }

            /*T ONLY RELEVANT WHEN MODIFYING VALUES.
             *  SEE RegisterInverseAssignment() and RegisterInverseCollectionChange().
             * else*/
            /*
             *  if (Current != ActiveEntityEditor)
             *      Console.WriteLine("Active Entity-Editor differs from that of Entity '" + EntityInstance.ToStringAlways() + "'."); */

            return(Current);
        }
Beispiel #2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public MEntityInstanceController(IModelEntity EntityInstance, ECloneOperationScope CloningScope)
        {
            General.ContractRequiresNotNull(EntityInstance);

            this.ControlledInstance = EntityInstance;
            this.EntityEditor       = EntityInstance.EditEngine;

            // Centralizes store-boxes references
            // IMPORTANT: The EntityEditor is used because exists while calling Constructors. So, do not use MainEditedEntity (Composition).
            foreach (var PropDef in EntityInstance.ClassDefinition.Properties.Where(prop => prop.IsStoreBoxBased))
            {
                PropDef.GetStoreBoxContainer(EntityInstance).CentralizeReferencesIn(EntityEditor.GlobalId);
            }

            this.CloningScope = CloningScope;

            this.ExistenceStatus       = EExistenceStatus.Created;
            this.ControlledProperties  = new ReadOnlyDictionary <string, MPropertyController>(this.ControlledProperties_);
            this.ControlledCollections = new ReadOnlyDictionary <string, MCollectionController>(this.ControlledCollections_);
            this.Errors = new ReadOnlyDictionary <string, string>(this.Errors_);
        }
Beispiel #3
0
        private static void PopulateProperties(TModelClass Target, TModelClass Source, IMModelClass TargetOwner,
                                               ECloneOperationScope CloningScope, bool IsForCloning, MModelPropertyDefinitor[] TargetProperties)
        {
            foreach (var PropDef in TargetProperties)
            {
                var SourceValue = PropDef.Read(Source);

                /*T if (//T PropDef.TechName.EndsWith("LinkRoleDef") ||
                 *  PropDef.TechName == "OwnerRelationshipDef")
                 *  Console.WriteLine("debug!"); */

                /*T if (PropDef.TechName == "ForegroundBrush")
                 * {
                 *  Console.WriteLine("Populating prop ForegroundBrush >>>>>>>>>>>>>>>>>>>>>");
                 *  Console.WriteLine("SourceEnt: {0}, TargetEnt: {1}", Source.GetHashCode(), Target.GetHashCode());
                 *  if (PropDef.IsStoreBoxBased)
                 *  {
                 *      Console.WriteLine("StoreBox-Source: {0}", PropDef.GetStoreBoxContainer(Source).GetHashCode());
                 *      Console.WriteLine("StoreBox-Target: {0}", PropDef.GetStoreBoxContainer(Target).GetHashCode());
                 *  }
                 *  Console.WriteLine("SourceVal: HC={0}", SourceValue.GetHashCode());
                 *  var TarVal = PropDef.Read(Target);
                 *  TarVal = TarVal.NullDefault("<NULL>");
                 *  Console.WriteLine("TargetVal: HC={0} (to be overwritten)", TarVal.GetHashCode());
                 *  Console.WriteLine("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
                 * } */

                var DoClone = PropDef.IsCloneableFor(CloningScope, Source);

                if (SourceValue is IMModelClass && DoClone.Item1)
                {
                    //T PopulationLevel++;
                    SourceValue = ((IMModelClass)SourceValue).CreateCopy(DoClone.Item2, Target);
                    //T PopulationLevel--;
                }

                if (PropDef.ReferencesOwner.HasValue && TargetOwner != null)
                {
                    // NOTE: See ModelFixes.ModelRev7_FixOwnerReferences method, which resulted in this piece of code for reassign Owners.
                    var SourceOwnership = SourceValue as MOwnership;
                    var Owner           = (SourceOwnership == null ? SourceValue : SourceOwnership.Owner);

                    if (Owner != null && Owner.GetType() == TargetOwner.GetType())
                    {
                        if (SourceOwnership != null)
                        {
                            SourceValue = SourceOwnership.CreateClone(TargetOwner);
                        }
                        else
                        {
                            SourceValue = TargetOwner;
                        }
                    }
                }

                // Refinements...
                // Needed because the initial clone only has duplicated the root properties (shallow copy)
                if (IsForCloning)
                {
                    var SourceAssignment = SourceValue as MAssignment;
                    if (SourceAssignment != null)
                    {
                        if (SourceAssignment.IsLocal && (SourceAssignment.AssignedValue is IMModelClass) && DoClone.Item1)
                        {
                            SourceAssignment = ((IMModelClass)SourceAssignment.AssignedValue).CreateCopy(DoClone.Item2, Target).Assign(true);
                        }
                        else
                        {
                            SourceAssignment = ((MAssignment)SourceValue).CreateClone();
                        }

                        SourceValue = SourceAssignment;
                    }

                    if (PropDef.IsStoreBoxBased)
                    {
                        var ClonedStore = PropDef.GetStoreBoxContainer(Target).CreateClone();
                        PropDef.SetStoreBoxBaseContainer(Target, ClonedStore);
                    }
                }

                PropDef.Write(Target, SourceValue);
            }
        }