public TextCacheFile(IIndexDocument doc, IndexTextCacheDataSource parent) { // create when enumerating Name = doc.Name; this.parent = parent; this.doc = doc.GetEnumerator(); }
/* Create IIndexDocument instance parsing url using parent as parent of created instance, * returns one of the known documents: html,txt,pdf, ... depending on server url responce content-Type*/ public static IIndexDocument FromUrl(string url, IIndexDataSource parent) { HttpWebRequest req = HttpWebRequest.CreateHttp(url); req.UserAgent = "DOCODO"; req.Accept = "text/html, text/plain, application/pdf"; req.Method = "GET"; IIndexDocument ret = null; WebResponse res; try { res = req.GetResponse(); } catch (WebException e) { return(null); } if (res.ContentType.ToLower().Equals("application/pdf")) { ret = new DocumentsDataSource.IndexPDFDocument(url, res.GetResponseStream(), parent); } else if (res.ContentType.ToLower().Equals("text/plain")) { using (StreamReader reader = new StreamReader(res.GetResponseStream())) { ret = new IndexPagedTextFile(url.Substring(parent.Path.Length), reader.ReadToEnd(), "Source=" + parent.Name); } } else { ret = FromHtml(res.GetResponseStream(), url.Substring(parent.Path.Length), parent.Name); } return(ret); }
/// <summary> /// Removes an existing document from the index /// </summary> public static void DeleteDocument(this IIndexStore store, IIndexDocument document) { store.DeleteDocuments(new[] { document }); }