/// <summary> /// Creates a new <see cref="DataConnection"/> instance inheriting the <see cref="Composite.Data.PublicationScope"/> /// and locale set on the call stack. When outside an existing scope this default to PublicationScope,Published and the /// default language on the website. You should use this constructure unless you need to force data to come from an alternative /// scope. <see cref="DataConnection"/> can be used to access the C1 CMS storage. /// </summary> /// <example> /// Here is an example of how to use it /// <code> /// using (DataConnection connection = new DataConnection()) /// { /// var q = /// from d in connection.Get<IMyDataType>() /// where d.Name == "Foo" /// select d; /// } /// </code> /// </example> public DataConnection() : base(() => ImplementationFactory.CurrentFactory.CreateDataConnection(null, null)) { CreateImplementation(); //_pageDataConnection = new ImplementationContainer<PageDataConnection>(() => new PageDataConnection()); _sitemapNavigator = new ImplementationContainer <SitemapNavigator>(() => new SitemapNavigator(this)); }
/// <summary> /// Creates a new <see cref="DataConnection"/> instance with the given <paramref name="scope"/> /// and the given <paramref name="locale"/>. <see cref="DataConnection"/> can be used to access the C1 CMS storage. /// </summary> /// <param name="scope">The <see cref="Composite.Data.PublicationScope"/> data should be read from.</param> /// <param name="locale">The desired locale. This should be one of the locale found in <see cref="Composite.Data.DataConnection.AllLocales"/></param> /// <example> /// Here is an example of how to use it /// <code> /// using (DataConnection connection = new DataConnection(PublicationScope.Published, new CultureInfo("da-DK"))) /// { /// var q = /// from d in connection.Get<IMyDataType>() /// where d.Name == "Foo" /// select d; /// } /// </code> /// </example> public DataConnection(PublicationScope scope, CultureInfo locale) : base(() => ImplementationFactory.CurrentFactory.CreateDataConnection(scope, locale)) { if ((scope < PublicationScope.Unpublished) || (scope > PublicationScope.Published)) { throw new ArgumentOutOfRangeException("scope"); } CreateImplementation(); //_pageDataConnection = new ImplementationContainer<PageDataConnection>(() => new PageDataConnection(scope, locale)); _sitemapNavigator = new ImplementationContainer <SitemapNavigator>(() => new SitemapNavigator(this)); }
/* ========== Private Members ======== */ /* ======= Class Constructors ======== */ // ? public DataScraper() {} // ? public DataCrawler(CrawlConfigurationX configX) {} #region Public Class Methods /* ================================= Class Methods {Public} ============================ */ /// <summary> /// Static method for crawling. Pass in a configuration /// (i.e. specify how many sites to crawl, whether or not to /// render js, etc) then creates and executes crawler /// </summary> public static async Task Crawl(CrawlConfigurationX configX, HttpClientHandler httpHandler, PageHandlerType pageHandlerType, string uriToCrawl = "http://google.com") { // 'using' sets up scope for crawlerX object to be used // disposes of object at end of scope. (i.e. close-curly-brace) // I saw this used in the github example. Maybe its good practice?? ImplementationContainer impContainer = new ImplementationContainer(); impContainer.PageRequester = new ProxyPageRequester(httpHandler, configX, new WebContentExtractor(), null); ImplementationOverride impOverride = new ImplementationOverride(configX, impContainer); using (var crawlerX = new CrawlerX(configX, impOverride)) { crawlerX.ShouldRenderPageJavascript((CrawledPage, CrawlContext) => { if (CrawledPage.Uri.AbsoluteUri.Contains("ghost")) { return new CrawlDecision { Allow = false, Reason = "scared to render ghost javascript." } } ; return(new CrawlDecision { Allow = true }); }); switch (pageHandlerType) { case PageHandlerType.wordFrequency: //add handler to be called when the crawl for that page is complete crawlerX.PageCrawlCompleted += WordFrequencyHandler; break; case PageHandlerType.sentimentAnalysis: crawlerX.PageCrawlCompleted += SentimentAnalysisHandler; break; } await crawlerX.CrawlAsync(new Uri(uriToCrawl)); } }
/// <summary> /// Creates a C1StreamReader. /// </summary> /// <param name="path">Path to the file.</param> /// <param name="encoding">Encoding to use.</param> /// <param name="detectEncodingFromByteOrderMarks">If true, the encoding will be deteced by the content of the file.</param> /// <param name="bufferSize">Buffer size to use.</param> public C1StreamReader(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize) { _implementation = new ImplementationContainer <C1StreamReaderImplementation>(() => ImplementationFactory.CurrentFactory.CreateC1StreamReader(path, encoding, detectEncodingFromByteOrderMarks, bufferSize)); }
/// <summary> /// Creates a new C1FileStream. /// </summary> /// <param name="path">Path to file.</param> /// <param name="mode">File mode to use.</param> /// <param name="access">File access to use.</param> /// <param name="share">File share to use.</param> /// <param name="bufferSize">Buffer size to use.</param> /// <param name="options">File options to use.</param> public C1FileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options) { _implementation = new ImplementationContainer <C1FileStreamImplementation>(() => ImplementationFactory.CurrentFactory.CreateC1FileStream(path, mode, access, share, bufferSize, options)); _implementation.CreateImplementation(); }
/// <summary> /// Creates a C1StreamWriter. /// </summary> /// <param name="stream">Stream to use.</param> /// <param name="encoding">Encoding to use.</param> /// <param name="bufferSize">Buffer size to use.</param> public C1StreamWriter(Stream stream, Encoding encoding, int bufferSize) { _implementation = new ImplementationContainer <C1StreamWriterImplementation>(() => ImplementationFactory.CurrentFactory.CreateC1StreamWriter(stream, encoding, bufferSize)); }
/// <summary> /// Creates a C1StreamWriter. /// </summary> /// <param name="path">Path to file.</param> /// <param name="append">If this is true, any writing will be appended to the file.</param> /// <param name="encoding">Encoding to use.</param> /// <param name="bufferSize">Buffer size to use.</param> public C1StreamWriter(string path, bool append, Encoding encoding, int bufferSize) { _implementation = new ImplementationContainer <C1StreamWriterImplementation>(() => ImplementationFactory.CurrentFactory.CreateC1StreamWriter(path, append, encoding, bufferSize)); }
private ScopeContext GetImplementationsOfBaseType(string implementationReference, ImplementationContainer baseTypes) { if (implementationReference == TypeLocatorNames.DefaultName) { return(baseTypes.Default); } ScopeContext context; return(baseTypes.Typesets.TryGetValue(implementationReference, out context) ? context : null); }
/// <summary> /// Creates a new C1FileStream. /// </summary> /// <param name="path">Path to file.</param> /// <param name="mode">File mode to use.</param> /// <param name="access">File access to use.</param> /// <param name="share">File share to use.</param> /// <param name="bufferSize">Buffer size to use.</param> /// <param name="options">File options to use.</param> public C1FileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options) { _implementation = new ImplementationContainer<C1FileStreamImplementation>(() => ImplementationFactory.CurrentFactory.CreateC1FileStream(path, mode, access, share, bufferSize, options)); _implementation.CreateImplementation(); }
/// <summary> /// Creates and initialize a new C1DirectoryInfo. /// </summary> /// <param name="path">Path to use.</param> public C1DirectoryInfo(string path) { _implementation = new ImplementationContainer<C1DirectoryInfoImplementation>(() => ImplementationFactory.CurrentFactory.CreateC1DirectoryInfo(path)); _implementation.CreateImplementation(); }
/// <summary> /// Creates a C1StreamWriter. /// </summary> /// <param name="stream">Stream to use.</param> /// <param name="encoding">Encoding to use.</param> /// <param name="bufferSize">Buffer size to use.</param> public C1StreamWriter(Stream stream, Encoding encoding, int bufferSize) { _implementation = new ImplementationContainer<C1StreamWriterImplementation>(() => ImplementationFactory.CurrentFactory.CreateC1StreamWriter(stream, encoding, bufferSize)); }
/// <summary> /// Creates a C1StreamWriter. /// </summary> /// <param name="path">Path to file.</param> /// <param name="append">If this is true, any writing will be appended to the file.</param> /// <param name="encoding">Encoding to use.</param> /// <param name="bufferSize">Buffer size to use.</param> public C1StreamWriter(string path, bool append, Encoding encoding, int bufferSize) { _implementation = new ImplementationContainer<C1StreamWriterImplementation>(() => ImplementationFactory.CurrentFactory.CreateC1StreamWriter(path, append, encoding, bufferSize)); }
/// <summary> /// Creates a C1StreamReader. /// </summary> /// <param name="path">Path to the file.</param> /// <param name="encoding">Encoding to use.</param> /// <param name="detectEncodingFromByteOrderMarks">If true, the encoding will be deteced by the content of the file.</param> /// <param name="bufferSize">Buffer size to use.</param> public C1StreamReader(string path, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize) { _implementation = new ImplementationContainer<C1StreamReaderImplementation>(() => ImplementationFactory.CurrentFactory.CreateC1StreamReader(path, encoding, detectEncodingFromByteOrderMarks, bufferSize)); }
/// <summary> /// Creates and initialize a new C1DirectoryInfo. /// </summary> /// <param name="path">Path to use.</param> public C1DirectoryInfo(string path) { _implementation = new ImplementationContainer <C1DirectoryInfoImplementation>(() => ImplementationFactory.CurrentFactory.CreateC1DirectoryInfo(path)); _implementation.CreateImplementation(); }
/// <summary> /// Creates a C1FileInfo. /// </summary> /// <param name="fileName">Path to file.</param> public C1FileInfo(string fileName) { _implementation = new ImplementationContainer<C1FileInfoImplementation>(() => ImplementationFactory.CurrentFactory.CreateC1FileInfo(fileName)); _implementation.CreateImplementation(); }
/// <summary> /// Creates a C1FileInfo. /// </summary> /// <param name="fileName">Path to file.</param> public C1FileInfo(string fileName) { _implementation = new ImplementationContainer <C1FileInfoImplementation>(() => ImplementationFactory.CurrentFactory.CreateC1FileInfo(fileName)); _implementation.CreateImplementation(); }