Loading CodeBeamer/CodeBeamer.sln +1 −1 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.10.35004.147 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeBeamer", "CodeBeamer\CodeBeamer.csproj", "{C1A32694-564E-4E82-9303-A4F0C60E819E}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Codebeamer", "Codebeamer\Codebeamer.csproj", "{C1A32694-564E-4E82-9303-A4F0C60E819E}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "..\Common\Common\Common.csproj", "{147DFD08-C22C-4E4E-9031-0A3041DC317F}" EndProject Loading CodeBeamer/CodeBeamer/CodeBeamer.csproj +3 −4 Original line number Diff line number Diff line Loading @@ -7,10 +7,9 @@ <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <NeutralLanguage>en</NeutralLanguage> <PlatformTarget>x64</PlatformTarget> <LangVersion>latestmajor</LangVersion> <GeneratePackageOnBuild>true</GeneratePackageOnBuild> <Title>CodeBeamer</Title> <Title>Codebeamer</Title> <UserSecretsId>f492f7c3-a156-472a-9728-c806d505ebc7</UserSecretsId> </PropertyGroup> Loading @@ -27,8 +26,8 @@ </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.4" /> </ItemGroup> <ItemGroup> Loading CodeBeamer/CodeBeamer/Control/CB.cs +22 −3 Original line number Diff line number Diff line Loading @@ -6,8 +6,8 @@ using System.Text; using Common.Models.Data.Parameter; using Common.Utilities.Handler; namespace CodeBeamer.Control; /// <summary> Class provides the '<see cref="CB"/>' handler, which allows access to the CodeBeamer-ALM-tool for adapting Tracker items. namespace Codebeamer.Control; /// <summary> Class provides the '<see cref="CB"/>' handler, which allows access to the Codebeamer ALM-tool for adapting Tracker items. /// </summary> public partial class CB : HandlerBase { Loading @@ -33,6 +33,10 @@ public partial class CB : HandlerBase /// </summary> private readonly HttpClient _client; /// <summary> Contains the Codebeamer's root url. /// </summary> private readonly string _rootURL = String.Empty; #endregion Fields #region Constructors Loading @@ -42,24 +46,39 @@ public partial class CB : HandlerBase /// <param name="timeOut"> The time in seconds to wait, when an access time out occurs (default = 1.0). </param> /// <param name="userName"> The username, which is a part of the credentials. </param> /// <param name="password"> The password, which is a part of the credentials. </param> /// <param name="rootURL"> The codebeamer's root url. </param> /// <param name="cancellation"> The cancellation object, allows immediate cancellation of background processes. </param> public CB( double timeOut, string userName, string password, string rootURL, Cancellation cancellation ) : base( timeOut, cancellation ) { this._userName = userName; this._password = password; this._rootURL = rootURL; this._client = CreateHttpClient(); } /// <summary> Constructor initializes class parameters with assigned parameter values. /// </summary> /// <param name="timeOut"> The time in seconds to wait, when an access time out occurs (default = 1.0). </param> /// <param name="userName"> The username, which is a part of the credentials. </param> /// <param name="password"> The password, which is a part of the credentials. </param> /// <param name="cancellation"> The cancellation object, allows immediate cancellation of background processes. </param> public CB( double timeOut, string userName, string password, Cancellation cancellation ) : this( timeOut, userName, password, "https://codebeamer.iavgroup.local/cb/api/v3/", cancellation ) { } #endregion Constructors #region Methods #region Client /// <summary> Creates http client for CodeBeamer connection. /// <summary> Creates http client for Codebeamer connection. /// </summary> /// <returns> Client. </returns> private HttpClient CreateHttpClient() { Loading CodeBeamer/CodeBeamer/Control/CBServices.cs +35 −18 Original line number Diff line number Diff line using CodeBeamer.Models.Tracker; using System.Net.Http; using System.Text; namespace CodeBeamer.Control; using Codebeamer.Models.Response; using Codebeamer.Models.Tracker; using Newtonsoft.Json; namespace Codebeamer.Control; // The partial implementation of the 'CB' handler, which contains the available services. public partial class CB { /// <summary> Adds elementary keyword to CodeBeamer. /// <summary> Adds an item to the Tracker of assigned identification value. /// </summary> /// <param name="trackerId"> The unique identification value of the tracker, which needs to be adapted. </param> /// <param name="trackerFields"> Keyword Tracker fields, which needs to be created. </param> /// <param name="trackerFields"> Tracker fields, which needs to be created. </param> /// <returns> The unique identification value of the created item. </returns> public int CreateElementaryKeyWordTrackerItem( int trackerId, public int AddTrackerItem( int trackerId, List<TrackerField> trackerFields ) { return AddTrackerItem( trackerId, trackerFields ); var requestUrl = String.Concat( this._rootURL, "trackers/", trackerId.ToString(), "/items" ); var jsonContent = JsonConvert.SerializeObject( new { customFields = trackerFields } ); var content = new StringContent( jsonContent, Encoding.UTF8, "application/json" ); var response = this._client.PostAsync( requestUrl, content ).Result; if ( !response.IsSuccessStatusCode ) { Console.WriteLine( $"Request failed with status code: {response.StatusCode}" ); return -1; } /// <summary> Adds an Syntax element to the CodeBeamer. /// </summary> /// <param name="trackerId"> The unique identification value of the tracker, which needs to be adapted. </param> /// <param name="trackerFields"> Syntax Tracker fields, which needs to be created. </param> /// <returns> The unique identification value of the created item. </returns> public int CreateSyntaxTrackerItem( int trackerId, List<TrackerField> trackerFields ) { return AddTrackerItem( trackerId, trackerFields ); string responseData = response.Content.ReadAsStringAsync().Result; if ( JsonConvert.DeserializeObject<PostResponse>( responseData ) is not PostResponse postResponse ) { Console.WriteLine( "Converting error occured!" ); return -1; } return postResponse.Id; } /// <summary> Clears the whole Tracker. Loading @@ -33,12 +48,12 @@ public partial class CB foreach ( int id in trackItemIds ) { var requestUrl = $"https://codebeamer.iavgroup.local/cb/api/v3/items/{id}"; var requestUrl = String.Concat( this._rootURL, "items/", id.ToString() ); var response = this._client.DeleteAsync( requestUrl ).Result; if ( !response.IsSuccessStatusCode ) { Console.WriteLine( $"Error while deleting KeyWord with id: {id}, Response: {response}" ); Console.WriteLine( $"Error while deleting Keyword with id: {id}, Response: {response}" ); return false; } Loading @@ -48,4 +63,6 @@ public partial class CB return true; } } CodeBeamer/CodeBeamer/Control/CBTracker.cs +3 −33 Original line number Diff line number Diff line using System.Net.Http; using System.Text; using CodeBeamer.Models.Response; using CodeBeamer.Models.Tracker; using Codebeamer.Models.Response; using Newtonsoft.Json; namespace CodeBeamer.Control; namespace Codebeamer.Control; // The partial implementation of the 'CB' handler, which contains common Tracker / TrackerItem functionalities. public partial class CB { Loading @@ -20,7 +18,7 @@ public partial class CB while ( true ) { string chunkUrlPart = $"/items?page={pageIndex}&pageSize={CHUNK_SIZE}"; var requestUrl = $"https://codebeamer.iavgroup.local/cb/api/v3/trackers/{trackerId}" + chunkUrlPart; var requestUrl = String.Concat( this._rootURL, "trackers/", trackerId.ToString(), chunkUrlPart ); var response = this._client.GetAsync( requestUrl ).Result; if ( !response.IsSuccessStatusCode ) Loading Loading @@ -54,32 +52,4 @@ public partial class CB return result; } /// <summary> Adds an item to the Tracker. /// </summary> /// <param name="trackerId"> The unique identification value of the tracker, which needs to be adapted. </param> /// <param name="trackerFields"> Tracker fields, which needs to be created. </param> /// <returns> The unique identification value of the created item. </returns> private int AddTrackerItem( int trackerId, List<TrackerField> trackerFields ) { var requestUrl = "https://codebeamer.iavgroup.local/cb/api/v3/trackers/157092/items"; var jsonContent = JsonConvert.SerializeObject( new { customFields = trackerFields } ); var content = new StringContent( jsonContent, Encoding.UTF8, "application/json" ); var response = this._client.PostAsync( requestUrl, content ).Result; if ( !response.IsSuccessStatusCode ) { Console.WriteLine( $"Request failed with status code: {response.StatusCode}" ); return -1; } string responseData = response.Content.ReadAsStringAsync().Result; if ( JsonConvert.DeserializeObject<PostResponse>( responseData ) is not PostResponse postResponse ) { Console.WriteLine( "Converting error occured!" ); return -1; } return postResponse.Id; } } Loading
CodeBeamer/CodeBeamer.sln +1 −1 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.10.35004.147 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeBeamer", "CodeBeamer\CodeBeamer.csproj", "{C1A32694-564E-4E82-9303-A4F0C60E819E}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Codebeamer", "Codebeamer\Codebeamer.csproj", "{C1A32694-564E-4E82-9303-A4F0C60E819E}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "..\Common\Common\Common.csproj", "{147DFD08-C22C-4E4E-9031-0A3041DC317F}" EndProject Loading
CodeBeamer/CodeBeamer/CodeBeamer.csproj +3 −4 Original line number Diff line number Diff line Loading @@ -7,10 +7,9 @@ <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <NeutralLanguage>en</NeutralLanguage> <PlatformTarget>x64</PlatformTarget> <LangVersion>latestmajor</LangVersion> <GeneratePackageOnBuild>true</GeneratePackageOnBuild> <Title>CodeBeamer</Title> <Title>Codebeamer</Title> <UserSecretsId>f492f7c3-a156-472a-9728-c806d505ebc7</UserSecretsId> </PropertyGroup> Loading @@ -27,8 +26,8 @@ </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.4" /> </ItemGroup> <ItemGroup> Loading
CodeBeamer/CodeBeamer/Control/CB.cs +22 −3 Original line number Diff line number Diff line Loading @@ -6,8 +6,8 @@ using System.Text; using Common.Models.Data.Parameter; using Common.Utilities.Handler; namespace CodeBeamer.Control; /// <summary> Class provides the '<see cref="CB"/>' handler, which allows access to the CodeBeamer-ALM-tool for adapting Tracker items. namespace Codebeamer.Control; /// <summary> Class provides the '<see cref="CB"/>' handler, which allows access to the Codebeamer ALM-tool for adapting Tracker items. /// </summary> public partial class CB : HandlerBase { Loading @@ -33,6 +33,10 @@ public partial class CB : HandlerBase /// </summary> private readonly HttpClient _client; /// <summary> Contains the Codebeamer's root url. /// </summary> private readonly string _rootURL = String.Empty; #endregion Fields #region Constructors Loading @@ -42,24 +46,39 @@ public partial class CB : HandlerBase /// <param name="timeOut"> The time in seconds to wait, when an access time out occurs (default = 1.0). </param> /// <param name="userName"> The username, which is a part of the credentials. </param> /// <param name="password"> The password, which is a part of the credentials. </param> /// <param name="rootURL"> The codebeamer's root url. </param> /// <param name="cancellation"> The cancellation object, allows immediate cancellation of background processes. </param> public CB( double timeOut, string userName, string password, string rootURL, Cancellation cancellation ) : base( timeOut, cancellation ) { this._userName = userName; this._password = password; this._rootURL = rootURL; this._client = CreateHttpClient(); } /// <summary> Constructor initializes class parameters with assigned parameter values. /// </summary> /// <param name="timeOut"> The time in seconds to wait, when an access time out occurs (default = 1.0). </param> /// <param name="userName"> The username, which is a part of the credentials. </param> /// <param name="password"> The password, which is a part of the credentials. </param> /// <param name="cancellation"> The cancellation object, allows immediate cancellation of background processes. </param> public CB( double timeOut, string userName, string password, Cancellation cancellation ) : this( timeOut, userName, password, "https://codebeamer.iavgroup.local/cb/api/v3/", cancellation ) { } #endregion Constructors #region Methods #region Client /// <summary> Creates http client for CodeBeamer connection. /// <summary> Creates http client for Codebeamer connection. /// </summary> /// <returns> Client. </returns> private HttpClient CreateHttpClient() { Loading
CodeBeamer/CodeBeamer/Control/CBServices.cs +35 −18 Original line number Diff line number Diff line using CodeBeamer.Models.Tracker; using System.Net.Http; using System.Text; namespace CodeBeamer.Control; using Codebeamer.Models.Response; using Codebeamer.Models.Tracker; using Newtonsoft.Json; namespace Codebeamer.Control; // The partial implementation of the 'CB' handler, which contains the available services. public partial class CB { /// <summary> Adds elementary keyword to CodeBeamer. /// <summary> Adds an item to the Tracker of assigned identification value. /// </summary> /// <param name="trackerId"> The unique identification value of the tracker, which needs to be adapted. </param> /// <param name="trackerFields"> Keyword Tracker fields, which needs to be created. </param> /// <param name="trackerFields"> Tracker fields, which needs to be created. </param> /// <returns> The unique identification value of the created item. </returns> public int CreateElementaryKeyWordTrackerItem( int trackerId, public int AddTrackerItem( int trackerId, List<TrackerField> trackerFields ) { return AddTrackerItem( trackerId, trackerFields ); var requestUrl = String.Concat( this._rootURL, "trackers/", trackerId.ToString(), "/items" ); var jsonContent = JsonConvert.SerializeObject( new { customFields = trackerFields } ); var content = new StringContent( jsonContent, Encoding.UTF8, "application/json" ); var response = this._client.PostAsync( requestUrl, content ).Result; if ( !response.IsSuccessStatusCode ) { Console.WriteLine( $"Request failed with status code: {response.StatusCode}" ); return -1; } /// <summary> Adds an Syntax element to the CodeBeamer. /// </summary> /// <param name="trackerId"> The unique identification value of the tracker, which needs to be adapted. </param> /// <param name="trackerFields"> Syntax Tracker fields, which needs to be created. </param> /// <returns> The unique identification value of the created item. </returns> public int CreateSyntaxTrackerItem( int trackerId, List<TrackerField> trackerFields ) { return AddTrackerItem( trackerId, trackerFields ); string responseData = response.Content.ReadAsStringAsync().Result; if ( JsonConvert.DeserializeObject<PostResponse>( responseData ) is not PostResponse postResponse ) { Console.WriteLine( "Converting error occured!" ); return -1; } return postResponse.Id; } /// <summary> Clears the whole Tracker. Loading @@ -33,12 +48,12 @@ public partial class CB foreach ( int id in trackItemIds ) { var requestUrl = $"https://codebeamer.iavgroup.local/cb/api/v3/items/{id}"; var requestUrl = String.Concat( this._rootURL, "items/", id.ToString() ); var response = this._client.DeleteAsync( requestUrl ).Result; if ( !response.IsSuccessStatusCode ) { Console.WriteLine( $"Error while deleting KeyWord with id: {id}, Response: {response}" ); Console.WriteLine( $"Error while deleting Keyword with id: {id}, Response: {response}" ); return false; } Loading @@ -48,4 +63,6 @@ public partial class CB return true; } }
CodeBeamer/CodeBeamer/Control/CBTracker.cs +3 −33 Original line number Diff line number Diff line using System.Net.Http; using System.Text; using CodeBeamer.Models.Response; using CodeBeamer.Models.Tracker; using Codebeamer.Models.Response; using Newtonsoft.Json; namespace CodeBeamer.Control; namespace Codebeamer.Control; // The partial implementation of the 'CB' handler, which contains common Tracker / TrackerItem functionalities. public partial class CB { Loading @@ -20,7 +18,7 @@ public partial class CB while ( true ) { string chunkUrlPart = $"/items?page={pageIndex}&pageSize={CHUNK_SIZE}"; var requestUrl = $"https://codebeamer.iavgroup.local/cb/api/v3/trackers/{trackerId}" + chunkUrlPart; var requestUrl = String.Concat( this._rootURL, "trackers/", trackerId.ToString(), chunkUrlPart ); var response = this._client.GetAsync( requestUrl ).Result; if ( !response.IsSuccessStatusCode ) Loading Loading @@ -54,32 +52,4 @@ public partial class CB return result; } /// <summary> Adds an item to the Tracker. /// </summary> /// <param name="trackerId"> The unique identification value of the tracker, which needs to be adapted. </param> /// <param name="trackerFields"> Tracker fields, which needs to be created. </param> /// <returns> The unique identification value of the created item. </returns> private int AddTrackerItem( int trackerId, List<TrackerField> trackerFields ) { var requestUrl = "https://codebeamer.iavgroup.local/cb/api/v3/trackers/157092/items"; var jsonContent = JsonConvert.SerializeObject( new { customFields = trackerFields } ); var content = new StringContent( jsonContent, Encoding.UTF8, "application/json" ); var response = this._client.PostAsync( requestUrl, content ).Result; if ( !response.IsSuccessStatusCode ) { Console.WriteLine( $"Request failed with status code: {response.StatusCode}" ); return -1; } string responseData = response.Content.ReadAsStringAsync().Result; if ( JsonConvert.DeserializeObject<PostResponse>( responseData ) is not PostResponse postResponse ) { Console.WriteLine( "Converting error occured!" ); return -1; } return postResponse.Id; } }