endpoint implementation ...

This commit is contained in:
2026-11-19 18:09:12 +03:30
parent 8c3f4dd55c
commit 53a2295225
7 changed files with 7597 additions and 60 deletions
+25 -34
View File
@@ -1,35 +1,26 @@
{ {
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
// Use IntelliSense to find out which attributes exist for C# debugging "name": "xApi",
// Use hover for the description of the existing attributes "type": "coreclr",
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md. "request": "launch",
"name": ".NET Core Launch (web)", "preLaunchTask": "build",
"type": "coreclr", "program": "${workspaceFolder}/xApi/bin/Debug/net8.0/xApi.dll",
"request": "launch", "args": [],
"preLaunchTask": "build", "cwd": "${workspaceFolder}/xApi",
// If you have changed target frameworks, make sure to update the program path. "stopAtEntry": false,
"program": "${workspaceFolder}/xApi/bin/Debug/net8.0/xApi.dll", "serverReadyAction": {
"args": [], "uriFormat": "%s/swagger",
"cwd": "${workspaceFolder}/xApi", "action": "openExternally",
"stopAtEntry": false, "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser },
"serverReadyAction": { "env": {
"action": "openExternally", "ASPNETCORE_ENVIRONMENT": "Development"
"pattern": "\\bNow listening on:\\s+(https?://\\S+)" },
}, "sourceFileMap": {
"env": { "/Views": "${workspaceFolder}/Views"
"ASPNETCORE_ENVIRONMENT": "Development" }
}, }
"sourceFileMap": { ]
"/Views": "${workspaceFolder}/Views" }
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
-24
View File
@@ -12,30 +12,6 @@
"/consoleloggerparameters:NoSummary;ForceNoAlign" "/consoleloggerparameters:NoSummary;ForceNoAlign"
], ],
"problemMatcher": "$msCompile" "problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/xApi/xApi.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/xApi/xApi.csproj"
],
"problemMatcher": "$msCompile"
} }
] ]
} }
File diff suppressed because it is too large Load Diff
+99
View File
@@ -0,0 +1,99 @@
{
"count": 10,
"value": [
{
"id": "06e1cb35-82e4-46a7-9132-07e0b703945a",
"name": "تخصیص خودرو بانک ملت",
"url": "http://192.168.10.22:8080/tfs/RPKavoshDevOps/_apis/projects/06e1cb35-82e4-46a7-9132-07e0b703945a",
"state": "wellFormed",
"revision": 1655,
"visibility": "private",
"lastUpdateTime": "2026-07-18T07:24:09.723Z"
},
{
"id": "366738e5-9d79-4656-bac6-20ffc02a139d",
"name": "Dem",
"description": "اعتبارات بانک ملت",
"url": "http://192.168.10.22:8080/tfs/RPKavoshDevOps/_apis/projects/366738e5-9d79-4656-bac6-20ffc02a139d",
"state": "wellFormed",
"revision": 1124,
"visibility": "private",
"lastUpdateTime": "2024-02-15T07:55:47.197Z"
},
{
"id": "ca2e302b-bf67-4724-b5e2-aec5e38aef81",
"name": "انبارداری بانک ملی(سمام)",
"url": "http://192.168.10.22:8080/tfs/RPKavoshDevOps/_apis/projects/ca2e302b-bf67-4724-b5e2-aec5e38aef81",
"state": "wellFormed",
"revision": 1559,
"visibility": "private",
"lastUpdateTime": "2026-05-19T11:10:39.243Z"
},
{
"id": "8743025b-340d-4f6b-ae38-49b91b0c9550",
"name": "اموال و انبار اداره ساختمان بانک ملت",
"description": "بانک ملت",
"url": "http://192.168.10.22:8080/tfs/RPKavoshDevOps/_apis/projects/8743025b-340d-4f6b-ae38-49b91b0c9550",
"state": "wellFormed",
"revision": 1547,
"visibility": "private",
"lastUpdateTime": "2026-05-19T10:18:27.96Z"
},
{
"id": "e06edf93-fb99-41b6-a2b5-00abdfb25e1e",
"name": "اموال و انبار بانک دی",
"url": "http://192.168.10.22:8080/tfs/RPKavoshDevOps/_apis/projects/e06edf93-fb99-41b6-a2b5-00abdfb25e1e",
"state": "wellFormed",
"revision": 1573,
"visibility": "private",
"lastUpdateTime": "2026-05-21T16:56:08.743Z"
},
{
"id": "39d89526-c3e4-4ab3-ac8f-e5f10fb06c72",
"name": "اموال و انبار بانک ملت",
"url": "http://192.168.10.22:8080/tfs/RPKavoshDevOps/_apis/projects/39d89526-c3e4-4ab3-ac8f-e5f10fb06c72",
"state": "wellFormed",
"revision": 1493,
"visibility": "private",
"lastUpdateTime": "2026-05-03T07:49:31.78Z"
},
{
"id": "3e7694be-8e6f-49e9-9c3f-9a6399a95ea5",
"name": "سامانه اعتبارات",
"url": "http://192.168.10.22:8080/tfs/RPKavoshDevOps/_apis/projects/3e7694be-8e6f-49e9-9c3f-9a6399a95ea5",
"state": "wellFormed",
"revision": 1596,
"visibility": "private",
"lastUpdateTime": "2026-06-08T09:39:16.443Z"
},
{
"id": "9bf097a0-15a6-495d-b8f0-bf7d8e631461",
"name": "Infrastructure Bizagi Extension",
"description": "پروژه زیرساخت و شبکه شرکت رایان پرداز کاوش",
"url": "http://192.168.10.22:8080/tfs/RPKavoshDevOps/_apis/projects/9bf097a0-15a6-495d-b8f0-bf7d8e631461",
"state": "wellFormed",
"revision": 1732,
"visibility": "private",
"lastUpdateTime": "2026-09-19T05:45:47.073Z"
},
{
"id": "1ae798a4-3b76-43bb-8ae2-71a827b39a2d",
"name": "SAJAK",
"description": "شناسایی و بهبود فرآیندهای املاک ( سازمان ثبت اسناد و املاک کشور)",
"url": "http://192.168.10.22:8080/tfs/RPKavoshDevOps/_apis/projects/1ae798a4-3b76-43bb-8ae2-71a827b39a2d",
"state": "wellFormed",
"revision": 1742,
"visibility": "private",
"lastUpdateTime": "2026-11-03T10:56:20.9Z"
},
{
"id": "33b3180c-c161-478f-a792-9b1ec36f3bcd",
"name": "Issue Tracker",
"url": "http://192.168.10.22:8080/tfs/RPKavoshDevOps/_apis/projects/33b3180c-c161-478f-a792-9b1ec36f3bcd",
"state": "wellFormed",
"revision": 1743,
"visibility": "private",
"lastUpdateTime": "2026-11-19T04:43:21.52Z"
}
]
}
+358
View File
@@ -0,0 +1,358 @@
using xApi.Models;
using xApi.Constants;
using xApi.Interfaces;
using xApi.Extensions;
using System.Text.Json;
using System.Net.Http.Headers;
namespace xApi.Providers
{
public class AzureServices : IAzureServices
{
//
private readonly ILogger<AzureServices> logger;
private readonly IHttpClientFactory httpClientFactory;
private readonly AzureServiceConfiguration configuration;
public AzureServices(
ILogger<AzureServices> logger,
IHttpClientFactory httpClientFactory,
AzureServiceConfiguration configuration
)
{
//
this.logger = logger;
this.configuration = configuration;
this.httpClientFactory = httpClientFactory;
}
/// <summary>
/// Retrieve Connection Info ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public async Task<AzureConnectionDataDto> GetConnectionDataAsync(
CancellationToken cancellationToken = default
)
{
//
// var json = await GetFromAzureAsync(
// AzureEndpoints.ConnectionDataEndpoint,
// cancellationToken: cancellationToken
// );
//
var json = await HandleAzureRequest(
method: HttpMethod.Get,
cancellationToken: cancellationToken,
path: AzureEndpoints.ConnectionDataEndpoint
);
//
var result = json.ParseJSON<AzureConnectionDataDto>();
if (result is null)
{
//
var message = "Failed to parse Azure connection data ...";
//
logger.LogError(message);
throw new InvalidOperationException(message);
}
//
return result;
}
public async Task<string> GetProjectsAsync(
CancellationToken cancellationToken = default
)
{
//
// var json = await GetFromAzureAsync(
// AzureEndpoints.ProjectsEndpoint,
// cancellationToken: cancellationToken
// );
//
var json = await HandleAzureRequest(
method: HttpMethod.Get,
cancellationToken: cancellationToken,
path: AzureEndpoints.ProjectsEndpoint
);
//
// var result = json.ParseJSON<AzureConnectionDataDto>();
// if (result is null)
// {
// //
// var message = "Failed to parse Azure connection data ...";
// //
// logger.LogError(message);
// throw new InvalidOperationException(message);
// }
//
return json;
}
//
#region Private ...
private async Task<string> HandleAzureRequest(
string path,
HttpMethod method,
bool forceJsonValidation = true,
IDictionary<string, string>? headers = null,
IDictionary<string, string>? queryParams = null,
IDictionary<string, string>? routeParams = null,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
var pat = configuration.Pat;
if (string.IsNullOrWhiteSpace(pat))
{
//
var message = "Azure PAT is not configured ...";
logger.LogError(message);
throw new InvalidOperationException(message);
}
if (string.IsNullOrWhiteSpace(path))
{
//
var message = "Request Path is not configured ...";
logger.LogError(message);
throw new InvalidOperationException(message);
}
//
// Create Http Client ...
var result = string.Empty;
using (HttpClient client = new())
{
//
// Add Accept ...
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
//
// Add Personal Access Token ...
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(
System.Text.Encoding.ASCII.GetBytes(
string.Format("{0}:{1}", "", pat))));
//
// Preparing Request Path ...
var url = configuration.BaseUrl;
if (!url!.EndsWith('/'))
{
url += "/";
}
if (path.StartsWith('/'))
{
path = path[1..];
}
//
// Handle Route Params ...
if (routeParams is not null &&
routeParams.Any())
{
//
var exists =
routeParams.Where(rp => path.Contains(rp.Key));
foreach (var irp in exists)
{
}
}
//
// Finalize Url ...
url = $"{url}{path}";
//
// Applying Query String ...
url = url
.ApplyQueryString(queries: queryParams);
//
// Preparing Request ...
var request = new HttpRequestMessage(
method: method,
requestUri: url
);
//
// Applying Headers ...
if (headers is not null &&
headers.Any())
{
//
foreach (var header in headers)
{
//
if (string.IsNullOrWhiteSpace(header.Value))
{
continue;
}
//
request.Headers.Add(
name: header.Key,
value: header.Value
);
}
}
//
try
{
//
using var cts = CancellationTokenSource
.CreateLinkedTokenSource(cancellationToken);
cts.CancelAfter(TimeSpan.FromSeconds(20));
//
// Execute Request ...
var response = await client.SendAsync(
request: request,
cancellationToken: cts.Token
);
//
// Validate Request ...
if (!response.IsSuccessStatusCode)
{
//
var content = await response.Content.ReadAsStringAsync(cts.Token);
//
logger.LogError("Azure returned HTTP {StatusCode}. Content: {Content} ...", response.StatusCode, content);
throw new HttpRequestException($"Azure returned HTTP {(int)response.StatusCode} ...");
}
//
// Reading Content ...
result = await response.Content.ReadAsStringAsync(cts.Token);
}
catch (TaskCanceledException ex) when (ex.InnerException is TimeoutException || !cancellationToken.IsCancellationRequested)
{
//
logger.LogError(ex, "Azure request timed out. Path: {Path} ...", path);
throw new TimeoutException("Azure request timed out ...");
}
catch (Exception ex)
{
//
logger.LogError(ex, "Could not connect to Azure. Path: {Path} ...", path);
throw;
}
}
//
// Force Json Validation ...
if (forceJsonValidation)
{
//
// Validating JSON ...
try
{
JsonDocument.Parse(result);
}
catch (JsonException ex)
{
//
logger.LogError(ex, "Azure returned non-JSON data. Path: {Path} ...", path);
throw new InvalidDataException("Azure returned non-JSON data ...");
}
}
//
return result;
}
private async Task<string> GetFromAzureAsync(
string relativePath,
CancellationToken cancellationToken = default
)
{
//
// Validate PAT ...
var pat = configuration.Pat;
if (string.IsNullOrWhiteSpace(pat))
{
//
logger.LogError("Azure PAT is not configured ...");
throw new InvalidOperationException("Azure PAT is not configured ...");
}
//
// Create Specified Http Client ...
var client = httpClientFactory.CreateClient(Params.AzureHttpClient);
//
// Url ...
var url = $"{client.BaseAddress}{relativePath}";
logger.LogInformation("Url: {url}", url);
//
// Handle Request and Response ...
try
{
//
using var cts = CancellationTokenSource
.CreateLinkedTokenSource(cancellationToken);
cts.CancelAfter(TimeSpan.FromSeconds(20));
//
var response = await client.GetAsync(relativePath, cts.Token);
if (!response.IsSuccessStatusCode)
{
//
var content = await response.Content.ReadAsStringAsync(cts.Token);
logger.LogError("Azure returned HTTP {StatusCode}. Content: {Content} ...", response.StatusCode, content);
throw new HttpRequestException($"Azure returned HTTP {(int)response.StatusCode} ...");
}
//
// Reading Content ...
var json = await response.Content.ReadAsStringAsync(cts.Token);
//
// Validating JSON ...
try
{
JsonDocument.Parse(json);
}
catch (JsonException ex)
{
//
logger.LogError(ex, "Azure returned non-JSON data. Path: {Path} ...", relativePath);
throw new InvalidDataException("Azure returned non-JSON data ...");
}
//
return json;
}
catch (TaskCanceledException ex) when (ex.InnerException is TimeoutException || !cancellationToken.IsCancellationRequested)
{
//
logger.LogError(ex, "Azure request timed out. Path: {Path} ...", relativePath);
throw new TimeoutException("Azure request timed out ...");
}
catch (Exception ex)
{
//
logger.LogError(ex, "Could not connect to Azure. Path: {Path} ...", relativePath);
throw;
}
}
#endregion
}
}
+1 -1
View File
@@ -4,6 +4,6 @@ https://learn.microsoft.com/en-us/javascript/api/azure-devops-extension-sdk/
https://cdn.jsdelivr.net/npm/azure-devops-extension-sdk@5.0.0/SDK.min.js https://cdn.jsdelivr.net/npm/azure-devops-extension-sdk@5.0.0/SDK.min.js
https://www.jsdelivr.com/package/npm/azure-devops-extension-sdk https://www.jsdelivr.com/package/npm/azure-devops-extension-sdk
https://learn.microsoft.com/en-us/rest/api/azure/devops/?view=azure-devops-rest-7.2
curl -u {username}[:{personalaccesstoken}] http://192.168.10.22:8080/tfs/RPKavoshDevOps/_apis/projects?api-version=2.0 curl -u {username}[:{personalaccesstoken}] http://192.168.10.22:8080/tfs/RPKavoshDevOps/_apis/projects?api-version=2.0
+1 -1
Submodule xApi updated: be47468e35...bc66d86ed2