From 9caf46a2666d0bbcd457a6ef82fecf1ea93237d8 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Wed, 29 Jul 2026 09:05:36 +0330 Subject: [PATCH] fix issues and build and run Successfully ... --- Controllers/StartupController.cs | 1 + Controllers/TestIdentityController.cs | 177 ------------------ Database/XAiApiDbContext.cs | 20 +- Extensions/XProgramExtensions.cs | 5 +- Program.cs | 253 +------------------------- Properties/launchSettings.json | 27 ++- Startup.cs | 29 ++- nuget.config | 2 +- xAiApi.csproj | 6 +- xAiApi.http | 6 - 10 files changed, 66 insertions(+), 460 deletions(-) delete mode 100644 Controllers/TestIdentityController.cs delete mode 100644 xAiApi.http diff --git a/Controllers/StartupController.cs b/Controllers/StartupController.cs index 7f92301..3717c43 100644 --- a/Controllers/StartupController.cs +++ b/Controllers/StartupController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; using xCommons.Configurations; using xCommons.Controllers; using xCommons.Providers; diff --git a/Controllers/TestIdentityController.cs b/Controllers/TestIdentityController.cs deleted file mode 100644 index fa4324d..0000000 --- a/Controllers/TestIdentityController.cs +++ /dev/null @@ -1,177 +0,0 @@ -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using xCommons.Attributes; -using xCommons.Configurations; -using xCommons.Providers; -using xIdentityHelper; -using xIdentityService.Controllers; -using xIdentityService.Interfaces; - -namespace xAiApi.Controllers -{ - /// - /// Test all Authentication Policies ... - /// - [RequireXPowered(false)] - public class TestIdentityController : XBaseIdentityController - { - public TestIdentityController( - ILogger logger, - XAppConfiguration appConfiguration, - IXIdentityProvider identityProvider, - XValidationProvider validationProvider - ) : base( - logger, - appConfiguration, - identityProvider, - validationProvider - ) - { } - - // - #region Test Actions ... - /// - /// API Read Scope - /// - /// string message - [HttpGet ("PassReadAccess")] - [Authorize (Policy = XPolicies.ReadAccess)] - public ActionResult PassReadAccess () { - return Ok ("Read Access Passed ..."); - } - - /// - /// API Write Scope - /// - /// string message - [HttpGet ("PassWriteAccess")] - [Authorize (Policy = XPolicies.WriteAccess)] - public ActionResult PassWriteAccess () { - return Ok ("Write Access Passed ..."); - } - - /// - /// API Admin Scope - /// - /// string message - [HttpGet ("PassAdminAccess")] - [Authorize (Policy = XPolicies.AdminAccess)] - public ActionResult PassAdminAccess () { - return Ok ("Admin Access Passed ..."); - } - - /// - /// API Manage Scop - /// - /// string message - [HttpGet ("PassManageAccess")] - [Authorize (Policy = XPolicies.ManageAccess)] - public ActionResult PassManageAccess () { - return Ok ("Manage Access Passed ..."); - } - - /// - /// a simple Action which returns a List of Authenticated User Claims - /// - /// string message which represent current user's claims - [HttpGet ("HiClaims")] - [Authorize (Policy = XPolicies.User)] - public ActionResult HiClaims () { - // - var result = new { - name = User?.Identity?.Name, - claims = User?.Claims.Select (c => new { - c.Type, c.Value - }) - }; - - // - return Ok (result); - } - - /// - /// a simple Hello User for Checking Authentication and Policy - /// - /// string message which contains authenticated user name - [HttpGet ("HiUser")] - [Authorize (Policy = XPolicies.User)] - public ActionResult HiUser () { - // - var result = $"Hi User: {User?.Identity?.Name} ..."; - - // - return Ok (result); - } - - /// - /// a simple Hello User for Checking Authentication and Policy - /// - /// string message which contains authenticated user name - [HttpGet ("HiEnabledUser")] - [Authorize (Policy = XPolicies.EnabledUser)] - public ActionResult HiEnabledUser () { - // - var result = $"Hi User: {User?.Identity?.Name} is Enabled ..."; - - // - return Ok (result); - } - - /// - /// a simple Hello User for Checking Authentication and Policy - /// - /// string message which contains authenticated user name - [HttpGet ("HiAgent")] - [Authorize (Policy = XPolicies.Agent)] - public ActionResult HiAgent () { - // - var result = $"Hi Agent: {User?.Identity?.Name} ..."; - - // - return Ok (result); - } - - /// - /// a simple Hello User for Checking Authentication and Policy - /// - /// string message which contains authenticated user name - [HttpGet ("HiEnabledAgent")] - [Authorize (Policy = XPolicies.EnabledAgent)] - public ActionResult HiEnabledAgent () { - // - var result = $"Hi Agent: {User?.Identity?.Name} is Enabled ..."; - - // - return Ok (result); - } - - /// - /// a simple Hello User for Checking Authentication and Policy - /// - /// string message which contains authenticated user name - [HttpGet ("HiAdmin")] - [Authorize (Policy = XPolicies.Admin)] - public ActionResult HiAdmin () { - // - var result = $"Hi Admin: {User?.Identity?.Name} ..."; - - // - return Ok (result); - } - - /// - /// a simple Hello User for Checking Authentication and Policy - /// - /// string message which contains authenticated user name - [HttpGet ("HiEnabledAdmin")] - [Authorize (Policy = XPolicies.EnabledAdmin)] - public ActionResult HiEnabledAdmin () { - // - var result = $"Hi Admin: {User?.Identity?.Name} is Enabled ..."; - - // - return Ok (result); - } - #endregion - } -} \ No newline at end of file diff --git a/Database/XAiApiDbContext.cs b/Database/XAiApiDbContext.cs index a460177..1425588 100644 --- a/Database/XAiApiDbContext.cs +++ b/Database/XAiApiDbContext.cs @@ -26,18 +26,18 @@ namespace xAiApi.Database // #region Constructor ... public XAiApiDbContext( - DbContextOptions options, - XDataServiceConfiguration config, - XEntityRegisterarHandlerService dynamicEntityHandlers + DbContextOptions options, + XDataServiceConfiguration config, + XEntityRegisterarHandlerService dynamicEntityHandlers ) : base( - config: config, - options: options, - database: XAiApiConstants.XAiApiDbIdentifier, - dynamicEntityHandlers: dynamicEntityHandlers, + config: config, + options: options, + database: XAiApiConstants.XAiApiDbIdentifier, + dynamicEntityHandlers: dynamicEntityHandlers, dynamicEntityRegisterarsNames: [ - nameof(XTagEntityRegisterar), - nameof(XFileEntityRegisterar), - nameof(XStringEntityRegisterar), + nameof(XTagEntityRegisterar), + nameof(XFileEntityRegisterar), + nameof(XStringEntityRegisterar), nameof(XAiMessageEntityRegisterar), nameof(XAiProjectEntityRegisterar), nameof(XAiConversationEntityRegisterar), diff --git a/Extensions/XProgramExtensions.cs b/Extensions/XProgramExtensions.cs index 5b05153..402bd34 100644 --- a/Extensions/XProgramExtensions.cs +++ b/Extensions/XProgramExtensions.cs @@ -1,5 +1,8 @@ +using System.Collections.Generic; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.HttpOverrides; +using Microsoft.Extensions.DependencyInjection; using xCommons.Authorization; using xCommons.Extensions; using xIdentityHelper; @@ -72,9 +75,7 @@ namespace xAiApi.Extensions }; // - #pragma warning disable ASPDEPR005 // Type or member is obsolete forwardOptions.KnownNetworks.Clear(); - #pragma warning restore ASPDEPR005 // Type or member is obsolete forwardOptions.KnownProxies.Clear(); // diff --git a/Program.cs b/Program.cs index 92842c0..ef7f973 100644 --- a/Program.cs +++ b/Program.cs @@ -1,22 +1,11 @@ -// using xHttpService.DI; -// using xAiApi.Database; -// using xFileService.DI; -// using xDataService.DI; -// using xPushService.DI; -// using System.Text.Json; -// using System.Reflection; -// using xAiApi.Extensions; -// using xStringService.DI; -// using xStorageService.DI; -// using xCommons.Extensions; -// using xDataService.Models; -// using xIdentityService.DI; -// using xPushService.Helpers; -// using xCommons.Configurations; -// using System.Text.Json.Serialization; -// using IdentityModel.AspNetCore.OAuth2Introspection; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; namespace xAiApi { @@ -29,231 +18,9 @@ namespace xAiApi public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); } } - -// -#region .net 10 Standard ... -// // -// // Create Application Builder ... -// var builder = WebApplication.CreateBuilder(args); - -// // -// #region Register services ... -// // -// // Register Validation Provider and all XCommons Module Services ... -// builder.Services.AddXCommons(); - -// // -// // Register App Configuration ... -// builder.Services.AddXAppConfiguration(builder.Configuration); -// var appConfiguration = builder.Services.GetRegisteredService(); - -// // -// // Register Allowed Origins ... -// builder.Services.AddXCors(appConfiguration.AllowedOrigins); - -// // -// // Register Swagger ... -// var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; -// var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); -// builder.Services.AddXSwagger(builder.Configuration, xmlFilePath: xmlPath); - -// // -// // Register HttpService ... -// builder.Services.AddXHttpService(builder.Configuration); - -// // -// // Add Api V1 Versioning ... -// builder.Services.AddXApiV1Versioning(); - -// // -// // OAuthIntrospectin Http Client Handler ... -// // this is for handling SSLErrors ... -// builder.Services.AddHttpClient(OAuth2IntrospectionDefaults.BackChannelHttpClientName) -// .ConfigurePrimaryHttpMessageHandler(() => -// { -// return new HttpClientHandler -// { -// ServerCertificateCustomValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true -// }; -// }); - -// // -// // Register Authorizations ... -// builder.Services.AddXAuthorization(); - -// // -// // Mapping Controllers ... -// builder.Services.AddControllers() -// .AddJsonOptions(x => -// { -// // -// // Optional but recommended for .NET 8+: -// // Allows reading properties case-insensitively (e.g., "myProp" matches "MyProp") ... -// x.JsonSerializerOptions.PropertyNameCaseInsensitive = true; - -// // -// // This tells STJ to ignore circular references instead of throwing an exception ... -// x.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles; - -// // -// // Camel Case Naming Policy ... -// x.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; -// }); - -// // -// var lifeTime = ServiceLifetime.Scoped; -// var repositoryType = xDataService.Constants.XRepositoryType.EF; - -// // -// // Register XIdentity Service ... -// builder.Services.AddXIdentityService( -// lifeTime: lifeTime, -// configuration: builder.Configuration -// ); - -// // -// // Storage Service ... -// builder.Services.AddXStorageService(builder.Configuration); - -// // -// // Push Service ... -// builder.Services.AddXPushService( -// lifeTime: lifeTime, -// config: builder.Configuration -// ); - -// // -// // Preparing DataBases ... -// var databases = new List -// { -// // -// // Introduce Ai Api Descriptor ... -// new XAiApiDatabaseDescriptor() -// }; -// if (databases.HasChild()) -// { -// // -// databases -// .ToList() -// .ForEach(database => -// { -// // -// // Register DataBase ... -// builder.Services.AddXDatabase( -// lifeTime: lifeTime, -// descriptor: database, -// configuration: builder.Configuration -// ); -// }); -// } - -// // -// // Register String Service ... -// builder.Services.AddXStringService( -// lifeTime: lifeTime, -// repositoryType: repositoryType -// ); - -// // -// // Register File Service ... -// builder.Services.AddXFileService( -// lifeTime: lifeTime, -// repositoryType: repositoryType -// ); -// #endregion - -// // -// // Creating Application ... -// var app = builder.Build(); - -// // -// #region Using Middlewares ... -// // -// // Configure the HTTP request pipeline. -// var isDevelopmentEnvironment = false; -// if (app.Environment.IsDevelopment()) -// { -// isDevelopmentEnvironment = true; -// app.UseDeveloperExceptionPage(); -// } - -// // -// // Use Swagger Middleware ... -// app.UseXSwagger(); - -// // -// // Force Https Redirection ... -// app.UseHttpsRedirection(); - -// // -// // Using Cors ... -// app.UseXCors(); - -// // -// // Using Routing ... -// app.UseRouting(); - -// // -// // Use xIdentityService ... -// app.UseXIdentityService(); - -// // -// // Use Authorization ... -// app.UseAuthorization(); - -// // -// // Using Endpoints ... -// app.UseEndpoints(endpoints => -// { -// _ = endpoints.MapControllers(); -// }); - -// // -// // Use Storage Service ... -// app.UseXStorageService(); - -// // -// // Using DataBase ... -// if (databases.HasChild()) -// { -// // -// databases -// .ToList() -// .ForEach(database => -// { -// // -// app.UseXDatabase( -// descriptor: database, -// isDevelopmentEnvironment: isDevelopmentEnvironment -// ); -// }); -// } - -// // -// // Use PushService ... -// var pushHelper = new XPushServiceHelper(); -// app.UseXPushService(pushHelper); - -// // -// // Using String Service ... -// app.UseXStringService( -// isDevelopmentEnvironment: isDevelopmentEnvironment -// ); - -// // -// // Using File Service ... -// app.UseXFileService( -// isDevelopmentEnvironment: isDevelopmentEnvironment -// ); -// #endregion - -// // -// // Runing Application ... -// app.Run(); -#endregion \ No newline at end of file diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json index 85a589a..6db5b65 100644 --- a/Properties/launchSettings.json +++ b/Properties/launchSettings.json @@ -1,20 +1,27 @@ { - "$schema": "https://json.schemastore.org/launchsettings.json", + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:6636", + "sslPort": 44322 + } + }, "profiles": { - "http": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": false, - "applicationUrl": "http://localhost:5012", + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "weatherforecast", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, - "https": { + "xAiApi": { "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": false, - "applicationUrl": "https://localhost:6001;http://localhost:6000;https://0.0.0.0:6001;", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "applicationUrl": "https://localhost:5001;http://localhost:5000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/Startup.cs b/Startup.cs index 079dab6..c362289 100644 --- a/Startup.cs +++ b/Startup.cs @@ -1,31 +1,45 @@ +using System; +using System.IO; +using System.Linq; using xTagService.DI; -using xHttpService.DI; +using System.Net.Http; using xAiApi.Database; +using xHttpService.DI; +using xPushService.DI; using xFileService.DI; using xDataService.DI; -using xPushService.DI; using Newtonsoft.Json; using System.Reflection; using xAiApi.Extensions; using xStringService.DI; using xStorageService.DI; -using xCommons.Extensions; -using xDataService.Models; using xIdentityService.DI; -using xPushService.Helpers; +using xDataService.Models; +using xCommons.Extensions; using xCommons.Configurations; +using System.Collections.Generic; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; using Newtonsoft.Json.Serialization; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using IdentityModel.AspNetCore.OAuth2Introspection; +using xPushService.Helpers; namespace xAiApi { public class Startup { // + #region Props ... public IConfiguration Configuration { get; } private readonly List databases; private readonly XAiApiDatabaseDescriptor apiDatabaseDescriptor; + #endregion + // + #region Constructor(s) ... public Startup(IConfiguration configuration) { // @@ -39,6 +53,7 @@ namespace xAiApi apiDatabaseDescriptor }; } + #endregion public void ConfigureServices(IServiceCollection services) { @@ -200,7 +215,7 @@ namespace xAiApi // // Use Storage Service ... app.UseXStorageService(); - + // // Use PushService ... var pushHelper = new XPushServiceHelper(); @@ -242,4 +257,4 @@ namespace xAiApi ); } } -} \ No newline at end of file +} diff --git a/nuget.config b/nuget.config index 394df7c..632defe 100644 --- a/nuget.config +++ b/nuget.config @@ -2,6 +2,6 @@ - + \ No newline at end of file diff --git a/xAiApi.csproj b/xAiApi.csproj index 7e8d366..790473d 100644 --- a/xAiApi.csproj +++ b/xAiApi.csproj @@ -3,14 +3,12 @@ 1.0.0 - enable 12.0 Hadi Khazaee Asl SaherElm IT Center xSaherElm.xAiApi - enable - - net8.0 + + netcoreapp3.1 a WebAPI Project which contains all Business Logic of xSaherElm Project's AI. diff --git a/xAiApi.http b/xAiApi.http deleted file mode 100644 index 1512eca..0000000 --- a/xAiApi.http +++ /dev/null @@ -1,6 +0,0 @@ -@xAiApi_HostAddress = http://localhost:5012 - -GET {{xAiApi_HostAddress}}/weatherforecast/ -Accept: application/json - -###