From 2f2755cbcb07ec04309877e8e3cdc267b2ca0430 Mon Sep 17 00:00:00 2001
From: "p.gross"
Date: Thu, 30 May 2024 15:10:49 +0300
Subject: [PATCH] Client for C# SDK
---
Program.cs | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++
client.csproj | 14 +++++++++
2 files changed, 98 insertions(+)
create mode 100644 Program.cs
create mode 100644 client.csproj
diff --git a/Program.cs b/Program.cs
new file mode 100644
index 0000000..3096e3c
--- /dev/null
+++ b/Program.cs
@@ -0,0 +1,84 @@
+using FrostFS.SDK.ClientV2;
+using FrostFS.SDK.ModelsV2;
+using FrostFS.SDK.ModelsV2.Enums;
+using FrostFS.SDK.ModelsV2.Netmap;
+
+try
+{
+ var fsClient = new Client("KwHDAJ66o8FoLBjVbjP2sWBmgBMGjt7Vv4boA7xQrBoAYBE397Aq", "http://172.29.238.97:8080");
+
+ // List containers
+ Console.WriteLine("Existing containers:");
+
+ await foreach(var cid in fsClient.ListContainersAsync())
+ {
+ Console.WriteLine(cid.ToString());
+ // await fsClient.DeleteContainerAsync(cid);
+ // Console.WriteLine($"REmoved container: {cid}");
+ }
+
+ // Create container
+ var placementPolicy = new PlacementPolicy(true, new Replica(1));
+
+ var containerId = await fsClient.CreateContainerAsync(new Container(BasicAcl.PublicRW, placementPolicy));
+ Console.WriteLine($"Created container: {containerId}");
+
+ Container? container = null;
+ while(container is null)
+ {
+ try
+ {
+ container = await fsClient.GetContainerAsync(containerId);
+ }
+ catch
+ {
+ Console.WriteLine("Waiting for the container is ready");
+ }
+ }
+
+ var currentDir = Directory.GetCurrentDirectory();
+
+ // Put object
+ using var fileStream = File.OpenRead("cat.jpg");
+
+ var cat = new ObjectHeader(
+ containerId: containerId,
+ type: ObjectType.Regular,
+ new ObjectAttribute("Filename", "cat.jpg")
+ );
+
+ var objectId = await fsClient.PutObjectAsync(cat, fileStream);
+
+ // Get object header
+ var objHeader = await fsClient.GetObjectHeadAsync(containerId, objectId);
+
+ Console.WriteLine("Attributes:");
+ foreach(var attribute in objHeader.Attributes)
+ {
+ Console.WriteLine($"{attribute.Key}:{attribute.Value}");
+ }
+
+ // Get object back
+ var obj = await fsClient.GetObjectAsync(containerId, objectId);
+
+ File.WriteAllBytes("downloaded.jpg", obj.Payload);
+
+ Console.WriteLine("Existing containers after creating:");
+ await foreach(var cid in fsClient.ListContainersAsync())
+ {
+ Console.WriteLine($"ContainerId: {cid} (removing...)");
+ await fsClient.DeleteContainerAsync(cid);
+ }
+
+ await Task.Delay(2000);
+
+ await foreach(var cid in fsClient.ListContainersAsync())
+ {
+ Console.WriteLine($"Container {cid} is alive!");
+ }
+}
+catch(Exception ex)
+{
+ Console.WriteLine($"Error: {ex.Message}");
+}
+
diff --git a/client.csproj b/client.csproj
new file mode 100644
index 0000000..73516c0
--- /dev/null
+++ b/client.csproj
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+ Exe
+ net6.0
+ enable
+ enable
+
+
+