示例#1
0
        /// <summary>
        /// Utility function containing the replace logic for both requests and responses
        /// </summary>
        /// <param name="originalValueBytes"></param>
        /// <param name="match"></param>
        /// <param name="replacement"></param>
        /// <returns></returns>
        private byte[] ReplaceInComponent(byte[] originalValueBytes, LineMatch match, string replacement)
        {
            string val   = Constants.DefaultEncoding.GetString(originalValueBytes);
            int    count = match.MatchCoordinatesList.Count;

            for (int i = count - 1; i > -1; i--)
            {
                MatchCoordinates coords = new MatchCoordinates(-1, -1);
                try
                {
                    coords = match.MatchCoordinatesList[i];

                    val = String.Format("{0}{1}{2}",
                                        val.Substring(0, coords.MatchPosition),
                                        replacement,
                                        val.Substring(coords.MatchPosition + coords.MatchLength));
                }
                catch (Exception ex)
                {
                    SdkSettings.Instance.Logger.Log(TraceLevel.Error, "Incorrect match coordinates for request id: '{0}', line match '{1}', context: '{2}', start: '{3}', length: '{4}', exception: '{5}'",
                                                    LogMessageType.Error,
                                                    match.RequestId,
                                                    match.Line,
                                                    match.Context,
                                                    coords.MatchPosition,
                                                    coords.MatchLength,
                                                    ex.Message);
                }
            }

            return(Constants.DefaultEncoding.GetBytes(val));
        }
示例#2
0
        /// <summary>
        /// Replaces the specified set of matches with the replacement string
        /// </summary>
        /// <param name="matchList"></param>
        /// <param name="replacement"></param>
        public void Replace(IList <LineMatch> matchList, string replacement)
        {
            int count = matchList.Count;

            for (int i = count - 1; i > -1; i--)
            {
                LineMatch match = matchList[i];
                if (match.Context == SearchContext.Request)
                {
                    byte[] reqBytes = LoadRequestData(match.RequestId);
                    reqBytes = ReplaceInComponent(reqBytes, match, replacement);
                    SaveRequest(match.RequestId, reqBytes);
                    //update request line
                    TVRequestInfo reqInfo = GetRequestInfo(match.RequestId);
                    if (String.Compare(match.Line, reqInfo.RequestLine) == 0)
                    {
                        HttpRequestInfo httpReqInfo = new HttpRequestInfo(reqBytes);
                        reqInfo.RequestLine = httpReqInfo.RequestLine;
                    }
                }
                else if (match.Context == SearchContext.Response)
                {
                    byte[] respBytes = LoadResponseData(match.RequestId);
                    respBytes = ReplaceInComponent(respBytes, match, replacement);
                    SaveResponse(match.RequestId, respBytes);
                }
            }

            if (ReplaceEvent != null)
            {
                ReplaceEvent.Invoke(new ReplaceEventArgs(matchList, replacement));
            }
        }
示例#3
0
 private void SelectedIndexChanged(object sender, EventArgs e)
 {
     if (SearchIndexChanged != null && _list.SelectedIndex > -1 && SearchIndexChanged != null)
     {
         LineMatch match = _matches[_list.SelectedIndex];
         SearchIndexChanged.Invoke(new SearchIndexChangedEventArgs(_boxSearchText.Text, match.RequestId, match.Line, _checkIsRegex.Checked));
     }
 }
示例#4
0
 public SearchMatch(string path, string shortPath, int lineNumber, string matchedText, string matchedLine)
 {
     m_Path          = path;
     m_ShortenedPath = shortPath;
     m_LineNumber    = lineNumber;
     m_MatchedText   = matchedText;
     m_MatchedLine   = matchedLine;
     m_LineMatch     = new LineMatch(m_MatchedLine, m_MatchedText);
 }
示例#5
0
        private SearchResultIndicatorStatus CalculateStatus(LineMatch firstMatch)
        {
            if (firstMatch == null)
            {
                return(SearchResultIndicatorStatus.None);
            }

            return(firstMatch.UseRegex ? SearchResultIndicatorStatus.Regex : SearchResultIndicatorStatus.Text);
        }
示例#6
0
 private void ReplaceOnceClick(object sender, EventArgs e)
 {
     if (ReplaceRequestedEvent != null && _list.SelectedIndex >= 0 && _list.SelectedIndex < _matches.Count)
     {
         LineMatch        match      = _matches[_list.SelectedIndex];
         List <LineMatch> matchesArg = new List <LineMatch>();
         matchesArg.Add(match);
         ReplaceRequestedEvent.Invoke(new ReplaceEventArgs(matchesArg, _boxReplace.Text));
         _matches.RemoveAt(_list.SelectedIndex);
         _list.Items.RemoveAt(_list.SelectedIndex);
     }
 }
示例#7
0
        public LineMatchProxy(LineMatch match, IThemeProvider themeProvider)
        {
            _match   = match;
            IconKind = _match.Icon.ParseEnum <PackIconKind>().ValueOr(() => PackIconKind.ArrowRightBold);

            var defaultHue = themeProvider.Accent.Select(hue => match.Hue == Hue.NotSpecified ? hue : _match.Hue);

            Foreground = defaultHue.Select(h => h.ForegroundBrush).ForBinding();
            Background = defaultHue.Select(h => h.BackgroundBrush).ForBinding();

            _cleanUp = new CompositeDisposable(Foreground, Background);
        }
示例#8
0
 public LineMatchProxy(LineMatch match)
 {
     _match   = match;
     IconKind = _match.Icon.ParseEnum <PackIconKind>().ValueOr(() => PackIconKind.ArrowRightBold);
 }