private async Task <List <MarketoFile> > GetFileResults(MarketoClient client, string id) { List <MarketoFile> fileResults = new List <MarketoFile>(); GetFilesResponse fileResult = await client.GetFiles(id, 0); if (fileResult?.Result != null) { fileResults.AddRange(fileResult.Result); int fileCounts = fileResult.Result.Count; int callTimes = 0; while (fileCounts >= 200) { callTimes += 1; //var clientNext = new MarketoClient(host, clientId, clientSecret); GetFilesResponse fileResultNext = await client.GetFiles(id, callTimes * 200); if (fileResultNext?.Result != null) { fileResults.AddRange(fileResultNext.Result); fileCounts = fileResultNext.Result.Count; } } } return(fileResults); }
private static void DownFile(string host, string clientId, string clientSecret, List<string> folderIds, string savePath) { MarketoClient client = new MarketoClient(host, clientId, clientSecret); foreach (string folderId in folderIds) { Console.WriteLine(folderId); GetFilesResponse fileResult = client.GetFiles(folderId, 0).Result; string saveRootPath = Path.Combine(savePath, folderId); if (fileResult?.Result != null) { if (!Directory.Exists(saveRootPath)) { Directory.CreateDirectory(saveRootPath); } WriteFileToDisk(fileResult, saveRootPath); if (fileResult.Result.Count >= 200) { MarketoClient client200 = new MarketoClient(host, clientId, clientSecret); GetFilesResponse fileResult200 = client200.GetFiles(folderId, 200).Result; if (fileResult200?.Result != null) { WriteFileToDisk(fileResult200, saveRootPath); } } } Console.WriteLine("Done!"); } Console.ReadKey(); }