public static T LoadDocument <T>(this IDocumentBrowser self, string url) where T : IDocument { var docType = GetDocumentType(typeof(T)); self.Navigate(docType, new Uri(url)); return(( T )self.Document); }
public static void Navigate(this IDocumentBrowser self, DocumentType docType, Uri url) { self.Navigate(docType, new DocumentLocator(new Request(url))); }
public static void Navigate(this IDocumentBrowser self, DocumentType docType, DocumentLocator locator) { self.Navigate(docType, locator, new NullLocatorMacroResolver()); }
private void TryFetch() { if (myDocumentBrowser == null) { return; } myData.Clear(); var descriptors = mySelectedSource.Figures .Cast <IPathDescriptor>() .Where(f => f.Figure == myFigureType.Name); foreach (var descriptor in descriptors) { try { ILocatorMacroResolver resolver = new StockMacroResolver(Stock); if (CustomResolverCreator != null) { resolver = CustomResolverCreator(resolver); } myDocumentBrowser.Navigate(DocumentType.Html, mySelectedSource.Location, resolver); var htmlDocument = ( IHtmlDocument )myDocumentBrowser.Document; // Mark the part of the document described by the FigureDescriptor to have a preview var cell = ( HtmlElementAdapter )MarkupFactory.FindElementByDescriptor(htmlDocument, descriptor); if (cell != null) { cell.Element.ScrollIntoView(false); } var marker = MarkupFactory.CreateMarker(descriptor); marker.Mark(cell); // already extract data here to check for format issues etc var parser = DocumentProcessingFactory.CreateParser(htmlDocument, descriptor); var table = parser.ExtractTable(); var converter = DocumentProcessingFactory.CreateConverter(descriptor, mySelectedSource, CurrenciesLut.Currencies); var series = converter.Convert(table, Stock); myData.AddRange(series); // we found s.th. with this format // -> skip alternative formats break; } catch (Exception ex) { ex.Data["Figure"] = myFigureType.Name; ex.Data["DataSource.Vendor"] = mySelectedSource.Vendor; ex.Data["DataSource.Name"] = mySelectedSource.Name; ex.Data["Location"] = mySelectedSource.Location.ToString(); ex.Data["FigureDescriptor"] = descriptor.GetType().FullName; if (ThrowOnError) { throw new Exception("Failed to extract data from datasource", ex); } else { myLogger.Error(ex, "Failed to fetch '{0}' from site {1}", myFigureType.Name, mySelectedSource.Name); } } } }