Merge branch 'master' into fit/master/Hassanzadeh
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
syntax="proto3";
|
||||
|
||||
option csharp_namespace="VizhTalk.Grpc.CDN";
|
||||
|
||||
package greet;
|
||||
|
||||
message UploadFileCommand{
|
||||
bytes file = 1;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
syntax="proto3";
|
||||
|
||||
option csharp_namespace="VizhTalk.Grpc.CDN";
|
||||
|
||||
package greet;
|
||||
|
||||
message Id{
|
||||
string value = 1;
|
||||
}
|
||||
|
||||
message UploadFileDTO{
|
||||
Id id = 1;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
syntax="proto3";
|
||||
|
||||
option csharp_namespace="VizhTalk.Grpc.CDN";
|
||||
|
||||
package greet;
|
||||
|
||||
import "DTOs.proto";
|
||||
import "Commands.proto";
|
||||
|
||||
service CDNGrpc{
|
||||
rpc UploadFile (UploadFileCommand) returns (UploadFileDTO);
|
||||
}
|
||||
@@ -5,5 +5,14 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Google.Protobuf" Version="3.32.0" />
|
||||
<PackageReference Include="Grpc.Net.Client" Version="2.71.0" />
|
||||
<PackageReference Include="Grpc.Tools" Version="2.58.0" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Protobuf Include="Services.proto" GrpcServices="Both" />
|
||||
<Protobuf Include="DTOs.proto" GrpcServices="Both" />
|
||||
<Protobuf Include="Commands.proto" GrpcServices="Both" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,31 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VizhTalk.Grpc.Learning.Helpers
|
||||
{
|
||||
internal class CompressionHelper
|
||||
{
|
||||
public static byte[] Compress(byte[] data)
|
||||
{
|
||||
using var output = new MemoryStream();
|
||||
using (var gzip = new GZipStream(output, CompressionMode.Compress))
|
||||
{
|
||||
gzip.Write(data, 0, data.Length);
|
||||
}
|
||||
return output.ToArray();
|
||||
}
|
||||
|
||||
public static byte[] Decompress(byte[] compressedData)
|
||||
{
|
||||
using var input = new MemoryStream(compressedData);
|
||||
using var gzip = new GZipStream(input, CompressionMode.Decompress);
|
||||
using var output = new MemoryStream();
|
||||
gzip.CopyTo(output);
|
||||
return output.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace VizhTalk.Grpc.Learning.Helpers
|
||||
{
|
||||
internal class EncryptionHelper
|
||||
{
|
||||
private const string Alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
public static string Encrypt(string input)
|
||||
{
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(input);
|
||||
|
||||
// تبدیل بایتها به عدد بزرگ
|
||||
var number = new System.Numerics.BigInteger(bytes);
|
||||
|
||||
// اگر منفی شد، مثبتش کن
|
||||
if (number < 0) number = -number;
|
||||
|
||||
// تبدیل به Base62
|
||||
StringBuilder result = new StringBuilder();
|
||||
while (number > 0)
|
||||
{
|
||||
result.Insert(0, Alphabet[(int)(number % 62)]);
|
||||
number /= 62;
|
||||
}
|
||||
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
public static string Decrypt(string encoded)
|
||||
{
|
||||
System.Numerics.BigInteger number = 0;
|
||||
foreach (char c in encoded)
|
||||
{
|
||||
number = number * 62 + Alphabet.IndexOf(c);
|
||||
}
|
||||
|
||||
// تبدیل دوباره به بایت
|
||||
byte[] bytes = number.ToByteArray();
|
||||
|
||||
// رشته اصلی
|
||||
return Encoding.UTF8.GetString(bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,13 @@
|
||||
using Vizhtalk.CDN.Presentation.Services;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.AddGrpc();
|
||||
var app = builder.Build();
|
||||
|
||||
app.MapGet("/", () => "Hello World!");
|
||||
|
||||
app.MapGrpcService<CDNService>();
|
||||
|
||||
|
||||
app.Run();
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using Grpc.Core;
|
||||
using VizhTalk.Grpc.CDN;
|
||||
|
||||
namespace Vizhtalk.CDN.Presentation.Services;
|
||||
|
||||
public class CDNService : CDNGrpc.CDNGrpcBase
|
||||
{
|
||||
public override Task<UploadFileDTO> UploadFile(UploadFileCommand request, ServerCallContext context)
|
||||
{
|
||||
return base.UploadFile(request, context);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,9 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VizhTalk.BuildingBlocks.Infrastructure\VizhTalk.BuildingBlocks.Infrastructure.csproj" />
|
||||
<PackageReference Include="Grpc.AspNetCore" Version="2.57.0" />
|
||||
<ProjectReference Include="..\VizhTalk.BuildingBlocks.Infrastructure\VizhTalk.BuildingBlocks.Infrastructure.csproj" />
|
||||
<ProjectReference Include="..\VizhTalk.Grpc.CDN\VizhTalk.Grpc.CDN.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user