CrazyIter_Bin 10 miesięcy temu
rodzic
commit
9c1961c876

+ 93 - 0
HTEX.Ceph/Controllers/WeatherForecastController.cs

@@ -0,0 +1,93 @@
+using Amazon;
+using Amazon.S3;
+using Amazon.S3.Model;
+using Amazon.S3.Transfer;
+using Microsoft.AspNetCore.Mvc;
+
+namespace HTEX.Ceph.Controllers
+{
+    [ApiController]
+    [Route("[controller]")]
+    public class WeatherForecastController : ControllerBase
+    {
+        private static readonly string[] Summaries = new[]
+        {
+            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
+        };
+
+        private readonly ILogger<WeatherForecastController> _logger;
+        private readonly IAmazonS3 _s3;
+        public WeatherForecastController(ILogger<WeatherForecastController> logger, IAmazonS3 s3)
+        {
+            _logger = logger;
+            _s3 = s3;
+        }
+
+        [HttpGet]
+        public IEnumerable<WeatherForecast> Get()
+        {
+            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
+            {
+                Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
+                TemperatureC = Random.Shared.Next(-20, 55),
+                Summary = Summaries[Random.Shared.Next(Summaries.Length)]
+            })
+            .ToArray();
+        }
+        [HttpPost("index")]
+        [RequestSizeLimit(102_400_000_00)] //最大10000m左右
+        public async Task<IActionResult> Index([FromForm]IFormFile file)
+        {
+            if (file != null)
+            {
+                var fileName = Path.GetFileName(file.FileName);
+                var fileTransUtility = new TransferUtility(_s3);
+                using var stream = file.OpenReadStream();
+                await fileTransUtility.UploadAsync(stream, "s3-ies-bucket", $"FormFileUpload/{fileName}");
+             
+               
+            }
+           
+             return Ok();
+        }
+        [HttpPost("list")]
+        public async Task<IActionResult> S3List()
+        {
+            var files = await _s3.GetAllObjectKeysAsync("s3-ies-bucket",null, null);
+            var response =  await _s3.GetObjectAsync("s3-ies-bucket", "FormFileUpload/202101001.pdf");
+            DateTime expires = DateTime.Now.AddDays(1); // URL有效期为1天
+                                                        // 生成预签名URL
+            GetPreSignedUrlRequest request = new GetPreSignedUrlRequest
+            {
+                BucketName = "s3-ies-bucket",
+                Key = "FormFileUpload/demo.mp4",
+                Verb = HttpVerb.GET, // 根据需要可以是GET, PUT, DELETE, HEAD等
+                Expires = expires
+            };
+            //http://192.168.8.157/s3-ies-bucket/FormFileUpload/202101001.pdf?AWSAccessKeyId=YR3H8OQKRC5PP6JZLYCQ&Expires=1722674382&Signature=zQzypGnaswQdfk4Ftll%2FWV0wjms%3D
+            var s3Endpoint = "http://192.168.8.160:8080";
+            var s3AccessKey = "YR3H8OQKRC5PP6JZLYCQ";
+            var s3SecretKey = "BQFGIB3vzGtdjXETSp5oD0dq28r0wbUwbx9XG2y8";
+
+            var s3Configuration = new AmazonS3Config
+            {
+                RegionEndpoint = RegionEndpoint.USEast1,
+                ServiceURL = s3Endpoint,
+                ForcePathStyle = true
+            };
+
+            var s3Client = new AmazonS3Client(s3AccessKey, s3SecretKey, s3Configuration);
+            string url = s3Client.GetPreSignedURL(request);
+            return Ok(new { files ,url});
+        }
+
+    }
+
+    public class FileUploadModel
+    {
+        public string Name { get; set; }
+
+        public IFormFile File { get; set; }
+    }
+
+}

+ 13 - 0
HTEX.Ceph/HTEX.Ceph.csproj

@@ -0,0 +1,13 @@
+<Project Sdk="Microsoft.NET.Sdk.Web">
+
+  <PropertyGroup>
+    <TargetFramework>net8.0</TargetFramework>
+    <Nullable>enable</Nullable>
+    <ImplicitUsings>enable</ImplicitUsings>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="AWSSDK.S3" Version="3.7.400.2" />
+  </ItemGroup>
+
+</Project>

+ 6 - 0
HTEX.Ceph/HTEX.Ceph.http

@@ -0,0 +1,6 @@
+@HTEX.Ceph_HostAddress = http://localhost:5166
+
+GET {{HTEX.Ceph_HostAddress}}/weatherforecast/
+Accept: application/json
+
+###

+ 46 - 0
HTEX.Ceph/Program.cs

@@ -0,0 +1,46 @@
+using Amazon;
+using Amazon.S3;
+using Amazon.S3.Model;
+using Microsoft.AspNetCore.Http.Features;
+
+var builder = WebApplication.CreateBuilder(args);
+
+// Add services to the container.
+
+builder.Services.AddControllers();
+
+builder.Services.AddControllersWithViews();
+builder.Services.Configure<FormOptions>(options =>
+{
+    options.MultipartBodyLengthLimit = 268435456;
+});
+//.NET CORE Aws S3 ʹÓÃ
+//https://blog.csdn.net/qq_36694046/article/details/136672057
+// ¹Ù·½Îĵµ https://docs.aws.amazon.com/zh_cn/AmazonS3/latest/userguide/optimizing-performance.html
+var s3Endpoint ="http://192.168.8.160:8080";
+var s3AccessKey = "YR3H8OQKRC5PP6JZLYCQ";
+var s3SecretKey = "BQFGIB3vzGtdjXETSp5oD0dq28r0wbUwbx9XG2y8";
+
+var s3Configuration = new AmazonS3Config
+{
+    RegionEndpoint = RegionEndpoint.USEast1,
+    ServiceURL = s3Endpoint,
+    ForcePathStyle = true
+};
+ 
+var s3Client=new AmazonS3Client(s3AccessKey, s3SecretKey, s3Configuration);
+builder.Services.AddSingleton<IAmazonS3>(sp => s3Client);
+
+
+
+var app = builder.Build();
+
+// Configure the HTTP request pipeline.
+
+app.UseHttpsRedirection();
+
+app.UseAuthorization();
+
+app.MapControllers();
+
+app.Run();

+ 41 - 0
HTEX.Ceph/Properties/launchSettings.json

@@ -0,0 +1,41 @@
+{
+  "$schema": "http://json.schemastore.org/launchsettings.json",
+  "iisSettings": {
+    "windowsAuthentication": false,
+    "anonymousAuthentication": true,
+    "iisExpress": {
+      "applicationUrl": "http://localhost:59796",
+      "sslPort": 44316
+    }
+  },
+  "profiles": {
+    "http": {
+      "commandName": "Project",
+      "dotnetRunMessages": true,
+      "launchBrowser": true,
+      "launchUrl": "weatherforecast",
+      "applicationUrl": "http://localhost:5166",
+      "environmentVariables": {
+        "ASPNETCORE_ENVIRONMENT": "Development"
+      }
+    },
+    "https": {
+      "commandName": "Project",
+      "dotnetRunMessages": true,
+      "launchBrowser": true,
+      "launchUrl": "weatherforecast",
+      "applicationUrl": "https://localhost:7155;http://localhost:5166",
+      "environmentVariables": {
+        "ASPNETCORE_ENVIRONMENT": "Development"
+      }
+    },
+    "IIS Express": {
+      "commandName": "IISExpress",
+      "launchBrowser": true,
+      "launchUrl": "weatherforecast",
+      "environmentVariables": {
+        "ASPNETCORE_ENVIRONMENT": "Development"
+      }
+    }
+  }
+}

+ 13 - 0
HTEX.Ceph/WeatherForecast.cs

@@ -0,0 +1,13 @@
+namespace HTEX.Ceph
+{
+    public class WeatherForecast
+    {
+        public DateOnly Date { get; set; }
+
+        public int TemperatureC { get; set; }
+
+        public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
+
+        public string? Summary { get; set; }
+    }
+}

+ 8 - 0
HTEX.Ceph/appsettings.Development.json

@@ -0,0 +1,8 @@
+{
+  "Logging": {
+    "LogLevel": {
+      "Default": "Information",
+      "Microsoft.AspNetCore": "Warning"
+    }
+  }
+}

+ 9 - 0
HTEX.Ceph/appsettings.json

@@ -0,0 +1,9 @@
+{
+  "Logging": {
+    "LogLevel": {
+      "Default": "Information",
+      "Microsoft.AspNetCore": "Warning"
+    }
+  },
+  "AllowedHosts": "*"
+}

+ 1 - 1
HTEX.Complex/Dockerfile

@@ -1,6 +1,6 @@
 #See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
 
-FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
+FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
 WORKDIR /app
 EXPOSE 80
 EXPOSE 443

+ 19 - 93
HTEXCosmosDB/Cosmos/AzureCosmosExtensions.cs

@@ -32,73 +32,7 @@ namespace HTEXCosmosDB
                 return null;
             }
         }
-
-        //public static async IAsyncEnumerable<(List<T> list, double RU, string? continuationToken)> GetItemQueryIterator<T>(this Container container, QueryDefinition queryDefinition, QueryRequestOptions requestOptions,string? continuationToken  = null, int? pageSize = null)
-        //{
-        //    List<T> list = new List<T>();
-        //    double RU = 0;
-        //    //if (string.IsNullOrWhiteSpace(partitionkey))
-        //    //{
-        //    //    return (list, RU, continuationToken);
-        //    //}
-        //    FeedIterator<T> iterator = container.GetItemQueryIterator<T>(queryDefinition: queryDefinition, continuationToken: continuationToken, requestOptions: requestOptions);
-        //    while (iterator.HasMoreResults)
-        //    {
-        //        FeedResponse<T> currentResultSet = await iterator.ReadNextAsync();
-        //        list.AddRange(currentResultSet);
-        //        RU += currentResultSet.RequestCharge;
-        //        //此处需要优化 ,检查相关的 关键字 用正则
-        //        if (queryDefinition.QueryText.Contains(" distinct ", StringComparison.OrdinalIgnoreCase)
-        //            || (queryDefinition.QueryText.Contains("order ", StringComparison.OrdinalIgnoreCase)
-        //            && !queryDefinition.QueryText.Contains(".order ", StringComparison.OrdinalIgnoreCase)))
-        //        {
-        //            continuationToken = null;
-        //        }
-        //        else
-        //        {
-        //            continuationToken = currentResultSet.ContinuationToken;
-        //        }
-        //        if (pageSize.HasValue && pageSize.Value >= 0 && list.Count >= pageSize)
-        //        {
-        //            break;
-        //        }
-        //        yield return  (list, RU, continuationToken);
-        //    }
-           
-        //}
-
-        //public static async Task<(List<T> list, double RU, string? continuationToken)> GetList<T>(this Container container, QueryDefinition queryDefinition, string? partitionkey = null , string? continuationToken = null, int? pageSize = null)
-        //{
-        //    List<T> list = new List<T>();
-        //    double RU = 0;
-        //    //if (string.IsNullOrWhiteSpace(partitionkey))
-        //    //{
-        //    //    return (list, RU, continuationToken);
-        //    //}
-        //    FeedIterator<T> iterator = container.GetItemQueryIterator<T>(queryDefinition: queryDefinition, continuationToken: continuationToken, requestOptions: new QueryRequestOptions { MaxItemCount = pageSize, PartitionKey =!string.IsNullOrWhiteSpace(partitionkey) ? new PartitionKey(partitionkey) : null });
-        //    while (iterator.HasMoreResults)
-        //    {
-        //        FeedResponse<T> currentResultSet = await iterator.ReadNextAsync();
-        //        list.AddRange(currentResultSet);
-        //        RU += currentResultSet.RequestCharge;
-        //        //此处需要优化 ,检查相关的 关键字 用正则
-        //        if (queryDefinition.QueryText.Contains(" distinct ", StringComparison.OrdinalIgnoreCase)
-        //            || (queryDefinition.QueryText.Contains("order ", StringComparison.OrdinalIgnoreCase)
-        //            && !queryDefinition.QueryText.Contains(".order ", StringComparison.OrdinalIgnoreCase)))
-        //        {
-        //            continuationToken = null;
-        //        }
-        //        else
-        //        {
-        //            continuationToken = currentResultSet.ContinuationToken;
-        //        }
-        //        if (pageSize.HasValue && pageSize.Value >= 0 && list.Count >= pageSize)
-        //        {
-        //            break;
-        //        }
-        //    }
-        //    return (list, RU, continuationToken);
-        //}
+      
         public static async Task<T?> GetOne<T>(this Container container, QueryDefinition queryDefinition, string? partitionkey = null)
         {
             List<T?> list = new List<T?>();
@@ -154,25 +88,22 @@ namespace HTEXCosmosDB
                 return list.First();
             }
         }
-        public static async IAsyncEnumerable<CosmosDBResult<T>> GetItemQueryIteratorList<T>(this Container container, string queryText, QueryRequestOptions? requestOptions= null,  string? continuationToken = null, int? pageSize = null)
+       
+        public static async Task<CosmosDBResult<T>> GetList<T>(this Container container, QueryDefinition queryDefinition, string? partitionkey = null, string? continuationToken = null, int? pageSize = null)
         {
-           
-            //if (string.IsNullOrWhiteSpace(partitionkey))
-            //{
-            //    return (new CosmosDBResult<T> { list = list, ru=RU, continuationToken=continuationToken });
-            //}
-            FeedIterator<T> iterator = container.GetItemQueryIterator<T>(queryText: queryText, continuationToken: continuationToken, requestOptions: requestOptions);
+            List<T> list = new List<T>();
+            double RU = 0;
+            
+            FeedIterator<T> iterator = container.GetItemQueryIterator<T>(queryDefinition: queryDefinition, continuationToken: continuationToken, requestOptions: new QueryRequestOptions { MaxItemCount=pageSize, PartitionKey =!string.IsNullOrWhiteSpace(partitionkey) ? new PartitionKey(partitionkey) : null });
             while (iterator.HasMoreResults)
             {
-                List<T> list = new List<T>();
-                double RU = 0;
                 FeedResponse<T> currentResultSet = await iterator.ReadNextAsync();
                 list.AddRange(currentResultSet);
                 RU += currentResultSet.RequestCharge;
                 //此处需要优化 ,检查相关的 关键字 用正则
-                if (queryText.Contains(" distinct ", StringComparison.OrdinalIgnoreCase)
-                    || (queryText.Contains("order ", StringComparison.OrdinalIgnoreCase)
-                    && !queryText.Contains(".order ", StringComparison.OrdinalIgnoreCase)))
+                if (queryDefinition.QueryText.Contains(" distinct ", StringComparison.OrdinalIgnoreCase)
+                    || (queryDefinition.QueryText.Contains("order ", StringComparison.OrdinalIgnoreCase)
+                    && !queryDefinition.QueryText.Contains(".order ", StringComparison.OrdinalIgnoreCase)))
                 {
                     continuationToken = null;
                 }
@@ -180,23 +111,19 @@ namespace HTEXCosmosDB
                 {
                     continuationToken = currentResultSet.ContinuationToken;
                 }
-                if (pageSize.HasValue && pageSize.Value >=0 && list.Count>=pageSize)
+                if (pageSize.HasValue && pageSize.Value >= 0 && list.Count >= pageSize)
                 {
                     break;
                 }
-                //记录日志,RU开销大于400(开发测试),1000(正式)
-                yield  return (new CosmosDBResult<T> { list = list, ru = RU, continuationToken = continuationToken });
             }
-           
+            return (new CosmosDBResult<T> { list = list, ru = RU, continuationToken = continuationToken });
         }
+
         public static async Task<CosmosDBResult<T>> GetList<T>(this Container container, string sql, string? partitionkey = null, string? continuationToken = null, int? pageSize = null)
         {
             List<T> list = new List<T>();
             double RU = 0;
-            //if (string.IsNullOrWhiteSpace(partitionkey))
-            //{
-            //    return (new CosmosDBResult<T> { list = list, ru=RU, continuationToken=continuationToken });
-            //}
+           
             FeedIterator<T> iterator = container.GetItemQueryIterator<T>(queryText: sql, continuationToken: continuationToken, requestOptions: new QueryRequestOptions { MaxItemCount=pageSize, PartitionKey =!string.IsNullOrWhiteSpace(partitionkey) ? new PartitionKey(partitionkey) : null });
             while (iterator.HasMoreResults)
             {
@@ -229,7 +156,7 @@ namespace HTEXCosmosDB
         /// <param name="partitionkey"></param>
         /// <param name="queryWhere"></param>
         /// <returns></returns>
-        public static async Task<int> GetCount(this Container container, string queryWhere = "WHERE 1=1", string? partitionkey = null)
+        public static async Task<int> GetCount(this Container container, string? partitionkey = null, string queryWhere = "WHERE 1=1")
         {
             int totalCount = 0;
             var items = container.GetItemQueryStreamIterator(
@@ -247,7 +174,6 @@ namespace HTEXCosmosDB
                     }
                 }
             }
-
             return totalCount;
         }
 
@@ -293,7 +219,7 @@ namespace HTEXCosmosDB
             return response;
         }
 
-        public static async IAsyncEnumerable<ResponseMessage> GetItemQueryStreamIteratorSql(this Microsoft.Azure.Cosmos.Container container, string queryText = null, string continuationToken = null, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = null)
+        public static async IAsyncEnumerable<ResponseMessage> GetItemQueryStreamIteratorSql(this Microsoft.Azure.Cosmos.Container container, string queryText = null,  Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = null, string continuationToken = null)
         {
             var items = container.GetItemQueryStreamIterator(
             queryText: queryText, continuationToken: continuationToken,
@@ -311,7 +237,7 @@ namespace HTEXCosmosDB
                 }
             }
         }
-        public static async IAsyncEnumerable<ResponseMessage> GetItemQueryStreamIteratorQuery(this Microsoft.Azure.Cosmos.Container container, Microsoft.Azure.Cosmos.QueryDefinition queryDefinition, string continuationToken = null, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = null)
+        public static async IAsyncEnumerable<ResponseMessage> GetItemQueryStreamIteratorQuery(this Microsoft.Azure.Cosmos.Container container, Microsoft.Azure.Cosmos.QueryDefinition queryDefinition, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = null, string continuationToken = null)
         {
             var items = container.GetItemQueryStreamIterator(
             queryDefinition: queryDefinition, continuationToken: continuationToken,
@@ -330,7 +256,7 @@ namespace HTEXCosmosDB
             }
         }
 
-        public static async IAsyncEnumerable<T> GetItemQueryIteratorQuery<T>(this Microsoft.Azure.Cosmos.Container container, Microsoft.Azure.Cosmos.QueryDefinition queryDefinition, string continuationToken = null, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = null)
+        public static async IAsyncEnumerable<T> GetItemQueryIteratorQuery<T>(this Microsoft.Azure.Cosmos.Container container, Microsoft.Azure.Cosmos.QueryDefinition queryDefinition, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = null, string continuationToken = null)
         {
             var items = container.GetItemQueryIterator<T>(
             queryDefinition: queryDefinition, continuationToken: continuationToken,
@@ -351,7 +277,7 @@ namespace HTEXCosmosDB
                 }
             }
         }
-        public static async IAsyncEnumerable<T> GetItemQueryIteratorSql<T>(this Microsoft.Azure.Cosmos.Container container, string queryText, string continuationToken = null, Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = null)
+        public static async IAsyncEnumerable<T> GetItemQueryIteratorSql<T>(this Microsoft.Azure.Cosmos.Container container, string queryText,Microsoft.Azure.Cosmos.QueryRequestOptions requestOptions = null, string continuationToken = null )
         {
             var items = container.GetItemQueryIterator<T>(
             queryText: queryText, continuationToken: continuationToken,

+ 15 - 1
TEAMModelHTEX.sln

@@ -39,7 +39,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HTEX.Complex", "HTEX.Comple
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HTEXGpt", "HTEXGpt\HTEXGpt.csproj", "{C2B6319D-E804-41DE-B48E-8555007280F9}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HTEXCosmosDB", "HTEXCosmosDB\HTEXCosmosDB.csproj", "{2B6EB00C-C0E7-4F0C-ABDC-05D802CF272E}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HTEXCosmosDB", "HTEXCosmosDB\HTEXCosmosDB.csproj", "{2B6EB00C-C0E7-4F0C-ABDC-05D802CF272E}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HTEX.Ceph", "HTEX.Ceph\HTEX.Ceph.csproj", "{57594F8A-9200-44BB-9CE2-1A68D1C07A61}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -279,6 +281,18 @@ Global
 		{2B6EB00C-C0E7-4F0C-ABDC-05D802CF272E}.Release|iPhone.Build.0 = Release|Any CPU
 		{2B6EB00C-C0E7-4F0C-ABDC-05D802CF272E}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
 		{2B6EB00C-C0E7-4F0C-ABDC-05D802CF272E}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
+		{57594F8A-9200-44BB-9CE2-1A68D1C07A61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{57594F8A-9200-44BB-9CE2-1A68D1C07A61}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{57594F8A-9200-44BB-9CE2-1A68D1C07A61}.Debug|iPhone.ActiveCfg = Debug|Any CPU
+		{57594F8A-9200-44BB-9CE2-1A68D1C07A61}.Debug|iPhone.Build.0 = Debug|Any CPU
+		{57594F8A-9200-44BB-9CE2-1A68D1C07A61}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
+		{57594F8A-9200-44BB-9CE2-1A68D1C07A61}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
+		{57594F8A-9200-44BB-9CE2-1A68D1C07A61}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{57594F8A-9200-44BB-9CE2-1A68D1C07A61}.Release|Any CPU.Build.0 = Release|Any CPU
+		{57594F8A-9200-44BB-9CE2-1A68D1C07A61}.Release|iPhone.ActiveCfg = Release|Any CPU
+		{57594F8A-9200-44BB-9CE2-1A68D1C07A61}.Release|iPhone.Build.0 = Release|Any CPU
+		{57594F8A-9200-44BB-9CE2-1A68D1C07A61}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
+		{57594F8A-9200-44BB-9CE2-1A68D1C07A61}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE