SendPostContents() protected static method

Sends the body text up to the server
protected static SendPostContents ( WebRequest request, string bodyText ) : void
request WebRequest
bodyText string
return void
Ejemplo n.º 1
0
    private SiteProject CreateProject(string projectName, string projectDescription)
    {
        //ref: http://onlinehelp.tableau.com/current/api/rest_api/en-us/help.htm#REST/rest_api_ref.htm#Create_Project%3FTocPath%3DAPI%2520Reference%7C_____12
        var sb          = new StringBuilder();
        var xmlSettings = new XmlWriterSettings();

        xmlSettings.OmitXmlDeclaration = true;
        var xmlWriter = XmlWriter.Create(sb, xmlSettings);

        xmlWriter.WriteStartElement("tsRequest");
        xmlWriter.WriteStartElement("project");
        xmlWriter.WriteAttributeString("name", projectName);
        xmlWriter.WriteAttributeString("description", projectDescription);
        xmlWriter.WriteEndElement(); //</project>
        xmlWriter.WriteEndElement(); // </tsRequest>
        xmlWriter.Close();

        var xmlText = sb.ToString(); //Get the XML text out

        //Generate the MIME message
        //var mimeGenerator = new OnlineMimeXmlPayload(xmlText);

        //Create a web request
        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 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("Data source upload, error parsing XML resposne " + parseXml.Message + "\r\n" + xNodeProject.InnerXml);
                return(null);
            }
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Create the user on the server
    /// </summary>
    /// <param name="userName"></param>
    /// <param name="userRole"></param>
    /// <param name="userAuthentication"></param>
    /// <returns></returns>
    private SiteUser CreateUser(string userName, string userRole, SiteUserAuth userAuthentication)
    {
        string authSettingText = SiteUserAuthToAttributeText(userAuthentication);

        //ref: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm#add_user_to_site
        var sb        = new StringBuilder();
        var xmlWriter = XmlWriter.Create(sb, XmlHelper.XmlSettingsForWebRequests);

        xmlWriter.WriteStartElement("tsRequest");
        xmlWriter.WriteStartElement("user");
        xmlWriter.WriteAttributeString("name", userName);
        xmlWriter.WriteAttributeString("siteRole", userRole);
        xmlWriter.WriteAttributeString("authSetting", authSettingText);
        xmlWriter.WriteEndElement(); //</user>
        xmlWriter.WriteEndElement(); //</tsRequest>
        xmlWriter.Close();

        var xmlText = sb.ToString(); //Get the XML text out

        //Generate the MIME message

        //Create a web request
        var urlCreateUser = _onlineUrls.Url_CreateSiteUser(_onlineSession);
        var webRequest    = this.CreateLoggedInWebRequest(urlCreateUser, "POST");

        TableauServerRequestBase.SendPostContents(webRequest, xmlText);

        //Get the response
        var response = GetWebReponseLogErrors(webRequest, "create user");

        using (response)
        {
            var xmlDoc = GetWebResponseAsXml(response);

            //Get all the workbook nodes
            var nsManager    = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline");
            var xNodeProject = xmlDoc.SelectSingleNode("//iwsOnline:user", nsManager);

            try
            {
                return(new SiteUser(xNodeProject));
            }
            catch (Exception parseXml)
            {
                StatusLog.AddError("Create user, error parsing XML response " + parseXml.Message + "\r\n" + xNodeProject.InnerXml);
                return(null);
            }
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Create the group on the server
    /// </summary>
    /// <param name="groupName"></param>
    /// <returns></returns>
    private SiteGroup CreateGroup(string groupName)
    {
        //ref: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm#create_group
        var sb        = new StringBuilder();
        var xmlWriter = XmlWriter.Create(sb, XmlHelper.XmlSettingsForWebRequests);

        xmlWriter.WriteStartElement("tsRequest");
        xmlWriter.WriteStartElement("group");
        xmlWriter.WriteAttributeString("name", groupName);
        xmlWriter.WriteEndElement(); //</user>
        xmlWriter.WriteEndElement(); //</tsRequest>
        xmlWriter.Close();

        var xmlText = sb.ToString(); //Get the XML text out

        //Generate the MIME message

        //Create a web request
        var urlCreateGroup = _onlineUrls.Url_CreateSiteGroup(_onlineSession);
        var webRequest     = this.CreateLoggedInWebRequest(urlCreateGroup, "POST");

        TableauServerRequestBase.SendPostContents(webRequest, xmlText);

        //Get the response
        var response = GetWebReponseLogErrors(webRequest, "create group");

        using (response)
        {
            var xmlDoc = GetWebResponseAsXml(response);

            //Get all the workbook nodes
            var nsManager  = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline");
            var xNodeGroup = xmlDoc.SelectSingleNode("//iwsOnline:group", nsManager);

            try
            {
                return(new SiteGroup(xNodeGroup, null));
            }
            catch (Exception exParseXml)
            {
                StatusLog.AddError("Create user, error parsing XML response " + exParseXml.Message + "\r\n" + xNodeGroup.InnerXml);
                return(null);
            }
        }
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Create the user on the server
    /// </summary>
    /// <param name="userId"></param>
    /// <param name="groupId"></param>
    /// <param name="userAuthentication"></param>
    /// <returns>TRUE: Suceess</returns>
    private bool AddUserToGroup(string userId, string groupId)
    {
        //ref: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm#add_user_to_group
        var sb        = new StringBuilder();
        var xmlWriter = XmlWriter.Create(sb, XmlHelper.XmlSettingsForWebRequests);

        xmlWriter.WriteStartElement("tsRequest");
        xmlWriter.WriteStartElement("user");
        xmlWriter.WriteAttributeString("id", userId);
        xmlWriter.WriteEndElement(); //</user>
        xmlWriter.WriteEndElement(); //</tsRequest>
        xmlWriter.Close();

        var xmlText = sb.ToString(); //Get the XML text out

        //Generate the MIME message

        //Create a web request
        var urlAddUserToGroup = _onlineUrls.Url_AddUserToGroup(_onlineSession, groupId);
        var webRequest        = this.CreateLoggedInWebRequest(urlAddUserToGroup, "POST");

        TableauServerRequestBase.SendPostContents(webRequest, xmlText);

        //Get the response
        var response = GetWebReponseLogErrors(webRequest, "add user to group");

        using (response)
        {
            var xmlDoc = GetWebResponseAsXml(response);

            //Get all the workbook nodes
            var nsManager = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline");
            var xNodeUser = xmlDoc.SelectSingleNode("//iwsOnline:user", nsManager);

            if (xNodeUser == null)
            {
                StatusLog.AddError("Add user to group failed. Repsonse was not a USER node");
                return(false); //Failure
            }

            return(true); //Success
        }
    }