Response returned from MyMessages api
    /// <summary>
    /// Retreives the message headers based on headerCount and inderCursor
    /// </summary>
    private void GetMessageHeaders()
    {
        try
        {
            HttpWebRequest mimRequestObject1;

            mimRequestObject1 = (HttpWebRequest)WebRequest.Create(string.Empty + this.endPoint + "/rest/1/MyMessages?HeaderCount=" + txtHeaderCount.Text);
            if (!string.IsNullOrEmpty(txtIndexCursor.Text))
            {
                mimRequestObject1 = (HttpWebRequest)WebRequest.Create(string.Empty + this.endPoint + "/rest/1/MyMessages?HeaderCount=" + txtHeaderCount.Text + "&IndexCursor=" + txtIndexCursor.Text);
            }

            mimRequestObject1.Headers.Add("Authorization", "Bearer " + this.accessToken);
            mimRequestObject1.Method    = "GET";
            mimRequestObject1.KeepAlive = true;

            WebResponse mimResponseObject1 = mimRequestObject1.GetResponse();
            using (StreamReader sr = new StreamReader(mimResponseObject1.GetResponseStream()))
            {
                string mimResponseData = sr.ReadToEnd();

                JavaScriptSerializer deserializeJsonObject = new JavaScriptSerializer();
                MIMResponse          deserializedJsonObj   = (MIMResponse)deserializeJsonObject.Deserialize(mimResponseData, typeof(MIMResponse));

                if (null != deserializedJsonObj)
                {
                    this.DrawPanelForSuccess(statusPanel, string.Empty);
                    this.DisplayGrid(deserializedJsonObj.MessageHeadersList);
                }
                else
                {
                    this.DrawPanelForFailure(statusPanel, "No response from server");
                }

                sr.Close();
            }
        }
        catch (WebException we)
        {
            string errorResponse = string.Empty;

            try
            {
                using (StreamReader sr2 = new StreamReader(we.Response.GetResponseStream()))
                {
                    errorResponse = sr2.ReadToEnd();
                    sr2.Close();
                }
            }
            catch
            {
                errorResponse = "Unable to get response";
            }

            this.DrawPanelForFailure(statusPanel, errorResponse + Environment.NewLine + we.Message);
        }
        catch (Exception ex)
        {
            this.DrawPanelForFailure(statusPanel, ex.Message);
            return;
        }
    }
Beispiel #2
0
    private void GetMessageHeaders(string acctoken, string epoint, string hCount, string iCursor)
    {
        try
        {
            HttpWebRequest mimRequestObject1;

            string getHeadersURL = string.Empty + endPoint + "/rest/1/MyMessages?HeaderCount=" + hCount;
            if (!string.IsNullOrEmpty(iCursor))
            {
                getHeadersURL += "&IndexCursor=" + iCursor;
            }
            mimRequestObject1 = (HttpWebRequest)WebRequest.Create(getHeadersURL);
            mimRequestObject1.Headers.Add("Authorization", "Bearer " + accessToken);
            mimRequestObject1.Method    = "GET";
            mimRequestObject1.KeepAlive = true;

            WebResponse mimResponseObject1 = mimRequestObject1.GetResponse();
            using (StreamReader sr = new StreamReader(mimResponseObject1.GetResponseStream()))
            {
                string mimResponseData = sr.ReadToEnd();

                JavaScriptSerializer deserializeJsonObject = new JavaScriptSerializer();
                MIMResponse          deserializedJsonObj   = (MIMResponse)deserializeJsonObject.Deserialize(mimResponseData, typeof(MIMResponse));

                if (null != deserializedJsonObj)
                {
                    getHeadersSuccessResponse = "Success";
                    messageHeaderList         = deserializedJsonObj.MessageHeadersList;
                }
                else
                {
                    getHeadersErrorResponse = "No response from server";
                }

                sr.Close();
            }
        }
        catch (WebException we)
        {
            string errorResponse = string.Empty;

            try
            {
                using (StreamReader sr2 = new StreamReader(we.Response.GetResponseStream()))
                {
                    errorResponse = sr2.ReadToEnd();
                    sr2.Close();
                }
                getHeadersErrorResponse = errorResponse;
            }
            catch
            {
                errorResponse           = "Unable to get response";
                getHeadersErrorResponse = errorResponse;
            }
        }
        catch (Exception ex)
        {
            getHeadersErrorResponse = ex.Message;
            return;
        }
    }