Ejemplo n.º 1
0
        public IEntityBase ImplementToNewType(PersistentTypeKind newTypeKind, string newTypeName, ImplementTypeOptions options)
        {
            if (!newTypeKind.In(PersistentTypeKind.Entity, PersistentTypeKind.Structure))
            {
                throw new ArgumentOutOfRangeException("newTypeKind", "Interface can be implemented only be Entities or Structures!");
            }

            EntityBase newEntity = null;

            this.Store.MakeActionWithinTransaction(string.Format("Implementing new '{0}': {1} from interface '{2}'",
                                                                 newTypeName, newTypeKind, this.Name),
                                                   delegate
            {
                newEntity = newTypeKind == PersistentTypeKind.Entity
                                            ? (EntityBase) new Entity(this.Partition)
                                            : new Structure(this.Partition);

                newEntity.Access        = this.Access;
                newEntity.Documentation = this.Documentation;
                newEntity.Name          = newTypeName;

                this.EntityModel.PersistentTypes.Add(newEntity);

                InternalImplementToType(newEntity, options);
            });

            return(newEntity);
        }
Ejemplo n.º 2
0
        public TypeInfo(TypeReference reference, PersistentTypeKind kind)
        {
            if (reference == null)
            {
                throw new ArgumentNullException("reference");
            }

            Name     = reference.Name;
            FullName = reference.FullName;
            Kind     = kind;

            InitializeCollections();
        }
Ejemplo n.º 3
0
        public TypeInfo(TypeDefinition definition, PersistentTypeKind kind, TypeInfo baseType = null)
        {
            if (definition == null)
            {
                throw new ArgumentNullException("definition");
            }

            Name     = definition.Name;
            FullName = definition.FullName;
            Kind     = kind;

            Definition = definition;
            BaseType   = baseType;

            InitializeCollections();
        }
Ejemplo n.º 4
0
        private EntityKind ConvertTypeKind(PersistentTypeKind typeKind)
        {
            switch (typeKind)
            {
            case PersistentTypeKind.Interface:
            {
                return(EntityKind.Interface);
            }

            case PersistentTypeKind.Entity:
            {
                return(EntityKind.Entity);
            }

            default:
            {
                return(EntityKind.Structure);
            }
            }
        }
Ejemplo n.º 5
0
 public IEntityBase ImplementToNewType(PersistentTypeKind newTypeKind, string newTypeName,
                                       ImplementTypeOptions options)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 6
0
        public override void ExecCommand(MenuCommand menuCommand)
        {
            CurrentModelSelection currentSelection = GetCurrentSelectedPersistentType();
            IInterface            sourceInterface  = currentSelection.CurrentPersistentType as IInterface;

            FormImplementInterface.ImplementData resultData;

            var helperDic           = new Dictionary <IInterface, FormImplementInterface.InterfaceTreeItem>();
            var sourceInterfaceItem = new FormImplementInterface.InterfaceTreeItem(sourceInterface.Name, sourceInterface);

            helperDic.Add(sourceInterface, sourceInterfaceItem);
            var currentInterfaceItem = sourceInterfaceItem;
            int currentLevel         = 0;

            var inheritanceTree = InheritanceTreeCache.Get(sourceInterface); //sourceInterface.GetInheritanceTree();

            if (!inheritanceTree.TreeRebuilded)
            {
                inheritanceTree.RebuildTree(false);
            }

            inheritanceTree.IterateTree(false, delegate(InheritanceTreeIterator iterator)
            {
                if (iterator.Level != currentLevel)
                {
                    currentLevel         = iterator.Level;
                    currentInterfaceItem = helperDic[iterator.Parent.Interface];
                }

                var childItem    = new FormImplementInterface.InterfaceTreeItem(iterator.Current.Interface.Name, iterator.Current.Interface);
                childItem.Parent = currentInterfaceItem;
                currentInterfaceItem.Childs.Add(childItem);

                if (!helperDic.ContainsKey(iterator.Current.Interface))
                {
                    helperDic.Add(iterator.Current.Interface, childItem);
                }
            });


            if (FormImplementInterface.DialogShow("Implement interface into new Entity or Structure", "Type name",
                                                  sourceInterfaceItem, out resultData))
            {
                PersistentTypeKind typeKind = resultData.EntityKind == EntityKind.Entity
                                                  ? PersistentTypeKind.Entity
                                                  : PersistentTypeKind.Structure;

                var        rootItem      = resultData.Root;
                IInterface rootInterface = (IInterface)rootItem.Data;

                (sourceInterface as PersistentType).Store.MakeActionWithinTransaction(
                    string.Format(
                        "Implementing root interface '{0}' (with in/direct inheritances) to new '{1}' named '{2}'",
                        rootInterface.Name, typeKind, resultData.Name),
                    delegate
                {
                    IEntityBase newEntity = rootInterface.ImplementToNewType(typeKind, resultData.Name, ImplementTypeOptions.Default);

                    if (newEntity != null)
                    {
                        foreach (var interfaceToImplementItem in resultData.Selection.Where(item => item.Parent == null))
                        {
                            IInterface interfaceToImplement = (IInterface)interfaceToImplementItem.Data;
                            if (interfaceToImplement != rootInterface)
                            {
                                interfaceToImplement.ImplementToType(newEntity, ImplementTypeOptions.Default);
                            }
                        }

                        Owner.SelectModelElement((ModelElement)newEntity);
                    }
                });
            }
        }