// TODO: STUB private async Task <bool> CheckUri(Uri uri) { var parser = new UrlExtractor(uri); var text = await parser.ExtractPlainTextAsync(); return(!string.IsNullOrEmpty(text)); }
public void Connect(string user, string host) { User = user; if (!host.Contains("://")) { host = string.Format("http://{0}", host); } Host = host; // Validate host Uri uri; UrlExtractor.TryCreate(Host, out uri, validHostUriSchemes); if (uri == null) { ConnectionFailed(this, DateTime.Now, string.Format("Invalid format for host: {0}", Host)); return; } Host = uri.ToString(); try { Binding binding; if (uri.Scheme.Equals(Uri.UriSchemeNetPipe)) { var namedPipeBinding = new NetNamedPipeBinding(); namedPipeBinding.Security.Mode = NetNamedPipeSecurityMode.None; binding = namedPipeBinding; } else if (uri.Scheme.Equals(Uri.UriSchemeNetTcp)) { var tcpBinding = new NetTcpBinding(); tcpBinding.Security.Mode = SecurityMode.None; binding = tcpBinding; } else { var httpBinding = new WSDualHttpBinding(); httpBinding.Security.Mode = WSDualHttpSecurityMode.None; binding = httpBinding; } // Append service name // Note: URI creation appends any missing "/" to the host, so it's safe to just append if (!Host.EndsWith(serviceName) && !Host.EndsWith(string.Format("{0}/", serviceName))) { Host = string.Format("{0}{1}", Host, serviceName); } // Create the endpoint address EndpointAddress endpointAddress = new EndpointAddress(Host); client = new ChatServiceClient(new InstanceContext(this), binding, endpointAddress); client.Open(); client.Connect(user); } catch (Exception exception) { TriggerConnectionFailed(exception); } }
public void GetTextFromHtml() { var uri = new Uri("https://docs.microsoft.com/en-us/dotnet/api/system.net.webclient.downloadstring?view=net-5.0"); var parser = new UrlExtractor(uri); var content = parser.ExtractPlainText(); Assert.IsFalse(string.IsNullOrEmpty(content)); }
public void GetTextFromPdfUri() { var uri = new Uri("http://www.africau.edu/images/default/sample.pdf"); var parser = new UrlExtractor(uri); var content = parser.ExtractPlainText(); Assert.IsFalse(string.IsNullOrEmpty(content)); }
public void GetTextFromWordUri() { var uri = new Uri("http://iiswc.org/iiswc2012/sample.doc"); var parser = new UrlExtractor(uri); var content = parser.ExtractPlainText(); Assert.IsFalse(string.IsNullOrEmpty(content)); }
public List <string> ExtractUrls(string websiteUrl, bool isRecursive) { UrlExtractor urlExtractor = new UrlExtractor(); var list = urlExtractor.GetUrls(websiteUrl, isRecursive); return(list.ToList()); //UrlExtractHelper urlExtractHelper = new UrlExtractHelper(); //return urlExtractHelper.RetrieveUrls(websiteUrl); }
public List <EntityInfo> ExtractUrls(string text) { var result = new List <EntityInfo>(); if (!string.IsNullOrEmpty(text)) { UrlExtractor.Extract(text, this.ExtractsUrlWithoutProtocol, this._tldDictionary, this._longestTldLength, this._shortestTldLength, result); } return(result); }
public async Task <IActionResult> GetActivo() { HttpClient client = new HttpClient(); var response = await client.GetAsync($"{UrlExtractor.ExtractBaseUrl(Request.GetDisplayUrl())}/api/reportecaso"); if (response.StatusCode == HttpStatusCode.OK) { return(Ok("API REST Activa.")); } return(Ok($"Hay un problema con el servicio. ${response.StatusCode}")); }
public void ShouldExtractOnlyHrefLinks() { string inputHtml = @"<html><body><a href='first' /><img src=''><a href=""second""</body></html>"; var urlExtractor = new UrlExtractor(); var urls = urlExtractor.ExtractUrlsFromPage(inputHtml); urls.Count.ShouldBe(2); urls[0].ShouldBe("first"); urls[1].ShouldBe("second"); }
public bool Send(ClientMessage message) { bool outOfSync = OutOfSync; SetVersion(); // See if this is a valid command (starts with /) if (TryHandleCommand(message.Content, message.Room)) { return(outOfSync); } var userId = Context.User.Identity.Name; ChatUser user = _repository.VerifyUserId(userId); ChatRoom room = _repository.VerifyUserRoom(_cache, user, message.Room); // REVIEW: Is it better to use _repository.VerifyRoom(message.Room, mustBeOpen: false) // here? if (room.Closed) { throw new InvalidOperationException(String.Format("You cannot post messages to '{0}'. The room is closed.", message.Room)); } // Update activity *after* ensuring the user, this forces them to be active UpdateActivity(user, room); ChatMessage chatMessage = _service.AddMessage(user, room, message.Id, message.Content); var messageViewModel = new MessageViewModel(chatMessage); Clients.Group(room.Name).addMessage(messageViewModel, room.Name); _repository.CommitChanges(); string clientMessageId = chatMessage.Id; // Update the id on the message chatMessage.Id = Guid.NewGuid().ToString("d"); _repository.CommitChanges(); var urls = UrlExtractor.ExtractUrls(chatMessage.Content); if (urls.Count > 0) { ProcessUrls(urls, room.Name, clientMessageId, message.Id); } return(outOfSync); }
public List <EntityInfo> ExtractEntities(string text) { var result = new List <EntityInfo>(); if (!string.IsNullOrEmpty(text)) { UrlExtractor.Extract(text, this.ExtractsUrlWithoutProtocol, this._tldDictionary, this._longestTldLength, this._shortestTldLength, result); HashtagExtractor.Extract(text, result); MentionExtractor.Extract(text, true, result); CashtagExtractor.Extract(text, result); RemoveOverlappingEntities(result); } return(result); }
public List <EntityInfo> ExtractHashtags(string text, bool checkUrlOverlap) { var result = new List <EntityInfo>(); if (!string.IsNullOrEmpty(text)) { HashtagExtractor.Extract(text, result); if (checkUrlOverlap && result.Count > 0) { UrlExtractor.Extract(text, this.ExtractsUrlWithoutProtocol, this._tldDictionary, this._longestTldLength, this._shortestTldLength, result); RemoveOverlappingEntities(result); result.RemoveAll(x => x.Type != EntityType.Hashtag); } } return(result); }
public static void Main(string[] args) { Console.WriteLine("Launch at " + DateTime.Now.ToString()); Console.WriteLine("Version " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()); // 実施判定 if (!hasToCheckUpdate()) { return; } // URL管理 UrlManager manager = new UrlManager(); // URL展開 UrlExtractor extractor = new UrlExtractor(); List <string> urls = extractor.ExtractUrls(); // ご新規さんを抽出 List <string> newUrls = manager.selectNonExists(urls); Console.WriteLine(" total: " + urls.Count + ", new: " + newUrls.Count); // ダウンロード PageDownloader downloader = new PageDownloader(); foreach (string url in newUrls) { System.Threading.Thread.Sleep(1000); Console.WriteLine(" new address: " + url); string fileName = downloader.Download(url); if (fileName != null) { manager.addUrl(url); } else { Console.WriteLine(" ...fail!!"); } } Console.WriteLine("Finish at " + DateTime.Now.ToString()); }
private void LoadSectionImages(string section) { string url = "http://browse.deviantart.com/" + section; WebProxy proxy = Proxy.GetConfig(); string[] images = UrlExtractor.GetImages(url, proxy); Gtk.Application.Invoke(delegate { ImageViewer imageViewer = new ImageViewer(); notebookViewer.AppendCustom(imageViewer, section, new Gtk.Image("DeviantART", IconSize.Menu)); foreach (string imgUrl in images) { byte[] imgData = UrlUtils.FetchPage(imgUrl, proxy); Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(imgData); imageViewer.Add(imgUrl, imgUrl, pixbuf); } }); }
public void PostNotification(ClientNotification notification, bool executeContentProviders) { string userId = Context.User.GetUserId(); ChatUser user = _repository.GetUserById(userId); ChatRoom room = _repository.VerifyUserRoom(_cache, user, notification.Room); // User must be an owner if (room == null || !room.Owners.Contains(user) || (room.Private && !user.AllowedRooms.Contains(room))) { throw new InvalidOperationException("You're not allowed to post a notification"); } var chatMessage = new ChatMessage { Id = Guid.NewGuid().ToString("d"), Content = notification.Content, User = user, Room = room, HtmlEncoded = false, ImageUrl = notification.ImageUrl, Source = notification.Source, When = DateTimeOffset.UtcNow, MessageType = (int)MessageType.Notification }; _repository.Add(chatMessage); _repository.CommitChanges(); Clients.Group(room.Name).addMessage(new MessageViewModel(chatMessage), room.Name); if (executeContentProviders) { var urls = UrlExtractor.ExtractUrls(chatMessage.Content); if (urls.Count > 0) { _resourceProcessor.ProcessUrls(urls, Clients, room.Name, chatMessage.Id); } } }
private void AppendText(DateTime dateTime, string sender, string senderInfo, string text, Color color) { // Create a textrange at the very end of the chat text box, extend the range with the new text var timestampTextRange = new TextRange(chatTextBox.Document.ContentEnd, chatTextBox.Document.ContentEnd) { Text = string.Format("[{0}] ", dateTime) }; // Colorize the timestamp timestampTextRange.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(color)); timestampTextRange.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Normal); var senderTextRange = new TextRange(chatTextBox.Document.ContentEnd, chatTextBox.Document.ContentEnd) { Text = string.Format("{0}", sender) }; // Colorize the sender and make it bold senderTextRange.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(color)); senderTextRange.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold); var senderInfoTextRange = new TextRange(chatTextBox.Document.ContentEnd, chatTextBox.Document.ContentEnd) { Text = string.IsNullOrWhiteSpace(senderInfo) ? ": " : string.Format(" {0}: ", senderInfo) }; // Colorize the sender info senderInfoTextRange.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(color)); senderInfoTextRange.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Normal); // Try to extract URLs and make them clickable foreach (var partialText in UrlExtractor.Extract(text)) { if (partialText.Value != null) { var linkTextRange = new TextRange(chatTextBox.Document.ContentEnd, chatTextBox.Document.ContentEnd) { Text = partialText.Key }; var link = new Hyperlink(linkTextRange.Start, linkTextRange.End); link.NavigateUri = partialText.Value; link.RequestNavigate += LinkRequestNavigate; } else { var regularTextRange = new TextRange(chatTextBox.Document.ContentEnd, chatTextBox.Document.ContentEnd) { Text = partialText.Key }; // Colorize the text regularTextRange.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(color)); regularTextRange.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Normal); } } // Add a new line and reset styles var resetTextRange = new TextRange(chatTextBox.Document.ContentEnd, chatTextBox.Document.ContentEnd) { Text = Environment.NewLine }; resetTextRange.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Normal); // Scroll to end of chat text if ScrollLock isn't on var scrollLock = (((ushort)GetKeyState(0x91)) & 0xffff) != 0; if (!scrollLock) { chatTextBox.ScrollToEnd(); } }
public void ExtractBaseUrlOk(string baseUrlExpected, string url) { Assert.Equal(baseUrlExpected, UrlExtractor.ExtractBaseUrl(url)); }
public bool Send(ClientMessage clientMessage) { CheckStatus(); // See if this is a valid command (starts with /) if (TryHandleCommand(clientMessage.Content, clientMessage.Room)) { return(true); } var userId = Context.User.Identity.Name; ChatUser user = _repository.VerifyUserId(userId); ChatRoom room = _repository.VerifyUserRoom(_cache, user, clientMessage.Room); if (room == null || (room.Private && !user.AllowedRooms.Contains(room))) { return(false); } // REVIEW: Is it better to use _repository.VerifyRoom(message.Room, mustBeOpen: false) // here? if (room.Closed) { throw new InvalidOperationException(String.Format("You cannot post messages to '{0}'. The room is closed.", clientMessage.Room)); } // Update activity *after* ensuring the user, this forces them to be active UpdateActivity(user, room); // Create a true unique id and save the message to the db string id = Guid.NewGuid().ToString("d"); ChatMessage chatMessage = _service.AddMessage(user, room, id, clientMessage.Content); _repository.CommitChanges(); var messageViewModel = new MessageViewModel(chatMessage); if (clientMessage.Id == null) { // If the client didn't generate an id for the message then just // send it to everyone. The assumption is that the client has some ui // that it wanted to update immediately showing the message and // then when the actual message is roundtripped it would "solidify it". Clients.Group(room.Name).addMessage(messageViewModel, room.Name); } else { // If the client did set an id then we need to give everyone the real id first Clients.OthersInGroup(room.Name).addMessage(messageViewModel, room.Name); // Now tell the caller to replace the message Clients.Caller.replaceMessage(clientMessage.Id, messageViewModel, room.Name); } // Add mentions AddMentions(chatMessage); var urls = UrlExtractor.ExtractUrls(chatMessage.Content); if (urls.Count > 0) { _resourceProcessor.ProcessUrls(urls, Clients, room.Name, chatMessage.Id); } return(true); }
public bool Send(ClientMessage clientMessage) { CheckStatus(); // reject it if it's too long if (_settings.MaxMessageLength > 0 && clientMessage.Content.Length > _settings.MaxMessageLength) { throw new HubException(String.Format(LanguageResources.SendMessageTooLong, _settings.MaxMessageLength)); } // See if this is a valid command (starts with /) //if (TryHandleCommand(clientMessage.Content, clientMessage.Room)) //{ // return true; //} var userId = Context.User.GetUserId(); ChatUser user = _repository.VerifyUserId(userId); ChatRoom room = _chatRoomRepository.VerifyUserRoom(_repository, _cache, user, clientMessage.Room); if (room == null || (room.Private && !user.AllowedRooms.Contains(room))) { return(false); } // REVIEW: Is it better to use the extension method room.EnsureOpen here? if (room.Closed) { throw new HubException(String.Format(LanguageResources.SendMessageRoomClosed, clientMessage.Room)); } // Update activity *after* ensuring the user, this forces them to be active UpdateActivity(user, room); // Create a true unique id and save the message to the db string id = Guid.NewGuid().ToString("d"); ChatMessage chatMessage = _service.AddMessage(user, room, id, clientMessage.Content); var messageViewModel = new MessageViewModel(chatMessage); if (clientMessage.Id == null) { // If the client didn't generate an id for the message then just // send it to everyone. The assumption is that the client has some ui // that it wanted to update immediately showing the message and // then when the actual message is roundtripped it would "solidify it". Clients.Group(room.Name).addMessage(messageViewModel, room.Name); } else { // If the client did set an id then we need to give everyone the real id first Clients.OthersInGroup(room.Name).addMessage(messageViewModel, room.Name); // Now tell the caller to replace the message Clients.Caller.replaceMessage(clientMessage.Id, messageViewModel, room.Name); } // Add mentions AddMentions(chatMessage); var urls = UrlExtractor.ExtractUrls(chatMessage.Content); if (urls.Count > 0) { // _resourceProcessor.ProcessUrls(urls, Clients, room.Name, chatMessage.Id); } return(true); }