fix issues and build and run Successfully ...

This commit is contained in:
2026-07-29 09:05:36 +03:30
parent 7dd333f013
commit 9caf46a266
10 changed files with 66 additions and 460 deletions
+1
View File
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using xCommons.Configurations; using xCommons.Configurations;
using xCommons.Controllers; using xCommons.Controllers;
using xCommons.Providers; using xCommons.Providers;
-177
View File
@@ -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
{
/// <summary>
/// Test all Authentication Policies ...
/// </summary>
[RequireXPowered(false)]
public class TestIdentityController : XBaseIdentityController
{
public TestIdentityController(
ILogger<TestIdentityController> logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider
)
{ }
//
#region Test Actions ...
/// <summary>
/// API Read Scope
/// </summary>
/// <returns>string message</returns>
[HttpGet ("PassReadAccess")]
[Authorize (Policy = XPolicies.ReadAccess)]
public ActionResult<string> PassReadAccess () {
return Ok ("Read Access Passed ...");
}
/// <summary>
/// API Write Scope
/// </summary>
/// <returns>string message</returns>
[HttpGet ("PassWriteAccess")]
[Authorize (Policy = XPolicies.WriteAccess)]
public ActionResult<string> PassWriteAccess () {
return Ok ("Write Access Passed ...");
}
/// <summary>
/// API Admin Scope
/// </summary>
/// <returns>string message</returns>
[HttpGet ("PassAdminAccess")]
[Authorize (Policy = XPolicies.AdminAccess)]
public ActionResult<string> PassAdminAccess () {
return Ok ("Admin Access Passed ...");
}
/// <summary>
/// API Manage Scop
/// </summary>
/// <returns>string message</returns>
[HttpGet ("PassManageAccess")]
[Authorize (Policy = XPolicies.ManageAccess)]
public ActionResult<string> PassManageAccess () {
return Ok ("Manage Access Passed ...");
}
/// <summary>
/// a simple Action which returns a List of Authenticated User Claims
/// </summary>
/// <returns>string message which represent current user's claims</returns>
[HttpGet ("HiClaims")]
[Authorize (Policy = XPolicies.User)]
public ActionResult<string> HiClaims () {
//
var result = new {
name = User?.Identity?.Name,
claims = User?.Claims.Select (c => new {
c.Type, c.Value
})
};
//
return Ok (result);
}
/// <summary>
/// a simple Hello User for Checking Authentication and Policy
/// </summary>
/// <returns>string message which contains authenticated user name</returns>
[HttpGet ("HiUser")]
[Authorize (Policy = XPolicies.User)]
public ActionResult<string> HiUser () {
//
var result = $"Hi User: {User?.Identity?.Name} ...";
//
return Ok (result);
}
/// <summary>
/// a simple Hello User for Checking Authentication and Policy
/// </summary>
/// <returns>string message which contains authenticated user name</returns>
[HttpGet ("HiEnabledUser")]
[Authorize (Policy = XPolicies.EnabledUser)]
public ActionResult<string> HiEnabledUser () {
//
var result = $"Hi User: {User?.Identity?.Name} is Enabled ...";
//
return Ok (result);
}
/// <summary>
/// a simple Hello User for Checking Authentication and Policy
/// </summary>
/// <returns>string message which contains authenticated user name</returns>
[HttpGet ("HiAgent")]
[Authorize (Policy = XPolicies.Agent)]
public ActionResult<string> HiAgent () {
//
var result = $"Hi Agent: {User?.Identity?.Name} ...";
//
return Ok (result);
}
/// <summary>
/// a simple Hello User for Checking Authentication and Policy
/// </summary>
/// <returns>string message which contains authenticated user name</returns>
[HttpGet ("HiEnabledAgent")]
[Authorize (Policy = XPolicies.EnabledAgent)]
public ActionResult<string> HiEnabledAgent () {
//
var result = $"Hi Agent: {User?.Identity?.Name} is Enabled ...";
//
return Ok (result);
}
/// <summary>
/// a simple Hello User for Checking Authentication and Policy
/// </summary>
/// <returns>string message which contains authenticated user name</returns>
[HttpGet ("HiAdmin")]
[Authorize (Policy = XPolicies.Admin)]
public ActionResult<string> HiAdmin () {
//
var result = $"Hi Admin: {User?.Identity?.Name} ...";
//
return Ok (result);
}
/// <summary>
/// a simple Hello User for Checking Authentication and Policy
/// </summary>
/// <returns>string message which contains authenticated user name</returns>
[HttpGet ("HiEnabledAdmin")]
[Authorize (Policy = XPolicies.EnabledAdmin)]
public ActionResult<string> HiEnabledAdmin () {
//
var result = $"Hi Admin: {User?.Identity?.Name} is Enabled ...";
//
return Ok (result);
}
#endregion
}
}
+10 -10
View File
@@ -26,18 +26,18 @@ namespace xAiApi.Database
// //
#region Constructor ... #region Constructor ...
public XAiApiDbContext( public XAiApiDbContext(
DbContextOptions options, DbContextOptions options,
XDataServiceConfiguration config, XDataServiceConfiguration config,
XEntityRegisterarHandlerService dynamicEntityHandlers XEntityRegisterarHandlerService dynamicEntityHandlers
) : base( ) : base(
config: config, config: config,
options: options, options: options,
database: XAiApiConstants.XAiApiDbIdentifier, database: XAiApiConstants.XAiApiDbIdentifier,
dynamicEntityHandlers: dynamicEntityHandlers, dynamicEntityHandlers: dynamicEntityHandlers,
dynamicEntityRegisterarsNames: [ dynamicEntityRegisterarsNames: [
nameof(XTagEntityRegisterar), nameof(XTagEntityRegisterar),
nameof(XFileEntityRegisterar), nameof(XFileEntityRegisterar),
nameof(XStringEntityRegisterar), nameof(XStringEntityRegisterar),
nameof(XAiMessageEntityRegisterar), nameof(XAiMessageEntityRegisterar),
nameof(XAiProjectEntityRegisterar), nameof(XAiProjectEntityRegisterar),
nameof(XAiConversationEntityRegisterar), nameof(XAiConversationEntityRegisterar),
+3 -2
View File
@@ -1,5 +1,8 @@
using System.Collections.Generic;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.Extensions.DependencyInjection;
using xCommons.Authorization; using xCommons.Authorization;
using xCommons.Extensions; using xCommons.Extensions;
using xIdentityHelper; using xIdentityHelper;
@@ -72,9 +75,7 @@ namespace xAiApi.Extensions
}; };
// //
#pragma warning disable ASPDEPR005 // Type or member is obsolete
forwardOptions.KnownNetworks.Clear(); forwardOptions.KnownNetworks.Clear();
#pragma warning restore ASPDEPR005 // Type or member is obsolete
forwardOptions.KnownProxies.Clear(); forwardOptions.KnownProxies.Clear();
// //
+10 -243
View File
@@ -1,22 +1,11 @@
// using xHttpService.DI; using System;
// using xAiApi.Database; using System.Collections.Generic;
// using xFileService.DI; using System.Linq;
// using xDataService.DI; using System.Threading.Tasks;
// 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 Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace xAiApi namespace xAiApi
{ {
@@ -29,231 +18,9 @@ namespace xAiApi
public static IHostBuilder CreateHostBuilder(string[] args) => public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args) Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => .ConfigureWebHostDefaults(webBuilder =>
{ {
webBuilder.UseStartup<Startup>(); webBuilder.UseStartup<Startup>();
}); });
} }
} }
//
#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<XAppConfiguration>();
// //
// // 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<XDatabaseDescriptor>
// {
// //
// // 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<XAiApiDbContext>(
// lifeTime: lifeTime,
// repositoryType: repositoryType
// );
// //
// // Register File Service ...
// builder.Services.AddXFileService<XAiApiDbContext>(
// 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
+17 -10
View File
@@ -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": { "profiles": {
"http": { "IIS Express": {
"commandName": "Project", "commandName": "IISExpress",
"dotnetRunMessages": true, "launchBrowser": true,
"launchBrowser": false, "launchUrl": "weatherforecast",
"applicationUrl": "http://localhost:5012",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }
}, },
"https": { "xAiApi": {
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "launchBrowser": true,
"launchBrowser": false, "launchUrl": "weatherforecast",
"applicationUrl": "https://localhost:6001;http://localhost:6000;https://0.0.0.0:6001;", "applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }
+22 -7
View File
@@ -1,31 +1,45 @@
using System;
using System.IO;
using System.Linq;
using xTagService.DI; using xTagService.DI;
using xHttpService.DI; using System.Net.Http;
using xAiApi.Database; using xAiApi.Database;
using xHttpService.DI;
using xPushService.DI;
using xFileService.DI; using xFileService.DI;
using xDataService.DI; using xDataService.DI;
using xPushService.DI;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Reflection; using System.Reflection;
using xAiApi.Extensions; using xAiApi.Extensions;
using xStringService.DI; using xStringService.DI;
using xStorageService.DI; using xStorageService.DI;
using xCommons.Extensions;
using xDataService.Models;
using xIdentityService.DI; using xIdentityService.DI;
using xPushService.Helpers; using xDataService.Models;
using xCommons.Extensions;
using xCommons.Configurations; using xCommons.Configurations;
using System.Collections.Generic;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Serialization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using IdentityModel.AspNetCore.OAuth2Introspection; using IdentityModel.AspNetCore.OAuth2Introspection;
using xPushService.Helpers;
namespace xAiApi namespace xAiApi
{ {
public class Startup public class Startup
{ {
// //
#region Props ...
public IConfiguration Configuration { get; } public IConfiguration Configuration { get; }
private readonly List<XDatabaseDescriptor> databases; private readonly List<XDatabaseDescriptor> databases;
private readonly XAiApiDatabaseDescriptor apiDatabaseDescriptor; private readonly XAiApiDatabaseDescriptor apiDatabaseDescriptor;
#endregion
//
#region Constructor(s) ...
public Startup(IConfiguration configuration) public Startup(IConfiguration configuration)
{ {
// //
@@ -39,6 +53,7 @@ namespace xAiApi
apiDatabaseDescriptor apiDatabaseDescriptor
}; };
} }
#endregion
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
@@ -200,7 +215,7 @@ namespace xAiApi
// //
// Use Storage Service ... // Use Storage Service ...
app.UseXStorageService(); app.UseXStorageService();
// //
// Use PushService ... // Use PushService ...
var pushHelper = new XPushServiceHelper(); var pushHelper = new XPushServiceHelper();
@@ -242,4 +257,4 @@ namespace xAiApi
); );
} }
} }
} }
+1 -1
View File
@@ -2,6 +2,6 @@
<configuration> <configuration>
<packageSources> <packageSources>
<add key="nuget" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> <add key="nuget" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="baget" value="https://nuget.saherelmhub.ir/v3/index.json" protocolVersion="3" disableTLSCertificateValidation="true" /> <add key="baget" value="https://nuget.saherelmhub.ir/v3/index.json" protocolVersion="3" />
</packageSources> </packageSources>
</configuration> </configuration>
+2 -4
View File
@@ -3,14 +3,12 @@
<!-- Runtime Definition --> <!-- Runtime Definition -->
<PropertyGroup> <PropertyGroup>
<Version>1.0.0</Version> <Version>1.0.0</Version>
<Nullable>enable</Nullable>
<LangVersion>12.0</LangVersion> <LangVersion>12.0</LangVersion>
<Authors>Hadi Khazaee Asl</Authors> <Authors>Hadi Khazaee Asl</Authors>
<Company>SaherElm IT Center</Company> <Company>SaherElm IT Center</Company>
<PackageId>xSaherElm.xAiApi</PackageId> <PackageId>xSaherElm.xAiApi</PackageId>
<ImplicitUsings>enable</ImplicitUsings> <!-- <TargetFramework>net8.0</TargetFramework> -->
<!-- <TargetFramework>netcoreapp3.1</TargetFramework> --> <TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Description> <Description>
a WebAPI Project which contains all Business Logic of xSaherElm Project's AI. a WebAPI Project which contains all Business Logic of xSaherElm Project's AI.
-6
View File
@@ -1,6 +0,0 @@
@xAiApi_HostAddress = http://localhost:5012
GET {{xAiApi_HostAddress}}/weatherforecast/
Accept: application/json
###