private static void RunTest(TableauSettings settings, TableauService _tService) { string username, password; Console.Write("Enter Username: "******"Enter Password: "******"MMAGold")); //var adminResp = CallAsync(_tService.TrySignin(settings.AdminUser, settings.AdminPassword)); var adminResp = _tService.TrySignin(settings.AdminUser, settings.AdminPassword); Console.WriteLine($"Returned Admin User Id: {adminResp.TableauUserId}"); if (adminResp.TableauToken == null || string.IsNullOrWhiteSpace(adminResp.TableauToken)) { Console.WriteLine($"Invalid Admin token returned. Program cannot continue."); if (adminResp.TsResponse.IsError) { Console.WriteLine(adminResp.TsResponse.ErrorResponse.ExceptionDetails); } return; } //var fullSiteList = CallAsync(_tService.TryGetSites(adminResp.TableauToken)); var fullSiteList = _tService.TryGetSites(adminResp.TableauToken); Console.WriteLine("Site list found -"); foreach (var site in fullSiteList.ItemList) { Console.WriteLine("======================================================"); Console.WriteLine($"Checking for site: {site.Name}, ContentUrl: {site.ContentUrl}\n Id: {site.Id}"); //var loginResp = CallAsync(_tService.TrySignin(username, password, site.ContentUrl)); var loginResp = _tService.TrySignin(username, password, site.ContentUrl); var eObj = loginResp.TsResponse as IResponse; if (eObj.IsError) { Console.WriteLine($"Failed. Http: {eObj.ErrorResponse.ErrorDetails.HttpStatusCode}, Code: {eObj.ErrorResponse.ErrorDetails.Code}"); Console.WriteLine($"Summary: {eObj.ErrorResponse.ErrorDetails.Summary}"); Console.WriteLine($"Details: {eObj.ErrorResponse.ErrorDetails.Details}"); } else { Console.WriteLine($"Success. User Id: {loginResp.TableauUserId}"); Console.WriteLine($"Token: {loginResp.TableauToken}"); } } }
private static bool GenerateWorkbookPreviewImages() { var workbookImagesFolderPath = @".\WorkbookImages"; if (Directory.Exists(workbookImagesFolderPath)) { Directory.Delete(workbookImagesFolderPath, true); } var workbookImagesFolder = Directory.CreateDirectory(workbookImagesFolderPath); var adminResp = _tService.TrySignin(settings.AdminUser, settings.AdminPassword); Console.WriteLine($"User Id: {adminResp.TableauUserId}"); var fullSiteList = _tService.TryGetSites(adminResp.TableauToken); foreach (var site in fullSiteList.ItemList) { var loginResp = _tService.TrySignin(settings.AdminUser, settings.AdminPassword, site.ContentUrl); if (loginResp.TsResponse.IsError) { Console.WriteLine($"Login failed for site name: {site.Name}, Id: {site.Id}"); Console.WriteLine(); Console.WriteLine("============================================================"); Console.WriteLine(); continue; } var workbooks = _tService.TryGetWorkbooks(site.Id, loginResp.TableauToken); if (workbooks == null || workbooks.ItemList == null || workbooks.ItemList.Count < 1) { Console.WriteLine($"No workbook list for site name: {site.Name}, Id: {site.Id}"); Console.WriteLine(); Console.WriteLine("============================================================"); Console.WriteLine(); continue; } var siteFolderPath = $"{workbookImagesFolder.FullName}\\site-{site.Id}"; if (Directory.Exists(siteFolderPath)) { Directory.Delete(siteFolderPath, true); } var siteFolder = Directory.CreateDirectory(siteFolderPath); Console.WriteLine($"Current Site Name: {site.Name}, Id: {site.Id}\nToken: {loginResp.TableauToken}\nLocation: {siteFolder.FullName}"); foreach (var workbook in workbooks.ItemList) { var workbookPreviewImage = _tService.TryGetPreviewImageForWorkbook(site.Id, workbook.Id, loginResp.TableauToken); using (var writer = File.Open($"{siteFolder.FullName}\\workbook-{workbook.Id}.png", FileMode.Create)) { writer.Write(workbookPreviewImage, 0, workbookPreviewImage.Length); var fileName = writer.Name.Split('\\').Last(); Console.WriteLine($"Workbook Name: {workbook.Name}, Filename: {fileName}"); } } var resp = _tService.TrySignout(loginResp.TableauToken); Console.WriteLine(); Console.WriteLine("============================================================"); Console.WriteLine(); } return(false); }