private async Task <ServerSite> CreateSiteAsync(string site, string name)
        {
            Error.HasError = false;
            ServerSite serverSite = new ServerSite();

            if (LogOn.Token == null)
            {
                await LogOnAsync();
            }

            if (Error.HasError)
            {
                throw new Exception(Error.Error.Detail);
            }

            var newSite = new NewSite
            {
                SiteDetails = new ServerSite
                {
                    Name       = name,
                    ContentUrl = site,
                    AdminMode  = "ContentOnly"
                }
            };

            string content = ToXML(newSite, "tsRequest");

            Client.DefaultRequestHeaders.Remove("X-Tableau-Auth");
            Client.DefaultRequestHeaders.TryAddWithoutValidation("X-Tableau-Auth", LogOn.Token);

            var request = new HttpRequestMessage(HttpMethod.Post, "3.3/sites")
            {
                Content = new StringContent(content, Encoding.UTF8, "application/xml")
            };

            try
            {
                using (var response = await Client.SendAsync(request))
                {
                    if (response.IsSuccessStatusCode)
                    {
                        var l = await response.Content.ReadAsAsync <NewSite>();
                        await SwitchSiteAsync(l.SiteDetails.ContentUrl);

                        serverSite = l.SiteDetails;
                    }
                    else
                    {
                        await Error.ManageHttpErrorAsync(response);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            request.Dispose();

            return(serverSite);
        }
 public ServerCredentials(string name, string password, string site)
 {
     Name     = name;
     Password = password;
     Site     = new ServerSite
     {
         ContentUrl = site
     };
 }
        private async Task <ServerSite> GetSiteAsync(string site)
        {
            ServerSite serverSite = new ServerSite();

            if (LogOn.Token == null)
            {
                await LogOnAsync(site);
            }
            else if (LogOn.Site.ContentUrl != site)
            {
                await SwitchSiteAsync(site);
            }

            if (Error.HasError)
            {
                throw new Exception(Error.Error.Detail);
            }
            Client.DefaultRequestHeaders.Remove("X-Tableau-Auth");
            Client.DefaultRequestHeaders.TryAddWithoutValidation("X-Tableau-Auth", LogOn.Token);

            using (var request = new HttpRequestMessage(HttpMethod.Get, $"3.3/sites/{site}?key=contentUrl"))
            {
                try
                {
                    using (var response = await Client.SendAsync(request))
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            var l = await response.Content.ReadAsAsync <Site>();

                            serverSite = l.SiteDetails;
                        }
                        else
                        {
                            await Error.ManageHttpErrorAsync(response);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            };



            return(serverSite);
        }