public void WriteXML(MashupWriteContext wc, string pathBase) { wc.writer.WriteStartElement(FutureDocumentFromUri.GetXMLTag()); wc.writer.WriteAttributeString(FutureDocumentFromUri.FetchedDocumentUriAttr, this.documentUri.ToString()); wc.writer.WriteAttributeString(FutureDocumentFromUri.FetchedDocumentPageNumberAttr, this.pageNumber.ToString(CultureInfo.InvariantCulture)); wc.writer.WriteEndElement(); }
public GeneralDocumentFuture(MashupParseContext context, string pathBase) { XMLTagReader xMLTagReader = context.NewTagReader(GeneralDocumentFuture.GetXMLTag()); while (xMLTagReader.FindNextStartTag()) { if (xMLTagReader.TagIs(FutureDocumentFromFilesystem.GetXMLTag())) { if (this._documentFuture != null) { throw new InvalidMashupFile(context, "Too many specs in " + GeneralDocumentFuture.GetXMLTag()); } this._documentFuture = new FutureDocumentFromFilesystem(context, pathBase); } else { if (xMLTagReader.TagIs(FutureDocumentFromUri.GetXMLTag())) { if (this._documentFuture != null) { throw new InvalidMashupFile(context, "Too many specs in " + GeneralDocumentFuture.GetXMLTag()); } this._documentFuture = new FutureDocumentFromUri(context); } } } if (this._documentFuture == null) { throw new InvalidMashupFile(context, "No spec in " + GeneralDocumentFuture.GetXMLTag()); } }
public FutureDocumentFromUri(MashupParseContext context) { XMLTagReader xMLTagReader = context.NewTagReader(FutureDocumentFromUri.GetXMLTag()); this.documentUri = new Uri(context.GetRequiredAttribute(FutureDocumentFromUri.FetchedDocumentUriAttr)); this.pageNumber = context.GetRequiredAttributeInt(FutureDocumentFromUri.FetchedDocumentPageNumberAttr); xMLTagReader.SkipAllSubTags(); }
public override Present Realize(string refCredit) { HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(this.documentUri); httpWebRequest.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.Revalidate); D.Sayf(0, "Fetching {0}", new object[] { this.documentUri }); HttpWebResponse httpWebResponse; try { httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); } catch (WebException ex) { throw new Exception(string.Format("timeout waiting for url ({0})", ex.ToString())); } if (httpWebResponse.StatusCode != HttpStatusCode.OK) { throw new Exception(string.Format("HTTP {0} from web source", httpWebResponse.StatusCode.ToString())); } Stream responseStream = httpWebResponse.GetResponseStream(); HashAlgorithm hashAlgorithm = new SHA1CryptoServiceProvider(); string text = FileUtilities.MakeTempFilename(FutureDocumentFromUri.MakeDownloadCacheDir(), "Download"); Stream outputStream = new FileStream(text, FileMode.CreateNew); StreamTee streamTee = new StreamTee(responseStream, outputStream); byte[] buffer = hashAlgorithm.ComputeHash(streamTee); streamTee.Close(); string arg = this.BytesToHexString(buffer); string text2 = Path.Combine(FutureDocumentFromUri.MakeDownloadCacheDir(), string.Format("Hash-{0}.{1}", arg, ImageTypeMapper.ByMimeType(httpWebResponse.ContentType).extension)); if (File.Exists(text2)) { File.Delete(text); } else { File.Move(text, text2); } httpWebResponse.Close(); return(new SourceDocument(new LocalDocumentDescriptor(text2, this.pageNumber))); }