/// <summary>
        /// Create Build Definition
        /// </summary>
        /// <param name="json"></param>
        /// <param name="project"></param>
        /// <param name="selectedTemplate"></param>
        /// <returns></returns>
        public string[] CreateBuildDefinition(string json, string project, string selectedTemplate)
        {
            try
            {
                BuildGetListofBuildDefinitionsResponse.Definitions viewModel = new BuildGetListofBuildDefinitionsResponse.Definitions();
                using (var client = GetHttpClient())
                {
                    string uuid = Guid.NewGuid().ToString();
                    uuid = uuid.Substring(0, 8);
                    json = json.Replace("$UUID$", uuid);

                    var jsonContent = new StringContent(json, Encoding.UTF8, "application/json");
                    var method      = new HttpMethod("POST");

                    string uri = "";
                    uri = _configuration.UriString + project + "/_apis/build/definitions?api-version=" + _configuration.VersionNumber;
                    var request = new HttpRequestMessage(method, uri)
                    {
                        Content = jsonContent
                    };
                    var response = client.SendAsync(request).Result;

                    if (response.IsSuccessStatusCode)
                    {
                        string result    = response.Content.ReadAsStringAsync().Result;
                        string buildId   = JObject.Parse(result)["id"].ToString();
                        string buildName = JObject.Parse(result)["name"].ToString();
                        return(new string[] { buildId, buildName });
                    }
                    else
                    {
                        var    errorMessage = response.Content.ReadAsStringAsync();
                        string error        = Utility.GeterroMessage(errorMessage.Result.ToString());
                        this.LastFailureMessage = error;
                        return(new string[] { });
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Debug(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + "CreateBuildDefinition" + "\t" + ex.Message + "\t" + "\n" + ex.StackTrace + "\n");
            }
            return(new string[] { });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create Build Definition
        /// </summary>
        /// <param name="json"></param>
        /// <param name="project"></param>
        /// <param name="SelectedTemplate"></param>
        /// <returns></returns>
        public string[] CreateBuildDefinition(string json, string project, string SelectedTemplate)
        {
            BuildGetListofBuildDefinitionsResponse.Definitions viewModel = new BuildGetListofBuildDefinitionsResponse.Definitions();
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _credentials);

                var    jsonContent = new StringContent(json, Encoding.UTF8, "application/json");
                var    method      = new HttpMethod("POST");
                string uri         = "";
                if (SelectedTemplate == "SmartHotel360")
                {
                    uri = _configuration.UriString + project + "/_apis/build/definitions?api-version=4.1-preview";
                }
                else
                {
                    uri = _configuration.UriString + project + "/_apis/build/definitions?api-version=" + _configuration.VersionNumber;
                }
                var request = new HttpRequestMessage(method, uri)
                {
                    Content = jsonContent
                };
                var response = client.SendAsync(request).Result;

                if (response.IsSuccessStatusCode)
                {
                    string result    = response.Content.ReadAsStringAsync().Result;
                    string buildId   = JObject.Parse(result)["id"].ToString();
                    string buildName = JObject.Parse(result)["name"].ToString();
                    return(new string[] { buildId, buildName });
                }
                else
                {
                    var    errorMessage = response.Content.ReadAsStringAsync();
                    string error        = Utility.GeterroMessage(errorMessage.Result.ToString());
                    this.lastFailureMessage = error;
                    return(new string[] { string.Empty, string.Empty });
                }
            }
            // return -1;
        }
Exemplo n.º 3
0
        public BuildGetListofBuildDefinitionsResponse.Definitions GetListOfBuildDefinitions(string project)
        {
            BuildGetListofBuildDefinitionsResponse.Definitions viewModel = new BuildGetListofBuildDefinitionsResponse.Definitions();

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(_configuration.UriString);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);

                HttpResponseMessage response = client.GetAsync(project + "/_apis/build/definitions?api-version=2.0").Result;

                if (response.IsSuccessStatusCode)
                {
                    viewModel = response.Content.ReadAsAsync <BuildGetListofBuildDefinitionsResponse.Definitions>().Result;
                }

                viewModel.HttpStatusCode = response.StatusCode;

                return(viewModel);
            }
        }