Ejemplo n.º 1
0
        /*
         * public LogReplayAssociations Play(LogAssociations Associations)
         * {
         *  return Play(Associations, null, new CookieStore());
         * }
         *
         * public LogReplayAssociations Play(LogAssociations Associations, CookieStore Cookies)
         * {
         *  return Play(Associations, null, Cookies);
         * }
         *
         * public LogReplayAssociations Play(LogAssociations Associations, UpdateRequestBeforeReplaying ReqUpdater)
         * {
         *  return Play(Associations, ReqUpdater, new CookieStore());
         * }
         * public LogReplayAssociations Play(LogAssociations Associations, UpdateRequestBeforeReplaying ReqUpdater, CookieStore Cookies)
         * {
         *  List<LogReplayAssociation> PlayAssociations = new List<LogReplayAssociation>();
         *  foreach (int LogId in Associations.LogIds)
         *  {
         *      LogAssociation Asso = Associations.GetAssociation(LogId);
         *      if (!Asso.IsIgnorable)
         *      {
         *          LogReplayAssociation PlayAsso = new LogReplayAssociation(Asso);
         *          PlayAssociations.Add(PlayAsso);
         *      }
         *  }
         *  foreach (LogReplayAssociation PlayAsso in PlayAssociations)
         *  {
         *      LogReplayAssociation PreviousAsso = null;
         *      foreach (LogReplayAssociation PrePlayAsso in PlayAssociations)
         *      {
         *          if (PrePlayAsso.OriginalAssociation != null
         *              && PrePlayAsso.OriginalAssociation.DestinationLog != null
         *              && PlayAsso.OriginalAssociation.SourceLog != null
         *              && PlayAsso.OriginalAssociation.SourceLog.LogId == PrePlayAsso.OriginalAssociation.DestinationLog.LogId)
         *          {
         *              PreviousAsso = PrePlayAsso;
         *          }
         *      }
         *      PlayAssociation(PlayAsso, PreviousAsso, Cookies, ReqUpdater);
         *  }
         *  return new LogReplayAssociations(PlayAssociations, Cookies);
         * }
         */

        //LogReplayAssociation PlayAssociation(LogAssociation CurrentAsso, List<LogReplayAssociation> PlayAssociations, LogAssociations Associations, CookieStore Cookies)

        /*
         * void PlayAssociation(LogReplayAssociation CurrentAsso, LogReplayAssociation PreviousAsso, CookieStore Cookies, UpdateRequestBeforeReplaying ReqUpdater)
         * {
         *  Request Req = GetRequest(CurrentAsso, PreviousAsso);
         *  Req.Cookie.RemoveAll();
         *  Req.SetCookie(Cookies);
         *  Req.SetSource("LogReplayer");
         *  if (ReqUpdater != null)
         *  {
         *      Req = ReqUpdater(Req, CurrentAsso.OriginalAssociation);
         *  }
         *  Response Res = Req.Send();
         *  Cookies.Add(Req, Res);
         *  if (PreviousAsso != null && PreviousAsso.ReplayAssociation != null && PreviousAsso.ReplayAssociation.DestinationLog != null)
         *  {
         *      CurrentAsso.ReplayAssociation = new LogAssociation(LogAssociationType.Unknown, RefererAssociationType.None, IronHtml.UrlInHtmlMatch.None, LogAssociationMatchLevel.Other, PreviousAsso.ReplayAssociation.DestinationLog, new Session(Req, Res));
         *  }
         *  else
         *  {
         *      CurrentAsso.ReplayAssociation = new LogAssociation(LogAssociationType.Unknown, RefererAssociationType.None, IronHtml.UrlInHtmlMatch.None, LogAssociationMatchLevel.Other, null, new Session(Req, Res));
         *  }
         * }
         */

        Request GetRequest(LogReplayAssociation PlayAsso, LogReplayAssociation PreviousPlayAsso)
        {
            LogAssociation OriAsso = PlayAsso.OriginalAssociation;

            if (OriAsso.AssociationType == LogAssociationType.UnAssociated || OriAsso.AssociationType == LogAssociationType.Unknown)
            {
                return(OriAsso.DestinationLog.Request.GetClone());
            }
            if (OriAsso.SourceLog == null || PreviousPlayAsso == null || PreviousPlayAsso.ReplayAssociation == null || PreviousPlayAsso.ReplayAssociation.DestinationLog == null)
            {
                return(OriAsso.DestinationLog.Request.GetClone());
            }

            Request Req = GetRequest(OriAsso, PreviousPlayAsso.ReplayAssociation.DestinationLog);

            if (Req == null)
            {
                //do something here
                //check in nearnest logs for redirect based variations otherwise just send the old request
            }
            else
            {
                return(Req);
            }

            return(OriAsso.DestinationLog.Request.GetClone());
        }
Ejemplo n.º 2
0
        LogAssociation GetBestAssociation(int LogId, List <LogAssociation> Associations)
        {
            int            ClosestSourceLogId = 0;
            LogAssociation BestAssociation    = null;

            foreach (LogAssociation Asso in Associations)
            {
                if (Asso.DestinationLog.LogId != LogId)
                {
                    continue;
                }
                if (Asso.SourceLog.LogId > ClosestSourceLogId)
                {
                    ClosestSourceLogId = Asso.SourceLog.LogId;
                    BestAssociation    = null;
                }
                if (Asso.SourceLog.LogId == ClosestSourceLogId)
                {
                    if (BestAssociation == null || Asso.AssociationScore > BestAssociation.AssociationScore)
                    {
                        BestAssociation = Asso;
                    }
                }
            }
            return(BestAssociation);
        }
Ejemplo n.º 3
0
 Request GetRedirect(LogAssociation CurrentAsso, Session PlaySess)
 {
     if (PlaySess.Response.IsRedirect)
     {
         return(PlaySess.Request.GetRedirect(PlaySess.Response));
     }
     return(null);
 }
Ejemplo n.º 4
0
        List <LogAssociation> FindRedirectAssociations(Session MainLog, List <Session> SessionList, RefererAssociationType RefAssoType)
        {
            List <LogAssociation> Associations = new List <LogAssociation>();

            if (MainLog.Response == null)
            {
                return(null);
            }

            if (MainLog.Response.IsRedirect)
            {
                if (MainLog.Response.Headers.Has("Location"))
                {
                    string RedirUrl = MainLog.Response.Headers.Get("Location").Trim();
                    try
                    {
                        Request RedirReq = new Request(RedirUrl);
                        foreach (Session Sess in SessionList)
                        {
                            if (!Sess.Request.Method.Equals("GET", StringComparison.OrdinalIgnoreCase))
                            {
                                continue;
                            }
                            if (Sess.Request.FullUrl.Equals(RedirReq.FullUrl) && Sess.Response != null)
                            {
                                LogAssociation LogAsso = new LogAssociation(LogAssociationType.Redirect, RefAssoType, IronHtml.UrlInHtmlMatch.FullAbsolute, LogAssociationMatchLevel.Other, MainLog, Sess);
                                Associations.Add(LogAsso);
                            }
                        }
                    }
                    catch
                    {
                        Request RedirReq = MainLog.Request.GetRedirect(MainLog.Response);
                        foreach (Session Sess in SessionList)
                        {
                            if (!Sess.Request.Method.Equals("GET", StringComparison.OrdinalIgnoreCase))
                            {
                                continue;
                            }
                            if (Sess.Request.FullUrl.Equals(RedirReq.FullUrl) && Sess.Response != null)
                            {
                                LogAssociation LogAsso = new LogAssociation(LogAssociationType.Redirect, RefAssoType, IronHtml.UrlInHtmlMatch.FullRelative, LogAssociationMatchLevel.Other, MainLog, Sess);
                                Associations.Add(LogAsso);
                            }
                        }
                    }
                }
            }
            return(Associations);
        }
Ejemplo n.º 5
0
        List <LogAssociation> FindLinkClickAssociations(Session MainLog, List <Session> SessionList, RefererAssociationType RefAssoType)
        {
            List <LogAssociation> Associations = new List <LogAssociation>();

            if (MainLog.Response == null)
            {
                return(Associations);
            }

            //Match link urls with absolute match
            foreach (string LinkUrl in MainLog.Response.Html.GetDecodedValues("a", "href"))
            {
                try
                {
                    Request LinkReq = new Request(LinkUrl.Trim());
                    foreach (Session Sess in SessionList)
                    {
                        if (!Sess.Request.Method.Equals("GET", StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }
                        if (Sess.Request.FullUrl.Equals(LinkReq.FullUrl) && Sess.Response != null)
                        {
                            LogAssociation LogAsso = new LogAssociation(LogAssociationType.LinkClick, RefAssoType, IronHtml.UrlInHtmlMatch.FullAbsolute, LogAssociationMatchLevel.UrlMatchOnly, MainLog, Sess);
                            Associations.Add(LogAsso);
                        }
                    }
                }
                catch
                {
                    Request LinkReq = new Request(MainLog.Request.RelativeUrlToAbsoluteUrl(LinkUrl.Trim()));
                    foreach (Session Sess in SessionList)
                    {
                        if (!Sess.Request.Method.Equals("GET", StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }
                        if (Sess.Request.FullUrl.Equals(LinkReq.FullUrl) && Sess.Response != null)
                        {
                            LogAssociation LogAsso = new LogAssociation(LogAssociationType.LinkClick, RefAssoType, IronHtml.UrlInHtmlMatch.FullRelative, LogAssociationMatchLevel.UrlMatchOnly, MainLog, Sess);
                            Associations.Add(LogAsso);
                        }
                    }
                }
            }
            return(Associations);
        }
Ejemplo n.º 6
0
        Request GetRequest(LogAssociation CurrentAsso, Session PlaySess)
        {
            switch (CurrentAsso.AssociationType)
            {
            case (LogAssociationType.LinkClick):
                return(GetLinkClick(CurrentAsso, PlaySess));

            case (LogAssociationType.FormSubmission):
                return(GetFormSubmission(CurrentAsso, PlaySess));

            case (LogAssociationType.Redirect):
                return(GetRedirect(CurrentAsso, PlaySess));

            default:
                return(null);
            }
        }
Ejemplo n.º 7
0
        public Request PrepareStepForPlay()
        {
            if (PlayAssociations.Count == 0 && Associations.NonIgnorableCount > 0)
            {
                foreach (int LogId in Associations.LogIds)
                {
                    LogAssociation Asso = Associations.GetAssociation(LogId);
                    if (!Asso.IsIgnorable)
                    {
                        LogReplayAssociation PlayAsso = new LogReplayAssociation(Asso);
                        PlayAssociations.Add(PlayAsso);
                    }
                }
            }

            //LogReplayAssociation PlayAsso = PlayAssociations[CurrentPlayIndex];

            CurrentAssociationBeingPlayed = PlayAssociations[CurrentPlayIndex];

            //LogReplayAssociation PreviousAsso = null;

            PreviousAssociationToOneBeingPlayed = null;
            foreach (LogReplayAssociation PrePlayAsso in PlayAssociations)
            {
                if (PrePlayAsso.OriginalAssociation != null &&
                    PrePlayAsso.OriginalAssociation.DestinationLog != null &&
                    CurrentAssociationBeingPlayed.OriginalAssociation.SourceLog != null &&
                    CurrentAssociationBeingPlayed.OriginalAssociation.SourceLog.LogId == PrePlayAsso.OriginalAssociation.DestinationLog.LogId)
                {
                    PreviousAssociationToOneBeingPlayed = PrePlayAsso;
                }
            }
            //Request Req = GetRequest(CurrentAsso, PreviousAsso);
            CurrentRequestBeingPlayed = GetRequest(CurrentAssociationBeingPlayed, PreviousAssociationToOneBeingPlayed);

            CurrentRequestBeingPlayed.Cookie.RemoveAll();
            CurrentRequestBeingPlayed.SetCookie(Cookies);
            CurrentRequestBeingPlayed.SetSource("LogReplayer");
            if (ReqUpdater != null)
            {
                CurrentRequestBeingPlayed = ReqUpdater(CurrentRequestBeingPlayed, CurrentAssociationBeingPlayed.OriginalAssociation);
            }

            return(CurrentRequestBeingPlayed);
        }
Ejemplo n.º 8
0
        List <LogAssociation> FinalizeAssociationsByPriority(Dictionary <int, Session> Sessions, List <LogAssociation> Associations)
        {
            List <LogAssociation> FinalizedAssociations = new List <LogAssociation>();

            List <int> LogIds = new List <int>(Sessions.Keys);

            LogIds.Sort();
            foreach (int LogId in LogIds)
            {
                LogAssociation Asso = GetBestAssociation(LogId, Associations);
                if (Asso == null)
                {
                    FinalizedAssociations.Add(new LogAssociation(LogAssociationType.UnAssociated, RefererAssociationType.None, IronHtml.UrlInHtmlMatch.None, LogAssociationMatchLevel.Other, null, Sessions[LogId]));
                }
                else
                {
                    if (!UninterestingAssociationTypes.Contains(Asso.AssociationType))
                    {
                        FinalizedAssociations.Add(Asso);
                    }
                }
            }
            return(FinalizedAssociations);
        }
Ejemplo n.º 9
0
        List <LogAssociation> FindFormSubmitAssociations(Session MainLog, List <Session> SessionList, RefererAssociationType RefAssoType)
        {
            List <LogAssociation> Associations = new List <LogAssociation>();

            if (MainLog.Response == null)
            {
                return(Associations);
            }

            //Match form submission with absolute url match and absolute field/values match
            foreach (IronHtml.FormElement FormEle in MainLog.Response.Html.GetFormElements())
            {
                try
                {
                    Request FormReq = new Request(FormEle.Action);
                    foreach (Session Sess in SessionList)
                    {
                        if (!Sess.Request.IsNormal)
                        {
                            continue;
                        }
                        if (Sess.Request.FullUrl.Equals(FormReq.FullUrl) && Sess.Request.Method.Equals(FormEle.Method, StringComparison.OrdinalIgnoreCase) && Sess.Response != null)
                        {
                            if (FormEle.DoAllInputFieldValuesMatchRequest(Sess.Request))
                            {
                                LogAssociation LogAsso = new LogAssociation(LogAssociationType.FormSubmission, RefAssoType, IronHtml.UrlInHtmlMatch.FullAbsolute, LogAssociationMatchLevel.FormNamesAndValues, MainLog, Sess);
                                Associations.Add(LogAsso);
                            }
                            else if (FormEle.DoHiddenInputFieldValuesMatchRequest(Sess.Request))
                            {
                                LogAssociation LogAsso = new LogAssociation(LogAssociationType.FormSubmission, RefAssoType, IronHtml.UrlInHtmlMatch.FullAbsolute, LogAssociationMatchLevel.FormNamesAndHiddenValuesOnly, MainLog, Sess);
                                Associations.Add(LogAsso);
                            }
                            else if (FormEle.DoInputFieldNamesMatchRequest(Sess.Request))
                            {
                                LogAssociation LogAsso = new LogAssociation(LogAssociationType.FormSubmission, RefAssoType, IronHtml.UrlInHtmlMatch.FullAbsolute, LogAssociationMatchLevel.FormNamesOnly, MainLog, Sess);
                                Associations.Add(LogAsso);
                            }
                        }
                    }
                }
                catch
                {
                    Request FormReq = new Request(MainLog.Request.RelativeUrlToAbsoluteUrl(FormEle.Action));
                    foreach (Session Sess in SessionList)
                    {
                        if (!Sess.Request.IsNormal)
                        {
                            continue;
                        }
                        if (Sess.Request.FullUrl.Equals(FormReq.FullUrl) && Sess.Request.Method.Equals(FormEle.Method, StringComparison.OrdinalIgnoreCase) && Sess.Response != null)
                        {
                            if (FormEle.DoAllInputFieldValuesMatchRequest(Sess.Request))
                            {
                                LogAssociation LogAsso = new LogAssociation(LogAssociationType.FormSubmission, RefAssoType, IronHtml.UrlInHtmlMatch.FullRelative, LogAssociationMatchLevel.FormNamesAndValues, MainLog, Sess);
                                Associations.Add(LogAsso);
                            }
                            else if (FormEle.DoHiddenInputFieldValuesMatchRequest(Sess.Request))
                            {
                                LogAssociation LogAsso = new LogAssociation(LogAssociationType.FormSubmission, RefAssoType, IronHtml.UrlInHtmlMatch.FullRelative, LogAssociationMatchLevel.FormNamesAndHiddenValuesOnly, MainLog, Sess);
                                Associations.Add(LogAsso);
                            }
                            else if (FormEle.DoInputFieldNamesMatchRequest(Sess.Request))
                            {
                                LogAssociation LogAsso = new LogAssociation(LogAssociationType.FormSubmission, RefAssoType, IronHtml.UrlInHtmlMatch.FullRelative, LogAssociationMatchLevel.FormNamesOnly, MainLog, Sess);
                                Associations.Add(LogAsso);
                            }
                        }
                    }
                }
            }
            return(Associations);
        }
Ejemplo n.º 10
0
        List <LogAssociation> FindImgSourceAssociations(Session MainLog, List <Session> SessionList, RefererAssociationType RefAssoType)
        {
            List <LogAssociation> Associations = new List <LogAssociation>();

            if (MainLog.Response == null)
            {
                return(Associations);
            }

            //Match img urls with absolute match and response content type match
            foreach (string ImgSrc in MainLog.Response.Html.GetDecodedValues("img", "src"))
            {
                try
                {
                    Request ImgReq = new Request(ImgSrc.Trim());
                    foreach (Session Sess in SessionList)
                    {
                        if (!Sess.Request.Method.Equals("GET", StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }
                        if (Sess.Request.FullUrl.Equals(ImgReq.FullUrl) && Sess.Response != null)// && Sess.Response.Code == 304 || Sess.Response.IsBinary)
                        {
                            if (Sess.Response.Code == 304 || Sess.Response.IsBinary)
                            {
                                LogAssociation LogAsso = new LogAssociation(LogAssociationType.ExternalImage, RefAssoType, IronHtml.UrlInHtmlMatch.FullAbsolute, LogAssociationMatchLevel.UrlMatchAndResponseType, MainLog, Sess);
                                Associations.Add(LogAsso);
                            }
                            else
                            {
                                LogAssociation LogAsso = new LogAssociation(LogAssociationType.ExternalImage, RefAssoType, IronHtml.UrlInHtmlMatch.FullAbsolute, LogAssociationMatchLevel.UrlMatchOnly, MainLog, Sess);
                                Associations.Add(LogAsso);
                            }
                        }
                    }
                }
                catch
                {
                    Request ImgReq = new Request(MainLog.Request.RelativeUrlToAbsoluteUrl(ImgSrc.Trim()));
                    foreach (Session Sess in SessionList)
                    {
                        if (!Sess.Request.Method.Equals("GET", StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }
                        if (Sess.Request.FullUrl.Equals(ImgReq.FullUrl) && Sess.Response != null)// && Sess.Response.Code == 304 || Sess.Response.IsBinary)
                        {
                            if (Sess.Response.Code == 304 || Sess.Response.IsBinary)
                            {
                                LogAssociation LogAsso = new LogAssociation(LogAssociationType.ExternalImage, RefAssoType, IronHtml.UrlInHtmlMatch.FullRelative, LogAssociationMatchLevel.UrlMatchAndResponseType, MainLog, Sess);
                                Associations.Add(LogAsso);
                            }
                            else
                            {
                                LogAssociation LogAsso = new LogAssociation(LogAssociationType.ExternalImage, RefAssoType, IronHtml.UrlInHtmlMatch.FullRelative, LogAssociationMatchLevel.UrlMatchOnly, MainLog, Sess);
                                Associations.Add(LogAsso);
                            }
                        }
                    }
                }
            }
            return(Associations);
        }
Ejemplo n.º 11
0
 public LogReplayAssociation(LogAssociation OriAsso, LogAssociation RepAsso)
 {
     this.OriginalAssociation = OriAsso;
     this.ReplayAssociation   = RepAsso;
 }
Ejemplo n.º 12
0
        Request GetFormSubmission(LogAssociation CurrentAsso, Session PlaySess)
        {
            Response Res = PlaySess.Response;
            List <IronHtml.FormElement> BestMatches       = new List <IronHtml.FormElement>();
            List <IronHtml.FormElement> SecondBestMatches = new List <IronHtml.FormElement>();

            IronHtml.FormElementCollection NewFormElements = new IronHtml.FormElementCollection(Res.Html.GetFormElements());

            Request ReqToMatchAgainst = CurrentAsso.DestinationLog.Request;

            //List<IronHtml.FormElement> FormElements = CurrentAsso.DestinationLog.Response.Html.GetFormElements();
            foreach (IronHtml.FormElement FormEle in CurrentAsso.SourceLog.Response.Html.GetFormElements())
            {
                if (FormEle.DoAllInputFieldValuesMatchRequest(ReqToMatchAgainst))
                {
                    BestMatches.Add(FormEle);
                }
                else if (FormEle.DoHiddenInputFieldValuesMatchRequest(ReqToMatchAgainst))
                {
                    BestMatches.Add(FormEle);
                }
                else if (FormEle.DoInputFieldNamesMatchRequest(ReqToMatchAgainst))
                {
                    SecondBestMatches.Add(FormEle);
                }
            }

            foreach (List <IronHtml.FormElement> Matches in new List <List <IronHtml.FormElement> >()
            {
                BestMatches, SecondBestMatches
            })
            {
                //check by link id
                foreach (IronHtml.FormElement FormEle in Matches)
                {
                    if (FormEle.HasId)
                    {
                        List <IronHtml.Element> MatchingForms = NewFormElements.GetElementsWithId(FormEle.Id);
                        if (MatchingForms.Count > 0 && ((IronHtml.FormElement)MatchingForms[0]).DoInputFieldNamesMatchRequest(ReqToMatchAgainst))
                        {
                            return(((IronHtml.FormElement)MatchingForms[0]).GetFormSubmissionWithHiddenValuesFromFormAndOtherFromSecondArgument(PlaySess.Request, ReqToMatchAgainst));
                        }
                    }
                }
                //check by link name
                foreach (IronHtml.FormElement FormEle in Matches)
                {
                    if (FormEle.HasName)
                    {
                        List <IronHtml.Element> MatchingForms = NewFormElements.GetElementsWithName(FormEle.Name);
                        if (MatchingForms.Count > 0 && ((IronHtml.FormElement)MatchingForms[0]).DoInputFieldNamesMatchRequest(ReqToMatchAgainst))
                        {
                            return(((IronHtml.FormElement)MatchingForms[0]).GetFormSubmissionWithHiddenValuesFromFormAndOtherFromSecondArgument(PlaySess.Request, ReqToMatchAgainst));
                        }
                    }
                }
            }

            foreach (IronHtml.FormElement NewFormEle in NewFormElements.GetElements())
            {
                if (NewFormEle.DoInputFieldNamesMatchRequest(ReqToMatchAgainst))
                {
                    return(NewFormEle.GetFormSubmissionWithHiddenValuesFromFormAndOtherFromSecondArgument(PlaySess.Request, ReqToMatchAgainst));
                }
            }

            return(null);
        }
Ejemplo n.º 13
0
        Request GetLinkClick(LogAssociation CurrentAsso, Session PlaySess)
        {
            Response Res = PlaySess.Response;
            List <IronHtml.LinkElement> BestMatches       = new List <IronHtml.LinkElement>();
            List <IronHtml.LinkElement> SecondBestMatches = new List <IronHtml.LinkElement>();

            IronHtml.LinkElementCollection NewLinkElements = new IronHtml.LinkElementCollection(Res.Html.GetLinkElements());

            Request ReqToMatchAgainst = CurrentAsso.DestinationLog.Request;

            //List<IronHtml.LinkElement> LinkElements = CurrentAsso.DestinationLog.Response.Html.GetLinkElements();
            foreach (IronHtml.LinkElement LinkEle in CurrentAsso.SourceLog.Response.Html.GetLinkElements())
            {
                if (LinkEle.IsAbsoluteHref)
                {
                    if (LinkEle.Href.Equals(ReqToMatchAgainst.FullUrl))
                    {
                        BestMatches.Add(LinkEle);
                    }
                }
                else if (!LinkEle.IsJavaScriptHref)
                {
                    if (LinkEle.GetLinkClick(CurrentAsso.SourceLog.Request).FullUrl.Equals(ReqToMatchAgainst.FullUrl))
                    {
                        SecondBestMatches.Add(LinkEle);
                    }
                }
            }

            foreach (List <IronHtml.LinkElement> Matches in new List <List <IronHtml.LinkElement> >()
            {
                BestMatches, SecondBestMatches
            })
            {
                //check by link id
                foreach (IronHtml.LinkElement LinkEle in Matches)
                {
                    if (LinkEle.HasId)
                    {
                        List <IronHtml.Element> MatchingClicks = NewLinkElements.GetElementsWithId(LinkEle.Id);
                        if (MatchingClicks.Count > 0)
                        {
                            return(((IronHtml.LinkElement)MatchingClicks[0]).GetLinkClick(PlaySess.Request));
                        }
                    }
                }
                //check by link name
                foreach (IronHtml.LinkElement LinkEle in Matches)
                {
                    if (LinkEle.HasName)
                    {
                        List <IronHtml.Element> MatchingClicks = NewLinkElements.GetElementsWithName(LinkEle.Name);
                        if (MatchingClicks.Count > 0)
                        {
                            return(((IronHtml.LinkElement)MatchingClicks[0]).GetLinkClick(PlaySess.Request));
                        }
                    }
                }
                //check by inner text
                foreach (IronHtml.LinkElement LinkEle in Matches)
                {
                    if (LinkEle.InnerText.Trim().Length > 0)
                    {
                        List <IronHtml.Element> MatchingClicks = NewLinkElements.GetElementsWithInnerText(LinkEle.InnerText);
                        if (MatchingClicks.Count > 0)
                        {
                            return(((IronHtml.LinkElement)MatchingClicks[0]).GetLinkClick(PlaySess.Request));
                        }
                    }
                }
            }

            foreach (List <IronHtml.LinkElement> Matches in new List <List <IronHtml.LinkElement> >()
            {
                BestMatches, SecondBestMatches
            })
            {
                foreach (IronHtml.LinkElement LinkEle in Matches)
                {
                    if (NewLinkElements.Count > LinkEle.Index)
                    {
                        foreach (IronHtml.LinkElement NewLinkEle in NewLinkElements.GetElements())
                        {
                            if (NewLinkEle.Index == LinkEle.Index)
                            {
                                return(NewLinkEle.GetLinkClick(PlaySess.Request));
                            }
                        }
                    }
                }
            }

            //foreach (List<IronHtml.LinkElement> Matches in new List<List<IronHtml.LinkElement>>() { BestMatches, SecondBestMatches })
            //{
            //    //check by class name
            //    foreach (IronHtml.LinkElement LinkEle in Matches)
            //    {
            //        if (LinkEle.HasClass)
            //        {
            //            List<IronHtml.Element> MatchingClicks = NewLinkClicks.GetElementsWithClass(LinkEle.Class);
            //            if (MatchingClicks.Count > 0)
            //            {
            //                return ((IronHtml.LinkElement)MatchingClicks[0]).GetLinkClick(PlaySess.Request);
            //            }
            //        }
            //    }
            //}
            return(null);
        }