예제 #1
0
 private void MatchUrl(string url)
 {
     try {
         LogInfo($"MatchUrl: {url}");
         _log.Info($"MatchUrl: {url}");
         var assemblies = _assemblyProvider.GetAssemblies();
         if (assemblies != null)
         {
             LogInfo($"Compiled successfully.");
             var urlMatcher     = new UrlMatcher(assemblies.Item1, assemblies.Item2);
             var matchUrlResult = urlMatcher.Match(url);
             LogInfo($"Matched successfully: {matchUrlResult.ServiceId}-{matchUrlResult.PageId}");
             _browserConnection.SendUrlMatchResult(matchUrlResult);
             if (!string.IsNullOrWhiteSpace(matchUrlResult.PageId))
             {
                 OpenDocumentWithType(matchUrlResult.PageId);
             }
         }
     }
     catch (Exception e) {
         LogInfo($"Error!!!");
         LogInfo(e.Message);
         LogInfo(e.StackTrace);
         if (e.InnerException != null)
         {
             LogInfo(e.InnerException.Message);
             LogInfo(e.InnerException.StackTrace);
         }
     }
 }
예제 #2
0
        public void GivenSourceNoExternalDependencies_WhenMatchUrl_returnsEmptyList()
        {
            //Arrange
            string siteSource = $"<html><head><script></script></head><body> </body></html>";
            var    matcher    = new UrlMatcher();

            //Act
            IList <string> result = matcher.MatchUrls(siteSource);

            //Assert
            Assert.AreEqual(0, result.Count);
        }
        public IDocumentHandler dispatch(IDocumentHandler previous)
        {
            if (DateTime.Now >= DateTime.Parse("2013-10-15"))
            {
                return(new DummyHandler(previous));
            }

            ConfigResolver resolver = ConfigResolver.GetInstance();
            UrlMatcher     matcher  = new UrlMatcher(this.url);

            if (matcher.matches(resolver.GetPopupPatterns()))
            {
                if (null != previous)
                {
                    previous.destroy();
                }

                if (matcher.matches(resolver.GetTmsPatterns()))
                {
                    LogUtil.log("Match tms patterns");
                    return(new PopupHandler(new TMSFiller(this.document)));
                }
                else if (matcher.matches(resolver.GetPmsPatterns()))
                {
                    LogUtil.log("Match pms patterns");
                    return(new PopupHandler(new PMSFiller(this.document)));
                }
                else if (matcher.matches(resolver.GetDmsPatterns()))
                {
                    LogUtil.log("Match dms patterns");
                    return(new PopupHandler(new DMSFiller(this.document)));
                }
                else
                {
                    return(new PopupHandler(new DummyFiller(this.document)));
                }
            }
            else if (matcher.matches(resolver.GetRewritePatterns()))
            {
                if (null != previous)
                {
                    previous.destroy();
                }

                return(new RewriteHandler(this.document));
            }
            else if (matcher.matches(resolver.GetWrapPatterns()))
            {
                return(new WrapHandler());
            }

            return(new DummyHandler(previous));
        }
예제 #4
0
        public void GivenSourceAllowedCharacterLink_WhenMatchUrl_returnsUrl()
        {
            //Arrange
            string jqueryCDNUrl = "https://guess-whoo.netlify24.app/ajax/libs/jquery/3.5.1/jquery.min.js";
            string siteSource   = $"<html><head><script src=\"{jqueryCDNUrl}\"></script></head><body></body></html>";
            var    matcher      = new UrlMatcher();

            //Act
            IList <string> result = matcher.MatchUrls(siteSource);

            //Assert
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(jqueryCDNUrl, result[0]);
        }
예제 #5
0
        public void GivenSourceHttpsWWWLink_WhenMatchUrl_returnsUrl()
        {
            //Arrange
            string jqueryCDNUrl = "https://www.ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js";
            string siteSource   = $"<html><head><script src=\"{jqueryCDNUrl}\"></script></head><body></body></html>";
            var    matcher      = new UrlMatcher();

            //Act
            IList <string> result = matcher.MatchUrls(siteSource);

            //Assert
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(jqueryCDNUrl, result[0]);
        }
예제 #6
0
        public void GivenSourceExternalDependenciesAsText_WhenMatchUrl_returnsUrl()
        {
            //Arrange
            string picURL = "https://cdn.pg.edu.pl/ekontakt-updated-theme/images/favicon/apple-touch-icon.png?v=jw6lLb8YQ4";

            string siteSource = $"<html><head><script></script></head><body> Sources avaliable at {picURL} </body></html>";
            var    matcher    = new UrlMatcher();

            //Act
            IList <string> result = matcher.MatchUrls(siteSource);

            //Assert
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(picURL, result[0]);
        }
예제 #7
0
        public void TestUrlMatching(bool expectation, string requestUrl, string nockedRequestUrl, string nockedRequestPath)
        {
            var webRequest = new NockHttpWebRequest()
            {
                RequestUri = requestUrl
            };
            var nockedRequest = new NockedRequest(nockedRequestUrl)
            {
                Path = nockedRequestPath
            };

            var result = UrlMatcher.IsMatch(webRequest, nockedRequest);

            Assert.That(result, Is.EqualTo(expectation));
        }
예제 #8
0
        public void GivenSourceManySites_WhenMatchUrl_returnsUrls()
        {
            //Arrange
            string jqueryCDNUrl = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js";
            string picURL       = "https://cdn.pg.edu.pl/ekontakt-updated-theme/images/favicon/apple-touch-icon.png?v=jw6lLb8YQ4";

            string siteSource = $"<html><head><script src=\"{jqueryCDNUrl}\"></script></head><body> <a class=\"logInButton\" href=\"{picURL}\" title=\"Login\">Login</a></body></html>";
            var    matcher    = new UrlMatcher();

            //Act
            IList <string> result = matcher.MatchUrls(siteSource);

            //Assert
            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(jqueryCDNUrl, result[0]);
            Assert.AreEqual(picURL, result[1]);
        }
예제 #9
0
        private static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (!(d is TextBlock textBlock))
            {
                return;
            }

            textBlock.Inlines.Clear();

            var newValue = (string)e.NewValue;

            if (string.IsNullOrEmpty(newValue))
            {
                return;
            }

            var previousPosition = 0;

            foreach (var match in UrlMatcher.MatchText(newValue))
            {
                if (match.Index != previousPosition)
                {
                    textBlock.Inlines.Add(new Run(newValue.Substring(previousPosition, match.Index - previousPosition)));
                }

                var link = new Hyperlink(new Run(match.Value))
                {
                    NavigateUri     = Uri.TryCreate(match.Value, UriKind.Absolute, out Uri uri) ? uri : null,
                    TextDecorations = null
                };

                link.Click += OnLinkClick;

                textBlock.Inlines.Add(link);

                previousPosition = match.Index + match.Length;
            }

            if (previousPosition < newValue.Length)
            {
                textBlock.Inlines.Add(new Run(newValue.Substring(previousPosition)));
            }
        }