Add project

Basic formatting applied. Unnecessary comments have been removed. Suspicious code is covered by TODO.
This commit is contained in:
2025-08-12 11:21:10 +09:00
parent bbcbe841a7
commit 33ab055b43
546 changed files with 176950 additions and 0 deletions

View File

@ -0,0 +1,67 @@
using Hcs.ClientApi;
using System;
using System.IO;
using System.Threading;
namespace Hcs.ClientDemo
{
public class FileStoreDemo
{
public static void DemoDownloadFile(HcsClient hcsClient)
{
Guid fileGuid = new Guid("e4c3b39f-ad59-11ef-bc8e-0242ac120002");
var file = hcsClient.FileStoreService.DownloadFile(
fileGuid, HcsFileStoreContext.homemanagement, CancellationToken.None).Result;
Console.WriteLine("\nКонтент len=" + file.Length +
" type=" + file.ContentType + " streamLength=" + file.Stream.Length +
" hash=" + hcsClient.ComputeGost94Hash(file.Stream));
using (var s = new FileStream(@"D:\temp\teplo0.pdf", FileMode.CreateNew, FileAccess.Write))
{
file.Stream.Seek(0, SeekOrigin.Begin);
file.Stream.CopyTo(s);
s.Close();
}
}
public static void DemoUploadFile(HcsClient hcsClient)
{
string sourceFileName = @"D:\temp\Проект договора.docx";
var contentType = HcsFile.GetMimeContentTypeForFileName(sourceFileName);
if (contentType == null) throw new HcsException("Не найден тип mime для файла");
Console.WriteLine("Выгружаем файл: " + sourceFileName);
using (var stream = new FileStream(sourceFileName, FileMode.Open, FileAccess.Read))
{
var file = new HcsFile(Path.GetFileName(sourceFileName), contentType, stream);
var guid = hcsClient.FileStoreService.UploadFile(
file, HcsFileStoreContext.homemanagement, CancellationToken.None).Result;
Console.WriteLine("Выгруженный файл GUID=" + guid);
}
}
public static void DemoGetFileLength(HcsClient hcsClient)
{
Guid fileGuid = new Guid("33ddc355-60bd-4537-adf6-fbb31322e16f");
var length = hcsClient.FileStoreService.GetFileLength(
HcsFileStoreContext.homemanagement, fileGuid, CancellationToken.None).Result;
Console.WriteLine($"\nДлина = {length} для файла с GUID " + fileGuid);
}
public static void DemoGostHash(HcsClient hcsClient)
{
PrintFileHash(hcsClient, @"D:\temp\teplo0.pdf");
}
public static void PrintFileHash(HcsClient hcsClient, string fileName)
{
using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
var hash = hcsClient.ComputeGost94Hash(stream);
Console.WriteLine($"{fileName} hash=" + hash + " len=" + new FileInfo(fileName).Length);
}
}
}
}