protected void Page_Load(object sender, EventArgs e)
 {
     if (Request.QueryString["oauth_token"] == null)
     {
         oAuth = new oAuthDossia();
         Response.Redirect(oAuth.GetTokens());
     }      
 }
    protected void btnRetrive_Click(object sender, EventArgs e)
    {
        string accessTokenRedirectUrl = string.Empty;
        string apiGetUrl;
        string getRecordUrl = string.Empty;
        string responseText = string.Empty;

        if (txtRecordId.Text.Length < 0)
        {
            lblMessage.Text = "Please enter record id.";
            return;
        }
        if (txtLabelId.Text.Length < 0)
        {
            lblMessage.Text = "Please enter label id.";
            return;
        }
        oAuth = new oAuthDossia();

        //Authorize and use the token and secret to get the new access token
        oAuth.AccessTokenGet();
        string recordId = txtRecordId.Text;
        string labelId = txtLabelId.Text;
        if (oAuth.Token.Length > 0 && oAuth.TokenSecret.Length > 0)
        {
            try
            {
                string contentType;
                byte[] outputData;

                //Get the App path
                string physicalPath = HttpContext.Current.Request.MapPath(HttpContext.Current.Request.ApplicationPath);

                //generate the API url
                apiGetUrl = oAuthDossia.DOSSIA_API_URL + "records/" + recordId + "/apps/documents/label/" + labelId;
                //get the access to API url
                accessTokenRedirectUrl = oAuth.AccessToAPILink(apiGetUrl, oAuth.Token, oAuth.TokenSecret, oAuthDossia.Method.GET.ToString());
                //do the request and set the response to text
                responseText = oAuth.MakeWebRequest(accessTokenRedirectUrl, out contentType, out outputData);

                //Save the reponse data in file stream
                FileStream fs = new FileStream(physicalPath + @"\output." + contentType.Split('/')[1], FileMode.Create, FileAccess.ReadWrite);
                fs.Write(outputData, 0, outputData.Length);
                fs.Close();

                this.txtDossiaAPIResponse.Text = "Binary file is saved at: " + fs.Name;
                clearSession();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        else
        {
            Response.Redirect("APITest.aspx", false);
        }
    }
 protected void btnPost_Click(object sender, EventArgs e)
 {
     if (!fileUploader.HasFile)
     {
         lblMessage.Text = "Please upload a file";
         return;
     }
     if (txtRecordId.Text.Length == 0)
     {
         lblMessage.Text = "Please enter record id.";
         return;
     }
     if (txtKeyId.Text.Length == 0)
     {
         lblMessage.Text = "Please enter key id.";
         return;
     }
     if (txtLabelId.Text.Length == 0)
     {
         lblMessage.Text = "Please enter Label id.";
         return;
     }
     string accessTokenRedirectUrl = string.Empty;
     string apiPostUrl = string.Empty;
     string responseText = string.Empty;
     string recordId = txtRecordId.Text;
     string keyId = txtKeyId.Text;
     string labelId = txtLabelId.Text;
     oAuth = new oAuthDossia();
     //Authorize and use this token and secret to get the Access Token
     oAuth.AccessTokenGet();
     //check the length is greather then 0
     if (oAuth.Token.Length > 0 && oAuth.TokenSecret.Length > 0)
     {
         try
         {
             //set the request API url
             apiPostUrl = oAuthDossia.DOSSIA_API_URL + "records/" + recordId + "/apps/documents/key/" + keyId + "/label/" + labelId;
             //get the access token url
             accessTokenRedirectUrl = oAuth.AccessToAPILink(apiPostUrl, oAuth.Token, oAuth.TokenSecret, oAuthDossia.Method.POST.ToString());
             //do the request and get the response,If any error is there it will throw the error
             responseText = oAuth.MakePostRequest(accessTokenRedirectUrl, fileUploader.FileBytes, fileUploader.PostedFile.ContentType);
             //set the response value
             txtDossiaAPIResponse.Text = responseText;
             //clear session
             clearSession();
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
     else
     {
         Response.Redirect("APITest.aspx", false);
     }
 }
    protected void btnPost_Click(object sender, EventArgs e)
    {
        if (txtDossiaAPIInputRequest.Text.Length == 0)
        {
            lblMessage.Text = "Please enter the Input";
            lblMessage.Visible = true;
            return;
        }
        if(txtDocumentId.Text.Length == 0)
        {
            lblMessage.Text ="please enter documentId.";
            lblMessage.Visible = true;
            return;
        }
        if(txtRecordId.Text.Length == 0)
        {
            lblMessage.Text = "please enter recordId.";
            lblMessage.Visible = true;
            return;
        }

        string accessTokenRedirectUrl = string.Empty;
        string apiPostUrl = string.Empty;
        string responseText = string.Empty;
        string recordId = txtRecordId.Text;
        string documentId = txtDocumentId.Text;
        oAuth = new oAuthDossia();       
        //Authorize and use the set the token and secret to get the access token
        oAuth.AccessTokenGet();
        //check the lenght is greather then 0
        if (oAuth.Token.Length > 0 && oAuth.TokenSecret.Length > 0)
        {
            try
            {   
                //set the request API url
                apiPostUrl = oAuthDossia.DOSSIA_API_URL + "records/" + recordId + "/documents/" + documentId + "/rels/related";
                //get the access token url
                accessTokenRedirectUrl = oAuth.AccessToAPILink(apiPostUrl, oAuth.Token, oAuth.TokenSecret, oAuthDossia.Method.POST.ToString());
                //do the request and get the response
                //If any error is there it will throw the error
                responseText = oAuth.MakePostRequest(accessTokenRedirectUrl, txtDossiaAPIInputRequest.Text);
                //set the response value
                txtDossiaAPIResponse.Text = responseText;
                //clear session
                clearSession();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        else
        {
            Response.Redirect("APITest.aspx", false);
        }
    }
예제 #5
0
    protected void btnRetrive_Click(object sender, EventArgs e)
    {
        string accessTokenRedirectUrl = string.Empty;
        string apiGetUrl = string.Empty;
        string getRecordUrl = string.Empty;
        string responseText = string.Empty;

        oAuth = new oAuthDossia();
        if (txtRecordId.Text.Length < 0)
        {
            lblMessage.Text = "Please enter record id.";
            lblMessage.Visible = true;
            return;
        }
        if (txtDocumentId.Text.Length < 0)
        {
            lblMessage.Text = "Please enter document id.";
            lblMessage.Visible = true;
            return;
        }
        string recordId = txtRecordId.Text;
        string documentId = txtDocumentId.Text;

        //Authorize and use the set the token and secret to get the new access token
        oAuth.AccessTokenGet();

        if (oAuth.Token.Length > 0 && oAuth.TokenSecret.Length > 0)
        {
            try
            {                    
                //generate the API url
                apiGetUrl = oAuthDossia.DOSSIA_API_URL + "records/" + recordId + "/documents/" + documentId + "/versions";
                //get the access to API url
                accessTokenRedirectUrl = oAuth.AccessToAPILink(apiGetUrl, oAuth.Token, oAuth.TokenSecret, oAuthDossia.Method.GET.ToString());
                //do the request and set the response to text
                responseText = oAuth.MakeWebRequest(accessTokenRedirectUrl);
                this.txtDossiaAPIResponse.Text = responseText;
                clearSession();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        else
        {
            Response.Redirect("APITest.aspx", false);
        }
        
    }
    protected void btnDeleteDocument_Click(object sender, EventArgs e)
    {
        if (txtRecordId.Text.Length == 0)
        {
            lblMessage.Text = "please enter the record id.";
        }
        else if (txtKeyId.Text.Length == 0)
        {
            lblMessage.Text = "please enter the key id.";
        }
        else
        {
            string accessTokenRedirectUrl = string.Empty;
            string apiGetUrl;
            string getRecordUrl = string.Empty;
            string responseText = string.Empty;

            string recordId = txtRecordId.Text;
            string keyId = txtKeyId.Text;
            oAuth = new oAuthDossia();

            //Authorize and use the token and secret to get the new access token
            oAuth.AccessTokenGet();

            if (oAuth.Token.Length > 0 && oAuth.TokenSecret.Length > 0)
            {
                try
                {
                   
                    //generate the API url
                    apiGetUrl = oAuthDossia.DOSSIA_API_URL + "records/" + recordId + "/apps/documents/key" + keyId;
                    //get the access to API url
                    accessTokenRedirectUrl = oAuth.AccessToAPILink(apiGetUrl, oAuth.Token, oAuth.TokenSecret, oAuthDossia.Method.DELETE.ToString());
                    //do the request and set the response to text
                    responseText = oAuth.MakeRequest(accessTokenRedirectUrl, oAuthDossia.Method.DELETE.ToString());
                    this.txtDossiaAPIResponse.Text = responseText;
                    clearSession();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                Response.Redirect("APITest.aspx", false);
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["oauth_token"] == null)
        {
            oAuth = new oAuthDossia();
            Response.Redirect(oAuth.GetTokens());
        }
        else if (!Page.IsPostBack)
        {        
            string accessTokenRedirectUrl = string.Empty;
            string apiGetUrl;
            string getRecordUrl = string.Empty;
            string responseText = string.Empty;

            oAuth = new oAuthDossia();
            //Authorize and use the token and secret to get the access token
            oAuth.AccessTokenGet();
            if (oAuth.Token.Length > 0 && oAuth.TokenSecret.Length > 0)
            {
                try
                {
                    apiGetUrl = oAuthDossia.DOSSIA_API_URL + "records";
                    //get the access to API url
                    accessTokenRedirectUrl = oAuth.AccessToAPILink(apiGetUrl, oAuth.Token, oAuth.TokenSecret, oAuthDossia.Method.GET.ToString());
                    //do the request and set the response to text
                    responseText = oAuth.MakeWebRequest(accessTokenRedirectUrl);
                    this.txtDossiaAPIResponse.Text = responseText;
                    clearSession();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                Response.Redirect("APITest.aspx", false);
            }
        }   
    }
    protected void btnRetriveAppDoc_Click(object sender, EventArgs e)
    {
        if (txtRecordId.Text.Length == 0)
        {
            lblMessage.Text = "please enter record Id.";
            lblMessage.Visible = true;
            return;
        }
        if (txtLabelId.Text.Length == 0)
        {
            lblMessage.Text = "please enter label id.";
            lblMessage.Visible = true;
            return;
        }
        string accessTokenRedirectUrl = string.Empty;
        string apiGetUrl;
        string getRecordUrl = string.Empty;
        string responseText = string.Empty;
        string recordId = txtRecordId.Text;
        string labelId = txtLabelId.Text;
        oAuth = new oAuthDossia();

        //Authorize and use the token and secret to get the new access token
        oAuth.AccessTokenGet();

        if (oAuth.Token.Length > 0 && oAuth.TokenSecret.Length > 0)
        {
            try
            {
                string contentType;
                byte[] outputData;

                //[section 1] Create a Application Document.
                string physicalPath = HttpContext.Current.Request.MapPath(HttpContext.Current.Request.ApplicationPath);

                //Read the binary data.
                FileStream fs = new FileStream(physicalPath + @"\InputFile\DossiaAPI_ServerError.jpg", FileMode.Open, FileAccess.Read);
                byte[] byteData = new byte[fs.Length];
                fs.Read(byteData, 0, (int)fs.Length);
                fs.Close();

                //set the request API url
                string apiPostUrl = oAuthDossia.DOSSIA_API_URL + "records/" + recordId + "/apps/documents/label/" + labelId;
                //get the access token url
                accessTokenRedirectUrl = oAuth.AccessToAPILink(apiPostUrl, oAuth.Token, oAuth.TokenSecret, oAuthDossia.Method.POST.ToString());
                //do the request and get the response,If any error is there it will throw the error
                responseText = oAuth.MakePostRequest(accessTokenRedirectUrl, byteData, @"image/jpg");

                //Create XMlDocumnet out of Response Text
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(responseText);

                //get Document ID
                string DocId = xmlDoc.GetElementsByTagName("api:container")[0].ChildNodes[0].Attributes["id"].Value;


                //[section 2] Get the doucment by Document ID.
                //generate the API url
                apiGetUrl = oAuthDossia.DOSSIA_API_URL + "records/" + recordId + "/apps/documents/" + DocId;
                //get the access to API url
                accessTokenRedirectUrl = oAuth.AccessToAPILink(apiGetUrl, oAuth.Token, oAuth.TokenSecret, oAuthDossia.Method.GET.ToString());
                //do the request and set the response to text
                responseText = oAuth.MakeWebRequest(accessTokenRedirectUrl, out contentType,out outputData);

                //Save the response in the FileStream.
                fs = new FileStream(physicalPath + @"\output." + contentType.Split('/')[1], FileMode.Create, FileAccess.ReadWrite);
                fs.Write(outputData, 0, outputData.Length);
                fs.Close();

                //Display the path of the file to the user.
                this.txtDossiaAPIResponse.Text = "Binary file is saved at: " + fs.Name;
                clearSession();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        else
        {
            Response.Redirect("APITest.aspx", false);
        }
        
    }
    protected void btnPost_Click(object sender, EventArgs e)
    {
        if (txtDossiaAPIInputRequest.Text.Length == 0)
        {
            lblMessage.Text = "Please enter the Input";
            lblMessage.Visible = true;
            return;
        }
        if (!fileUploader.HasFile)
        {
            lblMessage.Text = "Please upload a file";
            lblMessage.Visible = true;
            return;
        }
        if (txtRecordId.Text.Length == 0)
        {
            lblMessage.Text = "Please enter the record Id.";
            lblMessage.Visible = true;
            return;
        }

        string accessTokenRedirectUrl = string.Empty;
        string apiPostUrl = string.Empty;
        string responseText = string.Empty;
        string recordId = txtRecordId.Text;
        oAuth = new oAuthDossia();
        //Authorize and use this token and secret to get the Access Token
        oAuth.AccessTokenGet();
        //check the length is greather then 0
        if (oAuth.Token.Length > 0 && oAuth.TokenSecret.Length > 0)
        {
            try
            {
                //set the request API url
                apiPostUrl = oAuthDossia.DOSSIA_API_URL + "records/" + recordId + "/documents";
                //get the access token url
                accessTokenRedirectUrl = oAuth.AccessToAPILink(apiPostUrl, oAuth.Token, oAuth.TokenSecret, oAuthDossia.Method.POST.ToString());
                //do the request and get the response,If any error is there it will throw the error
                responseText = oAuth.MakePostRequest(accessTokenRedirectUrl, txtDossiaAPIInputRequest.Text);

                //Create XMlDocumnet out of Response Text
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(responseText);

                string DocId = xmlDoc.GetElementsByTagName("api:container")[0].ChildNodes[0].Attributes["id"].Value;
                //set the request API url
                apiPostUrl = oAuthDossia.DOSSIA_API_URL + "records/" + recordId + "/documents/" + DocId + "/binary";
                //get the access token url
                accessTokenRedirectUrl = oAuth.AccessToAPILink(apiPostUrl, oAuth.Token, oAuth.TokenSecret, oAuthDossia.Method.POST.ToString());
                //do the request and get the response,If any error is there it will throw the error
                responseText = oAuth.MakePostRequest(accessTokenRedirectUrl, fileUploader.FileBytes, fileUploader.PostedFile.ContentType);

                //set the response value
                txtDossiaAPIResponse.Text = responseText + " with Document Id: " + DocId;
                //clear session
                clearSession();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        else
        {
            Response.Redirect("APITest.aspx", false);
        }
    }