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(); }
private static void GetSmartList(string host, string clientId, string clientSecret) { MarketoClient client = new MarketoClient(host, clientId, clientSecret); bool isJson = true; GetSmartListResponse result = client.GetSmartList<GetSmartListResponse>(isJson); Console.WriteLine(result); Console.ReadKey(); }
private static async Task <List <string> > GetSubFolderIDsAsync(MarketoClient client, string rootFolderId) { //var client = new MarketoClient(apiConfig.Host, apiConfig.ClientId, apiConfig.ClientSecret); GetFoldersResponse result = await client.GetFolders(rootFolderId); List <string> folderIDs = new List <string>(); if (result.Result == null) { return(folderIDs); } folderIDs.AddRange(result.Result.Select(folder => folder.Id.ToString())); return(folderIDs); }
private async Task DownFile(ApiConfig apiConfig, string folderId, string savePath) { System.Diagnostics.Stopwatch watch = System.Diagnostics.Stopwatch.StartNew(); List <string> statusLog = new List <string>(); MarketoClient client = new MarketoClient(apiConfig.Host, apiConfig.ClientId, apiConfig.ClientSecret); List <string> folderIds = await GetAllFolderIDs(folderId, client); int processedFolderNums = 0; this.FolderStatus = 0; long elapsedMs; foreach (var id in folderIds) { this.CurrentFolder = id; Status += $"Reading folder {id}...{Environment.NewLine}"; var saveRootPath = Path.Combine(savePath, id); List <MarketoFile> fileResults = await GetFileResults(client, id); Progress <ProgressReportModel> progress = new Progress <ProgressReportModel>(); progress.ProgressChanged += ReportProgress; CreateDir(saveRootPath); try { await WriteFileToDiskParallelAsync(fileResults, saveRootPath, progress, cts.Token); } catch (OperationCanceledException e) { Status += $"Downloading is cancelled...{Environment.NewLine}"; watch.Stop(); elapsedMs = watch.ElapsedMilliseconds; Status += $"Total execution time: { elapsedMs }...{Environment.NewLine}"; return; } finally { cts.Dispose(); } //WriteFileToDisk(id, fileResults, saveRootPath, progress, cts.Token); Status += $"Done!{Environment.NewLine}"; processedFolderNums += 1; this.FolderStatus = (processedFolderNums * 100) / folderIds.Count; } watch.Stop(); elapsedMs = watch.ElapsedMilliseconds; Status += $"Total execution time: { elapsedMs }...{Environment.NewLine}"; }
private List <string> GetSubFolderIDs(string host, string clientId, string clientSecret, string rootFolderId) { MarketoClient client = new MarketoClient(host, clientId, clientSecret); GetFoldersResponse result = client.GetFolders(rootFolderId).Result; List <string> folderIDs = new List <string>(); if (result.Result != null) { foreach (MarketoFolder folder in result.Result) { folderIDs.Add(folder.Id.ToString()); } } return(folderIDs); }
private static List<string> GetSubFolderIDs(string host, string clientId, string clientSecret, string rootFolderId) { MarketoClient client = new MarketoClient(host, clientId, clientSecret); GetFoldersResponse result = client.GetFolders(rootFolderId).Result; List<string> folderIDs = new List<string>(); if (result.Result != null) { foreach (MarketoFolder folder in result.Result) { folderIDs.Add(folder.Id.ToString()); } } return folderIDs; //string prettyJson = JToken.Parse(result).ToString(Formatting.Indented); }
private async Task <List <string> > GetAllFolderIDs(string folderId, MarketoClient client) { List <string> folderIds = new List <string>(); if (HasSubFolders) { Status += $"Getting sub folders...{Environment.NewLine}"; folderIds = await GetSubFolderIDsAsync(client, folderId); } else { folderIds.Add(folderId); } return(folderIds); }