public void Run() { var name = "testpage3_embcss.html"; var xPath = "//ol/li"; // Upload source file to cloud storage (default is AmazonS3) var srcPath = Path.Combine(CommonSettings.DataFolder, name); if (File.Exists(srcPath)) { SdkBaseRunner.uploadToStorage(name, CommonSettings.DataFolder); } else { throw new Exception(string.Format("Error: file {0} not found.", srcPath)); } IDocumentApi docApi = new DocumentApi(CommonSettings.AppKey, CommonSettings.AppSID, CommonSettings.BasePath); // call the SDK method that returns a query result in the response stream. Stream stream = docApi.GetDocumentFragmentByXPath(name, xPath, "json", null, null); if (stream != null && typeof(FileStream) == stream.GetType()) { string outFile = $"{Path.GetFileNameWithoutExtension(name)}_fragments.json"; string outPath = Path.Combine(CommonSettings.OutDirectory, outFile); using (FileStream fstr = new FileStream(outPath, FileMode.Create, FileAccess.Write)) { stream.Position = 0; stream.CopyTo(fstr); fstr.Flush(); Console.WriteLine(string.Format("\nResult file downloaded to: {0}", outPath)); } } }
public void Test_GetDocumentFragmentByXPath_2() { string name = "testpage1.html"; string xpath = ".//ol/li"; string folder = "HtmlTestDoc"; string storagePath = $"{folder}/{name}"; string srcPath = Path.Combine(dataFolder, name); StorageApi.PutCreate(storagePath, null, null, File.ReadAllBytes(srcPath)); FileExistResponse resp = StorageApi.GetIsExist(storagePath, null, null); Assert.IsTrue(resp.FileExist.IsExist); Stream stream = DocumentApi.GetDocumentFragmentByXPath(name, xpath, "json", null, folder); Assert.IsNotNull(stream); Assert.IsTrue(stream.GetType() == typeof(FileStream)); Assert.IsTrue(File.Exists(((FileStream)stream).Name)); }
public void Test_GetDocumentFragmentByXPath_2() { string name = "testpage1.html"; string xpath = ".//ol/li"; string folder = "HtmlTestDoc"; string storagePath = $"{folder}/{name}"; string srcPath = Path.Combine(dataFolder, name); using (Stream fstr = new FileStream(srcPath, FileMode.Open, FileAccess.Read)) { var reqCr = new PutCreateRequest(storagePath, fstr); var respCr = this.StorageApi.PutCreate(reqCr); var reqExist = new GetIsExistRequest(storagePath); var respExist = this.StorageApi.GetIsExist(reqExist); Assert.IsTrue(respExist.FileExist.IsExist.HasValue && respExist.FileExist.IsExist.Value); } Stream stream = DocumentApi.GetDocumentFragmentByXPath(name, xpath, "json", null, folder); Assert.IsNotNull(stream); Assert.IsTrue(stream.GetType() == typeof(FileStream)); Assert.IsTrue(File.Exists(((FileStream)stream).Name)); }
public void Test_GetDocumentFragmentByXPath_1() { string name = "testpage5.html.zip"; string xpath = ".//p"; string folder = "HtmlTestDoc"; string storagePath = $"{folder}/{name}"; string srcPath = Path.Combine(dataFolder, name); using (Stream fstr = new FileStream(srcPath, FileMode.Open, FileAccess.Read)) { PutCreateRequest reqCr = new PutCreateRequest(storagePath, fstr); this.StorageApi.PutCreate(reqCr); GetIsExistRequest reqExist = new GetIsExistRequest(storagePath); FileExistResponse resp = this.StorageApi.GetIsExist(reqExist); Assert.IsTrue(resp.FileExist.IsExist.HasValue && resp.FileExist.IsExist.Value); } Stream stream = DocumentApi.GetDocumentFragmentByXPath(name, xpath, "plain", null, folder); Assert.IsNotNull(stream); Assert.IsTrue(stream is FileStream); Assert.IsTrue(File.Exists(((FileStream)stream).Name)); }