private void PrepareNodesPendingForDelete()
        {
            //1. Preparing potential nodes list for deletion
            PrepareNodesListForDeletion();

            //2. Removing Nodes that supposed to remove the same area
            mNodesToDeleteList = mNodesToDeleteList.GroupBy(x => x.ParentOuterXml).Select(group => group.First()).ToList();

            //For Json only - remove spaces and new lines from string
            if (requestBodyType == ApplicationAPIUtils.eContentType.JSon)//For Json - remove spaces
            {
                foreach (NodeToDelete nodeToDelete in mNodesToDeleteList)
                {
                    nodeToDelete.ParentOuterXml = Regex.Replace(nodeToDelete.ParentOuterXml, @"\s+", string.Empty);
                }
            }

            for (int i = 0; i < mNodesToDeleteList.Count; i++)
            {
                NodeToDelete NodeToInspect = mNodesToDeleteList[i];

                //3. For each node remove it if there is another node that overlap it
                List <NodeToDelete> overlappingNodeList = mNodesToDeleteList.Where(x => NodeToInspect.ParentOuterXml.Contains(x.ParentOuterXml) && !NodeToInspect.ParentOuterXml.Equals(x.ParentOuterXml)).ToList();
                foreach (NodeToDelete overlappingNode in overlappingNodeList)
                {
                    mNodesToDeleteList.Remove(overlappingNode);
                }

                //4.Find the actual node string inside the request body and save its text range
                if (requestBodyType == ApplicationAPIUtils.eContentType.XML)
                {
                    FindXMLElementAndSaveItsTextRange(NodeToInspect);
                }
                else if (requestBodyType == ApplicationAPIUtils.eContentType.JSon)
                {
                    FindJSONElementAndSaveItsTextRange(NodeToInspect);
                }
            }

            //5. Sort NodesToDelete List By text ranges in ascending order
            mNodesToDeleteList = mNodesToDeleteList.OrderBy(x => x.stringNodeRange.Item1).ToList(); //Sort Tuples inside NodesToDelete list
            DisplayAndColorTextRanges();
        }
        private void FindXMLElementAndSaveItsTextRange(NodeToDelete nodeToDelete)
        {
            string[]      splitedSearchText = nodeToDelete.ParentOuterXml.Split('>');
            StringBuilder regexString       = new StringBuilder();

            for (int i = 0; i < splitedSearchText.Length - 1; i++)
            {
                regexString.Append(splitedSearchText[i] + ">\\s*\\n*");
            }
            string regexStringAfterRemovedEndSpaces = regexString.ToString().Substring(0, regexString.ToString().Length - 6);

            var   regex = new Regex(regexStringAfterRemovedEndSpaces);
            Match match = regex.Match(mApplicationAPIModel.RequestBody);

            if (match.Success)
            {
                nodeToDelete.stringNodeRange = new Tuple <int, int>(match.Index, match.Index + match.Length);
            }
            else
            {
                mNodesToDeleteList.Remove(nodeToDelete);
            }
        }
        private void FindJSONElementAndSaveItsTextRange(NodeToDelete nodeToDelete)
        {
            int           i = 0;
            StringBuilder regexStringBuilder = new StringBuilder();
            string        regexString        = Regex.Replace(nodeToDelete.ParentOuterXml, @"\s+", string.Empty);

            string[] splitedSearchText = regexString.Split('{');
            for (i = 1; i < splitedSearchText.Length; i++)
            {
                regexStringBuilder.Append("{\\s*\\n*" + splitedSearchText[i]);
            }

            splitedSearchText = regexStringBuilder.ToString().Split('}');
            regexStringBuilder.Clear();
            for (i = 0; i < splitedSearchText.Length; i++)
            {
                regexStringBuilder.Append(splitedSearchText[i] + "\\s*\\n*}");
            }

            splitedSearchText = regexStringBuilder.ToString().Substring(0, regexStringBuilder.ToString().Length - 7).Split(':');
            regexStringBuilder.Clear();
            for (i = 0; i < splitedSearchText.Length; i++)
            {
                regexStringBuilder.Append(splitedSearchText[i] + ":\\s*\\n*");
            }

            splitedSearchText = regexStringBuilder.ToString().Substring(0, regexStringBuilder.ToString().Length - 7).Split(',');
            regexStringBuilder.Clear();
            for (i = 0; i < splitedSearchText.Length; i++)
            {
                regexStringBuilder.Append(splitedSearchText[i] + ",\\s*\\n*");
            }

            splitedSearchText = regexStringBuilder.ToString().Substring(0, regexStringBuilder.ToString().Length - 7).Split('[');
            regexStringBuilder.Clear();
            for (i = 0; i < splitedSearchText.Length; i++)
            {
                regexStringBuilder.Append(splitedSearchText[i] + "\\s*\\n*\\[\\s*\\n*");
            }

            splitedSearchText = regexStringBuilder.ToString().Substring(0, regexStringBuilder.ToString().Length - 14).Split(']');
            regexStringBuilder.Clear();
            for (i = 0; i < splitedSearchText.Length; i++)
            {
                regexStringBuilder.Append(splitedSearchText[i] + "\\s*\\n*\\]\\s*\\n*");
            }

            //string regexFinalString = regexStringBuilder.ToString().Substring(0, regexStringBuilder.ToString().Length - 7) + ',';
            string regexFinalString = regexStringBuilder.ToString().Substring(0, regexStringBuilder.ToString().Length - 14);
            var    regex            = new Regex(regexFinalString);
            Match  match            = regex.Match(mApplicationAPIModel.RequestBody);

            if (match.Success)
            {
                nodeToDelete.stringNodeRange = new Tuple <int, int>(match.Index, match.Index + match.Length);
            }
            else
            {
                mNodesToDeleteList.Remove(nodeToDelete);
            }
        }