NI.BalloonTipIcon = ToolTipIcon.Info;
using System;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using System.Text.Json.Serialization;
using var httpClient = new HttpClient();
// Как-то получаем upload_url
var r = @"{
""response"": {
""upload_url"": ""/something""
}
";
var response = JsonSerializer.Deserialize<Response>(r);
var uploadUrl = response!.ResponseData.UploadUrl;
using var fileStream = File.OpenRead("./file.mp4");
using var request = new HttpRequestMessage
{
RequestUri = new Uri(uploadUrl),
Method = HttpMethod.Post,
Content = new MultipartFormDataContent
{
{
new StreamContent(fileStream), "file", "file.mp4"
}
}
};
httpClient.Send(request);
class Response
{
[JsonPropertyName("response")] public ResponseData ResponseData { get; set; }
}
class ResponseData
{
[JsonPropertyName("upload_url")] public string UploadUrl { get; set; }
}
var uri= "https://snaptik.app/dl.php?........................";
var httpClient = new HttpClient();
var response = await httpClient.GetAsync(url);
var stream = await response.Content.ReadAsStreamAsync();
// Дальше стрим куда-нибудь деваем. Можно в принципе и как массив байтов прочитать.
public class CarsRepository
{
private readonly DbContext _dbContext;
public CarsRepository(DbContext dbContext) => _dbContext = dbContext;
public async Task<string> GetOrAddCarNumberAsync(string carName)
{
var car = await _dbContext.Cars.FirstOrDefaultAsync(x => x.Name == name);
if(car == null)
{
car = new Car {
Name = name,
Number = ""
};
_dbContext.Cars.AddAsync(car);
await _dbContext.SaveChangesAsync():
}
return car.Number;
}
}
var sb = new StringBuilder();
if (person as IWithX withX)
sb.AppendLine(person.X);
if(person as IWithY withY)
sb.AppendLine(person.Y);
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
var aes = new AesCryptoServiceProvider
{
Key = new byte[] {11, 22, 33, 44, 55, 66, 77, 88, 99, 100, 200, 123, 156, 34, 89, 93},
IV = new byte[] {34, 24, 32, 44, 55, 60, 13, 9, 22, 55, 77, 90, 23, 12, 13, 11}
};
var encryptor = aes.CreateEncryptor();
var decryptor = aes.CreateDecryptor();
//crypt
{
var text = Console.ReadLine();
var bytes = Encoding.UTF8.GetBytes(text);
// Тут вместо MemoryStream можно взять File.OpenRead, например
using var source = new MemoryStream(bytes);
using var destination = File.OpenWrite("file.txt.crypt");
Transform(source, destination, encryptor);
}
Console.WriteLine("---- See result in file.txt.crypt ----");
Console.WriteLine("<Press ENTER to continue>");
Console.ReadLine();
//decrypt
{
using var source = File.OpenRead("file.txt.crypt");
// тут, вместо stdout можно взять File.OpenWrite
using var destination = Console.OpenStandardOutput();
Transform(source, destination, decryptor);
}
static void Transform(Stream source, Stream destination, ICryptoTransform encryptor)
{
using var cryptoStream = new CryptoStream(destination, encryptor, CryptoStreamMode.Write);
source.CopyTo(cryptoStream);
}
allCubesRb = allCubes.GetComponent<Rigidbody>();