private static T Create <T>(BaseEntityModel model_, CreateParams params_ = null)
            where T : IBaseEntityController
        {
            GameObject prefab = (GameObject)Resources.Load("Prefabs/GameEntities/" + model_.DataType);
            GameObject go     = GameObject.Instantiate(prefab) as GameObject;

            //Apply params to transform
            Transform t = go.transform;

            if (params_ != null)
            {
                t.localRotation = Quaternion.Euler(params_.rotation);
                t.position      = params_.position;
                //t.localScale = params_.scale;
            }
            else
            {
                t.localRotation = Quaternion.identity;
                t.position      = Vector3.zero;
                //t.localScale = Vector3.one;
            }
            t.parent = _parentLevel.transform;
            go.SetActive(true);

            //Init model
            T actor = go.GetComponent <T>();

            actor.Init(model_);
            return(actor);
        }
예제 #2
0
        /// <summary>
        /// Генерация полей с текстом исходного кода для всех элементов коллекции
        /// </summary>
        public async Task <bool> SetPeripheryFields(CancellationToken token)
        {
            if (IsEmptyCategories())
            {
                return(false);
            }

            await Task.Run(() =>
            {
                foreach (var cat in Categories)
                {
                    foreach (var el in cat.S7Items)
                    {
                        foreach (var s in GetPeripheryCode(el))
                        {
                            var e = new BaseEntityModel {
                                Name = s
                            };
                            el.PeripheryCode.Add(e);
                        }

                        if (el.DeviceType.Equals("B"))
                        {
                            el.DeviceTag = "I_on";
                        }
                    }
                }
            }, token);

            return(true);
        }
예제 #3
0
 public void Apply(BaseEntityModel entity_)
 {
     if (CheckTargetTypes(entity_))
     {
         Execute(entity_);
     }
 }
예제 #4
0
 public void Apply(BaseEntityModel entity_)
 {
     foreach (var impact in _impacts)
     {
         impact.Apply(entity_);
     }
 }
예제 #5
0
 public bool CheckTargetTypes(BaseEntityModel entity_)
 {
     if (targetTypes == null || targetTypes.Length == 0)
     {
         return(true);
     }
     return(targetTypes.Contains(entity_.DataType));
 }
예제 #6
0
 void OnActorDeath(BaseEntityModel entity_)
 {
     if (entity_.DataType == DataTypes.HERO)
     {
         GameOver();
     }
     RemoveEntity(entity_);
 }
예제 #7
0
        public void Init(BaseEntityModel model_)
        {
            equipmentHolders = GetComponentsInChildren <AbstractEquipmentHolder>();

            model = (TModel)model_;
            InitEvents();
            InitCollisionController();
            OnInit();
        }
예제 #8
0
        /// <summary>
        /// Execute a mapping from the model to a new _event
        /// </summary>
        /// <typeparam name="TEvent">Event type</typeparam>
        /// <param name="model">Model to map from</param>
        /// <returns>Mapped _event</returns>
        public static TEvent ModelToEvent <TEvent>(this BaseEntityModel model) where TEvent : BaseEvent
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            return(model.Map <TEvent>());
        }
예제 #9
0
        /// <summary>
        /// Execute a mapping from the model to a new entity
        /// </summary>
        /// <typeparam name="TEntity">Entity type</typeparam>
        /// <param name="model">Model to map from</param>
        /// <returns>Mapped entity</returns>
        public static TEntity ToEntity <TEntity>(this BaseEntityModel model) where TEntity : BaseEntity
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            return(model.Map <TEntity>());
        }
예제 #10
0
        internal override Dictionary <MappingLovEFElement, string> GetListOfValues(ListOfValuesCollection type)
        {
            var lov = new Dictionary <MappingLovEFElement, string>();

            if (type == ListOfValuesCollection.FirstColumn)
            {
                BaseEntityModel storageModel = null;
                if (AssociationSet != null
                    &&
                    AssociationSet.AssociationSetMapping != null)
                {
                    var table = GetTable();
                    storageModel = table.EntityModel as StorageEntityModel;
                }
                else
                {
                    // this is a creator node, so get the list from the artifact
                    var assoc = MappingAssociation.Association;
                    storageModel = assoc.Artifact.StorageModel();
                }

                if (AssociationSet != null
                    &&
                    AssociationSet.AssociationSetMapping != null)
                {
                    // add the row at the top that the user can click on to remove the item
                    lov.Add(LovDeletePlaceHolder, LovDeletePlaceHolder.DisplayName);
                }

                if (storageModel.EntityTypeCount == 0)
                {
                    if (AssociationSet == null
                        ||
                        AssociationSet.AssociationSetMapping == null)
                    {
                        lov.Add(LovEmptyPlaceHolder, LovEmptyPlaceHolder.DisplayName);
                    }
                }
                else
                {
                    // add those remaining in our list
                    foreach (var entityType in storageModel.EntityTypes())
                    {
                        lov.Add(new MappingLovEFElement(entityType, entityType.DisplayName), entityType.DisplayName);
                    }
                }

                return(lov);
            }
            else
            {
                Debug.Fail("Unsupported lov type was sent");
            }

            return(base.GetListOfValues(type));
        }
예제 #11
0
        protected override void Execute(BaseEntityModel entity_)
        {
            var behaviourComponent = BehaviourFactory.Instance.Create(_behaviourImpactData);

            if (_timerData != null)
            {
                TimerComponent timer = new TimerComponent(_timerData);
                timer.OnComplete(behaviourComponent.Remove);
                behaviourComponent.AddComponent(timer);
                timer.Start();
            }
            entity_.AddComponent(behaviourComponent);
        }
예제 #12
0
        public static IHtmlString GetAuthor(BaseEntityModel model, string UserProfileUrl)
        {
            var    user = userService.GetUserById(model.AuthorId);
            string href = string.Empty;
            string userName;

            if (user != null)
            {
                userName = user.UserName;
                href     = UserProfileUrl + $"?id={user.Id}";
            }
            else
            {
                userName = "******";
                href     = UserProfileUrl;
            }

            return(new HtmlString($"Created {model.CreatedDate.ToString()} <br />by <a href=\"{href}\">{userName}<a />"));
        }
예제 #13
0
        private static void DeleteStaleAssociations(CommandProcessorContext cpc, BaseEntityModel model, HashSet <string> associationNames)
        {
            Debug.Assert(model != null, "Model was null, could not delete stale Fks between Pks");
            if (model != null)
            {
                var associationsToDelete = new List <Association>();

                foreach (var association in model.Associations())
                {
                    // If this association is longer present in the latest SqlSchema model, delete it
                    if (associationNames.Contains(association.Name.Value) == false)
                    {
                        associationsToDelete.Add(association);
                    }
                }

                foreach (var association in associationsToDelete)
                {
                    var deleteAssociationSetCommand = new DeleteEFElementCommand(
                        (c, subCpc) =>
                    {
                        var cmd       = c as DeleteEFElementCommand;
                        cmd.EFElement = ModelHelper.FindAssociationSet(model, association.Name.Value);
                        return(cmd.EFElement != null);
                    });

                    CommandProcessor.InvokeSingleCommand(cpc, deleteAssociationSetCommand);

                    var deleteAssociationCmd = new DeleteAssociationCommand(
                        (c, subCpc) =>
                    {
                        var cmd = c as DeleteAssociationCommand;
                        // Checking the model again for the association in case it's deleted already.
                        cmd.EFElement = ModelHelper.FindAssociation(model, association.Name.Value);
                        return(cmd.EFElement != null);
                    });

                    CommandProcessor.InvokeSingleCommand(cpc, deleteAssociationCmd);
                }
            }
        }
        private static void DeleteStaleAssociations(CommandProcessorContext cpc, BaseEntityModel model, HashSet<string> associationNames)
        {
            Debug.Assert(model != null, "Model was null, could not delete stale Fks between Pks");
            if (model != null)
            {
                var associationsToDelete = new List<Association>();

                foreach (var association in model.Associations())
                {
                    // If this association is longer present in the latest SqlSchema model, delete it
                    if (associationNames.Contains(association.Name.Value) == false)
                    {
                        associationsToDelete.Add(association);
                    }
                }

                foreach (var association in associationsToDelete)
                {
                    var deleteAssociationSetCommand = new DeleteEFElementCommand(
                        (c, subCpc) =>
                            {
                                var cmd = c as DeleteEFElementCommand;
                                cmd.EFElement = ModelHelper.FindAssociationSet(model, association.Name.Value);
                                return cmd.EFElement != null;
                            });

                    CommandProcessor.InvokeSingleCommand(cpc, deleteAssociationSetCommand);

                    var deleteAssociationCmd = new DeleteAssociationCommand(
                        (c, subCpc) =>
                            {
                                var cmd = c as DeleteAssociationCommand;
                                // Checking the model again for the association in case it's deleted already.
                                cmd.EFElement = ModelHelper.FindAssociation(model, association.Name.Value);
                                return cmd.EFElement != null;
                            });

                    CommandProcessor.InvokeSingleCommand(cpc, deleteAssociationCmd);
                }
            }
        }
예제 #15
0
 internal EntityType(BaseEntityModel model, XElement element)
     : base(model, element)
 {
 }
예제 #16
0
        private void CopyAssociation(
            CommandProcessorContext cpc, BaseEntityModel model, AssociationClipboardFormat clipboardAssociation
            , Dictionary <EntityTypeClipboardFormat, EntityType> entitiesMap)
        {
            var associationName  = ModelHelper.GetUniqueName(typeof(Association), model, clipboardAssociation.AssociationName);
            var clipboardEntity1 = clipboardAssociation.ClipboardEntity1;
            var clipboardEntity2 = clipboardAssociation.ClipboardEntity2;

            var entity1 = entitiesMap[clipboardEntity1] as ConceptualEntityType;
            var entity2 = entitiesMap[clipboardEntity2] as ConceptualEntityType;

            Debug.Assert(entity1 != null, "entity1 is not a ConceptualEntityType");
            Debug.Assert(entity2 != null, "entity2 is not a ConceptualEntityType");

            var navigationPropertyEntity1 = clipboardEntity1.GetNavigationPropertyClipboard(
                clipboardAssociation.AssociationName, clipboardAssociation.AssociationEndRole1);
            var navigationPropertyEntity2 = clipboardEntity2.GetNavigationPropertyClipboard(
                clipboardAssociation.AssociationName, clipboardAssociation.AssociationEndRole2);

            var navigationPropertyName1 = navigationPropertyEntity1 != null
                                              ? ModelHelper.GetUniqueConceptualPropertyName(navigationPropertyEntity1.PropertyName, entity1)
                                              : null;

            string navigationPropertyName2 = null;

            if (entity1 == entity2)
            {
                // if this is a self-association then the NavProp for end2 needs a different name from end1
                navigationPropertyName2 =
                    ModelHelper.GetUniqueConceptualPropertyName(
                        (navigationPropertyEntity2 != null ? navigationPropertyEntity2.PropertyName : entity1.LocalName.Value), entity2,
                        new HashSet <string> {
                    navigationPropertyName1
                });
            }
            else
            {
                navigationPropertyName2 =
                    ModelHelper.GetUniqueConceptualPropertyName(
                        (navigationPropertyEntity2 != null ? navigationPropertyEntity2.PropertyName : entity1.LocalName.Value), entity2);
            }
            var cmd = new CreateConceptualAssociationCommand(
                associationName, entity1, clipboardAssociation.Multiplicity1, navigationPropertyName1, entity2,
                clipboardAssociation.Multiplicity2, navigationPropertyName2, true, false);

            CommandProcessor.InvokeSingleCommand(cpc, cmd);

            // copy nav prop facets & structured annotations
            if (navigationPropertyEntity1 != null)
            {
                var np1 = entity1.FindNavigationPropertyForEnd(cmd.End1);
                CommandProcessor.InvokeSingleCommand(
                    cpc,
                    new SetNavigationPropertyFacetsCommand(
                        np1, navigationPropertyEntity1.GetterAccessModifier, navigationPropertyEntity1.SetterAccessModifier));
                AddAnnotations(navigationPropertyEntity1, np1);
            }
            if (navigationPropertyEntity2 != null)
            {
                var np2 = entity2.FindNavigationPropertyForEnd(cmd.End2);
                CommandProcessor.InvokeSingleCommand(
                    cpc,
                    new SetNavigationPropertyFacetsCommand(
                        np2, navigationPropertyEntity2.GetterAccessModifier, navigationPropertyEntity2.SetterAccessModifier));
                AddAnnotations(navigationPropertyEntity2, np2);
            }

            if (clipboardAssociation.ReferentialConstraint != null)
            {
                EntityType principal;
                EntityType dependent;
                if (entity1 == FindEntityByClipboardName(clipboardAssociation.ReferentialConstraint.PrincipalEntityName, entitiesMap))
                {
                    principal = entity1;
                    dependent = entity2;
                }
                else
                {
                    Debug.Assert(
                        entity2 == FindEntityByClipboardName(clipboardAssociation.ReferentialConstraint.PrincipalEntityName, entitiesMap),
                        "could not find entity using clipboard name " + clipboardAssociation.ReferentialConstraint.PrincipalEntityName);

                    principal = entity2;
                    dependent = entity1;
                }
                IEnumerable <Property> principalPropertyList = null;
                IEnumerable <Property> dependentPropertyList = null;
                var associationEnds = cmd.CreatedAssociation.AssociationEnds();
                if (associationEnds.Count == 2 &&
                    (principalPropertyList =
                         ModelHelper.FindProperties(principal, clipboardAssociation.ReferentialConstraint.PrincipalProperties)) != null &&
                    (dependentPropertyList =
                         ModelHelper.FindProperties(dependent, clipboardAssociation.ReferentialConstraint.DependentProperties)) != null)
                {
                    var refCmd = new CreateReferentialConstraintCommand(
                        associationEnds[0], associationEnds[1], principalPropertyList, dependentPropertyList
                        );
                    CommandProcessor.InvokeSingleCommand(cpc, refCmd);
                    AddAnnotations(clipboardAssociation.ReferentialConstraint, refCmd.ReferentialConstraint);
                }
            }

            // add structured annotations to the association
            AddAnnotations(clipboardAssociation, cmd.CreatedAssociation);
        }
예제 #17
0
        internal override Dictionary <MappingLovEFElement, string> GetListOfValues(ListOfValuesCollection type)
        {
            var lov = new Dictionary <MappingLovEFElement, string>();

            if (type == ListOfValuesCollection.FirstColumn)
            {
                BaseEntityModel storageModel = null;
                if (ModelItem != null)
                {
                    var table = ModelItem as EntityType;
                    storageModel = table.EntityModel as StorageEntityModel;
                }
                else
                {
                    // this is a creator node, so get the list from the artifact
                    var entity = MappingConceptualEntityType.ModelItem as EntityType;
                    storageModel = entity.Artifact.StorageModel();
                }

                var entities = new List <EntityType>();
                entities.AddRange(storageModel.EntityTypes());

                // filter the list down to those tables that we aren't already mapping
                foreach (var child in MappingConceptualEntityType.Children)
                {
                    var mset = child as MappingStorageEntityType;
                    Debug.Assert(mset != null, "expected child of type MappingStorageEntityType, got type " + child.GetType().FullName);
                    if (mset.StorageEntityType != null)
                    {
                        entities.Remove(mset.StorageEntityType);
                    }
                }

                if (StorageEntityType != null)
                {
                    // add the row at the top that the user can click on to remove the item
                    lov.Add(LovDeletePlaceHolder, LovDeletePlaceHolder.DisplayName);
                }

                if (entities.Count == 0)
                {
                    if (StorageEntityType == null)
                    {
                        lov.Add(LovEmptyPlaceHolder, LovEmptyPlaceHolder.DisplayName);
                    }
                }
                else
                {
                    // add those remaining in our list
                    foreach (var entityType in entities)
                    {
                        // adding the EntityType to the list
                        lov.Add(new MappingLovEFElement(entityType, entityType.DisplayName), entityType.DisplayName);
                    }
                }

                return(lov);
            }
            else
            {
                Debug.Fail("Unsupported lov type was sent");
            }

            return(base.GetListOfValues(type));
        }
        private void CopyAssociation(
            CommandProcessorContext cpc, BaseEntityModel model, AssociationClipboardFormat clipboardAssociation
            , Dictionary<EntityTypeClipboardFormat, EntityType> entitiesMap)
        {
            var associationName = ModelHelper.GetUniqueName(typeof(Association), model, clipboardAssociation.AssociationName);
            var clipboardEntity1 = clipboardAssociation.ClipboardEntity1;
            var clipboardEntity2 = clipboardAssociation.ClipboardEntity2;

            var entity1 = entitiesMap[clipboardEntity1] as ConceptualEntityType;
            var entity2 = entitiesMap[clipboardEntity2] as ConceptualEntityType;

            Debug.Assert(entity1 != null, "entity1 is not a ConceptualEntityType");
            Debug.Assert(entity2 != null, "entity2 is not a ConceptualEntityType");

            var navigationPropertyEntity1 = clipboardEntity1.GetNavigationPropertyClipboard(
                clipboardAssociation.AssociationName, clipboardAssociation.AssociationEndRole1);
            var navigationPropertyEntity2 = clipboardEntity2.GetNavigationPropertyClipboard(
                clipboardAssociation.AssociationName, clipboardAssociation.AssociationEndRole2);

            var navigationPropertyName1 = navigationPropertyEntity1 != null
                                              ? ModelHelper.GetUniqueConceptualPropertyName(navigationPropertyEntity1.PropertyName, entity1)
                                              : null;
            string navigationPropertyName2 = null;
            if (entity1 == entity2)
            {
                // if this is a self-association then the NavProp for end2 needs a different name from end1
                navigationPropertyName2 =
                    ModelHelper.GetUniqueConceptualPropertyName(
                        (navigationPropertyEntity2 != null ? navigationPropertyEntity2.PropertyName : entity1.LocalName.Value), entity2,
                        new HashSet<string> { navigationPropertyName1 });
            }
            else
            {
                navigationPropertyName2 =
                    ModelHelper.GetUniqueConceptualPropertyName(
                        (navigationPropertyEntity2 != null ? navigationPropertyEntity2.PropertyName : entity1.LocalName.Value), entity2);
            }
            var cmd = new CreateConceptualAssociationCommand(
                associationName, entity1, clipboardAssociation.Multiplicity1, navigationPropertyName1, entity2,
                clipboardAssociation.Multiplicity2, navigationPropertyName2, true, false);
            CommandProcessor.InvokeSingleCommand(cpc, cmd);

            // copy nav prop facets & structured annotations
            if (navigationPropertyEntity1 != null)
            {
                var np1 = entity1.FindNavigationPropertyForEnd(cmd.End1);
                CommandProcessor.InvokeSingleCommand(
                    cpc,
                    new SetNavigationPropertyFacetsCommand(
                        np1, navigationPropertyEntity1.GetterAccessModifier, navigationPropertyEntity1.SetterAccessModifier));
                AddAnnotations(navigationPropertyEntity1, np1);
            }
            if (navigationPropertyEntity2 != null)
            {
                var np2 = entity2.FindNavigationPropertyForEnd(cmd.End2);
                CommandProcessor.InvokeSingleCommand(
                    cpc,
                    new SetNavigationPropertyFacetsCommand(
                        np2, navigationPropertyEntity2.GetterAccessModifier, navigationPropertyEntity2.SetterAccessModifier));
                AddAnnotations(navigationPropertyEntity2, np2);
            }

            if (clipboardAssociation.ReferentialConstraint != null)
            {
                EntityType principal;
                EntityType dependent;
                if (entity1 == FindEntityByClipboardName(clipboardAssociation.ReferentialConstraint.PrincipalEntityName, entitiesMap))
                {
                    principal = entity1;
                    dependent = entity2;
                }
                else
                {
                    Debug.Assert(
                        entity2 == FindEntityByClipboardName(clipboardAssociation.ReferentialConstraint.PrincipalEntityName, entitiesMap),
                        "could not find entity using clipboard name " + clipboardAssociation.ReferentialConstraint.PrincipalEntityName);

                    principal = entity2;
                    dependent = entity1;
                }
                IEnumerable<Property> principalPropertyList = null;
                IEnumerable<Property> dependentPropertyList = null;
                var associationEnds = cmd.CreatedAssociation.AssociationEnds();
                if (associationEnds.Count == 2
                    && (principalPropertyList =
                        ModelHelper.FindProperties(principal, clipboardAssociation.ReferentialConstraint.PrincipalProperties)) != null
                    && (dependentPropertyList =
                        ModelHelper.FindProperties(dependent, clipboardAssociation.ReferentialConstraint.DependentProperties)) != null)
                {
                    var refCmd = new CreateReferentialConstraintCommand(
                        associationEnds[0], associationEnds[1], principalPropertyList, dependentPropertyList
                        );
                    CommandProcessor.InvokeSingleCommand(cpc, refCmd);
                    AddAnnotations(clipboardAssociation.ReferentialConstraint, refCmd.ReferentialConstraint);
                }
            }

            // add structured annotations to the association
            AddAnnotations(clipboardAssociation, cmd.CreatedAssociation);
        }
예제 #19
0
 void RemoveEntity(BaseEntityModel entity_)
 {
     entity_.Destroy();
 }
예제 #20
0
        protected override void Execute(BaseEntityModel entity_)
        {
            var timerImpactComponent = new PeriodImpactComponent(_impacts, _timerData);

            entity_.AddComponent(timerImpactComponent);
        }
예제 #21
0
 protected abstract void Execute(BaseEntityModel entity_);
예제 #22
0
 public static VM ToViewModel <VM>(this BaseEntityModel entity) where VM : BaseViewModel
 {
     return((VM)Mapper.Map(entity, entity.GetType(), typeof(VM)));
 }
예제 #23
0
 protected override void Execute(BaseEntityModel entity_)
 {
     Strategy.Apply(_impactValue, _targetSkills, entity_.Skills);
 }
 protected ExplorerEntityModel(EditingContext context, BaseEntityModel entityModel, ExplorerEFElement parent)
     : base(context, entityModel, parent)
 {
 }
예제 #25
0
 protected ExplorerEntityModel(EditingContext context, BaseEntityModel entityModel, ExplorerEFElement parent)
     : base(context, entityModel, parent)
 {
 }