Esempio n. 1
0
        /// <summary>
        /// Generates relevant Action and adds to the current/selected Activity
        /// </summary>
        /// <param name="mItem"> of type object and would successfully add an action with Act/ElementInfo/ApplicationModels type object is provided</param>
        /// <param name="mContext"> required to identify the currently selected Activity, Action is to be added to </param>
        public static int AddActionsHandler(object mItem, Context mContext, int targetIndex = -1)
        {
            Act instance = null;

            if (mContext.Activity != null)
            {
                mContext.BusinessFlow.CurrentActivity = mContext.Activity;//so new Actions will be added to correct Activity
            }

            if (mItem is Act)
            {
                Act selectedAction = mItem as Act;
                instance = GenerateSelectedAction(selectedAction, mContext);
            }
            else if (mItem is ElementInfo)
            {
                ElementInfo elementInfo = mItem as ElementInfo;
                instance = GeneratePOMElementRelatedAction(elementInfo, mContext);
            }
            else if (mItem is ApplicationPOMModel)
            {
                ApplicationPOMModel currentPOM = mItem as ApplicationPOMModel;
                //required to show all the actions added as selected
                int updatedTargetIndex = targetIndex;
                foreach (ElementInfo elemInfo in currentPOM.MappedUIElements)
                {
                    instance = GeneratePOMElementRelatedAction(elemInfo, mContext);
                    if (instance != null)
                    {
                        instance.Active = true;
                        if (updatedTargetIndex > -1)
                        {
                            mContext.Activity.Acts.Insert(updatedTargetIndex, instance);
                            updatedTargetIndex++;
                        }
                        else
                        {
                            mContext.BusinessFlow.AddAct(instance, true);
                        }
                    }
                }
                mContext.Activity.Acts.CurrentItem = instance;
                instance    = null;
                targetIndex = updatedTargetIndex;
            }
            else if (mItem is ApplicationAPIModel || mItem is RepositoryFolder <ApplicationAPIModel> )
            {
                ObservableList <ApplicationAPIModel> apiModelsList = new ObservableList <ApplicationAPIModel>();
                if (mItem is RepositoryFolder <ApplicationAPIModel> )
                {
                    apiModelsList = (mItem as RepositoryFolder <ApplicationAPIModel>).GetFolderItems();
                    apiModelsList = new ObservableList <ApplicationAPIModel>(apiModelsList.Where(a => a.TargetApplicationKey != null && Convert.ToString(a.TargetApplicationKey.ItemName) == mContext.Target.ItemName));
                }
                else
                {
                    apiModelsList.Add(mItem as ApplicationAPIModel);
                }

                AddApiModelActionWizardPage APIModelWizPage = new AddApiModelActionWizardPage(mContext, apiModelsList);
                WizardWindow.ShowWizard(APIModelWizPage);
            }

            if (instance != null)
            {
                instance.Active = true;

                if (targetIndex > -1)
                {
                    mContext.Activity.Acts.Insert(targetIndex, instance);
                }
                else
                {
                    mContext.BusinessFlow.AddAct(instance, true);
                }
                mContext.Activity.Acts.CurrentItem = instance;
            }

            return(targetIndex);
        }
Esempio n. 2
0
        /// <summary>
        /// Generates relevant Action and adds to the current/selected Activity
        /// </summary>
        /// <param name="mItem"> of type object and would successfully add an action with Act/ElementInfo/ApplicationModels type object is provided</param>
        /// <param name="mContext"> required to identify the currently selected Activity, Action is to be added to </param>
        public static int AddActionsHandler(object mItem, Context mContext, int targetIndex = -1)
        {
            Act           instance = null;
            ePlatformType currentActivityPlatform = (from x in WorkSpace.Instance.Solution.ApplicationPlatforms where x.AppName == mContext.Activity.TargetApplication select x.Platform).FirstOrDefault();

            if (mContext.Activity != null)
            {
                mContext.BusinessFlow.CurrentActivity = mContext.Activity;//so new Actions will be added to correct Activity
            }

            if (mItem is Act)
            {
                Act selectedAction = mItem as Act;
                if (!IsValidActionPlatformForActivity(selectedAction, mContext))
                {
                    Reporter.ToUser(eUserMsgKey.MissingTargetApplication, "Activity target platform is \"" + currentActivityPlatform + "\", where as action platform is \"" + selectedAction.Platform + "\"" + System.Environment.NewLine + "Please select same platform actions only.");
                    return(-1);
                }
                if (!(selectedAction is ActWithoutDriver))
                {
                    selectedAction.Platform = (from x in WorkSpace.Instance.Solution.ApplicationPlatforms where x.AppName == mContext.Activity.TargetApplication select x.Platform).FirstOrDefault();
                }
                instance = GenerateSelectedAction(selectedAction, mContext);
            }
            else if (mItem is ElementInfo)
            {
                ElementInfo elementInfo = mItem as ElementInfo;
                instance = GeneratePOMElementRelatedAction(elementInfo, mContext);
            }
            else if (mItem is ApplicationPOMModel)
            {
                ApplicationPOMModel currentPOM = mItem as ApplicationPOMModel;
                //required to show all the actions added as selected
                int updatedTargetIndex = targetIndex;
                foreach (ElementInfo elemInfo in currentPOM.MappedUIElements)
                {
                    instance = GeneratePOMElementRelatedAction(elemInfo, mContext);
                    if (instance != null)
                    {
                        instance.Active = true;
                        if (updatedTargetIndex > -1)
                        {
                            mContext.Activity.Acts.Insert(updatedTargetIndex, instance);
                            updatedTargetIndex++;
                        }
                        else
                        {
                            mContext.BusinessFlow.AddAct(instance, true);
                        }
                    }
                }
                mContext.Activity.Acts.CurrentItem = instance;
                instance    = null;
                targetIndex = updatedTargetIndex;
            }
            else if (mItem is ApplicationAPIModel || mItem is RepositoryFolder <ApplicationAPIModel> )
            {
                ObservableList <ApplicationAPIModel> apiModelsList = new ObservableList <ApplicationAPIModel>();
                if (mItem is RepositoryFolder <ApplicationAPIModel> )
                {
                    apiModelsList = (mItem as RepositoryFolder <ApplicationAPIModel>).GetFolderItems();
                    apiModelsList = new ObservableList <ApplicationAPIModel>(apiModelsList.Where(a => a.TargetApplicationKey != null && Convert.ToString(a.TargetApplicationKey.ItemName) == mContext.Target.ItemName));
                }
                else
                {
                    apiModelsList.Add(mItem as ApplicationAPIModel);
                }

                AddApiModelActionWizardPage APIModelWizPage = new AddApiModelActionWizardPage(mContext, apiModelsList);
                WizardWindow.ShowWizard(APIModelWizPage);
            }

            if (instance != null)
            {
                instance.Active = true;
                if (instance is ActWithoutDriver)
                {
                    instance.Platform = ePlatformType.NA;
                }
                else
                {
                    instance.Platform = currentActivityPlatform;
                }

                if (targetIndex > -1)
                {
                    mContext.Activity.Acts.Insert(targetIndex, instance);
                }
                else
                {
                    mContext.BusinessFlow.AddAct(instance, true);
                }
                mContext.Activity.Acts.CurrentItem = instance;
            }

            return(targetIndex);
        }