Files
hcs/Hcs.TestApp/ClientDemo/FileStoreDemo.cs
HOME-LAPTOP\kshkulev 33ab055b43 Add project
Basic formatting applied. Unnecessary comments have been removed. Suspicious code is covered by TODO.
2025-08-12 11:21:10 +09:00

68 lines
2.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}
}
}
}