Example #1
0
        /// <summary>
        /// Sets the Target Entity.
        /// </summary>
        public void SetTarget(IModelEntity TargetEntity)
        {
            if (this.WorkingEntity == TargetEntity)
            {
                return;
            }

            this.FinishExposeProperties();

            if (TargetEntity == null || TargetEntity.EditEngine == null)
            {
                this.WorkingEntity = null; // By propagation clears the sources+targets trees.
                this.PropertiesPanel.Children.Clear();
                return;
            }

            this.WorkingEntity = TargetEntity;

            if (this.WorkingEntity == null)
            {
                return;
            }

            this.ExposeProperties();
        }
Example #2
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);
        }
Example #3
0
 private void ShowModelRelationshipsIfBothEndsAreVisible(IModelEntity modelEntity)
 {
     foreach (var modelRelationship in Model.GetRelationships(modelEntity))
     {
         ShowModelRelationshipIfBothEndsAreVisible(modelRelationship);
     }
 }
        public virtual void BulkUpdate(IModelEntity entity, IEnumerable <int> ids)
        {
            string tableName   = GetTableName();
            var    fieldValues = GetChanges(entity);

            ExecuteUpdate(fieldValues, ids, tableName);
        }
Example #5
0
 /// <summary>
 /// Cheks the Rules Violations on the given <see cref="IModelEntity"/>. If rules violations exist,
 /// a <see cref="RulesViolationsException"/> is thrown.
 /// </summary>
 /// <param name="modelEntity">The model entity.</param>
 /// <exception cref="RulesViolationsException">
 /// Thrown if rules violations exist.
 /// </exception>
 public static void CheckRulesViolations(this IModelEntity modelEntity)
 {
     if (!modelEntity.IsValid())
     {
         throw new RulesViolationsException("Rule violations prevent saving", modelEntity.GetRuleViolations());
     }
 }
 ///-------------------------------------------------------------------------------------------------
 /// <summary>
 ///  Initializes a new instance of the <see cref="RemoveEntityCommand" /> class.
 /// </summary>
 /// <param name="entity">
 ///  The mel.
 /// </param>
 /// <param name="throwExceptionIfNotExists">
 ///  (Optional) if set to <c>true</c> [throw exception if not exists].
 /// </param>
 /// <param name="version">
 ///  (Optional) the version.
 /// </param>
 ///-------------------------------------------------------------------------------------------------
 public RemoveEntityCommand(IModelEntity entity, bool throwExceptionIfNotExists = true, long?version = null)
     : base(entity.DomainModel, version)
 {
     Contract.Requires(entity, "entity");
     Entity = entity;
     _throwExceptionIfNotExists = throwExceptionIfNotExists;
 }
Example #7
0
 public IReadOnlyList <IModelEntity> GetRelatedEntities(IModelEntity entity, EntityRelationType relationType, bool recursive = false)
 {
     return(_graph.GetConnectedVertices(entity,
                                        (otherEntity, relationship) => relationship.Type == relationType.Type &&
                                        relationship.IsEntityInRelationship(otherEntity, relationType.Direction),
                                        recursive));
 }
Example #8
0
        /// <summary>
        /// Registers the inverse change (READY TO BE UNDONE) of a supplied controlled collection and its owning instance, to be undone/redone in the future.
        /// This must happen  as part of a grouping combined variation (a command being performed).
        /// Also, it will not be performed if already an undo/redo operation is running.
        /// </summary>
        public static void RegisterInverseCollectionChange(IModelEntity Instance, EditableCollection SourceCollection, char AlterCode, params object[] Parameters)
        {
            if (Instance == null || Instance.EditEngine == null ||
                Instance.EditEngine.ExecutionStatus != EExecutionStatus.Running)
            {
                return;
            }

            // If no engine controlling or not within command variation declaration then abandon.
            if (!Instance.EditEngine.IsVariating)
            {
                //T Console.WriteLine("No variating at collection change.");
                return;
            }

            // IMPORTANT: EDIT-ENGINES MUST MATCH FOR CHANGING VALUES.
            if (Instance.EditEngine != ActiveEntityEditor)
            {
                throw new UsageAnomaly("Active Entity-Editor differs (for collection) from that of the changing Entity '" + Instance.ToStringAlways() + "'.");
            }

            // Stores the variation into the command being declared.
            var MemberDef = SourceCollection.VariatingInstance.ClassDefinition.GetMemberDef(SourceCollection.Name, false);

            Instance.EditEngine.StoreVariation(new CollectionVariation(SourceCollection, AlterCode, Parameters),
                                               (MemberDef != null && MemberDef.ChangesExistenceStatus));
        }
Example #9
0
        public void ExtendModelWithRelatedEntities(IModelEntity modelEntity, EntityRelationType?entityRelationType = null,
                                                   CancellationToken cancellationToken = default(CancellationToken), IIncrementalProgress progress = null, bool recursive = false)
        {
            var roslynBasedModelEntity = modelEntity as RoslynBasedModelEntity;

            if (roslynBasedModelEntity == null)
            {
                return;
            }

            var symbolRelations = roslynBasedModelEntity
                                  .FindRelatedSymbols(_roslynModelProvider, entityRelationType)
                                  .Select(GetOriginalDefinition)
                                  .Where(i => !IsHidden(i.RelatedSymbol)).ToList();

            foreach (var symbolRelation in symbolRelations)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var relatedEntity = GetOrAddEntity(symbolRelation.RelatedSymbol, progress);
                AddRelationshipIfNotExists(symbolRelation);

                // TODO: loop detection?
                if (recursive)
                {
                    ExtendModelWithRelatedEntities(relatedEntity, entityRelationType, cancellationToken, progress, recursive: true);
                }
            }
        }
Example #10
0
 public static void AddRulesViolations(this ModelStateDictionary modelState, IModelEntity modelEntity)
 {
     foreach (RuleViolation issue in modelEntity.GetRuleViolations())
     {
         modelState.AddModelError(issue.PropertyName, issue.ErrorMessage);
     }
 }
Example #11
0
 /// <summary>
 /// Notifies ExoModel that a value property is being accessed.
 /// </summary>
 /// <typeparam name="TProperty"></typeparam>
 /// <param name="instance"></param>
 /// <param name="property"></param>
 public static void BeforeGetValue(IModelEntity instance, string property)
 {
     // Raise property get notifications for initialized instances
     if (instance.IsInitialized)
     {
         instance.Instance.OnPropertyGet(property);
     }
 }
        /// <summary>
        /// Constructor.
        /// Notice that VariatingInstance can be null, thus disabling undo/redo but allowing change notifications.
        /// </summary>
        public EditableCollection(string Name, IModelEntity VariatingInstance, bool TreatModelClassValuesAsReferences)
        {
            General.ContractRequiresNotAbsent(Name);

            this.Name = Name;
            this.VariatingInstance = VariatingInstance;
            this.TreatModelClassValuesAsReferences = TreatModelClassValuesAsReferences;
        }
Example #13
0
        public IReadOnlyList <IDiagramNode> ShowEntityWithHierarchy(IModelEntity modelEntity, CancellationToken cancellationToken, IIncrementalProgress progress)
        {
            var baseTypes = Model.GetRelatedEntities(modelEntity, EntityRelationTypes.BaseType, recursive: true);
            var subtypes = Model.GetRelatedEntities(modelEntity, EntityRelationTypes.Subtype, recursive: true);
            var entities = new[] { modelEntity }.Union(baseTypes).Union(subtypes);

            return(ShowModelItems(entities, cancellationToken, progress).OfType <IDiagramNode>().ToArray());
        }
Example #14
0
 public DiagramNode(IModelEntity modelEntity)
     : base(modelEntity)
 {
     _size        = Size2D.Zero;
     _center      = Point2D.Undefined;
     _name        = modelEntity.Name;
     _fullName    = modelEntity.FullName;
     _description = modelEntity.Description;
 }
 public int DeleteObjectPermanently(IModelEntity dr)
 {
     if (dr != null)
     {
         db.Entry(dr).State = System.Data.Entity.EntityState.Deleted;
         return(db.SaveChanges());
     }
     return(-2);
 }
Example #16
0
 /// <summary>
 /// Raise property set notification when an unmapped reference changes
 /// </summary>
 /// <param name="instance"></param>
 /// <param name="property"></param>
 /// <param name="oldValue"></param>
 /// <param name="value"></param>
 /// <param name="newValue"></param>
 public static void AfterSetReferenceUnmapped(IModelEntity instance, string property, object oldValue, object value, object newValue)
 {
     // Ignore changes to uninitialized instances
     if (instance.IsInitialized)
     {
         // Raise property change notifications
         instance.Instance.OnPropertyChanged(property, oldValue, value);
     }
 }
Example #17
0
        private DiagramNode CreateDiagramNode(IModelEntity modelEntity)
        {
            var diagramNode = new DiagramNode(modelEntity);

            diagramNode.SizeChanged   += OnDiagramNodeSizeChanged;
            diagramNode.CenterChanged += OnDiagramNodeCenterChanged;

            return(diagramNode);
        }
Example #18
0
 /// <summary>
 /// Raise member changed events and property change notifications after a property is set.
 /// </summary>
 /// <typeparam name="TProperty"></typeparam>
 /// <param name="instance"></param>
 /// <param name="property"></param>
 /// <param name="oldValue"></param>
 /// <param name="value"></param>
 /// <param name="newValue"></param>
 public static void AfterSetValueUnmapped <TProperty>(IModelEntity instance, string property, TProperty oldValue, TProperty value, TProperty newValue)
 {
     // Ignore changes to uninitialized instances
     if (instance.IsInitialized)
     {
         // Raise property change notifications
         instance.Instance.OnPropertySet(property, oldValue, newValue);
     }
 }
Example #19
0
        public EntityEditPanel(IModelEntity AssociatedEntity)
            : this()
        {
            this.AssociatedEntity = AssociatedEntity;

            //  PENDING: Enable/show when there is helping content.
            this.HasHelpForShowing = false;

            this.Loaded += new RoutedEventHandler(IndividualEditPanel_Loaded);
        }
 public ProductService(IProductEntity entity,IModelEntity modelentity, IProductTypeEntity producttype,
     IManufacturerEntity manufacturer, ICategoryEntity category)
 {
     this.entity = entity;
        this.modelentity = modelentity;
        this.productentity = producttype;
        this.menufacturerentity = manufacturer;
        this.categoryentity = category;
     //bat 1 tien trinh check hang ton kho/thoi han khuyen mai
 }
Example #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ModelInstance"/> class.
 /// </summary>
 /// <param name="entityDescriptor">
 /// The <see cref="ModelEntityDescriptor"/> descriptor.
 /// </param>
 /// <param name="instance">
 /// The <see cref="IModelEntity"/> instance.
 /// </param>
 /// <param name="currentViewMode">
 /// The current View Mode.
 /// </param>
 public ModelInstance(ModelEntityDescriptor entityDescriptor, IModelEntity instance, ViewMode currentViewMode)
 {
     _modelEntityDescriptor = entityDescriptor;
     DomainModelInstance    = instance;
     CurrentViewMode        = currentViewMode;
     Key = instance.Key.Trim();
     MembersSingleValue    = new MemberList <MemberSingleValue>(entityDescriptor.MembersSingleValue.Select(mmd => new MemberSingleValue(mmd, instance)));
     MembersMultipleValues = new MemberList <MemberMultipleValues>(entityDescriptor.MembersMultipleValues.Select(mmd => new MemberMultipleValues(mmd, instance)));
     Members = new MemberList <Member>(MembersSingleValue.Cast <Member>().Concat(MembersMultipleValues.Cast <Member>()));
 }
Example #22
0
        public bool HasSource(IModelEntity modelEntity)
        {
            var roslyBasedModelEntity = modelEntity as IRoslynBasedModelEntity;

            if (roslyBasedModelEntity == null)
            {
                return(false);
            }

            return(_roslynModelProvider.HasSource(roslyBasedModelEntity.RoslynSymbol));
        }
Example #23
0
        public void ShowSource(IModelEntity modelEntity)
        {
            var roslyBasedModelEntity = modelEntity as IRoslynBasedModelEntity;

            if (roslyBasedModelEntity == null)
            {
                return;
            }

            _roslynModelProvider.ShowSource(roslyBasedModelEntity.RoslynSymbol);
        }
Example #24
0
        public virtual int Update(IModelEntity entity)
        {
            if (entity.Id > 0)
            {
                db.Entry(entity).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                return(entity.Id);
            }

            return(0);
        }
 public virtual int AddOrUpdate(IModelEntity entity)
 {
     if (entity.Id > 0)
     {
         return(Update(entity));
     }
     else
     {
         return(Add(entity));
     }
 }
Example #26
0
        /// <summary>
        /// Gets a navigation property reference for the specified property.
        /// </summary>
        /// <param name="instance"></param>
        /// <param name="property"></param>
        /// <returns></returns>
        public static object GetReference(IModelEntity instance, string property)
        {
            // Raise property get notifications
            instance.Instance.OnPropertyGet(property);

            // Return the property reference
            var reference = GetRelatedEnd(instance, property).GetEnumerator();

            reference.MoveNext();
            return(reference.Current);
        }
Example #27
0
        /// <summary>
        /// Raises member changing events before a value property is set.
        /// </summary>
        /// <typeparam name="TProperty"></typeparam>
        /// <param name="instance"></param>
        /// <param name="property"></param>
        /// <param name="oldValue"></param>
        /// <param name="value"></param>
        public static TProperty BeforeSetValueMapped <TProperty>(IModelEntity instance, string property, TProperty oldValue, TProperty value)
        {
            // Notify the change tracker that the property is changing
            if (instance.IsInitialized)
            {
                instance.ChangeTracker.EntityMemberChanging(property);
            }

            // Return the unmodified value
            return(value);
        }
        public static FrameworkElement CreateRichTextBoxPresenter(IModelEntity SourceEntity, MModelPropertyDefinitor SourceProperty)
        {
            if (SourceEntity == null || SourceProperty.DataType != typeof(string))
            {
                throw new UsageAnomaly("A valid source-entity and a string source-property must be provided to create a Rich-Text Editor.");
            }

            var RichEditor = new RichTextEditor(SourceEntity, SourceProperty);

            return(RichEditor);
        }
Example #29
0
        /// <summary>
        /// Raise member changed events and property change notifications after a property is set.
        /// </summary>
        /// <typeparam name="TProperty"></typeparam>
        /// <param name="instance"></param>
        /// <param name="property"></param>
        /// <param name="oldValue"></param>
        /// <param name="value"></param>
        /// <param name="newValue"></param>
        public static void AfterSetValueMapped <TProperty>(IModelEntity instance, string property, TProperty oldValue, TProperty value, TProperty newValue)
        {
            // Ignore changes to uninitialized instances
            if (instance.IsInitialized)
            {
                // Notify the change tracker that the property has changed
                instance.ChangeTracker.EntityMemberChanged(property);

                // Raise property change notifications
                instance.Instance.OnPropertySet(property, oldValue, newValue);
            }
        }
Example #30
0
        private void RemoveDiagramNode(IModelEntity modelEntity)
        {
            var result = _graph.RemoveVertex(i => i.ModelEntity == modelEntity);

            var surroundingNodes = result.RemovedEdges.EmptyIfNull()
                                   .Select(i => i.GetOtherEnd(result.RemovedVertex)).Distinct();

            foreach (var diagramNode in surroundingNodes)
            {
                ShowModelRelationshipsIfBothEndsAreVisible(diagramNode.ModelEntity);
            }
        }
        internal IModelElement CreateEntity(Identity id, ISchemaEntity metaClass, IModelEntity instance)
        {
            IModelElement mel = instance;
            var           r   = InnerGraph.CreateEntity(id, metaClass);

            if (instance == null)
            {
                mel = (IModelElement)metaClass.Deserialize(new SerializationContext(_domain, metaClass, r));
            }
            AddElement(mel);

            return(mel);
        }
 public ModelService(IModelEntity entity)
 {
     this.entity = entity;
 }
 protected BaseModelEntityDefinition(IModelEntity copyFrom) : base(copyFrom)
 {
     Description = copyFrom.Description;
     Name = copyFrom.Name;
     ResourceName = copyFrom.ResourceName;
 }