public SignIn(string name, string password, string site) { Credentials = new ServerCredentials { Name = name, Password = password, Site = new ServerSite { ContentUrl = site } }; }
private async Task SwitchSiteAsync(string site) { var switchSite = new Site { SiteDetails = new ServerSite { ContentUrl = site } }; var j = ToJson(switchSite); Client.DefaultRequestHeaders.Remove("X-Tableau-Auth"); Client.DefaultRequestHeaders.TryAddWithoutValidation("X-Tableau-Auth", LogOn.Token); var request = new HttpRequestMessage(HttpMethod.Post, "3.3/auth/switchsite") { Content = new StringContent(j, Encoding.UTF8, "application/json") }; try { var response = await Client.SendAsync(request); if (response.IsSuccessStatusCode) { var l = await response.Content.ReadAsAsync <SignIn>(); LogOn = l.Credentials; } else { LogOnError = true; } } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } }
private async Task LogOnAsync(string site = "") { LogOnError = false; var j = ToJson((new SignIn(User, Password, site))); var request = new HttpRequestMessage(HttpMethod.Post, "3.3/auth/signin") { Content = new StringContent(j, Encoding.UTF8, "application/json") }; try { var response = await Client.SendAsync(request); if (response.IsSuccessStatusCode) { var l = await response.Content.ReadAsAsync <SignIn>(); LogOn = l.Credentials; } else { var error = await response.Content.ReadAsAsync <ErrorDetails>();; error.StatusCode = response.StatusCode; error.ReasonPhrase = response.ReasonPhrase; LogOnError = true; } } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } }