Skip to content

Commit a0d9b24

Browse files
committed
- Added new LoadData and Save data functionality to the Data API on the OASIS API to allow quick and easy way to store and load data.
- Added SaveData, SaveDataAsync, LoadData & LoadDataAsync methods to AvatarManager in OASIS.API.Core. - Corrected typeos in LoadFile and SaveFile methods on HolonManager in OASIS.API.Core. - Updated MintNFTInternalAsync and MintNFTInternal so the URI points to load-file instead of getdata on the Data API. - Added SaveFile, LoadFile, SaveData & LoadData overloads to the DataController in the OASIS.API.ONODE.WebAPI. - Added LoadDataRequest & SaveDataRequest to OASIS.API.ONODE.WebAPI. - Changed the port from 5001 to 5002 in launchSettings.json so does not clash with IPFS in OASIS.API.ONODE.WebAPI.
1 parent 58699fd commit a0d9b24

8 files changed

Lines changed: 483 additions & 10 deletions

File tree

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using NextGenSoftware.OASIS.Common;
4+
using NextGenSoftware.OASIS.API.Core.Enums;
5+
using NextGenSoftware.OASIS.API.Core.Helpers;
6+
using NextGenSoftware.OASIS.API.Core.Interfaces;
7+
8+
namespace NextGenSoftware.OASIS.API.Core.Managers
9+
{
10+
public partial class AvatarManager : OASISManager
11+
{
12+
public OASISResult<bool> SaveData(string key, string value, Guid avatarId, ProviderType providerType = ProviderType.Default, AutoReplicationMode autoReplicationMode = AutoReplicationMode.UseGlobalDefaultInOASISDNA, AutoFailOverMode autoFailOverMode = AutoFailOverMode.UseGlobalDefaultInOASISDNA, AutoLoadBalanceMode autoLoadBalanceMode = AutoLoadBalanceMode.UseGlobalDefaultInOASISDNA, bool waitForAutoReplicationResult = false)
13+
{
14+
OASISResult<bool> result = new OASISResult<bool>();
15+
string errorMessage = "An error occured in AvatarManager.SaveData. Reason: ";
16+
17+
OASISResult<IAvatar> avatarLoadResult = AvatarManager.Instance.LoadAvatar(avatarId, false, true, providerType);
18+
19+
if (avatarLoadResult != null && avatarLoadResult.Result != null && !avatarLoadResult.IsError)
20+
{
21+
avatarLoadResult.Result.MetaData[key] = value;
22+
OASISResult<IAvatar> avatarSaveResult = avatarLoadResult.Result.Save(autoReplicationMode, autoFailOverMode, autoLoadBalanceMode, waitForAutoReplicationResult, providerType);
23+
24+
if (avatarSaveResult != null && avatarSaveResult.Result != null && !avatarSaveResult.IsError)
25+
{
26+
result = OASISResultHelper.CopyOASISResultOnlyWithNoInnerResult(avatarSaveResult, result);
27+
result.Result = true;
28+
result.Message = "Data Saved";
29+
}
30+
else
31+
OASISErrorHandling.HandleError(ref result, $"{errorMessage} There was an error saving the data to the avatar. Reason: {avatarSaveResult.Message}");
32+
}
33+
else
34+
OASISErrorHandling.HandleError(ref result, $"{errorMessage} There was an error loading the avatar. Reason: {avatarLoadResult.Message}");
35+
36+
return result;
37+
}
38+
39+
public async Task<OASISResult<bool>> SaveDataAsync(string key, string value, Guid avatarId, ProviderType providerType = ProviderType.Default, AutoReplicationMode autoReplicationMode = AutoReplicationMode.UseGlobalDefaultInOASISDNA, AutoFailOverMode autoFailOverMode = AutoFailOverMode.UseGlobalDefaultInOASISDNA, AutoLoadBalanceMode autoLoadBalanceMode = AutoLoadBalanceMode.UseGlobalDefaultInOASISDNA, bool waitForAutoReplicationResult = false)
40+
{
41+
OASISResult<bool> result = new OASISResult<bool>();
42+
string errorMessage = "An error occured in AvatarManager.SaveDataAsync. Reason: ";
43+
44+
OASISResult<IAvatar> avatarLoadResult = await AvatarManager.Instance.LoadAvatarAsync(avatarId, false, true, providerType);
45+
46+
if (avatarLoadResult != null && avatarLoadResult.Result != null && !avatarLoadResult.IsError)
47+
{
48+
avatarLoadResult.Result.MetaData[key] = value;
49+
OASISResult<IAvatar> avatarSaveResult = await avatarLoadResult.Result.SaveAsync(autoReplicationMode, autoFailOverMode, autoLoadBalanceMode, waitForAutoReplicationResult, providerType);
50+
51+
if (avatarSaveResult != null && avatarSaveResult.Result != null && !avatarSaveResult.IsError)
52+
{
53+
result = OASISResultHelper.CopyOASISResultOnlyWithNoInnerResult(avatarSaveResult, result);
54+
result.Result = true;
55+
result.Message = "Data Saved";
56+
}
57+
else
58+
OASISErrorHandling.HandleError(ref result, $"{errorMessage} There was an error saving the data to the avatar. Reason: {avatarSaveResult.Message}");
59+
}
60+
else
61+
OASISErrorHandling.HandleError(ref result, $"{errorMessage} There was an error loading the avatar. Reason: {avatarLoadResult.Message}");
62+
63+
return result;
64+
}
65+
66+
public OASISResult<string> LoadData(string key, Guid avatarId, ProviderType providerType = ProviderType.Default, AutoReplicationMode autoReplicationMode = AutoReplicationMode.UseGlobalDefaultInOASISDNA, AutoFailOverMode autoFailOverMode = AutoFailOverMode.UseGlobalDefaultInOASISDNA, AutoLoadBalanceMode autoLoadBalanceMode = AutoLoadBalanceMode.UseGlobalDefaultInOASISDNA, bool waitForAutoReplicationResult = false)
67+
{
68+
OASISResult<string> result = new OASISResult<string>();
69+
string errorMessage = "An error occured in AvatarManager.LoadData. Reason: ";
70+
71+
OASISResult<IAvatar> avatarLoadResult = AvatarManager.Instance.LoadAvatar(avatarId, false, true, providerType);
72+
73+
if (avatarLoadResult != null && avatarLoadResult.Result != null && !avatarLoadResult.IsError)
74+
{
75+
result.Result = avatarLoadResult.Result.MetaData[key].ToString();
76+
result.IsLoaded = true;
77+
result.Message = "Data Loaded";
78+
}
79+
else
80+
OASISErrorHandling.HandleError(ref result, $"{errorMessage} There was an error loading the avatar. Reason: {avatarLoadResult.Message}");
81+
82+
return result;
83+
}
84+
85+
public async Task<OASISResult<string>> LoadDataAsync(string key, Guid avatarId, ProviderType providerType = ProviderType.Default, AutoReplicationMode autoReplicationMode = AutoReplicationMode.UseGlobalDefaultInOASISDNA, AutoFailOverMode autoFailOverMode = AutoFailOverMode.UseGlobalDefaultInOASISDNA, AutoLoadBalanceMode autoLoadBalanceMode = AutoLoadBalanceMode.UseGlobalDefaultInOASISDNA, bool waitForAutoReplicationResult = false)
86+
{
87+
OASISResult<string> result = new OASISResult<string>();
88+
string errorMessage = "An error occured in AvatarManager.LoadDataAsync. Reason: ";
89+
90+
OASISResult<IAvatar> avatarLoadResult = await AvatarManager.Instance.LoadAvatarAsync(avatarId, false, true, providerType);
91+
92+
if (avatarLoadResult != null && avatarLoadResult.Result != null && !avatarLoadResult.IsError)
93+
{
94+
result.Result = avatarLoadResult.Result.MetaData[key].ToString();
95+
result.IsLoaded = true;
96+
result.Message = "Data Loaded";
97+
}
98+
else
99+
OASISErrorHandling.HandleError(ref result, $"{errorMessage} There was an error loading the avatar. Reason: {avatarLoadResult.Message}");
100+
101+
return result;
102+
}
103+
}
104+
}

NextGenSoftware.OASIS.API.Core/Managers/HolonManager/HolonManager-Save.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public OASISResult<Guid> SaveFile(byte[] data, Guid avatarId, ProviderType provi
3232
result.Message = "File Saved";
3333
}
3434
else
35-
OASISErrorHandling.HandleError(ref result, $"{errorMessage} There was an error saving the holon contianing the file. Reason: {holonResult.Message}");
35+
OASISErrorHandling.HandleError(ref result, $"{errorMessage} There was an error saving the holon containing the file. Reason: {holonResult.Message}");
3636

3737
return result;
3838
}
@@ -57,7 +57,7 @@ public async Task<OASISResult<Guid>> SaveFileAsync(byte[] data, Guid avatarId, P
5757
result.Message = "File Saved";
5858
}
5959
else
60-
OASISErrorHandling.HandleError(ref result, $"{errorMessage} There was an error saving the holon contianing the file. Reason: {holonResult.Message}");
60+
OASISErrorHandling.HandleError(ref result, $"{errorMessage} There was an error saving the holon containing the file. Reason: {holonResult.Message}");
6161

6262
return result;
6363
}
@@ -74,7 +74,7 @@ public OASISResult<byte[]> LoadFile(Guid id, Guid avatarId, ProviderType provide
7474
{
7575
result = OASISResultHelper.CopyOASISResultOnlyWithNoInnerResult(holonResult, result);
7676

77-
if (holonResult.Result.MetaData != null && holonResult.MetaData.ContainsKey("data") && holonResult.MetaData["data"] != null)
77+
if (holonResult.Result.MetaData != null && holonResult.Result.MetaData.ContainsKey("data") && holonResult.Result.MetaData["data"] != null)
7878
{
7979
result.Result = holonResult.Result.MetaData["data"] as byte[];
8080
result.Message = "File Loaded";
@@ -83,7 +83,7 @@ public OASISResult<byte[]> LoadFile(Guid id, Guid avatarId, ProviderType provide
8383
OASISErrorHandling.HandleError(ref result, $"{errorMessage} There was an error loading the metadata containing the file (metadata or metadata key not found).");
8484
}
8585
else
86-
OASISErrorHandling.HandleError(ref result, $"{errorMessage} There was an error loading the holon contianing the file. Reason: {holonResult.Message}");
86+
OASISErrorHandling.HandleError(ref result, $"{errorMessage} There was an error loading the holon containing the file. Reason: {holonResult.Message}");
8787

8888
return result;
8989
}
@@ -100,7 +100,7 @@ public async Task<OASISResult<byte[]>> LoadFileAsync(Guid id, Guid avatarId, Pro
100100
{
101101
result = OASISResultHelper.CopyOASISResultOnlyWithNoInnerResult(holonResult, result);
102102

103-
if (holonResult.Result.MetaData != null && holonResult.MetaData.ContainsKey("data") && holonResult.MetaData["data"] != null)
103+
if (holonResult.Result.MetaData != null && holonResult.Result.MetaData.ContainsKey("data") && holonResult.Result.MetaData["data"] != null)
104104
{
105105
result.Result = holonResult.Result.MetaData["data"] as byte[];
106106
result.Message = "File Loaded";

NextGenSoftware.OASIS.API.ONODE.Core/Managers/NFTManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ private async Task<OASISResult<INFTTransactionRespone>> MintNFTInternalAsync(IMi
11571157
break;
11581158

11591159
case NFTOffChainMetaType.OASIS:
1160-
request.ImageUrl = string.Concat(OASISDNA.OASIS.OASISAPIURL, "/data/getdata/", imageSaveResult.Result.Id);
1160+
request.ImageUrl = string.Concat(OASISDNA.OASIS.OASISAPIURL, "/data/load-file/", imageSaveResult.Result.Id);
11611161
break;
11621162
}
11631163
}
@@ -1187,7 +1187,7 @@ private async Task<OASISResult<INFTTransactionRespone>> MintNFTInternalAsync(IMi
11871187
break;
11881188

11891189
case NFTOffChainMetaType.OASIS:
1190-
providerRequest = CreateNFTTransactionRequestForProvider(request, string.Concat(OASISDNA.OASIS.OASISAPIURL, "/data/getdata/", jsonSaveResult.Result.Id));
1190+
providerRequest = CreateNFTTransactionRequestForProvider(request, string.Concat(OASISDNA.OASIS.OASISAPIURL, "/data/load-file/", jsonSaveResult.Result.Id));
11911191
break;
11921192
}
11931193

NextGenSoftware.OASIS.API.ONODE.WebAPI/Controllers/AvatarController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using NextGenSoftware.OASIS.API.ONode.WebAPI.Interfaces;
1818
using NextGenSoftware.OASIS.API.ONode.WebAPI.Models;
1919
using NextGenSoftware.OASIS.API.ONode.WebAPI.Models.Avatar;
20+
using NextGenSoftware.OASIS.API.ONode.WebAPI.Models.Data;
2021
using NextGenSoftware.OASIS.API.ONode.WebAPI.Models.Security;
2122
using NextGenSoftware.OASIS.Common;
2223

@@ -1439,6 +1440,7 @@ public async Task<OASISHttpResponseMessage<IAvatar>> GetLoggedInAvatar(ProviderT
14391440
return await GetLoggedInAvatar();
14401441
}
14411442

1443+
14421444

14431445
///// <summary>
14441446
///// Link's a given Avatar to a Providers Public Key (private/public key pairs or username, accountname, unique id, agentId, hash, etc).

0 commit comments

Comments
 (0)