Skip to content
This repository has been archived by the owner on Nov 18, 2024. It is now read-only.

Commit

Permalink
Fixed resource leakage problem (Web Responses were not being explicit…
Browse files Browse the repository at this point in the history
…ly Disposed())
  • Loading branch information
IvoSalmre-Tableau committed Aug 27, 2020
1 parent 473f2a2 commit 44890ac
Show file tree
Hide file tree
Showing 22 changed files with 104 additions and 106 deletions.
17 changes: 17 additions & 0 deletions TabRESTMigrate/RESTHelpers/TableauServerSignedInRequestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,23 @@ private void AppendLoggedInHeadersForRequest(WebHeaderCollection webHeaders)
_onlineSession.StatusLog.AddStatus("Append header X-Tableau-Auth: " + _onlineSession.LogInAuthToken, -20);
}



/// <summary>
/// Get the web-response as an XML document (handles releasing the response object)
/// </summary>
/// <param name="webRequest"></param>
/// <param name="description"></param>
/// <returns></returns>
protected System.Xml.XmlDocument GetWebReponseLogErrors_AsXmlDoc(WebRequest webRequest, string description)
{
var response = GetWebReponseLogErrors(webRequest, description);
using (response)
{
return GetWebResponseAsXml(response);
}
}

/// <summary>
/// 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
Expand Down
3 changes: 1 addition & 2 deletions TabRESTMigrate/RESTRequests/DownloadDatasourceConnections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 1 addition & 2 deletions TabRESTMigrate/RESTRequests/DownloadDatasourcesList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ private void ExecuteRequest_ForPage(List<SiteDatasource> 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");
Expand Down
3 changes: 1 addition & 2 deletions TabRESTMigrate/RESTRequests/DownloadGroupsList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 1 addition & 2 deletions TabRESTMigrate/RESTRequests/DownloadProjectsList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ private void ExecuteRequest_ForPage(List<SiteProject> 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");
Expand Down
3 changes: 1 addition & 2 deletions TabRESTMigrate/RESTRequests/DownloadSchedulesList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ private void ExecuteRequest_ForPage(List<SiteSchedule> 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");
Expand Down
4 changes: 1 addition & 3 deletions TabRESTMigrate/RESTRequests/DownloadSiteInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions TabRESTMigrate/RESTRequests/DownloadSubscriptionsList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ private void ExecuteRequest_ForPage(List<SiteSubscription> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ private void ExecuteRequest_ForPage(List<SiteTaskExtractRefresh> 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");
Expand Down
3 changes: 1 addition & 2 deletions TabRESTMigrate/RESTRequests/DownloadUsersListBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ private void ExecuteRequest_ForPage(List<SiteUser> 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");
Expand Down
3 changes: 1 addition & 2 deletions TabRESTMigrate/RESTRequests/DownloadViewsList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ private void ExecuteRequest_ForPage(List<SiteView> 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");
Expand Down
3 changes: 1 addition & 2 deletions TabRESTMigrate/RESTRequests/DownloadWorkbookConnections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 1 addition & 2 deletions TabRESTMigrate/RESTRequests/DownloadWorkbooksList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ private void ExecuteRequest_ForPage(List<SiteWorkbook> 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");
Expand Down
33 changes: 14 additions & 19 deletions TabRESTMigrate/RESTRequests/SendCreateProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}


Expand Down
8 changes: 7 additions & 1 deletion TabRESTMigrate/RESTRequests/SendDeleteDatasourceTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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...
}

}

}
6 changes: 5 additions & 1 deletion TabRESTMigrate/RESTRequests/SendDeleteWorkbookTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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...
}
}

}
9 changes: 6 additions & 3 deletions TabRESTMigrate/RESTRequests/SendPostLogInCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
31 changes: 13 additions & 18 deletions TabRESTMigrate/RESTRequests/SendUpdateDatasourceOwner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}


Expand Down
34 changes: 13 additions & 21 deletions TabRESTMigrate/RESTRequests/SendUpdateWorkbookOwner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}


}
4 changes: 4 additions & 0 deletions TabRESTMigrate/RESTRequests/TableauServerSignOut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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....
}

}
}
28 changes: 12 additions & 16 deletions TabRESTMigrate/RESTRequests/UploadDatasources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
3 changes: 1 addition & 2 deletions TabRESTMigrate/RESTRequests/UploadFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 44890ac

Please sign in to comment.