diff --git a/TabRESTMigrate/RESTHelpers/TableauServerSignedInRequestBase.cs b/TabRESTMigrate/RESTHelpers/TableauServerSignedInRequestBase.cs index bbbb1f9..db4b79d 100644 --- a/TabRESTMigrate/RESTHelpers/TableauServerSignedInRequestBase.cs +++ b/TabRESTMigrate/RESTHelpers/TableauServerSignedInRequestBase.cs @@ -169,6 +169,23 @@ private void AppendLoggedInHeadersForRequest(WebHeaderCollection webHeaders) _onlineSession.StatusLog.AddStatus("Append header X-Tableau-Auth: " + _onlineSession.LogInAuthToken, -20); } + + + /// + /// Get the web-response as an XML document (handles releasing the response object) + /// + /// + /// + /// + protected System.Xml.XmlDocument GetWebReponseLogErrors_AsXmlDoc(WebRequest webRequest, string description) + { + var response = GetWebReponseLogErrors(webRequest, description); + using (response) + { + return GetWebResponseAsXml(response); + } + } + /// /// Get the web response; log any error codes that occur and rethrow the exception. /// This allows us to get error log data with detailed information diff --git a/TabRESTMigrate/RESTRequests/DownloadDatasourceConnections.cs b/TabRESTMigrate/RESTRequests/DownloadDatasourceConnections.cs index 12b9646..fde296c 100644 --- a/TabRESTMigrate/RESTRequests/DownloadDatasourceConnections.cs +++ b/TabRESTMigrate/RESTRequests/DownloadDatasourceConnections.cs @@ -55,8 +55,7 @@ public void ExecuteRequest() webRequest.Method = "GET"; _onlineSession.StatusLog.AddStatus("Web request: " + urlQuery, -10); - var response = GetWebReponseLogErrors(webRequest, "get datasources's connections list"); - var xmlDoc = GetWebResponseAsXml(response); + var xmlDoc = GetWebReponseLogErrors_AsXmlDoc(webRequest, "get datasources's connections list"); //Get all the workbook nodes var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline"); diff --git a/TabRESTMigrate/RESTRequests/DownloadDatasourcesList.cs b/TabRESTMigrate/RESTRequests/DownloadDatasourcesList.cs index f102e00..cd734b4 100644 --- a/TabRESTMigrate/RESTRequests/DownloadDatasourcesList.cs +++ b/TabRESTMigrate/RESTRequests/DownloadDatasourcesList.cs @@ -80,8 +80,7 @@ private void ExecuteRequest_ForPage(List onlineDatasources, int webRequest.Method = "GET"; _onlineSession.StatusLog.AddStatus("Web request: " + urlQuery, -10); - var response = GetWebReponseLogErrors(webRequest, "get datasources list"); - var xmlDoc = GetWebResponseAsXml(response); + var xmlDoc = GetWebReponseLogErrors_AsXmlDoc(webRequest, "get datasources list"); //Get all the workbook nodes var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline"); diff --git a/TabRESTMigrate/RESTRequests/DownloadGroupsList.cs b/TabRESTMigrate/RESTRequests/DownloadGroupsList.cs index 49ee7f9..68d1110 100644 --- a/TabRESTMigrate/RESTRequests/DownloadGroupsList.cs +++ b/TabRESTMigrate/RESTRequests/DownloadGroupsList.cs @@ -83,8 +83,7 @@ private void ExecuteRequest_ForPage( webRequest.Method = "GET"; _onlineSession.StatusLog.AddStatus("Web request: " + urlQuery, -10); - var response = GetWebReponseLogErrors(webRequest, "get groups list"); - var xmlDoc = GetWebResponseAsXml(response); + var xmlDoc = GetWebReponseLogErrors_AsXmlDoc(webRequest, "get groups list"); //Get all the group nodes var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline"); diff --git a/TabRESTMigrate/RESTRequests/DownloadProjectsList.cs b/TabRESTMigrate/RESTRequests/DownloadProjectsList.cs index dafe6a3..96f4430 100644 --- a/TabRESTMigrate/RESTRequests/DownloadProjectsList.cs +++ b/TabRESTMigrate/RESTRequests/DownloadProjectsList.cs @@ -80,8 +80,7 @@ private void ExecuteRequest_ForPage(List onlineProjects, int pageTo webRequest.Method = "GET"; _onlineSession.StatusLog.AddStatus("Web request: " + urlQuery, -10); - var response = GetWebReponseLogErrors(webRequest, "get projects list"); - var xmlDoc = GetWebResponseAsXml(response); + var xmlDoc = GetWebReponseLogErrors_AsXmlDoc(webRequest, "get projects list"); //Get all the project nodes var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline"); diff --git a/TabRESTMigrate/RESTRequests/DownloadSchedulesList.cs b/TabRESTMigrate/RESTRequests/DownloadSchedulesList.cs index 0848d89..e94ef4b 100644 --- a/TabRESTMigrate/RESTRequests/DownloadSchedulesList.cs +++ b/TabRESTMigrate/RESTRequests/DownloadSchedulesList.cs @@ -79,8 +79,7 @@ private void ExecuteRequest_ForPage(List onlineSchedules, int page webRequest.Method = "GET"; _onlineSession.StatusLog.AddStatus("Web request: " + urlQuery, -10); - var response = GetWebReponseLogErrors(webRequest, "get schedules list"); - var xmlDoc = GetWebResponseAsXml(response); + var xmlDoc = GetWebReponseLogErrors_AsXmlDoc(webRequest, "get schedules list"); //Get all the schedule nodes var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline"); diff --git a/TabRESTMigrate/RESTRequests/DownloadSiteInfo.cs b/TabRESTMigrate/RESTRequests/DownloadSiteInfo.cs index aa2ba5e..f97e2e2 100644 --- a/TabRESTMigrate/RESTRequests/DownloadSiteInfo.cs +++ b/TabRESTMigrate/RESTRequests/DownloadSiteInfo.cs @@ -50,10 +50,8 @@ public void ExecuteRequest() //Request the data from server _onlineSession.StatusLog.AddStatus("Web request: " + urlRequest, -10); - var response = GetWebReponseLogErrors(webRequest, "get site info"); + var xmlDoc = GetWebReponseLogErrors_AsXmlDoc(webRequest, "get site info"); - var xmlDoc = GetWebResponseAsXml(response); - //Get all the workbook nodes var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline"); var sites = xmlDoc.SelectNodes("//iwsOnline:site", nsManager); diff --git a/TabRESTMigrate/RESTRequests/DownloadSubscriptionsList.cs b/TabRESTMigrate/RESTRequests/DownloadSubscriptionsList.cs index ccdbbc3..a9d4022 100644 --- a/TabRESTMigrate/RESTRequests/DownloadSubscriptionsList.cs +++ b/TabRESTMigrate/RESTRequests/DownloadSubscriptionsList.cs @@ -80,8 +80,7 @@ private void ExecuteRequest_ForPage(List onlineSubscriptions, webRequest.Method = "GET"; _onlineSession.StatusLog.AddStatus("Web request: " + urlQuery, -10); - var response = GetWebReponseLogErrors(webRequest, "get subscriptions list"); - var xmlDoc = GetWebResponseAsXml(response); + var xmlDoc = GetWebReponseLogErrors_AsXmlDoc(webRequest, "get subscriptions list"); //Get all the subscription nodes var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline"); diff --git a/TabRESTMigrate/RESTRequests/DownloadTasksExtractRefreshesList.cs b/TabRESTMigrate/RESTRequests/DownloadTasksExtractRefreshesList.cs index 88a1a39..048bd68 100644 --- a/TabRESTMigrate/RESTRequests/DownloadTasksExtractRefreshesList.cs +++ b/TabRESTMigrate/RESTRequests/DownloadTasksExtractRefreshesList.cs @@ -88,8 +88,7 @@ private void ExecuteRequest_ForPage(List onlineTasks, in webRequest.Method = "GET"; _onlineSession.StatusLog.AddStatus("Web request: " + urlQuery, -10); - var response = GetWebReponseLogErrors(webRequest, "get tasks list"); - var xmlDoc = GetWebResponseAsXml(response); + var xmlDoc = GetWebReponseLogErrors_AsXmlDoc(webRequest, "get tasks list"); //Get all the task nodes var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline"); diff --git a/TabRESTMigrate/RESTRequests/DownloadUsersListBase.cs b/TabRESTMigrate/RESTRequests/DownloadUsersListBase.cs index 242c637..b3c2205 100644 --- a/TabRESTMigrate/RESTRequests/DownloadUsersListBase.cs +++ b/TabRESTMigrate/RESTRequests/DownloadUsersListBase.cs @@ -106,8 +106,7 @@ private void ExecuteRequest_ForPage(List onlineUsers, int pageToReques webRequest.Method = "GET"; _onlineSession.StatusLog.AddStatus("Web request: " + urlQuery, -10); - var response = GetWebReponseLogErrors(webRequest, "get users list"); - var xmlDoc = GetWebResponseAsXml(response); + var xmlDoc = GetWebReponseLogErrors_AsXmlDoc(webRequest, "get users list"); //Get all the user nodes var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline"); diff --git a/TabRESTMigrate/RESTRequests/DownloadViewsList.cs b/TabRESTMigrate/RESTRequests/DownloadViewsList.cs index 93502bb..12928ad 100644 --- a/TabRESTMigrate/RESTRequests/DownloadViewsList.cs +++ b/TabRESTMigrate/RESTRequests/DownloadViewsList.cs @@ -80,8 +80,7 @@ private void ExecuteRequest_ForPage(List onlineViews, int pageToReques webRequest.Method = "GET"; _onlineSession.StatusLog.AddStatus("Web request: " + urlQuery, -10); - var response = GetWebReponseLogErrors(webRequest, "get views list"); - var xmlDoc = GetWebResponseAsXml(response); + var xmlDoc = GetWebReponseLogErrors_AsXmlDoc(webRequest, "get views list"); //Get all the view nodes var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline"); diff --git a/TabRESTMigrate/RESTRequests/DownloadWorkbookConnections.cs b/TabRESTMigrate/RESTRequests/DownloadWorkbookConnections.cs index 7eefccf..7b8fbd6 100644 --- a/TabRESTMigrate/RESTRequests/DownloadWorkbookConnections.cs +++ b/TabRESTMigrate/RESTRequests/DownloadWorkbookConnections.cs @@ -55,8 +55,7 @@ public void ExecuteRequest() webRequest.Method = "GET"; _onlineSession.StatusLog.AddStatus("Web request: " + urlQuery, -10); - var response = GetWebReponseLogErrors(webRequest, "get workbook's connections list"); - var xmlDoc = GetWebResponseAsXml(response); + var xmlDoc = GetWebReponseLogErrors_AsXmlDoc(webRequest, "get workbook's connections list"); //Get all the workbook nodes var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline"); diff --git a/TabRESTMigrate/RESTRequests/DownloadWorkbooksList.cs b/TabRESTMigrate/RESTRequests/DownloadWorkbooksList.cs index de21fde..f40d9ee 100644 --- a/TabRESTMigrate/RESTRequests/DownloadWorkbooksList.cs +++ b/TabRESTMigrate/RESTRequests/DownloadWorkbooksList.cs @@ -97,8 +97,7 @@ private void ExecuteRequest_ForPage(List onlineWorkbooks, int page webRequest.Method = "GET"; _onlineSession.StatusLog.AddStatus("Web request: " + urlQuery, -10); - var response = GetWebReponseLogErrors(webRequest, "get workbooks list"); - var xmlDoc = GetWebResponseAsXml(response); + var xmlDoc = GetWebReponseLogErrors_AsXmlDoc(webRequest, "get workbooks list"); //Get all the workbook nodes var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline"); diff --git a/TabRESTMigrate/RESTRequests/SendCreateProject.cs b/TabRESTMigrate/RESTRequests/SendCreateProject.cs index c0866f5..f1132b7 100644 --- a/TabRESTMigrate/RESTRequests/SendCreateProject.cs +++ b/TabRESTMigrate/RESTRequests/SendCreateProject.cs @@ -72,29 +72,24 @@ private SiteProject CreateProject(string projectName, string projectDescription) var urlCreateProject = _onlineUrls.Url_CreateProject(_onlineSession); var webRequest = this.CreateLoggedInWebRequest(urlCreateProject, "POST"); TableauServerRequestBase.SendPostContents(webRequest, xmlText); - - //Get the response - var response = GetWebReponseLogErrors(webRequest, "create project"); - using (response) - { - var xmlDoc = GetWebResponseAsXml(response); + //Get the response + var xmlDoc = GetWebReponseLogErrors_AsXmlDoc(webRequest, "create project"); - //Get all the workbook nodes - var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline"); - var xNodeProject = xmlDoc.SelectSingleNode("//iwsOnline:project", nsManager); + //Get all the workbook nodes + var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline"); + var xNodeProject = xmlDoc.SelectSingleNode("//iwsOnline:project", nsManager); - try - { - return new SiteProject(xNodeProject); - } - catch (Exception parseXml) - { - StatusLog.AddError("Create project, error parsing XML response " + parseXml.Message + "\r\n" + xNodeProject.InnerXml); - return null; - } - + try + { + return new SiteProject(xNodeProject); } + catch (Exception parseXml) + { + StatusLog.AddError("Create project, error parsing XML response " + parseXml.Message + "\r\n" + xNodeProject.InnerXml); + return null; + } + } diff --git a/TabRESTMigrate/RESTRequests/SendDeleteDatasourceTag.cs b/TabRESTMigrate/RESTRequests/SendDeleteDatasourceTag.cs index de4c5de..4cccad7 100644 --- a/TabRESTMigrate/RESTRequests/SendDeleteDatasourceTag.cs +++ b/TabRESTMigrate/RESTRequests/SendDeleteDatasourceTag.cs @@ -89,7 +89,13 @@ private void DeleteTagFromContent(string datasourceId, string tagText) //Create a web request var urlDeleteContentTag = _onlineUrls.Url_DeleteDatasourceTag(_onlineSession, datasourceId, tagText); var webRequest = this.CreateLoggedInWebRequest(urlDeleteContentTag, "DELETE"); - var response = GetWebReponseLogErrors(webRequest, "delete tag from content request"); + var response = GetWebReponseLogErrors(webRequest, "delete tag from content request"); + + using(response) + { + //No work to do... + } + } } diff --git a/TabRESTMigrate/RESTRequests/SendDeleteWorkbookTag.cs b/TabRESTMigrate/RESTRequests/SendDeleteWorkbookTag.cs index 5427600..24f2f06 100644 --- a/TabRESTMigrate/RESTRequests/SendDeleteWorkbookTag.cs +++ b/TabRESTMigrate/RESTRequests/SendDeleteWorkbookTag.cs @@ -85,7 +85,11 @@ private void DeleteTagFromContent(string workbookId, string tagText) //Create a web request var urlDeleteContentTag = _onlineUrls.Url_DeleteWorkbookTag(_onlineSession, workbookId, tagText); var webRequest = this.CreateLoggedInWebRequest(urlDeleteContentTag, "DELETE"); - var response = GetWebReponseLogErrors(webRequest, "delete tag from content request"); + var response = GetWebReponseLogErrors(webRequest, "delete tag from content request"); + using(response) + { + //No work to do... + } } } diff --git a/TabRESTMigrate/RESTRequests/SendPostLogInCommand.cs b/TabRESTMigrate/RESTRequests/SendPostLogInCommand.cs index f3f45ca..8fb9092 100644 --- a/TabRESTMigrate/RESTRequests/SendPostLogInCommand.cs +++ b/TabRESTMigrate/RESTRequests/SendPostLogInCommand.cs @@ -48,8 +48,11 @@ public string ExecuteRequest() _onlineSession.StatusLog.AddStatus("Custom web request: " + url, -10); var response = GetWebReponseLogErrors(webRequest, "custom request"); - var responseText = GetWebResponseAsText(response); - _commandResult = responseText; - return responseText; + using(response) + { + var responseText = GetWebResponseAsText(response); + _commandResult = responseText; + return responseText; + } } } diff --git a/TabRESTMigrate/RESTRequests/SendUpdateDatasourceOwner.cs b/TabRESTMigrate/RESTRequests/SendUpdateDatasourceOwner.cs index a471691..00d18a8 100644 --- a/TabRESTMigrate/RESTRequests/SendUpdateDatasourceOwner.cs +++ b/TabRESTMigrate/RESTRequests/SendUpdateDatasourceOwner.cs @@ -81,27 +81,22 @@ private SiteDatasource ChangeContentOwner(string datasourceId, string newOwnerId TableauServerRequestBase.SendPutContents(webRequest, xmlText); //Get the response - var response = GetWebReponseLogErrors(webRequest, "update datasource (change owner)"); - using (response) - { - var xmlDoc = GetWebResponseAsXml(response); - + var xmlDoc = GetWebReponseLogErrors_AsXmlDoc(webRequest, "update datasource (change owner)"); - //Get all the datasource nodes - var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline"); - var xNodeDs = xmlDoc.SelectSingleNode("//iwsOnline:datasource", nsManager); + //Get all the datasource nodes + var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline"); + var xNodeDs = xmlDoc.SelectSingleNode("//iwsOnline:datasource", nsManager); - try - { - return new SiteDatasource(xNodeDs); - } - catch (Exception parseXml) - { - StatusLog.AddError("Change datasource owner, error parsing XML response " + parseXml.Message + "\r\n" + xNodeDs.InnerXml); - return null; - } - + try + { + return new SiteDatasource(xNodeDs); } + catch (Exception parseXml) + { + StatusLog.AddError("Change datasource owner, error parsing XML response " + parseXml.Message + "\r\n" + xNodeDs.InnerXml); + return null; + } + } diff --git a/TabRESTMigrate/RESTRequests/SendUpdateWorkbookOwner.cs b/TabRESTMigrate/RESTRequests/SendUpdateWorkbookOwner.cs index d21e43e..977eaae 100644 --- a/TabRESTMigrate/RESTRequests/SendUpdateWorkbookOwner.cs +++ b/TabRESTMigrate/RESTRequests/SendUpdateWorkbookOwner.cs @@ -79,30 +79,22 @@ private SiteWorkbook ChangeContentOwner(string workbookId, string newOwnerId) var urlUpdateWorkbook = _onlineUrls.Url_UpdateWorkbook(_onlineSession, workbookId); var webRequest = this.CreateLoggedInWebRequest(urlUpdateWorkbook, "PUT"); TableauServerRequestBase.SendPutContents(webRequest, xmlText); - - //Get the response - var response = GetWebReponseLogErrors(webRequest, "update workbook (change owner)"); - using (response) - { - var xmlDoc = GetWebResponseAsXml(response); + //Get the response + var xmlDoc = GetWebReponseLogErrors_AsXmlDoc(webRequest, "update workbook (change owner)"); - //Get all the workbook nodes - var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline"); - var xNodeWb = xmlDoc.SelectSingleNode("//iwsOnline:workbook", nsManager); + //Get all the workbook nodes + var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline"); + var xNodeWb = xmlDoc.SelectSingleNode("//iwsOnline:workbook", nsManager); - try - { - return new SiteWorkbook(xNodeWb); - } - catch (Exception parseXml) - { - StatusLog.AddError("Change workbook owner, error parsing XML response " + parseXml.Message + "\r\n" + xNodeWb.InnerXml); - return null; - } - + try + { + return new SiteWorkbook(xNodeWb); } + catch (Exception parseXml) + { + StatusLog.AddError("Change workbook owner, error parsing XML response " + parseXml.Message + "\r\n" + xNodeWb.InnerXml); + return null; + } } - - } diff --git a/TabRESTMigrate/RESTRequests/TableauServerSignOut.cs b/TabRESTMigrate/RESTRequests/TableauServerSignOut.cs index 04deaeb..be0f8d6 100644 --- a/TabRESTMigrate/RESTRequests/TableauServerSignOut.cs +++ b/TabRESTMigrate/RESTRequests/TableauServerSignOut.cs @@ -43,6 +43,10 @@ public void ExecuteRequest() //Request the data from server _onlineSession.StatusLog.AddStatus("Web request: " + urlRequest, -10); var response = GetWebReponseLogErrors(webRequest, "sign out"); + using(response) + { + //No work to do.... + } } } diff --git a/TabRESTMigrate/RESTRequests/UploadDatasources.cs b/TabRESTMigrate/RESTRequests/UploadDatasources.cs index ce29a5c..fda1a07 100644 --- a/TabRESTMigrate/RESTRequests/UploadDatasources.cs +++ b/TabRESTMigrate/RESTRequests/UploadDatasources.cs @@ -346,24 +346,20 @@ private SiteDatasource FinalizePublish( //NOTE: The publish finalization step can take several minutes, because server needs to unpack the uploaded ZIP and file it away. // For this reason, we pass in a long timeout var webRequest = this.CreateAndSendMimeLoggedInRequest(urlFinalizeUpload, "POST", mimeGenerator, TableauServerWebClient.DefaultLongRequestTimeOutMs); - var response = GetWebReponseLogErrors(webRequest, "finalize datasource publish"); - using (response) - { - var xmlDoc = GetWebResponseAsXml(response); + var xmlDoc = GetWebReponseLogErrors_AsXmlDoc(webRequest, "finalize datasource publish"); - //Get all the datasource node from the response - var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline"); - var dataSourceXml = xmlDoc.SelectSingleNode("//iwsOnline:datasource", nsManager); + //Get all the datasource node from the response + var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline"); + var dataSourceXml = xmlDoc.SelectSingleNode("//iwsOnline:datasource", nsManager); - try - { - return new SiteDatasource(dataSourceXml); - } - catch(Exception parseXml) - { - StatusLog.AddError("Data source upload, error parsing XML response " + parseXml.Message + "\r\n" + dataSourceXml.InnerXml); - return null; - } + try + { + return new SiteDatasource(dataSourceXml); + } + catch(Exception parseXml) + { + StatusLog.AddError("Data source upload, error parsing XML response " + parseXml.Message + "\r\n" + dataSourceXml.InnerXml); + return null; } } diff --git a/TabRESTMigrate/RESTRequests/UploadFile.cs b/TabRESTMigrate/RESTRequests/UploadFile.cs index 5f0b481..134ef93 100644 --- a/TabRESTMigrate/RESTRequests/UploadFile.cs +++ b/TabRESTMigrate/RESTRequests/UploadFile.cs @@ -168,8 +168,7 @@ private string RequestUploadSessionId() var urlInitiateFileUpload = _onlineUrls.Url_InitiateFileUpload(_onlineSession); var webRequest = this.CreateLoggedInWebRequest(urlInitiateFileUpload, "POST"); //NOTE: This command requires a POST not a GET - var response = GetWebReponseLogErrors(webRequest, "get datasources list"); - var xmlDoc = GetWebResponseAsXml(response); + var xmlDoc = GetWebReponseLogErrors_AsXmlDoc(webRequest, "get datasources list"); //Get all the workbook nodes var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline");