private static void DownloadFiles(IScreenshotService proxy) { var localFileName = ""; var validPath = false; while (!validPath) { Console.WriteLine("Enter your desired path to save the screenshots: "); localFileName = Console.ReadLine(); try { Directory.CreateDirectory(localFileName); validPath = true; } catch (DirectoryNotFoundException e) { Console.WriteLine("The path you entered is not valid"); validPath = false; } } var request = new FileDownloadMessage(); request.FileMetaData = new FileMetaData(localFileName, "", ""); Console.WriteLine("Do you want to download all screenshots? Y/N"); var input = Console.ReadLine(); var downloadAll = input.ToUpper() == "Y"; var url = ""; if (!downloadAll) { Console.WriteLine("Write the URL of which you want to download: "); url = Console.ReadLine(); request.FileMetaData.Url = url; } try { using (FileDownloadReturnMessage response = downloadAll ? proxy.DownloadAllFiles(request) : proxy.DownloadFile(request)) { if (response != null && response.FileByteStream != null && !String.IsNullOrWhiteSpace(response.DownloadedFileMetadata.LocalFileName)) { SaveFile(response.FileByteStream, response.DownloadedFileMetadata.LocalFileName); Console.WriteLine("The download was successful."); } else { Console.WriteLine("Couldn't find the specified url"); } } } catch (Exception e) { Console.WriteLine("An error occured with the download."); } }
private string DownloadFile(string pFile) { if (pFile == string.Empty) { WriteInfoError("Kötelező megadni fájlt!"); return(string.Empty); } if (!File.Exists(pFile)) { WriteInfoError("A megadott fájl nem létezik!"); return(string.Empty); } string md5 = Cryptography.FileMD5Calculator(pFile); if (!client.SourceFileExist(md5)) { WriteInfoError("A megadott fájl még nem került feldolgozásra."); return(string.Empty); } FileDownloadReturnMessage fdrm = null; try { fdrm = client.GetResultFile(new FileDownloadMessage(md5)); } catch (FaultException <FaultTextAnalytics> ex) { WriteInfoError($"Az eredmény fájl letöltése a következő hibával állt le: { ex.Detail.ErrorText }."); return(string.Empty); } string resultFile = Path.Combine(c_ResultFilePath, $"{Path.GetFileNameWithoutExtension(fdrm.DownloadedFilename)}2.xml"); StreamFunc.StreamToFile(fdrm.FileByteStream, resultFile); return(resultFile); }