Exemplo n.º 1
0
        /// <summary>
        /// Runs a generic JIRA REST POST with multi-part data
        /// </summary>
        /// <param name="resource">The resource we're accessing</param>
        /// <param name="argument">The URL querystring arguments</param>
        /// <param name="data">The POST multi-part data</param>
        /// <param name="method">The HTTP method</param>
        protected string RunMultiPartQuery(JiraResource resource, string argument = null, byte[] data = null, string filename = "")
        {
            string url = string.Format("{0}{1}{2}/", baseUrl, API_PATH, resource.ToString());

            if (argument != null)
            {
                url = string.Format("{0}{1}", url, argument);
            }

            //Create the request
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

            //Add headers and credentials
            request.Headers.Add("X-Atlassian-Token: nocheck");
            request.UseDefaultCredentials = this.UseDefaultCredentials;
            string base64Credentials = GetEncodedCredentials();

            request.Headers.Add("Authorization", "Basic " + base64Credentials);

            Stream          stream   = new MemoryStream(data);
            UploadFile      file     = new UploadFile(stream, "file", filename, "application/octet-stream");
            HttpWebResponse response = HttpUploadHelper.Upload(request, new UploadFile[] { file });

            string result = string.Empty;

            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                result = reader.ReadToEnd();
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Runs a query towards the JIRA REST api
        /// </summary>
        /// <param name="resource">The kind of resource to ask for</param>
        /// <param name="argument">Any argument that needs to be passed, such as a issue</param>
        /// <param name="data">More advanced data sent in POST requests</param>
        /// <param name="method">Either GET or POST</param>
        /// <returns></returns>
        protected string RunQuery(JiraResource resource, string argument = null, string data = null, string method = "GET")
        {
            string result = string.Empty;
            string url = string.Format("{0}{1}/", ConfigSetting.JiraRestApiUrl, resource);

            if (argument != null)
            {
                url = string.Format("{0}{1}", url, argument);
            }

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.ContentType = "application/json";
            request.Method = method;

            if (data != null)
            {
                using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
                {
                    writer.Write(data);
                }
            }

            string base64Credentials = GetEncodedCredentials();
            request.Headers.Add("Authorization", "Basic " + base64Credentials);

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            using (var reader = new StreamReader(response.GetResponseStream()))
            {
                result = reader.ReadToEnd();
            }

            return result;
        }
Exemplo n.º 3
0
        public List <work_item_external_ref> RunQuery(JiraResource resource, string argument = null, string data = null, string method = "GET")
        {
            SetLogin("myuser", "mypassword");

            //string url = string.Format("{0}{1}/", m_BaseUrl, resource.ToString());

            //if (argument != null)
            //{
            //    url = string.Format("{0}{1}/", url, argument);
            //}

            //string url = m_BaseUrl;

            //HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            //request.ContentType = "application/json";
            //request.Method = method;

            //if (data != null)
            //{
            //    using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
            //    {
            //        writer.Write(data);
            //    }
            //}

            //string base64Credentials = GetEncodedCredentials();
            //request.Headers.Add("Authorization", "Basic " + base64Credentials);

            //HttpWebResponse response = request.GetResponse() as HttpWebResponse;


            string result   = string.Empty;
            string filepath = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/work_item_ref_stub.txt");

            using (StreamReader reader = new StreamReader(filepath))
            {
                result = reader.ReadToEnd();
            }

            JObject apidata = JObject.Parse(result);
            JArray  NewlyReceivedWorkItems = (JArray)apidata["WorkItems"]["row"];


            List <work_item_external_ref> NewlyReceivedWorkItemsToBeShown = new List <work_item_external_ref>();

            foreach (var wkitem in NewlyReceivedWorkItems)
            {
                work_item_external_ref row = new work_item_external_ref();
                row.work_item_ext_id = (wkitem["work_item_ext_id"] == null ? "<<Not available>>" : wkitem["work_item_ext_id"].ToString());
                row.work_item_title  = (wkitem["work_item_title"] == null ? "<<Not available>>" : wkitem["work_item_title"].ToString());
                row.sprint_nm        = (wkitem["sprint_nm"] == null ? "<<Not available>>" : wkitem["sprint_nm"].ToString());
                NewlyReceivedWorkItemsToBeShown.Add(row);
            }
            return(NewlyReceivedWorkItemsToBeShown);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Runs a query towards the JIRA REST api
        /// </summary>
        /// <param name="resource">The kind of resource to ask for</param>
        /// <param name="argument">Any argument that needs to be passed, such as a project key</param>
        /// <param name="data">More advanced data sent in POST requests</param>
        /// <param name="method">Either GET or POST</param>
        /// <returns></returns>
        protected string RunQuery(
            JiraResource resource,
            string argument = null,
            string data     = null,
            string method   = "GET")
        {
            try
            {
                string url = string.Format("{0}{1}/", m_BaseUrl, resource.ToString());

                if (argument != null)
                {
                    url = string.Format("{0}{1}/", url, argument);
                }

                HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
                request.ContentType = "application/json";
                request.Method      = method;

                if (data != null)
                {
                    using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
                    {
                        writer.Write(data);
                    }
                }

                //string base64Credentials = GetEncodedCredentials();
                //request.Headers.Add("Authorization", "Basic " + base64Credentials);

                HttpWebResponse response = request.GetResponse() as HttpWebResponse;

                string result = string.Empty;
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                {
                    result = reader.ReadToEnd();
                }

                return(result);
            }
            catch (WebException exp)
            {
                throw exp;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Runs a query towards the JIRA REST api
        /// </summary>
        /// <param name="resource">The kind of resource to ask for</param>
        /// <param name="argument">Any argument that needs to be passed, such as a project key</param>
        /// <param name="data">More advanced data sent in POST requests</param>
        /// <param name="method">Either GET or POST</param>
        /// <returns></returns>
        protected string RunQuery(
            JiraResource resource, 
            string argument = null, 
            string data = null,
            string method = "GET")
        {
            try
            {
                string url = string.Format("{0}{1}/", m_BaseUrl, resource.ToString());

            if (argument != null)
            {
                url = string.Format("{0}{1}/", url, argument);
            }

            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            request.ContentType = "application/json";
            request.Method = method;

            if (data != null)
            {
                using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
                {
                    writer.Write(data);
                }
            }

            //string base64Credentials = GetEncodedCredentials();
            //request.Headers.Add("Authorization", "Basic " + base64Credentials);

            HttpWebResponse response = request.GetResponse() as HttpWebResponse;

            string result = string.Empty;
            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                result = reader.ReadToEnd();
            }

            return result;
            }
            catch (WebException exp)
            {
                throw exp;
            }
        }
        /// <summary>
        /// Runs a query towards the JIRA REST api
        /// </summary>
        /// <param name="resource">The kind of resource to ask for</param>
        /// <param name="argument">Any argument that needs to be passed, such as a project key</param>
        /// <param name="data">More advanced data sent in POST requests</param>
        /// <param name="method">Either GET or POST</param>
        /// <param name="APIBase">Base or DevStatus</param>
        /// <returns></returns>
        protected string RunQuery(JiraResource resource, APIResource apiresource, string argument = null, string data = null, string method = "GET")
        {
            string url = string.Format("{0}{1}/", m_BaseUrl, resource.ToString());

            if (argument != null)
            {
                url = string.Format("{0}{1}/", url, argument);
            }

            HttpWebRequest         request       = WebRequest.Create(url) as HttpWebRequest;
            HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);

            request.CachePolicy = noCachePolicy;
            request.ContentType = "application/json";
            request.Method      = method;

            if (data != null)
            {
                using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
                {
                    writer.Write(data);
                }
            }

            string base64Credentials = GetEncodedCredentials();

            request.Headers.Add("Authorization", "Basic " + base64Credentials);

            HttpWebResponse response = request.GetResponse() as HttpWebResponse;

            string result = string.Empty;

            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                result = reader.ReadToEnd();
            }

            return(result);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Runs a query towards the JIRA REST api
        /// </summary>
        /// <param name="resource">The kind of resource to ask for</param>
        /// <param name="argument">Any argument that needs to be passed, such as a issue</param>
        /// <param name="data">More advanced data sent in POST requests</param>
        /// <param name="method">Either GET or POST</param>
        /// <returns></returns>
        protected string RunQuery(JiraResource resource, string argument = null, string data = null, string method = "GET")
        {
            string result = string.Empty;
            string url    = string.Format("{0}{1}/", ConfigSetting.JiraRestApiUrl, resource);

            if (argument != null)
            {
                url = string.Format("{0}{1}", url, argument);
            }

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.ContentType = "application/json";
            request.Method      = method;

            if (data != null)
            {
                using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
                {
                    writer.Write(data);
                }
            }

            string base64Credentials = GetEncodedCredentials();

            request.Headers.Add("Authorization", "Basic " + base64Credentials);

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            using (var reader = new StreamReader(response.GetResponseStream()))
            {
                result = reader.ReadToEnd();
            }

            return(result);
        }
Exemplo n.º 8
0
        public JiraProject[] RunQuery(JiraResource resource, string argument = null, string data = null, string method = "GET")
        {
            string url = string.Format("{0}{1}/", m_BaseUrl, resource.ToString());

            if (argument != null)
            {
                url = string.Format("{0}{1}/", url, argument);
            }

            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            request.ContentType = "application/json";
            request.Method = method;

            if (data != null)
            {
                using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
                {
                    writer.Write(data);
                }
            }

            if (m_Username != null && m_Password != null)
            {
                string base64Credentials = GetEncodedCredentials();
                request.Headers.Add("Authorization", "Basic " + base64Credentials);
            }

            HttpWebResponse response = request.GetResponse() as HttpWebResponse;

            string result = string.Empty;
            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                result = reader.ReadToEnd();
            }

            JavaScriptSerializer js = new JavaScriptSerializer();
            JiraProject[] results = js.Deserialize<JiraProject[]>(result);
            /*
            Console.WriteLine(results);
            Console.WriteLine(results[0].id);
            Console.WriteLine(results[0].name);
            Console.WriteLine(results[0].key);

            Console.WriteLine(results[1].id);
            Console.WriteLine(results[1].name);
            Console.WriteLine(results[1].key);
            */

            foreach(JiraProject proj in results){
                Console.WriteLine(proj.id);
                Console.WriteLine(proj.key);
                Console.WriteLine(proj.name);
            }

            return results;
            //Console.WriteLine(result);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Runs a generic JIRA REST query
        /// </summary>
        /// <param name="resource">The resource we're accessing</param>
        /// <param name="argument">The URL querystring arguments</param>
        /// <param name="data">The POST data</param>
        /// <param name="method">The HTTP method</param>
        protected string RunQuery(JiraResource resource, string argument = null, string data = null, string method = "GET")
        {
            try
            {
                string url = string.Format("{0}{1}{2}/", baseUrl, API_PATH, resource.ToString());

                if (argument != null)
                {
                    url = string.Format("{0}{1}", url, argument);
                }

                HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
                request.ContentType           = "application/json";
                request.Method                = method;
                request.UseDefaultCredentials = this.UseDefaultCredentials;

                if (data != null)
                {
                    using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
                    {
                        writer.Write(data);
                    }
                }

                string base64Credentials = GetEncodedCredentials();
                request.Headers.Add("Authorization", "Basic " + base64Credentials);

                HttpWebResponse response = request.GetResponse() as HttpWebResponse;

                if (response == null)
                {
                    throw new Exception("Null Response received from JIRA API");
                }

                string result = string.Empty;
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                {
                    result = reader.ReadToEnd();
                }

                return(result);
            }
            catch (WebException webException)
            {
                //See if we have a Response
                if (webException.Response != null)
                {
                    //Log the message with response and rethrow
                    HttpWebResponse errorResponse = webException.Response as HttpWebResponse;
                    string          details       = string.Empty;
                    using (StreamReader reader = new StreamReader(errorResponse.GetResponseStream()))
                    {
                        details = reader.ReadToEnd();
                    }
                    LogErrorEvent("Web Exception Error calling JIRA REST API: '" + webException.Message + "' Details: " + details);
                    throw new ApplicationException("Web Exception Error calling JIRA REST API: '" + webException.Message + "' Details: " + details);
                }

                //Log the basic message and rethrow
                LogErrorEvent("Web Exception Error calling JIRA REST API: " + webException.Message);
                throw new ApplicationException("Web Exception Error calling JIRA REST API: " + webException.Message);
            }
            catch (Exception exception)
            {
                //Log the message and rethrow
                LogErrorEvent("Error calling JIRA REST API: " + exception.Message);
                throw exception;
            }
        }