Esempio n. 1
0
        public override void OnCreate()
        {
            var hT = new HierarchyTransform(Position, Rotation, null);

            foreach (var seRef in SceneDef.Entities)
            {
                Locators.Add(new LocToId()
                {
                    Id = CurrentServer.AcquireId(), Loc = seRef.Def
                });
            }
            foreach (var seRef in Locators)
            {
                var spawnedEntitySceneDef = seRef.Loc;
                var spawnedEntityDef      = EntityObjectsMap.GetDefFromSceneDef(spawnedEntitySceneDef);
                var scenePos   = (Vec2)spawnedEntitySceneDef.GetType().GetProperty(nameof(IPositionedEntity.Position)).GetValue(spawnedEntitySceneDef);
                var sceneRot   = (float)spawnedEntitySceneDef.GetType().GetProperty(nameof(IPositionedEntity.Rotation)).GetValue(spawnedEntitySceneDef);
                var objItemDef = spawnedEntitySceneDef.GetType().GetProperty(nameof(WorldItemEntity.StartingItemDef));
                var itemDef    = objItemDef == null ? null : ((DefRef <ItemDef>)objItemDef.GetValue(spawnedEntitySceneDef)).Def;
                var lT         = new HierarchyTransform(scenePos, sceneRot, hT);
                CurrentServer.Create(seRef.Id, EntityObjectsMap.GetTypeFromDef(spawnedEntityDef), e =>
                {
                    ((IEntityObject)e).Def          = (IEntityObjectDef)(((ISceneDef)spawnedEntitySceneDef).Object.Def);
                    ((IPositionedEntity)e).Position = lT.GlobalPos;
                    ((IPositionedEntity)e).Rotation = lT.GlobalRot;
                    if (e is WorldItemEntity wie)
                    {
                        wie.StartingItemDef = itemDef;
                    }
                });
            }
        }
Esempio n. 2
0
    public void Register(Locator locator)
    {
        Locators.Add(locator);

        if (Started)
        {
            locator.SetupIndicators(Locatables);
        }
    }
 /// <summary>
 /// The logic used whenever a dependent locator is swapped.
 /// </summary>
 /// <param name="newLocator">The new locator.</param>
 /// <param name="oldLocator">The old locator.</param>
 /// <param name="token">The token to use to lock.</param>
 protected void ProcessLocatorSwap(ILocator newLocator, ILocator oldLocator, object token)
 {
     if (oldLocator != null)
     {
         Locators.Remove(oldLocator);
         oldLocator.SearchToBegin   -= Locator_SearchToBegin;
         oldLocator.SearchComplete  -= Locator_SearchComplete;
         oldLocator.RecordRequested -= Locator_RecordRequested;
     }
     if (newLocator != null)
     {
         Locators.Add(newLocator);
         newLocator.RequestClear();
         newLocator.RequestDisable(token);
         newLocator.SearchToBegin   += Locator_SearchToBegin;
         newLocator.SearchComplete  += Locator_SearchComplete;
         newLocator.RecordRequested += Locator_RecordRequested;
     }
 }
        /// <summary>
        /// The logic used to update the <see cref="ModelSearcher" />.
        /// </summary>
        /// <param name="searcher">The new <see cref="ModelSearcher" />.</param>
        /// <returns>Task for async use.</returns>
        public async Task UpdateModelSearcher(IVMLocator <TModelSearcher> searcher)
        {
            var oldValue = _modelSearcher;

            if (Perform.ReplaceIfDifferent(ref _modelSearcher, searcher).WasSuccessful)
            {
                if (oldValue != null)
                {
                    Locators.Remove(oldValue);
                    oldValue.SelectedItems.CollectionChanged -= SelectedItems_CollectionChanged;
                    oldValue.ExportId -= ModelSearcher_ExportId;
                    oldValue.Cleared  -= ModelSearcher_Cleared;
                }
                if (_modelSearcher != null)
                {
                    _modelSearcher.SelectedItems.CollectionChanged += SelectedItems_CollectionChanged;
                    _modelSearcher.ExportId += ModelSearcher_ExportId;
                    _modelSearcher.Cleared  += ModelSearcher_Cleared;
                    Locators.Add(_modelSearcher);
                    if (_modelSearcher.CurrentItems.Any())
                    {
                        var navCollection =
                            (_modelSearcher.SelectedItems.Take(2).Count() == 2 ?
                             _modelSearcher.SelectedItems :
                             _modelSearcher.CurrentItems
                            );

                        _backForwardNavigator.UpdateNavigationCollection(navCollection.Select(item => item.Id));

                        int currentItem =
                            (_modelSearcher.SelectedItems.Any() ?
                             _modelSearcher.SelectedItems :
                             _modelSearcher.CurrentItems
                            ).First().Id;
                        await _backForwardNavigator.UpdateCurrentItem(currentItem);
                    }
                }
                await OnModelSearcherSwapped(oldValue);

                OnPropertyChanged(nameof(ModelSearcher));
            }
        }
Esempio n. 5
0
 public void AddLocator <T>() where T : IViewLocator
 {
     Locators.Add(typeof(T));
 }
Esempio n. 6
0
        static NewPayLoad GeneratePlatformActionPayload(IActPluginExecution ACT, Agent agent)
        {
            PlatformAction platformAction = ACT.GetAsPlatformAction();

            if (ACT is ActUIElement actUi)
            {
                if (actUi.LocateBy == eLocateBy.POMElement)
                {
                    AddPOMLocators(ref platformAction, ref actUi, agent.ProjEnvironment, agent.BusinessFlow);
                }
            }

            // TODO: calculate VE ??!!

            NewPayLoad payload = new NewPayLoad("RunPlatformAction");

            payload.AddJSONValue <PlatformAction>(platformAction);
            payload.ClosePackage();

            // TODO: Process Valuefordriver!!!!

            return(payload);


            void AddPOMLocators(ref PlatformAction PlatformAction, ref ActUIElement UIElementAction, ProjEnvironment projEnvironment, BusinessFlow businessFlow)
            {
                Dictionary <string, string> Locators = null;

                if (PlatformAction.InputParams.ContainsKey("Locators"))
                {
                    Locators = (Dictionary <string, string>)PlatformAction.InputParams["Locators"];
                }
                else
                {
                    Locators = new Dictionary <string, string>();
                }


                List <string> Frames = new List <string>();

                string[]            pOMandElementGUIDs = UIElementAction.ElementLocateValue.ToString().Split('_');
                Guid                selectedPOMGUID    = new Guid(pOMandElementGUIDs[0]);
                ApplicationPOMModel currentPOM         = amdocs.ginger.GingerCoreNET.WorkSpace.Instance.SolutionRepository.GetRepositoryItemByGuid <ApplicationPOMModel>(selectedPOMGUID);

                if (currentPOM == null)
                {
                    UIElementAction.ExInfo = string.Format("Failed to find the mapped element Page Objects Model with GUID '{0}'", selectedPOMGUID.ToString());
                    return;
                }



                Guid        selectedPOMElementGUID = new Guid(pOMandElementGUIDs[1]);
                ElementInfo selectedPOMElement     = (ElementInfo)currentPOM.MappedUIElements.Where(z => z.Guid == selectedPOMElementGUID).FirstOrDefault();


                if (selectedPOMElement == null)
                {
                    UIElementAction.ExInfo = string.Format("Failed to find the mapped element with GUID '{0}' inside the Page Objects Model", selectedPOMElement.ToString());
                    return;
                }
                else
                {
                    List <NewPayLoad> switchframpayload = new List <NewPayLoad>();

                    if (selectedPOMElement.Path != null)
                    {
                        string[] spliter       = new string[] { "," };
                        string[] iframesPathes = selectedPOMElement.Path.Split(spliter, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string iframePath in iframesPathes)
                        {
                            Frames.Add(iframePath);
                        }
                    }



                    //adding all locators from POM

                    foreach (ElementLocator locator in selectedPOMElement.Locators.Where(x => x.Active == true).ToList())
                    {
                        string locateValue;
                        if (locator.IsAutoLearned)
                        {
                            locateValue = locator.LocateValue;
                        }
                        else
                        {
                            ElementLocator             evaluatedLocator = locator.CreateInstance() as ElementLocator;
                            GingerCore.ValueExpression VE = new GingerCore.ValueExpression(projEnvironment, businessFlow);
                            locateValue = VE.Calculate(evaluatedLocator.LocateValue);
                        }
                        Locators.Add(locator.LocateBy.ToString(), locateValue);
                    }
                }
            }
        }