/// <summary>
        /// Method to search for parent item
        /// </summary>
        /// <param name="itemID">child item id</param>
        /// <param name="customListNode">CustomListNode of ProjectList</param>
        /// <returns>Returns CustomListNode of the father list</returns>
        private CustomizationListNode SearchItemById(int itemID, CustomizationListNode customListNode)
        {
            int customListNodeID;
            CustomizationListNode currentListNode;

            if (customListNode.ChildrenCount > 0)
            {
                List childList = new List();
                childList = customListNode.Children;

                for (int i = 0; i < childList.Count; i++)
                {
                    CustomizationListNode childListNode = (CustomizationListNode)childList[i + 1];
                    customListNodeID = int.Parse(childListNode.ID.ToString());

                    if (customListNodeID == itemID)
                    {
                        return childListNode;
                    }

                    if (childListNode.ChildrenCount > 0)
                    {
                        currentListNode =  SearchItemById(itemID, childListNode);
                        customListNodeID = int.Parse(currentListNode.ID.ToString());

                        if (customListNodeID == itemID)
                        {
                            return currentListNode;
                        }
                    }
                }
            }

            return customListNode;
        }
Beispiel #2
0
        // Create New Defect in Defects Tab QC
        public static int CreateDefect(String Status, String Summary, String DetectedBy, String Version)
        {
            try
            {
                BugFactory bugFactory = mTDConn.BugFactory;

                //start of get bug mandatory fields
                Customization       field = (Customization)mTDConn.Customization;
                CustomizationFields f     = (CustomizationFields)field.Fields;

                List BugFieldsList = f.get_Fields("BUG");
                Dictionary <string, string>         MandatoryFields         = new Dictionary <string, string>();
                Dictionary <string, List <string> > MandatoryListSelections = new Dictionary <string, List <string> >();
                foreach (CustomizationField BugField in BugFieldsList)
                {
                    if (BugField.IsRequired)
                    {
                        List <string> FieldList = new List <string>();
                        if (BugField.List != null && BugField.List.RootNode.Children.Count > 0)
                        {
                            CustomizationListNode lnode = BugField.List.RootNode;
                            List cNodes = lnode.Children;
                            foreach (CustomizationListNode ccNode in cNodes)
                            {
                                //adds list of valid selections of Field
                                FieldList.Add(ccNode.Name);
                            }
                        }
                        if (!MandatoryFields.ContainsKey(BugField.UserLabel))
                        {
                            MandatoryFields.Add(BugField.UserLabel, BugField.ColumnName);
                            if (FieldList.Count > 0)
                            {
                                MandatoryListSelections.Add(BugField.UserLabel, FieldList);
                            }
                            else
                            {
                                MandatoryListSelections.Add(BugField.UserLabel, null);
                            }
                        }
                    }
                }
                //end of get mandatory fileds

                /*
                 *          Bug bug = bugFactory.AddItem(System.DBNull.Value);
                 *          //start of populate mandatory field with first one from dropdown
                 *          foreach (dynamic item in MandatoryFields)
                 *          {
                 *              dynamic staticSelection = MandatoryListSelections.Where(M => M.Key == item.Key).Select(m => m.Value).FirstOrDefault();
                 *              bug[item.Value] = staticSelection[0]; //statically selecting first item in list
                 *          }
                 *          //end of populate mandatory fields
                 */
                Bug bug = bugFactory.AddItem(System.DBNull.Value);
                bug.Status = Status;
                //bug.Project = "Internal";
                bug.Summary       = Summary;
                bug.DetectedBy    = DetectedBy;
                bug["BG_USER_08"] = Version;
                //bug.AssignedTo = "Nobody";
                //bug.Priority = "Low";

                bug.Post();
                return(bug.ID);
            }
            catch (Exception ex)
            {
                //String Text = "Defect Creation Failed.";
                Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex);
                return(0);
            }
        }
        /// <summary>
        /// Recursive method that fills the cells with the children list
        /// </summary>
        /// <param name="idxRow">Row position</param>
        /// <param name="customListNode">CustomlistNode object</param>
        /// <returns>Return current row position + 1</returns>
        private int FillCells(int idxRow, CustomizationListNode customListNode)
        {
            int idxCol = 0;

            if (customListNode.ChildrenCount > 0)
            {
                List childList = new List();
                childList = customListNode.Children;

                for (int i = 0; i < childList.Count; i++)
                {
                    CustomizationListNode childListNode = (CustomizationListNode)childList[i + 1];

                    //get column father position + 1
                    idxCol = int.Parse(positionHash[customListNode.ID].ToString()) + 1;

                    if (((Range)ws.Cells[1, idxCol]).Value2 == null)
                    {
                        ws.Cells[1, idxCol] = "LIST ITEM";
                        ((Range)ws.Cells[1, idxCol]).Font.Bold = true;
                        ((Range)ws.Cells[1, idxCol]).BorderAround();
                    }

                    ws.Cells[idxRow, idxCol] = childListNode.Name.ToString();
                    ((Range)ws.Cells[idxRow, idxCol]).BorderAround();
                    //((Range)ws.Cells[idxRow, idxCol]).Interior.Color = Color.LightGoldenrodYellow;

                    //Saves the position of item
                    positionHash.Add(childListNode.ID, idxCol.ToString());

                    idxRow += 1;

                    if (childListNode.Children.Count > 0)
                    {
                        idxRow = FillCells(idxRow, childListNode);
                    }
                }
            }

            return idxRow;
        }
        /// <summary>
        /// Fills all the children of a particular list
        /// </summary>
        /// <param name="parentNode">Root list</param>
        /// <param name="parentCListNode">Custom list node</param>
        private void FillTreeViewChildren(ref TreeNode parentNode, CustomizationListNode parentCListNode)
        {
            if (parentCListNode.ChildrenCount > 0)
            {
                List childList = new List();
                childList = parentCListNode.Children;

                for (int i = 0; i < childList.Count; i++)
                {
                    CustomizationListNode childListNode = (CustomizationListNode)childList[i + 1];

                    parentNode.Nodes.Add(childListNode.ID.ToString(), childListNode.Name);

                    if (parentNode.ForeColor == Color.Gray)
                    {
                        parentNode.Nodes[i].ForeColor = Color.Gray;
                    }

                    if (childListNode.Children.Count > 0)
                    {
                        TreeNode currentNode = parentNode.Nodes[childListNode.ID.ToString()];
                        FillTreeViewChildren(ref currentNode,childListNode);
                    }
                }
            }
        }
        /// <summary>
        /// Validates that the item exists in the list
        /// </summary>
        /// <param name="listNodeName">Name of the list to validate</param>
        /// <param name="customListNode">CustomizationListNode to validate</param>
        /// <returns>True if exists, False if don't</returns>
        private bool ExistsCustomListNode(string listNodeName, CustomizationListNode customListNode)
        {
            CustomizationListNode childListNode;
            for (int i = 0; i < customListNode.ChildrenCount; i++)
            {
                List childList = new List();
                childList = customListNode.Children;

                childListNode = (CustomizationListNode)childList[i + 1];

                if (childListNode.Name.Equals(listNodeName))
                {
                    return true;
                }
            }

            return false;
        }
        /// <summary>
        /// Method to add items to a ALM customList
        /// </summary>
        /// <param name="oriCustomListNode">Original CustomListNode where will be add new items</param>
        /// <param name="currentCustomListNode">CustomListNode where the items are taken to save them to the original customList</param>
        /// <returns>Returns the message of the performed operations</returns>
        private string AddItemsToList(CustomizationListNode oriCustomListNode, CustomizationListNode currentCustomListNode)
        {
            string message = "";
            for (int i = 0; i < oriCustomListNode.ChildrenCount; i++)
            {
                CustomizationListNode customGrandChild = null;
                List oriChildList = new List();
                List currentChildList = new List();
                oriChildList = oriCustomListNode.Children;
                currentChildList = currentCustomListNode.Children;

                //Get the original ChildListNode
                CustomizationListNode oriChildListNode = (CustomizationListNode)oriChildList[i + 1];

                if (oriChildListNode.ChildrenCount > 0) //If the child has grandchildren
                {
                    if (!ExistsCustomListNode(oriChildListNode.Name, currentCustomListNode)) //If the item doesn't exist
                    {
                        currentCustomListNode.AddChild(oriChildListNode.Name);
                        customGrandChild = (CustomizationListNode)currentCustomListNode.get_Child(oriChildListNode.Name);

                        AddItemsToList(oriChildListNode, customGrandChild);
                        message += "\t \t \t \t \t Item '" + oriChildListNode.Name + "' added to List '" + oriCustomListNode.Name + "'" + Environment.NewLine;
                    }
                }
                else // If child has no more children
                {
                    if (!ExistsCustomListNode(oriChildListNode.Name, currentCustomListNode)) //If the item doesn't exist
                    {
                        currentCustomListNode.AddChild(oriChildListNode.Name);
                        message += "\t \t \t \t \t Item '" + oriChildListNode.Name + "' added to List '" + oriCustomListNode.Name + "'" + Environment.NewLine;
                    }
                }
            }

            return message;
        }
        private List<string> GetAllNodesNames(CustomizationListNode rootNode, bool isRoot, [Optional, DefaultParameterValue(null)]  List<string> nodesNames)
        {
            var names = new List<string>();
            if (nodesNames != null)
                names = nodesNames;
            if (!isRoot)
                names.Add(rootNode.Name);
            if (rootNode.ChildrenCount > 0)
            {
                foreach (CustomizationListNode curNode in rootNode.Children)
                {
                    names = GetAllNodesNames(curNode, false, names);
                }
            }

            return names;
        }