/// <summary>
        /// This method contains the logic performed when the context menu is selected.
        /// </summary>
        /// <param name="objectToExecuteOn">TCObject on which the context menu task is performed.</param>
        /// <param name="taskContext">Task Context of the AddOn Task.</param>
        /// <returns>TCObject Instance</returns>
        public override TCObject Execute(TCObject objectToExecuteOn, TCAddOnTaskContext taskContext)
        {
            TCProject workspaceRoot = objectToExecuteOn as TCProject;
            //Opens the File Upload dialog.
            string filepath = taskContext.GetFilePath("Upload UFT Object archive");
            //Instantiation of this object is mandatory. This class contains the necessary methods for migration.
            ToscaObjectDefinition toscaObjects = new ToscaObjectDefinition();

            try
            {
                //Instantiates the MigrationTask class that contains the business logic of migration.
                MigrationTask migrationObjectImporter = new MigrationTask(toscaObjects, Engine.Html);
                //Entry point of MigrationTask class.
                migrationObjectImporter.ProcessArchive(filepath);

                //Calling this method is mandatory. It outputs the file containing the migrated object information.
                string outputFilePath = toscaObjects.FinishObjectDefinitionTask();
                //Imports the output file from MigrationTask.
                workspaceRoot?.ImportExternalObjects(outputFilePath);
                //Cleans the migration metafiles.
                Directory.Delete(toscaObjects.MigrationFolderPath, true);
            }
            catch (Exception e)
            {
                //Pops-up the error message in case of any error in Migration.
                taskContext.ShowErrorMessage("Exception occured", e.Message);
            }
            return(null);
        }
        public override TCObject Execute(List<TCObject> objs, TCAddOnTaskContext taskContext)
        {
            try
            {
                TestSheet ts = (TestSheet)objs.First().OwningObject;
                List<string> selectedAttribs = new List<string>();
                foreach (TCObject obj in objs)
                {
                    selectedAttribs.Add(obj.UniqueId);
                }

                foreach (TDInstance inst in ts.Instances.Items)
                {

                    string instName = "";
                    foreach (TDInstanceValue instValue in inst.Values)
                    {
                        if (selectedAttribs.Contains(instValue.Element.UniqueId))
                        {
                            if ((instValue.ValueInstance == null) || (instValue.ValueInstance.Character != TDCharacterE.StraightThrough))
                            {
                                if (string.IsNullOrWhiteSpace(instName))
                                {
                                    instName = string.Format("{0}", Settings.Default.TSRenameSplit);
                                }
                                else
                                {
                                    instName += string.Format("{0}", Settings.Default.TSRenameAnd);
                                }
                                instName += string.Format("{0}{1}{2}",
                                    instValue.Element.Name,
                                    Settings.Default.TSRenameEquals,
                                    instValue.ValueInstance == null ? instValue.Value : instValue.ValueInstance.Name);
                            }
                        }
                    }

                    inst.Name = string.Format("{0} {1} {2}", Settings.Default.TSRenamePrefix, ts.Name, instName).Trim();
                    inst.EnsureUniqueName();
                }
            }
            catch (Exception e)
            {
                taskContext.ShowErrorMessage("Well, this is embarrassing",
                    string.Format("An unhandled exception has occured."
                    + Environment.NewLine + Environment.NewLine + "{0}", e.ToString()));
            }

            return null;
        }
Example #3
0
        public override TCObject Execute(TCObject requirementSet, TCAddOnTaskContext taskContext)
        {
            RequirementSet rs     = (RequirementSet)requirementSet;
            JiraConfig     config = rs.GetJiraConfig();

            #region Setup
            if (config == null)
            {
                string url      = taskContext.GetStringValue("Jira Instance URL: ", false);
                string jqlValue = taskContext.GetStringValue("JQL Filter for requirements: ", false);
                config = new JiraConfig
                {
                    baseURL   = url,
                    jqlFilter = jqlValue,
                    fieldMaps = new List <FieldMap>()
                    {
                        new FieldMap {
                            direction = JiraService.Configuration.Direction.jira_to_tosca, jiraJsonPath = "$.fields.summary", toscaField = "Name"
                        }
                    }
                };
                rs.SaveConfig(config);
            }
            string username, password;
            if (CredentialManager.Instance.Credentials.Any(x => x.BaseURL == config.baseURL))
            {
                Credential credential = CredentialManager.Instance.Credentials.First(x => x.BaseURL == config.baseURL);
                username = credential.Username;
                password = credential.Password;
            }
            else
            {
                username = taskContext.GetStringValue("Jira Username", false);
                password = taskContext.GetStringValue("Jira Password", true);
                CredentialManager.Instance.StoreOrUpdateCredential(new Credential
                {
                    BaseURL     = config.baseURL,
                    Description = "Created by Jira Config",
                    Username    = username,
                    Password    = password
                });
            }
            #endregion

            var    jira         = new JiraService.Jira(config.baseURL, username, password);
            var    issueService = jira.GetIssueService();
            String startTime    = DateTime.Now.ToString("yyyyMMddHHmmss");
            string jql          = config.jqlFilter;
            JiraService.Issue.Issue[]        issues    = null;
            Task <JiraService.Issue.Issue[]> issueTask = null;
            try
            {
                issueTask = issueService.SearchAsync(jql);
                while (!issueTask.IsCompleted)
                {
                    taskContext.ShowStatusInfo($"Gettign issues for JQL: {jql}");
                    System.Threading.Thread.Sleep(100);
                }
                //order the issues so that subtasks are not created before parent tasks
                issues = issueTask.Result.OrderBy(x => x.fields.project.name).ThenBy(x => x.id).ToArray();
                taskContext.ShowStatusInfo("Creating Requirements");
            }
            catch (Exception e)
            {
                string err = e.Message;
                if (e.InnerException != null)
                {
                    err += "\r\n" + e.InnerException.Message;
                }
                taskContext.ShowErrorMessage($"Error synchronising", err);
                taskContext.ShowStatusInfo($"Error synchronising: {err}");
                return(requirementSet);
            }
            HashSet <string> updatedItems = new HashSet <string>();
            if (issues != null)
            {
                foreach (var issue in issues)
                {
                    var req = CreateOrUpdateRequirement(rs, config, issue);
                    updatedItems.Add(req.UniqueId);
                }

                // Prompt status
                taskContext.ShowMessageBox("Jira Sync", issues.Length.ToString() + " requirements have been synchronised.");
            }
            return(null);
        }