From e4a271115c61fafc9a83d819da84e9edcfbdc7e2 Mon Sep 17 00:00:00 2001 From: David Ellams Date: Wed, 1 Jun 2022 14:45:07 -0500 Subject: [PATCH] - LOTS of work done over past few days on new key/wallet API's as well as improvements to the OASIS Architecture. - Added new None, StorageLocal, StorageLocalAndNetwork enum types to ProviderCategory (to be used in the new key/wallet api for storing private keys to local storage only. - Added new LocalFileOASIS enum type to ProviderType and moved None, All & Default to the top. - Save & SaveAsync methods on Avatar/IAvatar now take a optional providerType param. - Added SendTrasaction & SendTrasactionAsync methods to IOASISBlockchainStorageProvider interface that blockchain OASIS Providers need to implmenet. - Added new IOASISLocalStorageProvider interface that contains LoadProviderWallets, LoadProviderWalletsAsync, SaveProviderWallets & SaveProviderWalletsAsync methods that a Local Storage OASIS Provider need to implement such as HoloOASIS, SQLLiteDBOASIS & LocalFileOASIS. There will be more to come... - Added SendNFT & SendNFTAsync methods to IOASISNFTProvider interface. - Added Import, ExportAllDataForAvatarById, ExportAllDataForAvatarByUsername, ExportAllDataForAvatarByEmail & ExportAll methods to IOASISStorageProvider interface. - Added SendTransaction, SendTransactionAsync, SendNFT & SendNFTAsync methods to IOASISWallet & IProviderWallet interfaces & OASISWallet & ProviderWallet objects. - Added new Instance properties to all OASISManagers such as AvatarManager, HolonManager, KeyManager, WalletManager & SearchManager allowing static instances to be used instead of having to create new instances (singleton pattern best practice). - Moved OASISDNA & OASISDNAPath from OASISStorageProviderBase to OASISProvider abstract class because these are relevant to all providers, not just storage providers. - Added Import, ExportAllDataForAvatarById, ExportAllDataForAvatarByUsername, ExportAllDataForAvatarByEmail & ExportAll methods to OASISStorageProviderBase. - Added new LocalFileOASIS setting to OASISDNA. - Added new Import, ExportAllDataForAvatarById, ExportAllDataForAvatarByUsername, ExportAllDataForAvatarByEmail & ExportAll methods to all OASIS Providers including ActivityPubOASIS, BlockstackOASIS, ChainLinkOASIS, EOSIOOASIS, EthereumOASIS, HashgraphOASIS, HoloOASIS, IPFSOASIS, LocalFileOASIS, MongoDBOASIS, Neo4jOASIS, PLANOASIS, ScuttlebuttOASIS, SolanaOASIS, SOLIDOASIS, SQLLiteDBOASIS, TelosOASIS, ThreeFoldOASIS& TRONOASIS. - Added new LocalFileOASIS Provider which will serialize the avatar & holon data objects to a JSON file. Currently is serializes the Provider Wallets containing the private keys (encrypted) but will add additional encryption soon including quantum level encryption. - Removed ProviderPrivateKey, ProviderPublicKey, ProviderUsername & ProviderWalletAddress properties from the AvatarDetail entity in MongoDBOASIS Provider. - Added new LocalFileOASIS Provider to OASISBootLoader and fixed some other minor bugs. --- .../Enums/ProviderCategory.cs | 3 + .../Enums/ProviderType.cs | 7 +- .../Holons/Avatar.cs | 20 +- .../Interfaces/Avatar/IAvatar.cs | 6 +- .../IOASISBlockchainStorageProvider.cs | 6 + .../Providers/IOASISLLocalStorageProvider.cs | 16 + .../Interfaces/Providers/IOASISNFTProvider.cs | 5 + .../Interfaces/Providers/IOASISProvider.cs | 3 +- .../Providers/IOASIStorageProvider.cs | 17 +- .../Interfaces/Wallets/IOASISWallet.cs | 7 + .../Interfaces/Wallets/IProviderWallet.cs | 7 + .../{ => AvatarManager}/AvatarManager.cs | 342 ++++- .../Managers/HolonManager.cs | 15 +- .../Managers/KeyManager - OLD.cs | 1346 ----------------- .../Managers/KeyManager.cs | 56 +- .../Managers/OASISManager.cs | 8 +- .../Managers/ProviderManager.cs | 17 +- .../Managers/SearchManager.cs | 13 + .../Managers/WalletManager.cs | 80 +- .../OASISProvider.cs | 33 +- .../OASISStorageProviderBase.cs | 133 +- .../Objects/Wallets/OASISWallet.cs | 22 + .../Objects/Wallets/ProviderWallet.cs | 22 + NextGenSoftware.OASIS.API.DNA/OASISDNA.cs | 6 + .../OASIS_DNA.json | 17 +- .../AcitvityPubOASIS.cs | 25 + .../BlockStackOASIS.cs | 45 + .../ChainLinkOASIS.cs | 45 + .../EOSIOOASIS.cs | 45 + .../EthereumOASIS.cs | 25 + .../HashgraphOASIS.cs | 45 + .../HoloOASISBase.cs | 87 +- .../HoloOASIS.cs | 6 +- .../IPFSOASIS.cs | 27 +- .../LocalFileOASIS.cs | 373 +++++ ....OASIS.API.Providers.LocalFileOASIS.csproj | 13 + .../Entities/Avatar.cs | 2 +- .../Entities/AvatarDetail.cs | 16 +- .../MongoDBOASIS.cs | 58 +- .../Neo4jOASIS.cs | 25 + .../PLANOASIS.cs | 25 + .../SolanaOasis.cs | 45 + .../SOLIDOASIS.cs | 25 + .../Entities/AvatarEntity.cs | 9 +- .../SQLLiteDBOASIS.cs | 65 +- .../ScuttlebuttOASIS.cs | 25 + .../TRONOASIS.cs | 45 + .../TelosOASIS.cs | 45 + .../ThreeFoldOASIS.cs | 45 + ...xtGenSoftware.OASIS.OASISBootLoader.csproj | 1 + .../OASISBootLoader.cs | 36 +- NextGenSoftware.OASIS.STAR/DNA/OASIS_DNA.json | 24 +- The OASIS.sln | 22 +- 53 files changed, 1818 insertions(+), 1638 deletions(-) create mode 100644 NextGenSoftware.OASIS.API.Core/Interfaces/Providers/IOASISLLocalStorageProvider.cs rename NextGenSoftware.OASIS.API.Core/Managers/{ => AvatarManager}/AvatarManager.cs (93%) delete mode 100644 NextGenSoftware.OASIS.API.Core/Managers/KeyManager - OLD.cs create mode 100644 NextGenSoftware.OASIS.API.Providers.LocalFileOASIS/LocalFileOASIS.cs create mode 100644 NextGenSoftware.OASIS.API.Providers.LocalFileOASIS/NextGenSoftware.OASIS.API.Providers.LocalFileOASIS.csproj diff --git a/NextGenSoftware.OASIS.API.Core/Enums/ProviderCategory.cs b/NextGenSoftware.OASIS.API.Core/Enums/ProviderCategory.cs index 6fbd81745..072946916 100644 --- a/NextGenSoftware.OASIS.API.Core/Enums/ProviderCategory.cs +++ b/NextGenSoftware.OASIS.API.Core/Enums/ProviderCategory.cs @@ -3,9 +3,12 @@ namespace NextGenSoftware.OASIS.API.Core.Enums { public enum ProviderCategory { + None, Storage, + StorageLocal, Network, StorageAndNetwork, + StorageLocalAndNetwork, SmartContract, NFT, Application, diff --git a/NextGenSoftware.OASIS.API.Core/Enums/ProviderType.cs b/NextGenSoftware.OASIS.API.Core/Enums/ProviderType.cs index 221f55b29..0e61fc8ae 100644 --- a/NextGenSoftware.OASIS.API.Core/Enums/ProviderType.cs +++ b/NextGenSoftware.OASIS.API.Core/Enums/ProviderType.cs @@ -2,6 +2,9 @@ { public enum ProviderType { + None, + All, + Default, SolanaOASIS, HoloOASIS, EthereumOASIS, @@ -31,9 +34,7 @@ public enum ProviderType HoloWebOASIS, TRONOASIS, Neo4jOASIS, - All, - None, - Default, CosmosBlockChainOASIS, + LocalFileOASIS } } diff --git a/NextGenSoftware.OASIS.API.Core/Holons/Avatar.cs b/NextGenSoftware.OASIS.API.Core/Holons/Avatar.cs index ff0ea723e..90e3f4914 100644 --- a/NextGenSoftware.OASIS.API.Core/Holons/Avatar.cs +++ b/NextGenSoftware.OASIS.API.Core/Holons/Avatar.cs @@ -124,16 +124,26 @@ public bool OwnsToken(string token) return this.RefreshTokens?.Find(x => x.Token == token) != null; } - public async Task> SaveAsync() + public async Task> SaveAsync(ProviderType providerType = ProviderType.Default) { - OASISResult result = await (ProviderManager.CurrentStorageProvider).SaveAvatarAsync(this); - return result; + return await AvatarManager.Instance.SaveAvatarAsync(this, providerType); } - public OASISResult Save() + public OASISResult Save(ProviderType providerType = ProviderType.Default) { - return (ProviderManager.CurrentStorageProvider).SaveAvatar(this); + return AvatarManager.Instance.SaveAvatar(this, providerType); } + //public OASISResult SaveProviderWallets(ProviderType providerType = ProviderType.Default) + //{ + // return AvatarManager.Instance.SaveProviderWallets(this, providerType); + //} + + //TODO: Implement async version ASAP... + //public Task> SaveProviderWalletsAsync(ProviderType providerType = ProviderType.Default) + //{ + // return await AvatarManager.Instance.SaveProviderWalletsAsync(this, providerType); + //} + /* private int GetKarmaForType(KarmaTypePositive karmaType) { diff --git a/NextGenSoftware.OASIS.API.Core/Interfaces/Avatar/IAvatar.cs b/NextGenSoftware.OASIS.API.Core/Interfaces/Avatar/IAvatar.cs index 28e8a19e6..e685847b1 100644 --- a/NextGenSoftware.OASIS.API.Core/Interfaces/Avatar/IAvatar.cs +++ b/NextGenSoftware.OASIS.API.Core/Interfaces/Avatar/IAvatar.cs @@ -41,7 +41,9 @@ public interface IAvatar : IHolonBase //int Level { get; } //int XP { get; set; } bool OwnsToken(string token); - OASISResult Save(); - Task> SaveAsync(); + OASISResult Save(ProviderType providerType = ProviderType.Default); + Task> SaveAsync(ProviderType providerType = ProviderType.Default); + //OASISResult SaveProviderWallets(ProviderType providerType = ProviderType.Default); + //Task> SaveProviderWalletsAsync(ProviderType providerType = ProviderType.Default); } } \ No newline at end of file diff --git a/NextGenSoftware.OASIS.API.Core/Interfaces/Providers/IOASISBlockchainStorageProvider.cs b/NextGenSoftware.OASIS.API.Core/Interfaces/Providers/IOASISBlockchainStorageProvider.cs index ad4ec5d15..bee6f3fad 100644 --- a/NextGenSoftware.OASIS.API.Core/Interfaces/Providers/IOASISBlockchainStorageProvider.cs +++ b/NextGenSoftware.OASIS.API.Core/Interfaces/Providers/IOASISBlockchainStorageProvider.cs @@ -15,6 +15,12 @@ public interface IOASISBlockchainStorageProvider : IOASISStorageProvider //Central Storage/DB's by default can update the same record, if this flag is set below then they will act more like a Blockchain and store a new copy of the record and link to the previous version. //public bool IsVersionControlEnabled { get; set; } //You cannot turn VersionControl off for Blockchains because it is built in. + + public OASISResult SendTrasaction(IWalletTransaction transation); + public Task> SendTrasactionAsync(IWalletTransaction transation); + //public OASISResult SendNFT(IWalletTransaction transation); + //public Task> SendNFTAsync(IWalletTransaction transation); + //TODO: More specefic Blockchain options will appear here soon... ;-) } } \ No newline at end of file diff --git a/NextGenSoftware.OASIS.API.Core/Interfaces/Providers/IOASISLLocalStorageProvider.cs b/NextGenSoftware.OASIS.API.Core/Interfaces/Providers/IOASISLLocalStorageProvider.cs new file mode 100644 index 000000000..eb7158c95 --- /dev/null +++ b/NextGenSoftware.OASIS.API.Core/Interfaces/Providers/IOASISLLocalStorageProvider.cs @@ -0,0 +1,16 @@ +using NextGenSoftware.OASIS.API.Core.Enums; +using NextGenSoftware.OASIS.API.Core.Helpers; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace NextGenSoftware.OASIS.API.Core.Interfaces +{ + // This interface is responsbile for persisting provider wallets (including private keys) to local storage ONLY. + public interface IOASISLocalStorageProvider //: IOASISStorageProvider + { + public OASISResult>> LoadProviderWallets(); + public Task>>> LoadProviderWalletsAsync(); + public OASISResult SaveProviderWallets(Dictionary> providerWallets); + public Task> SaveProviderWalletsAsync(Dictionary> providerWallets); + } +} \ No newline at end of file diff --git a/NextGenSoftware.OASIS.API.Core/Interfaces/Providers/IOASISNFTProvider.cs b/NextGenSoftware.OASIS.API.Core/Interfaces/Providers/IOASISNFTProvider.cs index 1bd40cd80..1215d920c 100644 --- a/NextGenSoftware.OASIS.API.Core/Interfaces/Providers/IOASISNFTProvider.cs +++ b/NextGenSoftware.OASIS.API.Core/Interfaces/Providers/IOASISNFTProvider.cs @@ -1,8 +1,13 @@  +using NextGenSoftware.OASIS.API.Core.Helpers; +using System.Threading.Tasks; + namespace NextGenSoftware.OASIS.API.Core.Interfaces { public interface IOASISNFTProvider : IOASISProvider { //TODO: More to come soon... ;-) + public OASISResult SendNFT(IWalletTransaction transation); + public Task> SendNFTAsync(IWalletTransaction transation); } } \ No newline at end of file diff --git a/NextGenSoftware.OASIS.API.Core/Interfaces/Providers/IOASISProvider.cs b/NextGenSoftware.OASIS.API.Core/Interfaces/Providers/IOASISProvider.cs index ce6f8ecd1..c71508304 100644 --- a/NextGenSoftware.OASIS.API.Core/Interfaces/Providers/IOASISProvider.cs +++ b/NextGenSoftware.OASIS.API.Core/Interfaces/Providers/IOASISProvider.cs @@ -1,5 +1,4 @@ - -using NextGenSoftware.OASIS.API.Core.Enums; +using NextGenSoftware.OASIS.API.Core.Enums; using NextGenSoftware.OASIS.API.Core.Helpers; namespace NextGenSoftware.OASIS.API.Core.Interfaces diff --git a/NextGenSoftware.OASIS.API.Core/Interfaces/Providers/IOASIStorageProvider.cs b/NextGenSoftware.OASIS.API.Core/Interfaces/Providers/IOASIStorageProvider.cs index 5e1a09c37..4acbb9668 100644 --- a/NextGenSoftware.OASIS.API.Core/Interfaces/Providers/IOASIStorageProvider.cs +++ b/NextGenSoftware.OASIS.API.Core/Interfaces/Providers/IOASIStorageProvider.cs @@ -4,7 +4,7 @@ using NextGenSoftware.OASIS.API.Core.Enums; using NextGenSoftware.OASIS.API.Core.Helpers; using NextGenSoftware.OASIS.API.Core.Objects; -using static NextGenSoftware.OASIS.API.Core.Managers.AvatarManager; +using static NextGenSoftware.OASIS.API.Core.Managers.OASISManager; namespace NextGenSoftware.OASIS.API.Core.Interfaces { @@ -22,8 +22,6 @@ public interface IOASISStorageProvider : IOASISProvider Task> LoadAvatarByUsernameAsync(string avatarUsername, int version = 0); OASISResult LoadAvatar(string username, int version = 0); Task> LoadAvatarAsync(string username, int version = 0); - //OASISResult LoadAvatar(string username, string password, int version = 0); - //Task> LoadAvatarAsync(string username, string password, int version = 0); OASISResult> LoadAllAvatars(int version = 0); Task>> LoadAllAvatarsAsync(int version = 0); OASISResult LoadAvatarDetail(Guid id, int version = 0); @@ -75,16 +73,15 @@ public interface IOASISStorageProvider : IOASISProvider Task> DeleteHolonAsync(string providerKey, bool softDelete = true); //TODO: Implement these methods ASAP - this is how we can share data across silos, then merge, aggregate, sense-make, perform actions on the full internet data, etc... - //Task> Import(IEnumerable holons); //Imports all data into the OASIS from a given provider (will then be auto-replicated to all providers). NOTE: The Provider will need to convert the providers raw data into a list of holons (holonize the data). - //Task>> ExportAllDataForAvatarById(Guid avatarId, int version = 0); //Exports all data for a given avatar and provider. Version = 0 - Latest version. Version = -1 All versions. - //Task>> ExportAllDataForAvatarByUsername(string avatarUsername, int version = 0); //Exports all data for a given avatar and provider. Version = 0 - Latest version. Version = -1 All versions. - //Task>> ExportAllDataForAvatarByEmail(string avatarEmailAddress, int version = 0); //Exports all data for a given avatar and provider. Version = 0 - Latest version. Version = -1 All versions. - //Task>> ExportAll(int version = 0); //Exports all data for a given provider. Version = 0 - Latest version. Version = -1 All versions. + Task> Import(IEnumerable holons); //Imports all data into the OASIS from a given provider (will then be auto-replicated to all providers). NOTE: The Provider will need to convert the providers raw data into a list of holons (holonize the data). + Task>> ExportAllDataForAvatarById(Guid avatarId, int version = 0); //Exports all data for a given avatar and provider. Version = 0 - Latest version. Version = -1 All versions. + Task>> ExportAllDataForAvatarByUsername(string avatarUsername, int version = 0); //Exports all data for a given avatar and provider. Version = 0 - Latest version. Version = -1 All versions. + Task>> ExportAllDataForAvatarByEmail(string avatarEmailAddress, int version = 0); //Exports all data for a given avatar and provider. Version = 0 - Latest version. Version = -1 All versions. + Task>> ExportAll(int version = 0); //Exports all data for a given provider. Version = 0 - Latest version. Version = -1 All versions. Task> SearchAsync(ISearchParams searchParams, bool loadChildren = true, bool recursive = true, int maxChildDepth = 0, bool continueOnError = true, int version = 0); - event StorageProviderError StorageProviderError; - + public event StorageProviderError StorageProviderError; //TODO: Lots more to come! ;-) } } \ No newline at end of file diff --git a/NextGenSoftware.OASIS.API.Core/Interfaces/Wallets/IOASISWallet.cs b/NextGenSoftware.OASIS.API.Core/Interfaces/Wallets/IOASISWallet.cs index 48cf71e29..7ecead4ea 100644 --- a/NextGenSoftware.OASIS.API.Core/Interfaces/Wallets/IOASISWallet.cs +++ b/NextGenSoftware.OASIS.API.Core/Interfaces/Wallets/IOASISWallet.cs @@ -1,5 +1,7 @@  +using NextGenSoftware.OASIS.API.Core.Helpers; using System.Collections.Generic; +using System.Threading.Tasks; namespace NextGenSoftware.OASIS.API.Core.Interfaces { @@ -8,5 +10,10 @@ public interface IOASISWallet public List Wallets { get; set; } public List Transactions { get; set; } public int Balance { get; set; } + + public OASISResult SendTrasaction(IWalletTransaction transation); + public Task> SendTrasactionAsync(IWalletTransaction transation); + public OASISResult SendNFT(IWalletTransaction transation); + public Task> SendNFTAsync(IWalletTransaction transation); } } \ No newline at end of file diff --git a/NextGenSoftware.OASIS.API.Core/Interfaces/Wallets/IProviderWallet.cs b/NextGenSoftware.OASIS.API.Core/Interfaces/Wallets/IProviderWallet.cs index 79f8a412e..2754f3cdb 100644 --- a/NextGenSoftware.OASIS.API.Core/Interfaces/Wallets/IProviderWallet.cs +++ b/NextGenSoftware.OASIS.API.Core/Interfaces/Wallets/IProviderWallet.cs @@ -1,6 +1,8 @@  using NextGenSoftware.OASIS.API.Core.Enums; +using NextGenSoftware.OASIS.API.Core.Helpers; using System.Collections.Generic; +using System.Threading.Tasks; namespace NextGenSoftware.OASIS.API.Core.Interfaces { @@ -20,5 +22,10 @@ public interface IProviderWallet : IHolonBase public List Transactions {get;set;} public ProviderType ProviderType { get; set; } public int Balance { get; set; } + + public OASISResult SendTrasaction(IWalletTransaction transation); + public Task> SendTrasactionAsync(IWalletTransaction transation); + public OASISResult SendNFT(IWalletTransaction transation); + public Task> SendNFTAsync(IWalletTransaction transation); } } diff --git a/NextGenSoftware.OASIS.API.Core/Managers/AvatarManager.cs b/NextGenSoftware.OASIS.API.Core/Managers/AvatarManager/AvatarManager.cs similarity index 93% rename from NextGenSoftware.OASIS.API.Core/Managers/AvatarManager.cs rename to NextGenSoftware.OASIS.API.Core/Managers/AvatarManager/AvatarManager.cs index a500e3aea..3cae3185d 100644 --- a/NextGenSoftware.OASIS.API.Core/Managers/AvatarManager.cs +++ b/NextGenSoftware.OASIS.API.Core/Managers/AvatarManager/AvatarManager.cs @@ -9,7 +9,6 @@ using System.Threading.Tasks; using BC = BCrypt.Net.BCrypt; using NextGenSoftware.OASIS.API.Core.Enums; -using NextGenSoftware.OASIS.API.Core.Events; using NextGenSoftware.OASIS.API.Core.Helpers; using NextGenSoftware.OASIS.API.Core.Interfaces; using NextGenSoftware.OASIS.API.Core.Objects; @@ -20,10 +19,23 @@ namespace NextGenSoftware.OASIS.API.Core.Managers { public class AvatarManager : OASISManager { - public static IAvatar LoggedInAvatar { get; set; } + private static AvatarManager _instance = null; private ProviderManagerConfig _config; - public List OASISStorageProviders { get; set; } + public static IAvatar LoggedInAvatar { get; set; } + //public List OASISStorageProviders { get; set; } + + //TODO Implement this singleton pattern for other Managers... + public static AvatarManager Instance + { + get + { + if (_instance == null) + _instance = new AvatarManager(ProviderManager.CurrentStorageProvider); + + return _instance; + } + } public ProviderManagerConfig Config { @@ -43,7 +55,7 @@ public enum SaveMode AutoReplication } - public delegate void StorageProviderError(object sender, AvatarManagerErrorEventArgs e); + //public delegate void StorageProviderError(object sender, AvatarManagerErrorEventArgs e); //TODO: Not sure we want to pass the OASISDNA here? public AvatarManager(IOASISStorageProvider OASISStorageProvider, OASISDNA OASISDNA = null) : base(OASISStorageProvider, OASISDNA) @@ -1423,6 +1435,7 @@ public OASISResult SaveAvatar(IAvatar avatar, ProviderType providerType { int removingDays = OASISDNA.OASIS.Security.RemoveOldRefreshTokensAfterXDays; int removeQty = avatar.RefreshTokens.RemoveAll(token => (DateTime.Today - token.Created).TotalDays > removingDays); + Dictionary> wallets = CopyProviderWallets(avatar.ProviderWallets); result = SaveAvatarForProvider(avatar, result, SaveMode.FirstSaveAttempt, providerType); previousProviderType = ProviderManager.CurrentStorageProviderType.Value; @@ -1433,6 +1446,7 @@ public OASISResult SaveAvatar(IAvatar avatar, ProviderType providerType { if (type.Value != previousProviderType && type.Value != ProviderManager.CurrentStorageProviderType.Value) { + avatar.ProviderWallets = CopyProviderWallets(wallets); result = SaveAvatarForProvider(avatar, result, SaveMode.AutoFailOver, type.Value); if (!result.IsError && result.Result != null) @@ -1462,6 +1476,8 @@ public OASISResult SaveAvatar(IAvatar avatar, ProviderType providerType { foreach (EnumValue type in ProviderManager.GetProvidersThatAreAutoReplicating()) { + avatar.ProviderWallets = CopyProviderWallets(wallets); + if (type.Value != previousProviderType && type.Value != ProviderManager.CurrentStorageProviderType.Value) result = SaveAvatarForProvider(avatar, result, SaveMode.AutoReplication, type.Value); } @@ -2641,6 +2657,78 @@ public OASISResult RemoveKarmaFromAvatar(Guid avatarId, Karm return result; } + public OASISResult SaveProviderWallets(IAvatar avatar, ProviderType providerType = ProviderType.Default) + { + return SaveProviderWallets(avatar.ProviderWallets, providerType); + } + + public OASISResult SaveProviderWallets(Dictionary> wallets, ProviderType providerType = ProviderType.Default) + { + OASISResult result = new OASISResult(); + string errorMessageTemplate = "Error in SaveProviderWallets method in AvatarManager saving wallets for provider {0}. Reason: "; + string errorMessage = string.Format(errorMessageTemplate, providerType); + + try + { + OASISResult providerResult = ProviderManager.SetAndActivateCurrentStorageProvider(providerType); + errorMessage = string.Format(errorMessageTemplate, ProviderManager.CurrentStorageProviderType.Name); + + if (!providerResult.IsError && providerResult.Result != null) + { + //Make sure private keys are ONLY stored locally. + if (ProviderManager.CurrentStorageProviderCategory.Value != ProviderCategory.StorageLocal && ProviderManager.CurrentStorageProviderCategory.Value != ProviderCategory.StorageLocalAndNetwork) + { + foreach (ProviderType proType in wallets.Keys) + { + foreach (IProviderWallet wallet in wallets[proType]) + wallet.PrivateKey = null; + } + } + else + { + //TODO: Was going to load the private keys from the local storage and then restore any missing private keys before saving (in case they had been removed before saving to a non-local storage provider) but then there will be no way of knowing if the keys have been removed by the user (if they were then this would then incorrectly restore them again!). + //Commented out code was an alternative to saving the private keys seperatley as the next block below does... + //(result, IAvatar originalAvatar) = OASISResultHelper.UnWrapOASISResult(ref result, LoadAvatar(avatar.Id, true, providerType), String.Concat(errorMessage, "Error loading avatar. Reason: {0}")); + + //if (!result.IsError) + //{ + + //} + + + //We need to save the wallets (with private keys) seperatley to the local storage provider otherwise the next time a non local provider replicates to local it will overwrite the wallets and private keys (will be blank). + //TODO: The PrivateKeys are already encrypted but I want to add an extra layer of protection to encrypt the full wallet! ;-) + //TODO: Soon will also add a 3rd level of protection by quantum encrypting the keys/wallets... :) + + + var walletsTask = Task.Run(() => ((IOASISLocalStorageProvider)providerResult.Result).SaveProviderWallets(wallets)); + + if (walletsTask.Wait(TimeSpan.FromSeconds(OASISDNA.OASIS.StorageProviders.ProviderMethodCallTimeOutSeconds * 1000))) + { + if (walletsTask.Result.IsError || !walletsTask.Result.Result) + { + if (string.IsNullOrEmpty(walletsTask.Result.Message)) + walletsTask.Result.Message = "Unknown error occured saving provider wallets."; + + ErrorHandling.HandleWarning(ref result, string.Concat(errorMessage, walletsTask.Result.Message), walletsTask.Result.DetailedMessage); + } + } + else + ErrorHandling.HandleWarning(ref result, string.Concat(errorMessage, "timeout occured saving provider wallets.")); + } + + } + else + ErrorHandling.HandleWarning(ref result, string.Concat(errorMessage, providerResult.Message), providerResult.DetailedMessage); + } + catch (Exception ex) + { + ErrorHandling.HandleWarning(ref result, string.Concat(errorMessage, ex.Message), ex); + } + + return result; + } + //public bool CheckIfEmailIsAlreadyInUse(string email) //{ // OASISResult result = LoadAvatarByEmail(email); @@ -3110,7 +3198,12 @@ private async Task> LoadAvatarForProviderAsync(Guid id, OAS else { result.Result = task.Result.Result; - result.IsLoaded = true; + + //If we are loading from a local storge provider then load the provider wallets (including their private keys stored ONLY on local storage). + if (ProviderManager.CurrentStorageProviderCategory.Value == ProviderCategory.StorageLocal || ProviderManager.CurrentStorageProviderCategory.Value == ProviderCategory.StorageLocalAndNetwork) + result = await LoadProviderWalletsAsync(providerResult.Result, result, errorMessage); + else + result.IsLoaded = true; } } else @@ -3159,59 +3252,12 @@ private async Task> LoadAvatarForProviderAsync(string usern else { result.Result = task.Result.Result; - result.IsLoaded = true; - } - } - else - ErrorHandling.HandleWarning(ref result, string.Concat(errorMessage, "timeout occured.")); - } - else - ErrorHandling.HandleWarning(ref result, string.Concat(errorMessage, providerResult.Message), providerResult.DetailedMessage); - } - catch (Exception ex) - { - ErrorHandling.HandleWarning(ref result, string.Concat(errorMessage, ex.Message), ex); - } - - return result; - } - - /* - private OASISResult LoadAvatarForProvider(string username, string password, OASISResult result, ProviderType providerType = ProviderType.Default, int version = 0) - { - return LoadAvatarForProviderAsync(username, password, result).Result; - } - - private async Task> LoadAvatarForProviderAsync(string username, string password, OASISResult result, ProviderType providerType = ProviderType.Default, int version = 0) - { - //string errorMessage = $"Error in LoadAvatarForProviderAsync method in AvatarManager loading avatar with username {username} for provider {providerType}. Reason: "; - string errorMessageTemplate = "Error in LoadAvatarForProviderAsync method in AvatarManager loading avatar with username {0} for provider {1}. Reason: "; - string errorMessage = string.Format(errorMessageTemplate, username, providerType); - - try - { - OASISResult providerResult = ProviderManager.SetAndActivateCurrentStorageProvider(providerType); - errorMessage = string.Format(errorMessageTemplate, username, ProviderManager.CurrentStorageProviderType.Name); - - if (!providerResult.IsError && providerResult.Result != null) - { - var task = providerResult.Result.LoadAvatarAsync(username, password, version); - - if (await Task.WhenAny(task, Task.Delay(OASISDNA.OASIS.StorageProviders.ProviderMethodCallTimeOutSeconds * 1000)) == task) - { - result = task.Result; - - if (task.Result.IsError || task.Result.Result == null) - { - if (string.IsNullOrEmpty(task.Result.Message)) - task.Result.Message = "Avatar Not Found."; - ErrorHandling.HandleWarning(ref result, string.Concat(errorMessage, task.Result.Message), task.Result.DetailedMessage); - } - else - { - result.IsLoaded = true; - result.Result = task.Result.Result; + //If we are loading from a local storge provider then load the provider wallets (including their private keys stored ONLY on local storage). + if (ProviderManager.CurrentStorageProviderCategory.Value == ProviderCategory.StorageLocal) + result = await LoadProviderWalletsAsync(providerResult.Result, result, errorMessage); + else + result.IsLoaded = true; } } else @@ -3226,8 +3272,8 @@ private async Task> LoadAvatarForProviderAsync(string usern } return result; - }*/ - + } + private OASISResult LoadAvatarByEmailForProvider(string email, OASISResult result, ProviderType providerType = ProviderType.Default, int version = 0) { return LoadAvatarByEmailForProviderAsync(email, result, providerType, version).Result; @@ -3258,8 +3304,13 @@ private async Task> LoadAvatarByEmailForProviderAsync(strin } else { - result.IsLoaded = true; result.Result = task.Result.Result; + + //If we are loading from a local storge provider then load the provider wallets (including their private keys stored ONLY on local storage). + if (ProviderManager.CurrentStorageProviderCategory.Value == ProviderCategory.StorageLocal) + result = await LoadProviderWalletsAsync(providerResult.Result, result, errorMessage); + else + result.IsLoaded = true; } } else @@ -3528,6 +3579,37 @@ public async Task> SaveAvatarForProviderAsync(IAvatar avata if (!providerResult.IsError && providerResult.Result != null) { + //Make sure private keys are ONLY stored locally. + if (ProviderManager.CurrentStorageProviderCategory.Value != ProviderCategory.StorageLocal && ProviderManager.CurrentStorageProviderCategory.Value != ProviderCategory.StorageLocalAndNetwork) + { + foreach (ProviderType proType in avatar.ProviderWallets.Keys) + { + foreach (IProviderWallet wallet in avatar.ProviderWallets[proType]) + wallet.PrivateKey = null; + } + } + else + { + //We need to save the wallets (with private keys) seperatley to the local storage provider otherwise the next time a non local provider replicates to local it will overwrite the wallets and private keys (will be blank). + //TODO: The PrivateKeys are already encrypted but I want to add an extra layer of protection to encrypt the full wallet! ;-) + //TODO: Soon will also add a 3rd level of protection by quantum encrypting the keys/wallets... :) + + var walletsTask = Task.Run(() => ((IOASISLocalStorageProvider)providerResult.Result).SaveProviderWalletsAsync(avatar.ProviderWallets)); + + if (await Task.WhenAny(walletsTask, Task.Delay(OASISDNA.OASIS.StorageProviders.ProviderMethodCallTimeOutSeconds * 1000)) == walletsTask) + { + if (walletsTask.Result.IsError || !walletsTask.Result.Result) + { + if (string.IsNullOrEmpty(walletsTask.Result.Message) && saveMode != SaveMode.AutoReplication) + walletsTask.Result.Message = "Unknown error occured saving provider wallets."; + + ErrorHandling.HandleWarning(ref result, string.Concat(errorMessage, walletsTask.Result.Message), walletsTask.Result.DetailedMessage, saveMode == SaveMode.AutoReplication); + } + } + else + ErrorHandling.HandleWarning(ref result, string.Concat(errorMessage, "timeout occured saving provider wallets."), saveMode == SaveMode.AutoReplication); + } + var task = providerResult.Result.SaveAvatarAsync(avatar); if (await Task.WhenAny(task, Task.Delay(OASISDNA.OASIS.StorageProviders.ProviderMethodCallTimeOutSeconds * 1000)) == task) @@ -3559,9 +3641,9 @@ public async Task> SaveAvatarForProviderAsync(IAvatar avata return result; } - public OASISResult SaveAvatarForProvider(IAvatar avatar, OASISResult result, SaveMode saveMode, ProviderType providerType = ProviderType.Default) + private OASISResult SaveAvatarForProvider(IAvatar avatar, OASISResult result, SaveMode saveMode, ProviderType providerType = ProviderType.Default) { - string errorMessageTemplate = "Error in SaveAvatarForProvider method in AvatarManager saving avatar detail with name {0}, username {1} and id {2} for provider {3} for {4}. Reason: "; + string errorMessageTemplate = "Error in SaveAvatarForProvider method in AvatarManager saving avatar with name {0}, username {1} and id {2} for provider {3} for {4}. Reason: "; string errorMessage = string.Format(errorMessageTemplate, avatar.Name, avatar.Username, avatar.Id, providerType, Enum.GetName(typeof(SaveMode), saveMode)); try @@ -3571,9 +3653,51 @@ public OASISResult SaveAvatarForProvider(IAvatar avatar, OASISResult.UnWrapOASISResult(ref result, LoadAvatar(avatar.Id, true, providerType), String.Concat(errorMessage, "Error loading avatar. Reason: {0}")); + + //if (!result.IsError) + //{ + + //} + + + //We need to save the wallets (with private keys) seperatley to the local storage provider otherwise the next time a non local provider replicates to local it will overwrite the wallets and private keys (will be blank). + //TODO: The PrivateKeys are already encrypted but I want to add an extra layer of protection to encrypt the full wallet! ;-) + //TODO: Soon will also add a 3rd level of protection by quantum encrypting the keys/wallets... :) + + + var walletsTask = Task.Run(() => ((IOASISLocalStorageProvider)providerResult.Result).SaveProviderWallets(avatar.ProviderWallets)); + + if (walletsTask.Wait(TimeSpan.FromSeconds(OASISDNA.OASIS.StorageProviders.ProviderMethodCallTimeOutSeconds * 1000))) + { + if (walletsTask.Result.IsError || !walletsTask.Result.Result) + { + if (string.IsNullOrEmpty(walletsTask.Result.Message) && saveMode != SaveMode.AutoReplication) + walletsTask.Result.Message = "Unknown error occured saving provider wallets."; + + ErrorHandling.HandleWarning(ref result, string.Concat(errorMessage, walletsTask.Result.Message), walletsTask.Result.DetailedMessage, saveMode == SaveMode.AutoReplication); + } + } + else + ErrorHandling.HandleWarning(ref result, string.Concat(errorMessage, "timeout occured saving provider wallets."), saveMode == SaveMode.AutoReplication); + } + var task = Task.Run(() => providerResult.Result.SaveAvatar(avatar)); - if (task.Wait(TimeSpan.FromSeconds(OASISDNA.OASIS.StorageProviders.ProviderMethodCallTimeOutSeconds))) + if (task.Wait(TimeSpan.FromSeconds(OASISDNA.OASIS.StorageProviders.ProviderMethodCallTimeOutSeconds * 1000))) { if (task.Result.IsError || task.Result.Result == null) { @@ -4111,6 +4235,98 @@ private async Task> UpdateAvatarDetailAsync(IAvatarDe return result; } + private async Task> LoadProviderWalletsAsync(IOASISStorageProvider provider, OASISResult result, string errorMessage) + { + //If we are loading from a local storge provider then load the provider wallets (including their private keys stored ONLY on local storage). + if (ProviderManager.CurrentStorageProviderCategory.Value == ProviderCategory.StorageLocal || ProviderManager.CurrentStorageProviderCategory.Value == ProviderCategory.StorageLocalAndNetwork) + { + var walletTask = ((IOASISLocalStorageProvider)provider).LoadProviderWalletsAsync(); + + if (await Task.WhenAny(walletTask, Task.Delay(OASISDNA.OASIS.StorageProviders.ProviderMethodCallTimeOutSeconds * 1000)) == walletTask) + { + if (walletTask.Result.IsError || walletTask.Result.Result == null) + { + if (string.IsNullOrEmpty(walletTask.Result.Message)) + walletTask.Result.Message = "Error loading avatar wallets."; + + ErrorHandling.HandleWarning(ref result, string.Concat(errorMessage, walletTask.Result.Message), walletTask.Result.DetailedMessage); + } + else + { + result.Result.ProviderWallets = walletTask.Result.Result; + result.IsLoaded = true; + } + } + else + ErrorHandling.HandleWarning(ref result, string.Concat(errorMessage, "timeout occured loading provider wallets.")); + } + + return result; + } + + private OASISResult LoadProviderWallets(IOASISStorageProvider provider, OASISResult result, string errorMessage) + { + return LoadProviderWalletsAsync(provider, result, errorMessage).Result; + + /* + //If we are loading from a local storge provider then load the provider wallets (including their private keys stored ONLY on local storage). + if (ProviderManager.CurrentStorageProviderCategory.Value == ProviderCategory.StorageLocal) + { + var walletTask = ((IOASISLocalStorageProvider)provider).LoadProviderWallets(); + + if (Task.WhenAny(walletTask, Task.Delay(OASISDNA.OASIS.StorageProviders.ProviderMethodCallTimeOutSeconds * 1000)) == walletTask) + { + if (walletTask.Result.IsError || walletTask.Result.Result == null) + { + if (string.IsNullOrEmpty(walletTask.Result.Message)) + walletTask.Result.Message = "Error loading avatar wallets."; + + ErrorHandling.HandleWarning(ref result, string.Concat(errorMessage, walletTask.Result.Message), walletTask.Result.DetailedMessage); + } + else + { + result.Result.ProviderWallets = walletTask.Result.Result; + result.IsLoaded = true; + } + } + else + ErrorHandling.HandleWarning(ref result, string.Concat(errorMessage, "timeout occured loading provider wallets.")); + } + + return result;*/ + } + + private Dictionary> CopyProviderWallets(Dictionary> wallets) + { + Dictionary> walletsCopy = new Dictionary>(); + + foreach (ProviderType pType in wallets.Keys) + { + foreach (IProviderWallet wallet in wallets[pType]) + { + if (!walletsCopy.ContainsKey(pType)) + walletsCopy[pType] = new List(); + + walletsCopy[pType].Add(new ProviderWallet() + { + PublicKey = wallet.PublicKey, + PrivateKey = wallet.PrivateKey, + WalletAddress = wallet.WalletAddress, + Id = wallet.Id, + CreatedByAvatarId = wallet.CreatedByAvatarId, + CreatedDate = wallet.CreatedDate, + ModifiedByAvatarId = wallet.ModifiedByAvatarId, + ModifiedDate = wallet.ModifiedDate, + Version = wallet.Version + }); + + //wallets[pType].Add(wallet); + } + } + + return walletsCopy; + } + //private OASISResult ProcessAvatarLogin(OASISResult result, string username, string password, string ipAddress, Func> saveFunc) // diff --git a/NextGenSoftware.OASIS.API.Core/Managers/HolonManager.cs b/NextGenSoftware.OASIS.API.Core/Managers/HolonManager.cs index a336057b7..ac2a90701 100644 --- a/NextGenSoftware.OASIS.API.Core/Managers/HolonManager.cs +++ b/NextGenSoftware.OASIS.API.Core/Managers/HolonManager.cs @@ -15,7 +15,20 @@ namespace NextGenSoftware.OASIS.API.Core.Managers { public class HolonManager : OASISManager { - public delegate void StorageProviderError(object sender, AvatarManagerErrorEventArgs e); + private static HolonManager _instance = null; + + //public delegate void StorageProviderError(object sender, AvatarManagerErrorEventArgs e); + + public static HolonManager Instance + { + get + { + if (_instance == null) + _instance = new HolonManager(ProviderManager.CurrentStorageProvider); + + return _instance; + } + } //TODO: In future more than one storage provider can be active at a time where each call can specify which provider to use. public HolonManager(IOASISStorageProvider OASISStorageProvider, OASISDNA OASISDNA = null) : base(OASISStorageProvider, OASISDNA) diff --git a/NextGenSoftware.OASIS.API.Core/Managers/KeyManager - OLD.cs b/NextGenSoftware.OASIS.API.Core/Managers/KeyManager - OLD.cs deleted file mode 100644 index 5b0840671..000000000 --- a/NextGenSoftware.OASIS.API.Core/Managers/KeyManager - OLD.cs +++ /dev/null @@ -1,1346 +0,0 @@ -//using System; -//using System.Collections.Generic; -//using System.Linq; -//using Cryptography.ECDSA; -//using BC = BCrypt.Net.BCrypt; -//using Rijndael256; -//using NextGenSoftware.OASIS.API.DNA; -//using NextGenSoftware.OASIS.API.Core.Enums; -//using NextGenSoftware.OASIS.API.Core.Events; -//using NextGenSoftware.OASIS.API.Core.Helpers; -//using NextGenSoftware.OASIS.API.Core.Interfaces; -//using NextGenSoftware.OASIS.API.Core.Objects; -//using NextGenSoftware.OASIS.API.Core.Security; -//using NextGenSoftware.OASIS.API.Core.Utilities; - -//namespace NextGenSoftware.OASIS.API.Core.Managers -//{ -// //TODO: Add Async version of all methods and add IKeyManager Interface. -// public class KeyManager : OASISManager -// { -// private static Dictionary _avatarIdToProviderUniqueStorageKeyLookup = new Dictionary(); -// private static Dictionary> _avatarIdToProviderPublicKeysLookup = new Dictionary>(); -// private static Dictionary _avatarIdToProviderPrivateKeyLookup = new Dictionary(); -// private static Dictionary _avatarUsernameToProviderUniqueStorageKeyLookup = new Dictionary(); -// private static Dictionary> _avatarUsernameToProviderPublicKeysLookup = new Dictionary>(); -// private static Dictionary _avatarUsernameToProviderPrivateKeyLookup = new Dictionary(); -// private static Dictionary _avatarEmailToProviderUniqueStorageKeyLookup = new Dictionary(); -// private static Dictionary> _avatarEmailToProviderPublicKeysLookup = new Dictionary>(); -// private static Dictionary _avatarEmailToProviderPrivateKeyLookup = new Dictionary(); -// private static Dictionary _providerUniqueStorageKeyToAvatarIdLookup = new Dictionary(); -// private static Dictionary _providerPublicKeyToAvatarIdLookup = new Dictionary(); -// private static Dictionary _providerPrivateKeyToAvatarIdLookup = new Dictionary(); -// private static Dictionary _providerUniqueStorageKeyToAvatarUsernameLookup = new Dictionary(); -// private static Dictionary _providerPublicKeyToAvatarUsernameLookup = new Dictionary(); -// private static Dictionary _providerPrivateKeyToAvatarUsernameLookup = new Dictionary(); -// private static Dictionary _providerUniqueStorageKeyToAvatarEmailLookup = new Dictionary(); -// private static Dictionary _providerPublicKeyToAvatarEmailLookup = new Dictionary(); -// private static Dictionary _providerPrivateKeyToAvatarEmailLookup = new Dictionary(); -// private static Dictionary _providerUniqueStorageKeyToAvatarLookup = new Dictionary(); -// private static Dictionary _providerPublicKeyToAvatarLookup = new Dictionary(); -// private static Dictionary _providerPrivateKeyToAvatarLookup = new Dictionary(); - -// public WifUtility WifUtility { get; set; } = new WifUtility(); -// public AvatarManager AvatarManager { get; set; } - -// public List OASISStorageProviders { get; set; } - -// public delegate void StorageProviderError(object sender, AvatarManagerErrorEventArgs e); - -// public KeyManager(IOASISStorageProvider OASISStorageProvider, AvatarManager avatarManager, OASISDNA OASISDNA = null) : base(OASISStorageProvider, OASISDNA) -// { -// AvatarManager = avatarManager; -// } - -// //public static void Init(IOASISStorageProvider OASISStorageProvider, AvatarManager avatarManager, OASISDNA OASISDNA = null) -// //{ -// // AvatarManager = avatarManager; -// //} - -// //TODO: Implement later (Cache Disabled). -// //public bool IsCacheEnabled { get; set; } = true; - -// public OASISResult GenerateKeyPair(ProviderType provider) -// { -// return GenerateKeyPair(Enum.GetName(typeof(ProviderType), provider)); -// } - -// public OASISResult GenerateKeyPair(string prefix) -// { -// OASISResult result = new OASISResult(new KeyPair()); -// byte[] privateKey = Secp256K1Manager.GenerateRandomKey(); - -// OASISResult privateWifResult = GetPrivateWif(privateKey); - -// if (!privateWifResult.IsError && privateWifResult.Result != null) -// { -// result.Result.PrivateKey = privateWifResult.Result; - -// byte[] publicKey = Secp256K1Manager.GetPublicKey(privateKey, true); - -// OASISResult publicWifResult = GetPublicWif(publicKey, prefix); - -// if (!publicWifResult.IsError && publicWifResult.Result != null) -// result.Result.PublicKey = publicWifResult.Result; -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GenerateKeyPair generating public WIF. Reason: {publicWifResult.Message}"); -// } -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GenerateKeyPair generating private WIF. Reason: {privateWifResult.Message}"); - -// return result; -// } - -// public OASISResult ClearCache() -// { -// _avatarIdToProviderUniqueStorageKeyLookup.Clear(); -// _avatarIdToProviderPublicKeysLookup.Clear(); -// _avatarIdToProviderPrivateKeyLookup.Clear(); -// _avatarUsernameToProviderUniqueStorageKeyLookup.Clear(); -// _avatarUsernameToProviderPublicKeysLookup.Clear(); -// _avatarUsernameToProviderPrivateKeyLookup.Clear(); -// _avatarEmailToProviderUniqueStorageKeyLookup.Clear(); -// _avatarEmailToProviderPublicKeysLookup.Clear(); -// _avatarEmailToProviderPrivateKeyLookup.Clear(); -// _providerUniqueStorageKeyToAvatarIdLookup.Clear(); -// _providerPublicKeyToAvatarIdLookup.Clear(); -// _providerPrivateKeyToAvatarIdLookup.Clear(); -// _providerUniqueStorageKeyToAvatarUsernameLookup.Clear(); -// _providerPublicKeyToAvatarUsernameLookup.Clear(); -// _providerPrivateKeyToAvatarUsernameLookup.Clear(); -// _providerUniqueStorageKeyToAvatarEmailLookup.Clear(); -// _providerPublicKeyToAvatarEmailLookup.Clear(); -// _providerPrivateKeyToAvatarEmailLookup.Clear(); -// _providerUniqueStorageKeyToAvatarLookup.Clear(); -// _providerPublicKeyToAvatarLookup.Clear(); -// _providerPrivateKeyToAvatarLookup.Clear(); - -// return new OASISResult(true) { Message = "Cache Cleared."}; -// } - -// //TODO: Finish Later. -// //public OASISResult ClearCacheForAvatarById(Guid id) -// //{ -// // _avatarIdToProviderUniqueStorageKeyLookup[id.ToString()] = null; -// // _avatarIdToProviderPublicKeysLookup[id.ToString()] = null; -// // _avatarIdToProviderPrivateKeyLookup[id.ToString()] = null; -// // _avatarUsernameToProviderUniqueStorageKeyLookup.Clear(); -// // _avatarUsernameToProviderPublicKeysLookup.Clear(); -// // _avatarUsernameToProviderPrivateKeyLookup.Clear(); -// // _avatarEmailToProviderUniqueStorageKeyLookup.Clear(); -// // _avatarEmailToProviderPublicKeysLookup.Clear(); -// // _avatarEmailToProviderPrivateKeyLookup.Clear(); -// // _providerUniqueStorageKeyToAvatarIdLookup.Clear(); -// // _providerPublicKeyToAvatarIdLookup.Clear(); -// // _providerPrivateKeyToAvatarIdLookup.Clear(); -// // _providerUniqueStorageKeyToAvatarUsernameLookup.Clear(); -// // _providerPublicKeyToAvatarUsernameLookup.Clear(); -// // _providerPrivateKeyToAvatarUsernameLookup.Clear(); -// // _providerUniqueStorageKeyToAvatarEmailLookup.Clear(); -// // _providerPublicKeyToAvatarEmailLookup.Clear(); -// // _providerPrivateKeyToAvatarEmailLookup.Clear(); -// // _providerUniqueStorageKeyToAvatarLookup.Clear(); -// // _providerPublicKeyToAvatarLookup.Clear(); -// // _providerPrivateKeyToAvatarLookup.Clear(); - -// // return new OASISResult(true); -// //} - -// // Could be used as the public key for private/public key pairs. Could also be a username/accountname/unique id/etc, etc. -// public OASISResult LinkProviderPublicKeyToAvatarById(Guid avatarId, ProviderType providerTypeToLinkTo, string providerKey, ProviderType providerToLoadAvatarFrom = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); - -// try -// { -// OASISResult avatarResult = AvatarManager.LoadAvatar(avatarId, false, providerToLoadAvatarFrom); - -// //TODO Apply same fix in ALL other methods. -// if (!avatarResult.IsError && avatarResult.Result != null) -// result = LinkProviderPublicKeyToAvatar(avatarResult.Result, providerTypeToLinkTo, providerKey, providerToLoadAvatarFrom); -// else -// ErrorHandling.HandleError(ref result, $"Error occured in LinkProviderPublicKeyToAvatarById loading avatar for id {avatarId}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } -// catch (Exception ex) -// { -// ErrorHandling.HandleError(ref result, $"Unknown error occured in LinkProviderPublicKeyToAvatarById for avatar {avatarId} and providerType {Enum.GetName(typeof(ProviderType), providerToLoadAvatarFrom)} and key {providerKey}: {ex.Message}"); -// } - -// return result; -// } - -// // Could be used as the public key for private/public key pairs. Could also be a username/accountname/unique id/etc, etc. -// public OASISResult LinkProviderPublicKeyToAvatarByUsername(string username, ProviderType providerTypeToLinkTo, string providerKey, ProviderType providerToLoadAvatarFrom = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); - -// try -// { -// OASISResult avatarResult = AvatarManager.LoadAvatar(username, false, providerToLoadAvatarFrom); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// result = LinkProviderPublicKeyToAvatar(avatarResult.Result, providerTypeToLinkTo, providerKey, providerToLoadAvatarFrom); -// else -// ErrorHandling.HandleError(ref result, $"Error occured in LinkProviderPublicKeyToAvatarByUsername loading avatar for username {username}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } -// catch (Exception ex) -// { -// ErrorHandling.HandleError(ref result, $"Unknown error occured in LinkProviderPublicKeyToAvatarByUsername for avatar {username} and providerType {Enum.GetName(typeof(ProviderType), providerToLoadAvatarFrom)} and key {providerKey}: {ex.Message}"); -// } - -// return result; -// } - -// public OASISResult LinkProviderPublicKeyToAvatarByEmail(string email, ProviderType providerTypeToLinkTo, string providerKey, ProviderType providerToLoadAvatarFrom = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); - -// try -// { -// OASISResult avatarResult = AvatarManager.LoadAvatarByEmail(email, false, providerToLoadAvatarFrom); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// result = LinkProviderPublicKeyToAvatar(avatarResult.Result, providerTypeToLinkTo, providerKey, providerToLoadAvatarFrom); -// else -// ErrorHandling.HandleError(ref result, $"Error occured in LinkProviderPublicKeyToAvatarByEmail loading avatar for email {email}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } -// catch (Exception ex) -// { -// ErrorHandling.HandleError(ref result, $"Unknown error occured in LinkProviderPublicKeyToAvatarByEmail for avatar {email} and providerType {Enum.GetName(typeof(ProviderType), providerToLoadAvatarFrom)} and key {providerKey}: {ex.Message}"); -// } - -// return result; -// } - -// public OASISResult GetWalletThatPublicKeyBelongsTo(string providerKey, ProviderType providerType) -// { -// OASISResult result = new OASISResult(); -// OASISResult> avatarsResult = AvatarManager.LoadAllAvatars(); - -// if (!avatarsResult.IsError && avatarsResult.Result != null) -// { -// foreach (IAvatar avatar in avatarsResult.Result) -// { -// result = GetWalletThatPublicKeyBelongsTo(providerKey, providerType, avatar); - -// if (result.Result != null) -// break; -// } -// } -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GetWalletThatPublicKeyBelongsTo whilst loading avatars. Reason:{avatarsResult.Message}"); - -// return result; -// } - -// public OASISResult GetWalletThatPublicKeyBelongsTo(string providerKey, ProviderType providerType, IAvatar avatar) -// { -// OASISResult result = new OASISResult(); - -// foreach (IProviderWallet wallet in avatar.ProviderWallets[providerType]) -// { -// if (wallet.PublicKey == providerKey) -// { -// result.Result = wallet; -// result.Message = "Wallet Found"; -// break; -// } -// } - -// return result; -// } - -// public OASISResult LinkProviderPublicKeyToAvatar(IAvatar avatar, ProviderType providerTypeToLinkTo, string providerKey, ProviderType providerToLoadAvatarFrom = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); - -// try -// { - - -// if (!avatar.ProviderPublicKey.ContainsKey(providerTypeToLinkTo)) -// avatar.ProviderPublicKey.Add(providerTypeToLinkTo, new List()); - -// if (!avatar.ProviderPublicKey[providerTypeToLinkTo].Contains(providerKey)) -// avatar.ProviderPublicKey[providerTypeToLinkTo].Add(providerKey); -// else -// { -// ErrorHandling.HandleError(ref result, $"The Public ProviderKey {providerKey} is already linked to the avatar {avatar.Id} {avatar.Username}. The ProviderKey must be unique per provider."); -// return result; -// } - -// //TODO: Upgrade Avatar.Save() methods to return OASISResult ASAP. -// result.Result = avatar.Save() != null; - -// //TODO Apply same fix in ALL other methods. -// if (result.Result) -// { -// result.IsSaved = true; -// result.Message = $"Public key {providerKey} successfully linked to avatar {avatar.Id} - {avatar.Username} for provider {Enum.GetName(typeof(ProviderType), providerTypeToLinkTo)}"; -// } -// else -// ErrorHandling.HandleError(ref result, $"Error occured in LinkProviderPublicKeyToAvatar saving avatar {avatar.Id} - {avatar.Username} for providerType {Enum.GetName(typeof(ProviderType), providerToLoadAvatarFrom)} and key {providerKey}"); -// } -// catch (Exception ex) -// { -// ErrorHandling.HandleError(ref result, $"Unknown error occured in LinkProviderPublicKeyToAvatar for avatar {avatar.Id} {avatar.Username} and providerType {Enum.GetName(typeof(ProviderType), providerToLoadAvatarFrom)} and key {providerKey}: {ex.Message}"); -// } - -// return result; -// } - -// public OASISResult GenerateKeyPairAndLinkProviderKeysToAvatarById(Guid avatarId, ProviderType providerTypeToLinkTo, bool showPublicKey = true, bool showPrivateKey = false, ProviderType providerToLoadAvatarFrom = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); - -// try -// { -// OASISResult avatarResult = AvatarManager.LoadAvatar(avatarId, false, providerToLoadAvatarFrom); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// result = GenerateKeyPairAndLinkProviderKeysToAvatar(avatarResult.Result, providerTypeToLinkTo, showPublicKey, showPrivateKey, providerToLoadAvatarFrom); -// else -// ErrorHandling.HandleError(ref result, $"An error occured in GenerateKeyPairAndLinkProviderKeysToAvatarById loading avatar for id {avatarId}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } -// catch (Exception ex) -// { -// ErrorHandling.HandleError(ref result, $"An unknown error occured in GenerateKeyPairAndLinkProviderKeysToAvatarById for avatar {avatarId} and providerType {Enum.GetName(typeof(ProviderType), providerToLoadAvatarFrom)}: {ex.Message}"); -// } - -// return result; -// } - -// // Could be used as the public key for private/public key pairs. Could also be a username/accountname/unique id/etc, etc. -// public OASISResult GenerateKeyPairAndLinkProviderKeysToAvatarByUsername(string username, ProviderType providerTypeToLinkTo, bool showPublicKey = true, bool showPrivateKey = false, ProviderType providerToLoadAvatarFrom = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); - -// try -// { -// OASISResult avatarResult = AvatarManager.LoadAvatar(username, false, providerToLoadAvatarFrom); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// result = GenerateKeyPairAndLinkProviderKeysToAvatar(avatarResult.Result, providerTypeToLinkTo, showPublicKey, showPrivateKey, providerToLoadAvatarFrom); -// else -// ErrorHandling.HandleError(ref result, $"An error occured in GenerateKeyPairAndLinkProviderKeysToAvatarByUsername loading avatar for username {username}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } -// catch (Exception ex) -// { -// ErrorHandling.HandleError(ref result, $"An unknown error occured in GenerateKeyPairAndLinkProviderKeysToAvatarByUsername for username {username} and providerType {Enum.GetName(typeof(ProviderType), providerToLoadAvatarFrom)}: {ex.Message}"); -// } - -// return result; -// } - -// public OASISResult GenerateKeyPairAndLinkProviderKeysToAvatarByEmail(string email, ProviderType providerTypeToLinkTo, bool showPublicKey = true, bool showPrivateKey = false, ProviderType providerToLoadAvatarFrom = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); - -// try -// { -// OASISResult avatarResult = AvatarManager.LoadAvatarByEmail(email, false, providerToLoadAvatarFrom); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// result = GenerateKeyPairAndLinkProviderKeysToAvatar(avatarResult.Result, providerTypeToLinkTo, showPublicKey, showPrivateKey, providerToLoadAvatarFrom); -// else -// ErrorHandling.HandleError(ref result, $"An error occured in GenerateKeyPairAndLinkProviderKeysToAvatarByUsername loading avatar for email {email}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } -// catch (Exception ex) -// { -// ErrorHandling.HandleError(ref result, $"An unknown error occured in GenerateKeyPairAndLinkProviderKeysToAvatarByUsername for email {email} and providerType {Enum.GetName(typeof(ProviderType), providerToLoadAvatarFrom)}: {ex.Message}"); -// } - -// return result; -// } - -// public OASISResult GenerateKeyPairAndLinkProviderKeysToAvatar(IAvatar avatar, ProviderType providerTypeToLinkTo, bool showPublicKey = true, bool showPrivateKey = false, ProviderType providerToLoadAvatarFrom = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); - -// if (avatar == null) -// { -// ErrorHandling.HandleError(ref result, "An error occured in GenerateKeyPairAndLinkProviderKeysToAvatar. The avatar passed in is null."); -// return result; -// } - -// try -// { -// result = GenerateKeyPair(providerTypeToLinkTo); - -// if (!result.IsError && result.Result != null) -// { -// OASISResult publicKeyResult = LinkProviderPublicKeyToAvatar(avatar, providerTypeToLinkTo, result.Result.PublicKey, providerToLoadAvatarFrom); - -// if (!publicKeyResult.IsError && publicKeyResult.Result) -// { -// OASISResult privateKeyResult = LinkProviderPrivateKeyToAvatar(avatar, providerTypeToLinkTo, result.Result.PrivateKey, providerToLoadAvatarFrom); - -// if (privateKeyResult.IsError || !privateKeyResult.Result) -// ErrorHandling.HandleError(ref result, $"An error occured in GenerateKeyPairAndLinkProviderKeysToAvatar whilst linking the generated private key to the avatar {avatar.Id} - {avatar.Username}. Reason: {privateKeyResult.Message}", privateKeyResult.DetailedMessage); -// else -// { -// result.Message = "KeyPair Generated & Linked To Avatar."; - -// if (!showPublicKey) -// result.Result.PublicKey = null; - -// if (!showPrivateKey) -// result.Result.PrivateKey = null; -// } -// } -// else -// ErrorHandling.HandleError(ref result, $"An error occured in GenerateKeyPairAndLinkProviderKeysToAvatar whilst linking the generated public key to the avatar {avatar.Id} - {avatar.Username}. Reason: {publicKeyResult.Message}", publicKeyResult.DetailedMessage); -// } -// } -// catch (Exception ex) -// { -// ErrorHandling.HandleError(ref result, $"Unknown error occured in LinkProviderPublicKeyToAvatar for avatar {avatar.Id} {avatar.Username} and providerType {Enum.GetName(typeof(ProviderType), providerToLoadAvatarFrom)}: {ex.Message}"); -// } - -// return result; -// } - -// // Private key for a public/private keypair. -// public OASISResult LinkProviderPrivateKeyToAvatarById(Guid avatarId, ProviderType providerTypeToLinkTo, string providerPrivateKey, ProviderType providerToLoadAvatarFrom = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); - -// try -// { -// OASISResult avatarResult = AvatarManager.LoadAvatar(avatarId, false, providerToLoadAvatarFrom); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// result = LinkProviderPrivateKeyToAvatar(avatarResult.Result, providerTypeToLinkTo, providerPrivateKey, providerToLoadAvatarFrom); -// else -// ErrorHandling.HandleError(ref result, $"Error occured in LinkProviderPrivateKeyToAvatar loading avatar for id {avatarId}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } -// catch (Exception ex) -// { -// ErrorHandling.HandleError(ref result, $"Unknown error occured in LinkPrivateProviderKeyToAvatar for avatar {avatarId} and providerType {Enum.GetName(typeof(ProviderType), providerToLoadAvatarFrom)} and key {providerPrivateKey}: {ex.Message}"); -// } - -// return result; -// } - -// // Private key for a public/private keypair. -// public OASISResult LinkProviderPrivateKeyToAvatarByUsername(string username, ProviderType providerTypeToLinkTo, string providerPrivateKey, ProviderType providerToLoadAvatarFrom = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); - -// try -// { -// OASISResult avatarResult = AvatarManager.LoadAvatar(username, false, providerToLoadAvatarFrom); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// result = LinkProviderPrivateKeyToAvatar(avatarResult.Result, providerTypeToLinkTo, providerPrivateKey, providerToLoadAvatarFrom); -// else -// ErrorHandling.HandleError(ref result, $"Error occured in LinkProviderPrivateKeyToAvatar loading avatar for username {username}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } -// catch (Exception ex) -// { -// ErrorHandling.HandleError(ref result, $"Unknown error occured in LinkPrivateProviderKeyToAvatar for avatar {username} and providerType {Enum.GetName(typeof(ProviderType), providerToLoadAvatarFrom)} and key {providerPrivateKey}: {ex.Message}"); -// } - -// return result; -// } - -// // Private key for a public/private keypair. -// public OASISResult LinkProviderPrivateKeyToAvatarByEmail(string email, ProviderType providerTypeToLinkTo, string providerPrivateKey, ProviderType providerToLoadAvatarFrom = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); - -// try -// { -// OASISResult avatarResult = AvatarManager.LoadAvatarByEmail(email, false, providerToLoadAvatarFrom); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// result = LinkProviderPrivateKeyToAvatar(avatarResult.Result, providerTypeToLinkTo, providerPrivateKey, providerToLoadAvatarFrom); -// else -// ErrorHandling.HandleError(ref result, $"Error occured in LinkProviderPrivateKeyToAvatarByEmail loading avatar for email {email}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } -// catch (Exception ex) -// { -// ErrorHandling.HandleError(ref result, $"Unknown error occured in LinkProviderPrivateKeyToAvatarByEmail for avatar {email} and providerType {Enum.GetName(typeof(ProviderType), providerToLoadAvatarFrom)} and key {providerPrivateKey}: {ex.Message}"); -// } - -// return result; -// } - -// public OASISResult LinkProviderPrivateKeyToAvatar(IAvatar avatar, ProviderType providerTypeToLinkTo, string providerPrivateKey, ProviderType providerToLoadAvatarFrom = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); - -// try -// { -// //TODO Apply same fix in ALL other methods. -// //if (!avatar.ProviderPrivateKey.ContainsKey(providerTypeToLinkTo)) -// // avatar.ProviderPrivateKey.Add(providerTypeToLinkTo, new List()); - -// if (!avatar.ProviderPrivateKey[providerTypeToLinkTo].Contains(providerPrivateKey)) -// avatar.ProviderPrivateKey[providerTypeToLinkTo] = providerPrivateKey; -// else -// { -// ErrorHandling.HandleError(ref result, $"The Private ProviderKey {providerPrivateKey} is already linked to the avatar {avatar.Id} {avatar.Username}. The ProviderKey must be unique per provider."); -// return result; -// } - -// //TODO: Upgrade Avatar.Save() methods to return OASISResult ASAP. -// //TODO: Fix the StringCipher below or find the strongest encryption, maybe the Qunatum Encryption? :) -// //avatar.ProviderPrivateKey[providerTypeToLinkTo] = StringCipher.Encrypt(providerPrivateKey); -// //avatar.ProviderPrivateKey[providerTypeToLinkTo] = BC.HashPassword(providerPrivateKey); -// avatar.ProviderPrivateKey[providerTypeToLinkTo] = Rijndael.Encrypt(providerPrivateKey, OASISDNA.OASIS.Security.OASISProviderPrivateKeys.Rijndael256Key, KeySize.Aes256); -// result.Result = avatar.Save() != null; - -// //TODO Apply same fix in ALL other methods. -// if (result.Result) -// { -// result.IsSaved = true; -// result.Message = $"Private key successfully linked to avatar {avatar.Id} - {avatar.Username} for provider {Enum.GetName(typeof(ProviderType), providerTypeToLinkTo)}"; -// } -// else -// ErrorHandling.HandleError(ref result, $"Error occured in LinkProviderPrivateKeyToAvatar saving avatar {avatar.Id} - {avatar.Username} for providerType {Enum.GetName(typeof(ProviderType), providerToLoadAvatarFrom)}"); -// } -// catch (Exception ex) -// { -// ErrorHandling.HandleError(ref result, $"Unknown error occured in LinkProviderPrivateKeyToAvatar for avatar {avatar.Id} {avatar.Username} and providerType {Enum.GetName(typeof(ProviderType), providerToLoadAvatarFrom)}: {ex.Message}"); -// } - -// return result; -// } - -// public OASISResult GetProviderUniqueStorageKeyForAvatarById(Guid avatarId, ProviderType providerType = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); -// string key = string.Concat(Enum.GetName(providerType), avatarId); - -// if (!_avatarIdToProviderUniqueStorageKeyLookup.ContainsKey(key)) -// { -// OASISResult avatarResult = AvatarManager.LoadAvatar(avatarId, true, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// result = GetProviderUniqueStorageKeyForAvatar(avatarResult.Result, key, _avatarIdToProviderUniqueStorageKeyLookup, providerType); -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GetProviderUniqueStorageKeyForAvatarById loading the avatar with id {avatarId}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } - -// return result; -// } - -// public OASISResult GetProviderUniqueStorageKeyForAvatarByUsername(string avatarUsername, ProviderType providerType = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); - -// string key = string.Concat(Enum.GetName(providerType), avatarUsername); - -// if (!_avatarUsernameToProviderUniqueStorageKeyLookup.ContainsKey(key)) -// { -// OASISResult avatarResult = AvatarManager.LoadAvatar(avatarUsername, true, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// result = GetProviderUniqueStorageKeyForAvatar(avatarResult.Result, key, _avatarUsernameToProviderUniqueStorageKeyLookup, providerType); -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GetProviderUniqueStorageKeyForAvatarByUsername loading avatar with username {avatarUsername}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } - -// return result; -// } - -// public OASISResult GetProviderUniqueStorageKeyForAvatarByEmail(string avatarEmail, ProviderType providerType = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); - -// string key = string.Concat(Enum.GetName(providerType), avatarEmail); - -// if (!_avatarEmailToProviderUniqueStorageKeyLookup.ContainsKey(key)) -// { -// OASISResult avatarResult = AvatarManager.LoadAvatarByEmail(avatarEmail, true, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// result = GetProviderUniqueStorageKeyForAvatar(avatarResult.Result, key, _avatarEmailToProviderUniqueStorageKeyLookup, providerType); -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GetProviderUniqueStorageKeyForAvatarByEmail loading avatar with avatarEmail {avatarEmail}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } - -// return result; -// } - -// public OASISResult> GetProviderPublicKeysForAvatarById(Guid avatarId, ProviderType providerType = ProviderType.Default) -// { -// OASISResult> result = new OASISResult>(); -// string key = string.Concat(Enum.GetName(providerType), avatarId); - -// if (!_avatarIdToProviderPublicKeysLookup.ContainsKey(key)) -// { -// OASISResult avatarResult = AvatarManager.LoadAvatar(avatarId, true, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// { -// if (avatarResult.Result.ProviderPublicKey.ContainsKey(providerType)) -// { -// _avatarIdToProviderPublicKeysLookup[key] = avatarResult.Result.ProviderPublicKey[providerType]; -// result.Result = _avatarIdToProviderPublicKeysLookup[key]; -// } -// else -// ErrorHandling.HandleError(ref result, string.Concat("Error occured in GetProviderPublicKeysForAvatarById. The avatar with id ", avatarId, " has not been linked to the ", Enum.GetName(providerType), " provider. Please use the LinkProviderPublicKeyToAvatar method on the AvatarManager or avatar REST API.")); -// } -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GetProviderPublicKeysForAvatarById loading avatar with id {avatarId}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } - -// return result; -// } - -// public OASISResult> GetProviderPublicKeysForAvatarByUsername(string avatarUsername, ProviderType providerType = ProviderType.Default) -// { -// OASISResult> result = new OASISResult>(); -// string key = string.Concat(Enum.GetName(providerType), avatarUsername); - -// if (!_avatarUsernameToProviderPublicKeysLookup.ContainsKey(key)) -// { -// OASISResult avatarResult = AvatarManager.LoadAvatar(avatarUsername, true, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// { -// if (avatarResult.Result.ProviderPublicKey.ContainsKey(providerType)) -// { -// _avatarUsernameToProviderPublicKeysLookup[key] = avatarResult.Result.ProviderPublicKey[providerType]; -// result.Result = _avatarUsernameToProviderPublicKeysLookup[key]; -// } -// else -// ErrorHandling.HandleError(ref result, string.Concat("The avatar with username ", avatarUsername, " has not been linked to the ", Enum.GetName(providerType), " provider. Please use the LinkProviderPublicKeyToAvatar method on the AvatarManager or avatar REST API.")); -// } -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GetProviderPublicKeysForAvatarByUsername loading avatar with username {avatarUsername}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } - -// return result; -// } - -// public OASISResult> GetProviderPublicKeysForAvatarByEmail(string avatarEmail, ProviderType providerType = ProviderType.Default) -// { -// OASISResult> result = new OASISResult>(); -// string key = string.Concat(Enum.GetName(providerType), avatarEmail); - -// if (!_avatarEmailToProviderPublicKeysLookup.ContainsKey(key)) -// { -// OASISResult avatarResult = AvatarManager.LoadAvatarByEmail(avatarEmail, true, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// { -// if (avatarResult.Result.ProviderPublicKey.ContainsKey(providerType)) -// { -// _avatarEmailToProviderPublicKeysLookup[key] = avatarResult.Result.ProviderPublicKey[providerType]; -// result.Result = _avatarEmailToProviderPublicKeysLookup[key]; -// } -// else -// ErrorHandling.HandleError(ref result, string.Concat("The avatar with email ", avatarEmail, " has not been linked to the ", Enum.GetName(providerType), " provider. Please use the LinkProviderPublicKeyToAvatar method on the AvatarManager or avatar REST API.")); -// } -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GetProviderPublicKeysForAvatarByEmail loading avatar with email {avatarEmail}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } - -// return result; -// } - -// public OASISResult GetProviderPrivateKeyForAvatarById(Guid avatarId, ProviderType providerType = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); -// string key = string.Concat(Enum.GetName(providerType), avatarId); - -// if (AvatarManager.LoggedInAvatar.Id != avatarId) -// { -// result.IsError = true; -// result.Message = "You cannot retreive the private key for another person's avatar. Please login to this account and try again."; -// } - -// if (!_avatarIdToProviderPrivateKeyLookup.ContainsKey(key)) -// { -// OASISResult avatarResult = AvatarManager.LoadAvatar(avatarId, false, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// { -// if (avatarResult.Result.ProviderPublicKey.ContainsKey(providerType)) -// { -// _avatarIdToProviderPrivateKeyLookup[key] = avatarResult.Result.ProviderPrivateKey[providerType]; -// //result.Result = StringCipher.Decrypt(_avatarIdToProviderPrivateKeyLookup[key]); -// result.Result = Rijndael.Decrypt(_avatarIdToProviderPrivateKeyLookup[key], OASISDNA.OASIS.Security.OASISProviderPrivateKeys.Rijndael256Key, KeySize.Aes256); -// } -// else -// ErrorHandling.HandleError(ref result, string.Concat("The avatar with id ", avatarId, " has not been linked to the ", Enum.GetName(providerType), " provider. Please use the LinkProviderPrivateKeyToAvatar method on the AvatarManager or avatar REST API.")); -// } -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GetProviderPrivateKeyForAvatarById loading avatar with id {avatarId}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } - -// return result; -// } - -// public OASISResult GetProviderPrivateKeyForAvatarByUsername(string avatarUsername, ProviderType providerType = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); -// string key = string.Concat(Enum.GetName(providerType), avatarUsername); - -// if (AvatarManager.LoggedInAvatar.Username != avatarUsername) -// ErrorHandling.HandleError(ref result, "Error occured in GetProviderPrivateKeyForAvatarByUsername. You cannot retreive the private key for another person's avatar. Please login to this account and try again."); - -// if (!_avatarUsernameToProviderPrivateKeyLookup.ContainsKey(key)) -// { -// OASISResult avatarResult = AvatarManager.LoadAvatar(avatarUsername, false, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// { -// if (avatarResult.Result.ProviderPublicKey.ContainsKey(providerType)) -// { -// _avatarUsernameToProviderPrivateKeyLookup[key] = avatarResult.Result.ProviderPrivateKey[providerType]; -// //result.Result = StringCipher.Decrypt(_avatarUsernameToProviderPrivateKeyLookup[key]); -// result.Result = Rijndael.Decrypt(_avatarUsernameToProviderPrivateKeyLookup[key], OASISDNA.OASIS.Security.OASISProviderPrivateKeys.Rijndael256Key, KeySize.Aes256); -// } -// else -// ErrorHandling.HandleError(ref result, string.Concat("Error occured in GetProviderPrivateKeyForAvatarByUsername. The avatar with username ", avatarUsername, " was not found.")); -// } -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GetProviderPrivateKeyForAvatarByUsername loading avatar with username {avatarUsername}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } - -// return result; -// } - -// //public OASISResult GetProviderPrivateKeyForAvatarByEmail(string avatarEmail, ProviderType providerType = ProviderType.Default) -// //{ -// // OASISResult result = new OASISResult(); -// // string key = string.Concat(Enum.GetName(providerType), avatarEmail); - -// // if (AvatarManager.LoggedInAvatar.Email != avatarEmail) -// // ErrorHandling.HandleError(ref result, "Error occured in GetProviderPrivateKeyForAvatarByEmail. You cannot retreive the private key for another person's avatar. Please login to this account and try again."); - -// // if (!_avatarEmailToProviderPrivateKeyLookup.ContainsKey(key)) -// // { -// // OASISResult avatarResult = AvatarManager.LoadAvatarByEmail(avatarEmail, false, providerType); - -// // if (!avatarResult.IsError && avatarResult.Result != null) -// // { -// // if (avatarResult.Result.ProviderPublicKey.ContainsKey(providerType)) -// // _avatarEmailToProviderPrivateKeyLookup[key] = avatarResult.Result.ProviderPrivateKey[providerType]; -// // else -// // ErrorHandling.HandleError(ref result, string.Concat("Error occured in GetProviderPrivateKeyForAvatarByEmail. The avatar with email ", avatarEmail, " was not found.")); -// // } -// // else -// // ErrorHandling.HandleError(ref result, $"Error occured in GetProviderPrivateKeyForAvatarByEmail loading avatar with email {avatarEmail}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// // } - -// // //result.Result = StringCipher.Decrypt(_avatarEmailToProviderPrivateKeyLookup[key]); -// // result.Result = Rijndael.Decrypt(_avatarEmailToProviderPrivateKeyLookup[key], OASISDNA.OASIS.Security.OASISProviderPrivateKeys.Rijndael256Key, KeySize.Aes256); -// // return result; -// //} - -// //public OASISResult GetProviderPrivateKeyForAvatarByEmail(string email, ProviderType providerType = ProviderType.Default) -// //{ -// // OASISResult result = new OASISResult(); -// // string key = string.Concat(Enum.GetName(providerType), avatarUsername); - -// // if (AvatarManager.LoggedInAvatar.Email != email) -// // ErrorHandling.HandleError(ref result, "Error occured in GetProviderPrivateKeyForAvatar. You cannot retreive the private key for another person's avatar. Please login to this account and try again."); - -// // if (!_avatarUsernameToProviderPrivateKeyLookup.ContainsKey(key)) -// // { -// // OASISResult avatarResult = AvatarManager.LoadAvatarByEmail(email, false, providerType); - -// // if (!avatarResult.IsError && avatarResult.Result != null) -// // { -// // if (avatarResult.Result.ProviderPublicKey.ContainsKey(providerType)) -// // _avatarIdToProviderPrivateKeyLookup[key] = avatarResult.Result.ProviderPrivateKey[providerType]; -// // else -// // ErrorHandling.HandleError(ref result, string.Concat("Error occured in GetProviderPrivateKeyForAvatar. The avatar with username ", avatarUsername, " was not found.")); -// // } -// // else -// // ErrorHandling.HandleError(ref result, $"Error occured in GetProviderPrivateKeyForAvatar loading avatar with username {avatarUsername}. Reason: {avatarResult.Message}"); -// // } - -// // result.Result = StringCipher.Decrypt(_avatarUsernameToProviderPrivateKeyLookup[key]); -// // return result; -// //} - -// public OASISResult GetAvatarIdForProviderUniqueStorageKey(string providerKey, ProviderType providerType = ProviderType.Default) -// { -// // TODO: Do we need to store both the id and whole avatar in the cache? Think only need one? Just storing the id would use less memory and be faster but there may be use cases for when we need the whole avatar? -// // In future, if there is not a use case for the whole avatar we will just use the id cache and remove the other. -// OASISResult result = new OASISResult(); -// string key = string.Concat(Enum.GetName(providerType), providerKey); - -// if (!_providerUniqueStorageKeyToAvatarIdLookup.ContainsKey(key)) -// { -// OASISResult avatarResult = GetAvatarForProviderUniqueStorageKey(providerKey, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// { -// _providerUniqueStorageKeyToAvatarIdLookup[key] = avatarResult.Result.Id; -// result.Result = _providerUniqueStorageKeyToAvatarIdLookup[key]; -// } -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GetAvatarIdForProviderUniqueStorageKey loading avatar for providerKey {providerKey}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } - -// return result; -// } - -// public OASISResult GetAvatarUsernameForProviderUniqueStorageKey(string providerKey, ProviderType providerType = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); - -// // TODO: Do we need to store both the id and whole avatar in the cache? Think only need one? Just storing the id would use less memory and be faster but there may be use cases for when we need the whole avatar? -// // In future, if there is not a use case for the whole avatar we will just use the id cache and remove the other. - -// string key = string.Concat(Enum.GetName(providerType), providerKey); - -// if (!_providerUniqueStorageKeyToAvatarUsernameLookup.ContainsKey(key)) -// { -// OASISResult avatarResult = GetAvatarForProviderUniqueStorageKey(providerKey, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// { -// _providerUniqueStorageKeyToAvatarUsernameLookup[key] = avatarResult.Result.Username; -// result.Result = _providerUniqueStorageKeyToAvatarUsernameLookup[key]; -// } -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GetAvatarUsernameForProviderUniqueStorageKey loading avatar for providerKey {providerKey}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } - -// return result; -// } - -// public OASISResult GetAvatarEmailForProviderUniqueStorageKey(string providerKey, ProviderType providerType = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); - -// // TODO: Do we need to store both the id and whole avatar in the cache? Think only need one? Just storing the id would use less memory and be faster but there may be use cases for when we need the whole avatar? -// // In future, if there is not a use case for the whole avatar we will just use the id cache and remove the other. - -// string key = string.Concat(Enum.GetName(providerType), providerKey); - -// if (!_providerUniqueStorageKeyToAvatarEmailLookup.ContainsKey(key)) -// { -// OASISResult avatarResult = GetAvatarForProviderUniqueStorageKey(providerKey, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// { -// _providerUniqueStorageKeyToAvatarEmailLookup[key] = avatarResult.Result.Email; -// result.Result = _providerUniqueStorageKeyToAvatarEmailLookup[key]; -// } -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GetAvatarEmailForProviderUniqueStorageKey loading avatar for providerKey {providerKey}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } - -// return result; -// } - -// public OASISResult GetAvatarForProviderUniqueStorageKey(string providerKey, ProviderType providerType = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); -// string key = string.Concat(Enum.GetName(providerType), providerKey); - -// if (!_providerUniqueStorageKeyToAvatarLookup.ContainsKey(key)) -// { -// //TODO: Ideally need a new overload for LoadAvatar that takes the provider key. -// //TODO: In the meantime should we cache the full list of Avatars? Could take up a LOT of memory so probably not good idea? -// OASISResult> avatarsResult = AvatarManager.LoadAllAvatars(true, providerType); - -// if (!avatarsResult.IsError && avatarsResult.Result != null) -// { -// IAvatar avatar = avatarsResult.Result.FirstOrDefault(x => x.ProviderUniqueStorageKey.ContainsKey(providerType) && x.ProviderUniqueStorageKey[providerType] == providerKey); - -// if (avatar != null) -// { -// _providerUniqueStorageKeyToAvatarIdLookup[key] = avatar.Id; -// _providerUniqueStorageKeyToAvatarUsernameLookup[key] = avatar.Username; -// _providerUniqueStorageKeyToAvatarEmailLookup[key] = avatar.Email; -// _providerUniqueStorageKeyToAvatarLookup[key] = avatar; - -// result.Result = _providerUniqueStorageKeyToAvatarLookup[key]; -// } -// else -// ErrorHandling.HandleError(ref result, string.Concat("The provider Key ", providerKey, " for the ", Enum.GetName(providerType), " providerType has not been linked to an avatar. Please use the LinkProviderKeyToAvatar method on the AvatarManager or avatar REST API.")); - -// } -// else -// ErrorHandling.HandleError(ref result, $"Error in GetAvatarForProviderUniqueStorageKey loading all avatars. Reason: {avatarsResult.Message}", avatarsResult.DetailedMessage); -// } - -// return result; -// } - -// public OASISResult GetAvatarIdForProviderPublicKey(string providerKey, ProviderType providerType = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); - -// // TODO: Do we need to store both the id and whole avatar in the cache? Think only need one? Just storing the id would use less memory and be faster but there may be use cases for when we need the whole avatar? -// // In future, if there is not a use case for the whole avatar we will just use the id cache and remove the other. - -// string key = string.Concat(Enum.GetName(providerType), providerKey); - -// if (!_providerPublicKeyToAvatarIdLookup.ContainsKey(key)) -// { -// OASISResult avatarResult = GetAvatarForProviderPublicKey(providerKey, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// { -// _providerPublicKeyToAvatarIdLookup[key] = avatarResult.Result.Id; -// result.Result = _providerPublicKeyToAvatarIdLookup[key]; -// } -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GetAvatarIdForProviderPublicKey loading avatar for providerKey {providerKey}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } - -// return result; -// } - -// public OASISResult GetAvatarUsernameForProviderPublicKey(string providerKey, ProviderType providerType = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); -// // TODO: Do we need to store both the id and whole avatar in the cache? Think only need one? Just storing the id would use less memory and be faster but there may be use cases for when we need the whole avatar? -// // In future, if there is not a use case for the whole avatar we will just use the id cache and remove the other. - -// string key = string.Concat(Enum.GetName(providerType), providerKey); - -// if (!_providerPublicKeyToAvatarUsernameLookup.ContainsKey(key)) -// { -// OASISResult avatarResult = GetAvatarForProviderPublicKey(providerKey, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// { -// _providerPublicKeyToAvatarUsernameLookup[key] = avatarResult.Result.Username; -// result.Result = _providerPublicKeyToAvatarUsernameLookup[key]; -// } -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GetAvatarUsernameForProviderPublicKey loading avatar for providerKey {providerKey}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } - -// return result; -// } - -// public OASISResult GetAvatarEmailForProviderPublicKey(string providerKey, ProviderType providerType = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); -// // TODO: Do we need to store both the id and whole avatar in the cache? Think only need one? Just storing the id would use less memory and be faster but there may be use cases for when we need the whole avatar? -// // In future, if there is not a use case for the whole avatar we will just use the id cache and remove the other. - -// string key = string.Concat(Enum.GetName(providerType), providerKey); - -// if (!_providerPublicKeyToAvatarEmailLookup.ContainsKey(key)) -// { -// OASISResult avatarResult = GetAvatarForProviderPublicKey(providerKey, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// { -// _providerPublicKeyToAvatarEmailLookup[key] = avatarResult.Result.Email; -// result.Result = _providerPublicKeyToAvatarEmailLookup[key]; -// } -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GetAvatarEmailForProviderPublicKey loading avatar for providerKey {providerKey}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } - -// return result; -// } - -// public OASISResult GetAvatarForProviderPublicKey(string providerKey, ProviderType providerType = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); -// string key = string.Concat(Enum.GetName(providerType), providerKey); - -// if (!_providerPublicKeyToAvatarLookup.ContainsKey(key)) -// { -// //TODO: Ideally need a new overload for LoadAvatarDetail that takes the public provider key. -// //TODO: In the meantime should we cache the full list of AvatarDetails? Could take up a LOT of memory so probably not good idea? -// OASISResult> avatarsResult = AvatarManager.LoadAllAvatars(true, providerType); - -// if (!avatarsResult.IsError && avatarsResult.Result != null) -// { -// IAvatar avatar = avatarsResult.Result.FirstOrDefault(x => x.ProviderPublicKey.ContainsKey(providerType) && x.ProviderPublicKey[providerType].Contains(providerKey)); - -// if (avatar != null) -// { -// _providerPublicKeyToAvatarIdLookup[key] = avatar.Id; -// _providerPublicKeyToAvatarUsernameLookup[key] = avatar.Username; -// _providerPublicKeyToAvatarEmailLookup[key] = avatar.Email; -// _providerPublicKeyToAvatarLookup[key] = avatar; - -// result.Result = _providerPublicKeyToAvatarLookup[key]; -// } -// else -// ErrorHandling.HandleError(ref result, string.Concat("The provider public Key ", providerKey, " for the ", Enum.GetName(providerType), " providerType has not been linked to an avatar. Please use the LinkProviderPublicKeyToAvatar method on the AvatarManager or avatar REST API.")); -// } -// else -// ErrorHandling.HandleError(ref result, string.Concat("Error in GetAvatarForProviderPublicKey for the provider public Key ", providerKey, " for the ", Enum.GetName(providerType), " providerType. There was an error loading all avatars. Reason: ", avatarsResult.Message)); -// } - -// return result; -// } - -// public OASISResult GetAvatarIdForProviderPrivateKey(string providerKey, ProviderType providerType = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); - -// // TODO: Do we need to store both the id and whole avatar in the cache? Think only need one? Just storing the id would use less memory and be faster but there may be use cases for when we need the whole avatar? -// // In future, if there is not a use case for the whole avatar we will just use the id cache and remove the other. - -// string key = string.Concat(Enum.GetName(providerType), providerKey); - -// if (!_providerPrivateKeyToAvatarIdLookup.ContainsKey(key)) -// { -// OASISResult avatarResult = GetAvatarForProviderPrivateKey(providerKey, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// { -// _providerPrivateKeyToAvatarIdLookup[key] = avatarResult.Result.Id; -// result.Result = _providerPrivateKeyToAvatarIdLookup[key]; -// } -// else -// ErrorHandling.HandleError(ref result, string.Concat("Error occured in GetAvatarIdForProviderPrivateKey. The provider public Key ", providerKey, " for the ", Enum.GetName(providerType), " providerType has not been linked to an avatar. Please use the LinkProviderPublicKeyToAvatar method on the AvatarManager or avatar REST API.")); -// } - -// return result; -// } - -// public OASISResult GetAvatarUsernameForProviderPrivateKey(string providerKey, ProviderType providerType = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); -// // TODO: Do we need to store both the id and whole avatar in the cache? Think only need one? Just storing the id would use less memory and be faster but there may be use cases for when we need the whole avatar? -// // In future, if there is not a use case for the whole avatar we will just use the id cache and remove the other. - -// string key = string.Concat(Enum.GetName(providerType), providerKey); - -// if (!_providerPrivateKeyToAvatarUsernameLookup.ContainsKey(key)) -// { -// OASISResult avatarResult = GetAvatarForProviderPrivateKey(providerKey, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// { -// _providerPrivateKeyToAvatarUsernameLookup[key] = avatarResult.Result.Username; -// result.Result = _providerPrivateKeyToAvatarUsernameLookup[key]; -// } -// else -// ErrorHandling.HandleError(ref result, string.Concat("Error occured in GetAvatarUsernameForProviderPrivateKey for the ", Enum.GetName(providerType), " providerType has not been linked to an avatar. Please use the LinkProviderPublicKeyToAvatar method on the AvatarManager or avatar REST API.")); -// } - -// return result; -// } - -// public OASISResult GetAvatarEmailForProviderPrivateKey(string providerKey, ProviderType providerType = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); -// // TODO: Do we need to store both the id and whole avatar in the cache? Think only need one? Just storing the id would use less memory and be faster but there may be use cases for when we need the whole avatar? -// // In future, if there is not a use case for the whole avatar we will just use the id cache and remove the other. - -// string key = string.Concat(Enum.GetName(providerType), providerKey); - -// if (!_providerPrivateKeyToAvatarEmailLookup.ContainsKey(key)) -// { -// OASISResult avatarResult = GetAvatarForProviderPrivateKey(providerKey, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// { -// _providerPrivateKeyToAvatarEmailLookup[key] = avatarResult.Result.Email; -// result.Result = _providerPrivateKeyToAvatarEmailLookup[key]; -// } -// else -// ErrorHandling.HandleError(ref result, string.Concat("Error occured in GetAvatarEmailForProviderPrivateKey for the ", Enum.GetName(providerType), " providerType has not been linked to an avatar. Please use the LinkProviderPublicKeyToAvatar method on the AvatarManager or avatar REST API.")); -// } - -// return result; -// } - -// public OASISResult GetAvatarForProviderPrivateKey(string providerKey, ProviderType providerType = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); - -// //TODO: Fix the StringCipher below or find the strongest encryption, maybe the Qunatum Encryption? :) -// //string key = string.Concat(Enum.GetName(providerType), StringCipher.Encrypt(providerKey)); -// //string key = string.Concat(Enum.GetName(providerType), BC.HashPassword(providerKey)); -// string key = string.Concat(Enum.GetName(providerType), Rijndael.Encrypt(providerKey, OASISDNA.OASIS.Security.OASISProviderPrivateKeys.Rijndael256Key, KeySize.Aes256)); - -// if (!_providerPrivateKeyToAvatarLookup.ContainsKey(key)) -// { -// //TODO: Ideally need a new overload for LoadAvatarDetail that takes the public provider key. -// //TODO: In the meantime should we cache the full list of AvatarDetails? Could take up a LOT of memory so probably not good idea? -// OASISResult> avatarsResult = AvatarManager.LoadAllAvatars(true, providerType); - -// if (!avatarsResult.IsError && avatarsResult.Result != null) -// { -// IAvatar avatar = avatarsResult.Result.FirstOrDefault(x => x.ProviderPrivateKey.ContainsKey(providerType) && x.ProviderPrivateKey[providerType] == providerKey); - -// if (avatar != null) -// { -// _providerPublicKeyToAvatarIdLookup[key] = avatar.Id; -// _providerPublicKeyToAvatarUsernameLookup[key] = avatar.Username; -// _providerPublicKeyToAvatarEmailLookup[key] = avatar.Email; -// _providerPublicKeyToAvatarLookup[key] = avatar; - -// result.Result = _providerPrivateKeyToAvatarLookup[key]; -// } -// else -// ErrorHandling.HandleError(ref result, string.Concat("The provider private Key ", providerKey, " for the ", Enum.GetName(providerType), " providerType has not been linked to an avatar. Please use the LinkProviderPrivateKeyToAvatar method on the AvatarManager or avatar REST API.")); -// } -// else -// ErrorHandling.HandleError(ref result, string.Concat("Error in GetAvatarForProviderPrivateKey for the provider private Key ", providerKey, " for the ", Enum.GetName(providerType), " providerType. There was an error loading all avatars. Reason: ", avatarsResult.Message)); -// } - -// return result; -// } - -// public OASISResult> GetAllProviderUniqueStorageKeysForAvatarById(Guid avatarId, ProviderType providerType = ProviderType.Default) -// { -// OASISResult> result = new OASISResult>(); -// OASISResult avatarResult = AvatarManager.LoadAvatar(avatarId, true, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// result.Result = avatarResult.Result.ProviderUniqueStorageKey; -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GetAllProviderUniqueStorageKeysForAvatarById loading avatar with avatarId {avatarId}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); - -// return result; -// } - -// public OASISResult> GetAllProviderUniqueStorageKeysForAvatarByUsername(string username, ProviderType providerType = ProviderType.Default) -// { -// OASISResult> result = new OASISResult>(); -// OASISResult avatarResult = AvatarManager.LoadAvatar(username, true, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// result.Result = avatarResult.Result.ProviderUniqueStorageKey; -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GetAllProviderUniqueStorageKeysForAvatarByUsername loading avatar with username {username}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); - -// return result; -// } - -// public OASISResult> GetAllProviderUniqueStorageKeysForAvatarByEmail(string email, ProviderType providerType = ProviderType.Default) -// { -// OASISResult> result = new OASISResult>(); -// OASISResult avatarResult = AvatarManager.LoadAvatarByEmail(email, true, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// result.Result = avatarResult.Result.ProviderUniqueStorageKey; -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GetAllProviderUniqueStorageKeysForAvatarByEmail loading avatar with email {email}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); - -// return result; -// } - -// public OASISResult>> GetAllProviderPublicKeysForAvatarById(Guid avatarId, ProviderType providerType = ProviderType.Default) -// { -// OASISResult>> result = new OASISResult>>(); -// OASISResult avatarResult = AvatarManager.LoadAvatar(avatarId, true, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// result.Result = avatarResult.Result.ProviderPublicKey; -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GetAllProviderPublicKeysForAvatarById loading avatar with avatarId {avatarId}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); - -// return result; -// } - -// public OASISResult>> GetAllProviderPublicKeysForAvatarByUsername(string username, ProviderType providerType = ProviderType.Default) -// { -// OASISResult>> result = new OASISResult>>(); -// OASISResult avatarResult = AvatarManager.LoadAvatar(username, true, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// result.Result = avatarResult.Result.ProviderPublicKey; -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GetAllProviderPublicKeysForAvatarByUsername loading avatar with username {username}. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); - -// return result; -// } - -// public OASISResult>> GetAllProviderPublicKeysForAvatarByEmail(string email, ProviderType providerType = ProviderType.Default) -// { -// OASISResult>> result = new OASISResult>>(); -// OASISResult avatarResult = AvatarManager.LoadAvatarByEmail(email, true, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// result.Result = avatarResult.Result.ProviderPublicKey; -// else -// ErrorHandling.HandleError(ref result, $"Error occured in GetAllProviderPublicKeysForAvatarByEmail loading avatar with email {email}. Reason: {avatarResult.Message}"); - -// return result; -// } - -// public OASISResult> GetAllProviderPrivateKeysForAvatarById(Guid avatarId, ProviderType providerType = ProviderType.Default) -// { -// OASISResult> result = new OASISResult>(); - -// if (AvatarManager.LoggedInAvatar.Id != avatarId) -// ErrorHandling.HandleError(ref result, "An error occured in GetAllProviderPrivateKeysForAvatarById. You can only retreive your own private keys, not another persons avatar."); -// else -// { -// OASISResult avatarResult = AvatarManager.LoadAvatar(avatarId, false, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// { -// result.Result = avatarResult.Result.ProviderPrivateKey; - -// // Decrypt the keys only for this return object (there are not stored in memory or storage unenrypted). -// foreach (ProviderType privateKeyProviderType in result.Result.Keys) -// result.Result[privateKeyProviderType] = Rijndael.Decrypt(result.Result[privateKeyProviderType], OASISDNA.OASIS.Security.OASISProviderPrivateKeys.Rijndael256Key, KeySize.Aes256); -// //result.Result[privateKeyProviderType] = StringCipher.Decrypt(result.Result[privateKeyProviderType]); -// } -// else -// ErrorHandling.HandleError(ref result, $"An error occured in GetAllProviderPrivateKeysForAvatarById, the avatar with id {avatarId} could not be loaded. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } - -// return result; -// } - -// public OASISResult> GetAllProviderPrivateKeysForAvatarByUsername(string username, ProviderType providerType = ProviderType.Default) -// { -// OASISResult> result = new OASISResult>(); - -// if (AvatarManager.LoggedInAvatar.Username != username) -// ErrorHandling.HandleError(ref result, "Error occured in GetAllProviderPrivateKeysForAvatarByUsername, you can only retreive your own private keys, not another persons avatar."); -// else -// { -// OASISResult avatarResult = AvatarManager.LoadAvatar(username, false, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// { -// result.Result = avatarResult.Result.ProviderPrivateKey; - -// // Decrypt the keys only for this return object (there are not stored in memory or storage unenrypted). -// foreach (ProviderType privateKeyProviderType in result.Result.Keys) -// result.Result[privateKeyProviderType] = Rijndael.Decrypt(result.Result[privateKeyProviderType], OASISDNA.OASIS.Security.OASISProviderPrivateKeys.Rijndael256Key, KeySize.Aes256); -// //result.Result[privateKeyProviderType] = StringCipher.Decrypt(result.Result[privateKeyProviderType]); -// } -// else -// ErrorHandling.HandleError(ref result, $"An error occured in GetAllProviderPrivateKeysForAvatarByUsername, the avatar with username {username} could not be loaded. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } - -// return result; -// } - -// public OASISResult> GetAllProviderPrivateKeysForAvatarByEmail(string email, ProviderType providerType = ProviderType.Default) -// { -// OASISResult> result = new OASISResult>(); - -// if (AvatarManager.LoggedInAvatar.Email != email) -// ErrorHandling.HandleError(ref result, "Error occured in GetAllProviderPrivateKeysForAvatarByEmail, you can only retreive your own private keys, not another persons avatar."); -// else -// { -// OASISResult avatarResult = AvatarManager.LoadAvatarByEmail(email, false, providerType); - -// if (!avatarResult.IsError && avatarResult.Result != null) -// { -// result.Result = avatarResult.Result.ProviderPrivateKey; - -// // Decrypt the keys only for this return object (there are not stored in memory or storage unenrypted). -// foreach (ProviderType privateKeyProviderType in result.Result.Keys) -// result.Result[privateKeyProviderType] = Rijndael.Decrypt(result.Result[privateKeyProviderType], OASISDNA.OASIS.Security.OASISProviderPrivateKeys.Rijndael256Key, KeySize.Aes256); -// //result.Result[privateKeyProviderType] = StringCipher.Decrypt(result.Result[privateKeyProviderType]); -// } -// else -// ErrorHandling.HandleError(ref result, $"An error occured in GetAllProviderPrivateKeysForAvatarByEmail, the avatar with email {email} could not be loaded. Reason: {avatarResult.Message}", avatarResult.DetailedMessage); -// } - -// return result; -// } - -// public OASISResult GetPrivateWif(byte[] source) -// { -// OASISResult result = new OASISResult(); - -// try -// { -// result.Result = WifUtility.GetPrivateWif(source); -// } -// catch (Exception ex) -// { -// ErrorHandling.HandleError(ref result, $"Error occured in GetPrivateWif. Reason: {ex}", ex); -// } - -// return result; -// } - -// public OASISResult GetPublicWif(byte[] publicKey, string prefix) -// { -// OASISResult result = new OASISResult(); - -// try -// { -// result.Result = WifUtility.GetPublicWif(publicKey, prefix); -// } -// catch (Exception ex) -// { -// ErrorHandling.HandleError(ref result, $"Error occured in GetPublicWif. Reason: {ex}", ex); -// } - -// return result; ; -// } - -// public OASISResult DecodePrivateWif(string data) -// { -// OASISResult result = new OASISResult(); - -// try -// { -// result.Result = WifUtility.DecodePrivateWif(data); -// } -// catch (Exception ex) -// { -// ErrorHandling.HandleError(ref result, $"Error occured in DecodePrivateWif. Reason: {ex}", ex); -// } - -// return result; -// } - -// public OASISResult Base58CheckDecode(string data) -// { -// OASISResult result = new OASISResult(); - -// try -// { -// result.Result = WifUtility.Base58CheckDecode(data); -// } -// catch (Exception ex) -// { -// ErrorHandling.HandleError(ref result, $"Error occured in Base58CheckDecode. Reason: {ex}", ex); -// } - -// return result; -// } - -// public OASISResult EncodeSignature(byte[] source) -// { -// OASISResult result = new OASISResult(); - -// try -// { -// result.Result = WifUtility.EncodeSignature(source); -// } -// catch (Exception ex) -// { -// ErrorHandling.HandleError(ref result, $"Error occured in EncodeSignature. Reason: {ex}", ex); -// } - -// return result; -// } - -// private OASISResult GetProviderUniqueStorageKeyForAvatar(IAvatar avatar, string key, Dictionary dictionaryCache, ProviderType providerType = ProviderType.Default) -// { -// OASISResult result = new OASISResult(); - -// if (avatar != null) -// { -// if (avatar.ProviderUniqueStorageKey.ContainsKey(providerType)) -// { -// dictionaryCache[key] = avatar.ProviderUniqueStorageKey[providerType]; -// result.Result = dictionaryCache[key]; -// } -// else -// ErrorHandling.HandleError(ref result, string.Concat("The avatar with id ", avatar.Id, " and username ", avatar.Username, " has not been linked to the ", Enum.GetName(providerType), " provider.")); -// } -// else -// ErrorHandling.HandleError(ref result, string.Concat("The avatar with id ", avatar.Id, " and username ", avatar.Username, " was not found.")); - -// //result.Result = dictionaryCache[key]; -// return result; -// } -// } -//} \ No newline at end of file diff --git a/NextGenSoftware.OASIS.API.Core/Managers/KeyManager.cs b/NextGenSoftware.OASIS.API.Core/Managers/KeyManager.cs index 1481a99ac..90b46f5ea 100644 --- a/NextGenSoftware.OASIS.API.Core/Managers/KeyManager.cs +++ b/NextGenSoftware.OASIS.API.Core/Managers/KeyManager.cs @@ -39,13 +39,25 @@ public class KeyManager : OASISManager private static Dictionary _providerUniqueStorageKeyToAvatarLookup = new Dictionary(); private static Dictionary _providerPublicKeyToAvatarLookup = new Dictionary(); private static Dictionary _providerPrivateKeyToAvatarLookup = new Dictionary(); + private static KeyManager _instance = null; + + public static KeyManager Instance + { + get + { + if (_instance == null) + _instance = new KeyManager(ProviderManager.CurrentStorageProvider, AvatarManager.Instance); + + return _instance; + } + } public WifUtility WifUtility { get; set; } = new WifUtility(); public AvatarManager AvatarManager { get; set; } - public List OASISStorageProviders { get; set; } + //public List OASISStorageProviders { get; set; } - public delegate void StorageProviderError(object sender, AvatarManagerErrorEventArgs e); + //public delegate void StorageProviderError(object sender, AvatarManagerErrorEventArgs e); public KeyManager(IOASISStorageProvider OASISStorageProvider, AvatarManager avatarManager, OASISDNA OASISDNA = null) : base(OASISStorageProvider, OASISDNA) { @@ -534,7 +546,7 @@ public OASISResult LinkProviderPrivateKeyToAvatar(Guid walletId, IAvatar a if (wallet != null) { - wallet.PrivateKey = providerPrivateKey; + wallet.PrivateKey = Rijndael.Encrypt(providerPrivateKey, OASISDNA.OASIS.Security.OASISProviderPrivateKeys.Rijndael256Key, KeySize.Aes256); result.Result = wallet.Id; } else @@ -550,37 +562,17 @@ public OASISResult LinkProviderPrivateKeyToAvatar(Guid walletId, IAvatar a return result; } - //if (!avatar.ProviderWallets[providerTypeToLinkTo].Any(x => x.PublicKey == providerPrivateKey)) - //{ - // if (walletId == Guid.Empty) - // { - // ProviderWallet newWallet = new ProviderWallet() { PrivateKey = providerPrivateKey }; - // result.Result = newWallet.Id; - // avatar.ProviderWallets[providerTypeToLinkTo].Add(newWallet); - // } - // else - // { - // IProviderWallet wallet = avatar.ProviderWallets[providerTypeToLinkTo].FirstOrDefault(x => x.PrivateKey == providerPrivateKey); + //Will save private keys (along with the rest of the wallet) to local storage providers only and wallets minus the private keys to the other non local storage providers. + //This way the private keys (and rest of the wallet) can be auto-replicated to other local storage providers and the wallets minus the private keys will be auto-replicated to other non storage providers. + OASISResult avatarResult = avatar.Save(); - // if (wallet != null) - // { - // wallet.PrivateKey = providerPrivateKey; - // result.Result = wallet.Id; - // } - // else - // { - // ErrorHandling.HandleError(ref result, $"The Wallet with ID {walletId} was not found. Please pass in a valid ID or leave empty if you wish to create a new wallet for this provider key."); - // return result; - // } - // } - //} - //else - //{ - // ErrorHandling.HandleError(ref result, $"The Private ProviderKey is already linked to the avatar {avatar.Id} {avatar.Username}. The ProviderKey must be unique per provider."); - // return result; - //} + // Could save the wallets without having to save the full avatar but then would need to add additional looping code to go through all providers looking for only local storage ones. + // But we STILL need to save the wallets (without private keys) for all non-local storage providers so not much point doing it seperatley and just call the Save method above... ;-) + //avatar.SaveProviderWallets(); + + //The only issue is when a avatar is loaded from a non local storage provider how it will know the difference between that and if the user had deleted the private keys? + //We - OASISResult avatarResult = avatar.Save(); if (!avatarResult.IsError && avatarResult.Result != null) { diff --git a/NextGenSoftware.OASIS.API.Core/Managers/OASISManager.cs b/NextGenSoftware.OASIS.API.Core/Managers/OASISManager.cs index 7aca63b5c..ad3e9d7d3 100644 --- a/NextGenSoftware.OASIS.API.Core/Managers/OASISManager.cs +++ b/NextGenSoftware.OASIS.API.Core/Managers/OASISManager.cs @@ -1,8 +1,4 @@ -using System; -using System.Threading.Tasks; -using NextGenSoftware.OASIS.API.Core.Enums; -using NextGenSoftware.OASIS.API.Core.Events; -using NextGenSoftware.OASIS.API.Core.Helpers; +using NextGenSoftware.OASIS.API.Core.Events; using NextGenSoftware.OASIS.API.Core.Interfaces; using NextGenSoftware.OASIS.API.DNA; @@ -40,7 +36,7 @@ public OASISManager(IOASISStorageProvider OASISStorageProvider, OASISDNA OASISDN //TODO: Need to unsubscribe events to stop memory leaks... } - private void OASISStorageProvider_StorageProviderError(object sender, AvatarManagerErrorEventArgs e) + private void OASISStorageProvider_StorageProviderError(object sender, OASISErrorEventArgs e) { OnOASISManagerError?.Invoke(this, new OASISErrorEventArgs() { Exception = e.Exception, Reason = e.Reason }); } diff --git a/NextGenSoftware.OASIS.API.Core/Managers/ProviderManager.cs b/NextGenSoftware.OASIS.API.Core/Managers/ProviderManager.cs index 76fb23741..6fd0c769b 100644 --- a/NextGenSoftware.OASIS.API.Core/Managers/ProviderManager.cs +++ b/NextGenSoftware.OASIS.API.Core/Managers/ProviderManager.cs @@ -18,6 +18,7 @@ public class ProviderManager private static bool _setProviderGlobally = false; public static EnumValue CurrentStorageProviderType { get; private set; } = new EnumValue(ProviderType.Default); + public static EnumValue CurrentStorageProviderCategory { get; private set; } = new EnumValue(ProviderCategory.None); public static OASISProviderBootType OASISProviderBootType { get; set; } = OASISProviderBootType.Hot; public static bool IsAutoReplicationEnabled { get; set; } = true; @@ -140,7 +141,7 @@ public static List GetStorageProviders() { List storageProviders = new List(); - foreach (IOASISProvider provider in _registeredProviders.Where(x => x.ProviderCategory.Value == ProviderCategory.Storage || x.ProviderCategory.Value == ProviderCategory.StorageAndNetwork).ToList()) + foreach (IOASISProvider provider in _registeredProviders.Where(x => x.ProviderCategory.Value == ProviderCategory.Storage || x.ProviderCategory.Value == ProviderCategory.StorageAndNetwork || x.ProviderCategory.Value == ProviderCategory.StorageLocal || x.ProviderCategory.Value == ProviderCategory.StorageLocalAndNetwork).ToList()) storageProviders.Add((IOASISStorageProvider)provider); return storageProviders; @@ -156,7 +157,7 @@ public static List GetNetworkProviders() { List networkProviders = new List(); - foreach (IOASISProvider provider in _registeredProviders.Where(x => x.ProviderCategory.Value == ProviderCategory.Network || x.ProviderCategory.Value == ProviderCategory.StorageAndNetwork).ToList()) + foreach (IOASISProvider provider in _registeredProviders.Where(x => x.ProviderCategory.Value == ProviderCategory.Network || x.ProviderCategory.Value == ProviderCategory.StorageAndNetwork || x.ProviderCategory.Value == ProviderCategory.StorageLocalAndNetwork).ToList()) networkProviders.Add((IOASISNETProvider)provider); return networkProviders; @@ -201,17 +202,20 @@ public static IOASISProvider GetProvider(ProviderType type) public static IOASISStorageProvider GetStorageProvider(ProviderType type) { - return (IOASISStorageProvider)_registeredProviders.FirstOrDefault(x => x.ProviderType.Value == type && x.ProviderCategory.Value == ProviderCategory.Storage); + return (IOASISStorageProvider)_registeredProviders.FirstOrDefault(x => x.ProviderType.Value == type); + //return (IOASISStorageProvider)_registeredProviders.FirstOrDefault(x => x.ProviderType.Value == type && x.ProviderCategory.Value == ProviderCategory.Storage); } public static IOASISNETProvider GetNetworkProvider(ProviderType type) { - return (IOASISNETProvider)_registeredProviders.FirstOrDefault(x => x.ProviderType.Value == type && x.ProviderCategory.Value == ProviderCategory.Network); + return (IOASISNETProvider)_registeredProviders.FirstOrDefault(x => x.ProviderType.Value == type); + //return (IOASISNETProvider)_registeredProviders.FirstOrDefault(x => x.ProviderType.Value == type && x.ProviderCategory.Value == ProviderCategory.Network); } public static IOASISRenderer GetRendererProvider(ProviderType type) { - return (IOASISRenderer)_registeredProviders.FirstOrDefault(x => x.ProviderType.Value == type && x.ProviderCategory.Value == ProviderCategory.Renderer); + return (IOASISRenderer)_registeredProviders.FirstOrDefault(x => x.ProviderType.Value == type); + //return (IOASISRenderer)_registeredProviders.FirstOrDefault(x => x.ProviderType.Value == type && x.ProviderCategory.Value == ProviderCategory.Renderer); } public static bool IsProviderRegistered(IOASISProvider provider) @@ -315,7 +319,8 @@ public static OASISResult SetAndActivateCurrentStoragePro result.Message = deactivateProviderResult.Message; } } - + + CurrentStorageProviderCategory = provider.ProviderCategory; CurrentStorageProviderType.Value = providerType; CurrentStorageProvider = (IOASISStorageProvider)provider; diff --git a/NextGenSoftware.OASIS.API.Core/Managers/SearchManager.cs b/NextGenSoftware.OASIS.API.Core/Managers/SearchManager.cs index 8d8f91d22..8761a0c4a 100644 --- a/NextGenSoftware.OASIS.API.Core/Managers/SearchManager.cs +++ b/NextGenSoftware.OASIS.API.Core/Managers/SearchManager.cs @@ -9,8 +9,21 @@ namespace NextGenSoftware.OASIS.API.Core.Managers { public class SearchManager : OASISManager { + private static SearchManager _instance = null; + public delegate void StorageProviderError(object sender, AvatarManagerErrorEventArgs e); + public static SearchManager Instance + { + get + { + if (_instance == null) + _instance = new SearchManager(ProviderManager.CurrentStorageProvider); + + return _instance; + } + } + public SearchManager(IOASISStorageProvider OASISStorageProvider, OASISDNA OASISDNA = null) : base(OASISStorageProvider, OASISDNA) { diff --git a/NextGenSoftware.OASIS.API.Core/Managers/WalletManager.cs b/NextGenSoftware.OASIS.API.Core/Managers/WalletManager.cs index e2af2408b..8256170a9 100644 --- a/NextGenSoftware.OASIS.API.Core/Managers/WalletManager.cs +++ b/NextGenSoftware.OASIS.API.Core/Managers/WalletManager.cs @@ -4,17 +4,31 @@ using NextGenSoftware.OASIS.API.Core.Events; using NextGenSoftware.OASIS.API.Core.Helpers; using NextGenSoftware.OASIS.API.Core.Interfaces; +using System; namespace NextGenSoftware.OASIS.API.Core.Managers { //TODO: Add Async version of all methods and add IWalletManager Interface. public class WalletManager : OASISManager { - public AvatarManager AvatarManager { get; set; } + private static WalletManager _instance = null; + + //public delegate void StorageProviderError(object sender, AvatarManagerErrorEventArgs e); + + public static WalletManager Instance + { + get + { + if (_instance == null) + _instance = new WalletManager(ProviderManager.CurrentStorageProvider, AvatarManager.Instance); + + return _instance; + } + } - public List OASISStorageProviders { get; set; } + public AvatarManager AvatarManager { get; set; } - public delegate void StorageProviderError(object sender, AvatarManagerErrorEventArgs e); + // public List OASISStorageProviders { get; set; } public WalletManager(IOASISStorageProvider OASISStorageProvider, AvatarManager avatarManager, OASISDNA OASISDNA = null) : base(OASISStorageProvider, OASISDNA) { @@ -59,6 +73,66 @@ public OASISResult GetWalletThatPublicKeyBelongsTo(string provi return result; } + public OASISResult ImportWalletUsingSecretPhase(string phase) + { + OASISResult result = new OASISResult(); + + //TODO: Finish implementing... (allow user to import a wallet using the secret recovering phase (memonic words). + //Can derive the public key and private key from the phase (need to look into how to do this...) + + return result; + } + + public OASISResult ImportWalletUsingJSONFile(string pathToJSONFile) + { + OASISResult result = new OASISResult(); + + //TODO: Finish implementing... (allow user to import a wallet using the JSON import file (standard wallet format). + + return result; + } + + public OASISResult ImportWalletUsingPrivateKeyById(Guid avatarId, string key, ProviderType providerToImportTo) + { + //OASISResult result = new OASISResult(); + + //TODO: Finish implementing... Can derive the public key from the private key (need to look into how to do this and update Link methods with new logic...) + + + return KeyManager.Instance.LinkProviderPrivateKeyToAvatarById(Guid.Empty, avatarId, providerToImportTo, key); + } + + public OASISResult ImportWalletUsingPrivateKeyByUsername(string username, string key, ProviderType providerToImportTo) + { + return KeyManager.Instance.LinkProviderPrivateKeyToAvatarByUsername(Guid.Empty, username, providerToImportTo, key); + } + + public OASISResult ImportWalletUsingPrivateKeyByEmail(string email, string key, ProviderType providerToImportTo) + { + return KeyManager.Instance.LinkProviderPrivateKeyToAvatarByUsername(Guid.Empty, email, providerToImportTo, key); + } + + public OASISResult ImportWalletUsingPublicKeyById(Guid avatarId, string key, ProviderType providerToImportTo) + { + //OASISResult result = new OASISResult(); + + //TODO: Finish implementing... The wallet will only be read-only without the private key. + //This will be very similar to the LinkProviderPublicKeyToAvatarById/LinkProviderPublicKeyToAvatarByUsername/LinkProviderPublicKeyToAvatarByEmail methods in KeyManager. + //Ideally this method will call into the Link methods above (probably best to just have this method call them direct, no additional logic needed. + + return KeyManager.Instance.LinkProviderPublicKeyToAvatarById(Guid.Empty, avatarId, providerToImportTo, key); + } + + public OASISResult ImportWalletUsingPublicKeyByUsername(string username, string key, ProviderType providerToImportTo) + { + return KeyManager.Instance.LinkProviderPublicKeyToAvatarByUsername(Guid.Empty, username, providerToImportTo, key); + } + + public OASISResult ImportWalletUsingPublicKeyByEmail(string email, string key, ProviderType providerToImportTo) + { + return KeyManager.Instance.LinkProviderPublicKeyToAvatarByEmail(Guid.Empty, email, providerToImportTo, key); + } + //TODO: Lots more coming soon! ;-) } } \ No newline at end of file diff --git a/NextGenSoftware.OASIS.API.Core/OASISProvider.cs b/NextGenSoftware.OASIS.API.Core/OASISProvider.cs index 51e333916..d475be13b 100644 --- a/NextGenSoftware.OASIS.API.Core/OASISProvider.cs +++ b/NextGenSoftware.OASIS.API.Core/OASISProvider.cs @@ -1,12 +1,15 @@ - -using NextGenSoftware.OASIS.API.Core.Enums; +using NextGenSoftware.OASIS.API.Core.Enums; using NextGenSoftware.OASIS.API.Core.Helpers; using NextGenSoftware.OASIS.API.Core.Interfaces; +using NextGenSoftware.OASIS.API.DNA; namespace NextGenSoftware.OASIS.API.Core { public abstract class OASISProvider : IOASISProvider { + public OASISDNA OASISDNA { get; set; } + public string OASISDNAPath { get; set; } + public string ProviderName { get; set; } public string ProviderDescription { get; set; } @@ -16,6 +19,32 @@ public abstract class OASISProvider : IOASISProvider //public bool ProviderActivated { get; set; } public bool ProviderActivated { get; private set; } + public OASISProvider() + { + OASISDNAManager.LoadDNA(); + this.OASISDNA = OASISDNAManager.OASISDNA; + this.OASISDNAPath = OASISDNAManager.OASISDNAPath; + } + + public OASISProvider(string OASISDNAPath) + { + this.OASISDNAPath = OASISDNAPath; + OASISDNAManager.LoadDNA(OASISDNAPath); + this.OASISDNA = OASISDNAManager.OASISDNA; + } + + public OASISProvider(OASISDNA OASISDNA) + { + this.OASISDNA = OASISDNA; + this.OASISDNAPath = OASISDNAManager.OASISDNAPath; + } + + public OASISProvider(OASISDNA OASISDNA, string OASISDNAPath) + { + this.OASISDNA = OASISDNA; + this.OASISDNAPath = OASISDNAPath; + } + virtual public OASISResult ActivateProvider() { ProviderActivated = true; diff --git a/NextGenSoftware.OASIS.API.Core/OASISStorageProviderBase.cs b/NextGenSoftware.OASIS.API.Core/OASISStorageProviderBase.cs index 35006c010..8cb7603fc 100644 --- a/NextGenSoftware.OASIS.API.Core/OASISStorageProviderBase.cs +++ b/NextGenSoftware.OASIS.API.Core/OASISStorageProviderBase.cs @@ -13,61 +13,15 @@ namespace NextGenSoftware.OASIS.API.Core { public abstract class OASISStorageProviderBase : OASISProvider, IOASISStorageProvider { - public OASISDNA OASISDNA { get; set; } - public string OASISDNAPath { get; set; } + public OASISStorageProviderBase() : base() { } - public event AvatarManager.StorageProviderError StorageProviderError; + public OASISStorageProviderBase(string OASISDNAPath) : base(OASISDNAPath) { } - public OASISStorageProviderBase() - { - OASISDNAManager.LoadDNA(); - this.OASISDNA = OASISDNAManager.OASISDNA; - this.OASISDNAPath = OASISDNAManager.OASISDNAPath; - } - - public OASISStorageProviderBase(string OASISDNAPath) - { - this.OASISDNAPath = OASISDNAPath; - OASISDNAManager.LoadDNA(OASISDNAPath); - this.OASISDNA = OASISDNAManager.OASISDNA; - } - - public OASISStorageProviderBase(OASISDNA OASISDNA) - { - this.OASISDNA = OASISDNA; - this.OASISDNAPath = OASISDNAManager.OASISDNAPath; - } + public OASISStorageProviderBase(OASISDNA OASISDNA) : base (OASISDNA) { } - public OASISStorageProviderBase(OASISDNA OASISDNA, string OASISDNAPath) - { - this.OASISDNA = OASISDNA; - this.OASISDNAPath = OASISDNAPath; - } + public OASISStorageProviderBase(OASISDNA OASISDNA, string OASISDNAPath) : base (OASISDNA, OASISDNAPath) { } - //event StorageProviderError IOASISStorageProvider.StorageProviderError - //{ - // add - // { - // throw new NotImplementedException(); - // } - - // remove - // { - // throw new NotImplementedException(); - // } - //} - - //TODO: COme back to this... - //public List LoadAvatarsWithoutPasswords(IEnumerable avatars) - //{ - // return avatars.Select(x => x.WithoutPassword()); - //} - - //public Avatar WithoutPassword(this Avatar user) - //{ - // user.Password = null; - // return user; - //} + public event OASISManager.StorageProviderError StorageProviderError; public Task> AddKarmaToAvatarAsync(IAvatarDetail avatar, KarmaTypePositive karmaType, KarmaSourceType karmaSourceType, string karamSourceTitle, string karmaSourceDesc, string karmaSourceWebLink) { @@ -91,69 +45,9 @@ public OASISResult RemoveKarmaFromAvatar(IAvatarDetail avata protected void OnStorageProviderError(string endPoint, string reason, Exception errorDetails) { - StorageProviderError?.Invoke(this, new AvatarManagerErrorEventArgs { EndPoint = endPoint, Reason = reason, Exception = errorDetails }); + StorageProviderError?.Invoke(this, new OASISErrorEventArgs { EndPoint = endPoint, Reason = reason, Exception = errorDetails }); } - /* - public abstract Task> LoadAllAvatarsAsync(); - public abstract IEnumerable LoadAllAvatars(); - public abstract IAvatar LoadAvatarByUsername(string avatarUsername); - public abstract Task LoadAvatarAsync(Guid Id); - public abstract Task LoadAvatarByEmailAsync(string avatarEmail); - public abstract Task LoadAvatarByUsernameAsync(string avatarUsername); - public abstract IAvatar LoadAvatar(Guid Id); - public abstract IAvatar LoadAvatarByEmail(string avatarEmail); - public abstract Task LoadAvatarAsync(string username, string password); - public abstract IAvatar LoadAvatar(string username, string password); - public abstract IAvatar LoadAvatar(string username); - public abstract Task LoadAvatarAsync(string username); - public abstract Task LoadAvatarForProviderKeyAsync(string providerKey); - public abstract IAvatar LoadAvatarForProviderKey(string providerKey); - // public abstract Task LoadAvatarThumbnailAsync(Guid id); - // public abstract IAvatarThumbnail LoadAvatarThumbnail(Guid id); - public abstract IAvatarDetail LoadAvatarDetail(Guid id); - public abstract IAvatarDetail LoadAvatarDetailByEmail(string avatarEmail); - public abstract IAvatarDetail LoadAvatarDetailByUsername(string avatarUsername); - public abstract Task LoadAvatarDetailAsync(Guid id); - public abstract Task LoadAvatarDetailByUsernameAsync(string avatarUsername); - public abstract Task LoadAvatarDetailByEmailAsync(string avatarEmail); - public abstract IEnumerable LoadAllAvatarDetails(); - public abstract Task> LoadAllAvatarDetailsAsync(); - public abstract IAvatar SaveAvatar(IAvatar Avatar); - public abstract Task SaveAvatarAsync(IAvatar Avatar); - public abstract IAvatarDetail SaveAvatarDetail(IAvatarDetail Avatar); - public abstract Task SaveAvatarDetailAsync(IAvatarDetail Avatar); - public abstract OASISResult DeleteAvatar(Guid id, bool softDelete = true); - public abstract OASISResult DeleteAvatarByEmail(string avatarEmail, bool softDelete = true); - public abstract OASISResult DeleteAvatarByUsername(string avatarUsername, bool softDelete = true); - public abstract Task> DeleteAvatarAsync(Guid id, bool softDelete = true); - public abstract Task> DeleteAvatarByEmailAsync(string avatarEmail, bool softDelete = true); - public abstract Task> DeleteAvatarByUsernameAsync(string avatarUsername, bool softDelete = true); - public abstract OASISResult DeleteAvatar(string providerKey, bool softDelete = true); - public abstract Task> DeleteAvatarAsync(string providerKey, bool softDelete = true); - public abstract Task SearchAsync(ISearchParams searchParams); - public abstract IHolon LoadHolon(Guid id); - public abstract Task LoadHolonAsync(Guid id); - public abstract IHolon LoadHolon(string providerKey); - public abstract Task LoadHolonAsync(string providerKey); - public abstract IEnumerable LoadHolonsForParent(Guid id, HolonType type = HolonType.All); - public abstract Task> LoadHolonsForParentAsync(Guid id, HolonType type = HolonType.All); - public abstract IEnumerable LoadHolonsForParent(string providerKey, HolonType type = HolonType.All); - public abstract Task>> LoadHolonsForParentAsync(string providerKey, HolonType type = HolonType.All); - public abstract IEnumerable LoadAllHolons(HolonType type = HolonType.All); - public abstract Task> LoadAllHolonsAsync(HolonType type = HolonType.All); - - //TODO: We need to migrate ALL OASIS methods to use the OASISResult Pattern ASAP! Thankyou! :) - public abstract OASISResult SaveHolon(IHolon holon, bool saveChildrenRecursive = true); - public abstract Task> SaveHolonAsync(IHolon holon, bool saveChildrenRecursive = true); - public abstract OASISResult> SaveHolons(IEnumerable holons, bool saveChildrenRecursive = true); - public abstract Task>> SaveHolonsAsync(IEnumerable holons, bool saveChildrenRecursive = true); - public abstract bool DeleteHolon(Guid id, bool softDelete = true); - public abstract Task DeleteHolonAsync(Guid id, bool softDelete = true); - public abstract bool DeleteHolon(string providerKey, bool softDelete = true); - public abstract Task DeleteHolonAsync(string providerKey, bool softDelete = true); - */ - public abstract Task>> LoadAllAvatarsAsync(int version = 0); public abstract OASISResult> LoadAllAvatars(int version = 0); public abstract OASISResult LoadAvatarByUsername(string avatarUsername, int version = 0); @@ -162,14 +56,10 @@ protected void OnStorageProviderError(string endPoint, string reason, Exception public abstract Task> LoadAvatarByUsernameAsync(string avatarUsername, int version = 0); public abstract OASISResult LoadAvatar(Guid Id, int version = 0); public abstract OASISResult LoadAvatarByEmail(string avatarEmail, int version = 0); - //public abstract Task> LoadAvatarAsync(string username, string password, int version = 0); - //public abstract OASISResult LoadAvatar(string username, string password, int version = 0); public abstract OASISResult LoadAvatar(string username, int version = 0); public abstract Task> LoadAvatarAsync(string username, int version = 0); public abstract Task> LoadAvatarForProviderKeyAsync(string providerKey, int version = 0); public abstract OASISResult LoadAvatarForProviderKey(string providerKey, int version = 0); - // public abstract Task LoadAvatarThumbnailAsync(Guid id); - // public abstract IAvatarThumbnail LoadAvatarThumbnail(Guid id); public abstract OASISResult LoadAvatarDetail(Guid id, int version = 0); public abstract OASISResult LoadAvatarDetailByEmail(string avatarEmail, int version = 0); public abstract OASISResult LoadAvatarDetailByUsername(string avatarUsername, int version = 0); @@ -202,7 +92,6 @@ protected void OnStorageProviderError(string endPoint, string reason, Exception public abstract OASISResult> LoadAllHolons(HolonType type = HolonType.All, bool loadChildren = true, bool recursive = true, int maxChildDepth = 0, int curentChildDepth = 0, bool continueOnError = true, int version = 0); public abstract Task>> LoadAllHolonsAsync(HolonType type = HolonType.All, bool loadChildren = true, bool recursive = true, int maxChildDepth = 0, int curentChildDepth = 0, bool continueOnError = true, int version = 0); - //TODO: We need to migrate ALL OASIS methods to use the OASISResult Pattern ASAP! Thankyou! :) public abstract OASISResult SaveHolon(IHolon holon, bool saveChildren = true, bool recursive = true, int maxChildDepth = 0, bool continueOnError = true); public abstract Task> SaveHolonAsync(IHolon holon, bool saveChildren = true, bool recursive = true, int maxChildDepth = 0, bool continueOnError = true); public abstract OASISResult> SaveHolons(IEnumerable holons, bool saveChildren = true, bool recursive = true, int maxChildDepth = 0, int curentChildDepth = 0, bool continueOnError = true); @@ -211,5 +100,15 @@ protected void OnStorageProviderError(string endPoint, string reason, Exception public abstract Task> DeleteHolonAsync(Guid id, bool softDelete = true); public abstract OASISResult DeleteHolon(string providerKey, bool softDelete = true); public abstract Task> DeleteHolonAsync(string providerKey, bool softDelete = true); + + public abstract Task> Import(IEnumerable holons); + + public abstract Task>> ExportAllDataForAvatarById(Guid avatarId, int version = 0); + + public abstract Task>> ExportAllDataForAvatarByUsername(string avatarUsername, int version = 0); + + public abstract Task>> ExportAllDataForAvatarByEmail(string avatarEmailAddress, int version = 0); + + public abstract Task>> ExportAll(int version = 0); } } diff --git a/NextGenSoftware.OASIS.API.Core/Objects/Wallets/OASISWallet.cs b/NextGenSoftware.OASIS.API.Core/Objects/Wallets/OASISWallet.cs index 3dc259e51..1a94b913b 100644 --- a/NextGenSoftware.OASIS.API.Core/Objects/Wallets/OASISWallet.cs +++ b/NextGenSoftware.OASIS.API.Core/Objects/Wallets/OASISWallet.cs @@ -1,6 +1,8 @@  +using NextGenSoftware.OASIS.API.Core.Helpers; using NextGenSoftware.OASIS.API.Core.Interfaces; using System.Collections.Generic; +using System.Threading.Tasks; namespace NextGenSoftware.OASIS.API.Core.Objects { @@ -9,5 +11,25 @@ public class OASISWallet : IOASISWallet public List Wallets { get; set; } public List Transactions { get; set; } public int Balance { get; set; } + + public OASISResult SendNFT(IWalletTransaction transation) + { + throw new System.NotImplementedException(); + } + + public Task> SendNFTAsync(IWalletTransaction transation) + { + throw new System.NotImplementedException(); + } + + public OASISResult SendTrasaction(IWalletTransaction transation) + { + throw new System.NotImplementedException(); + } + + public Task> SendTrasactionAsync(IWalletTransaction transation) + { + throw new System.NotImplementedException(); + } } } \ No newline at end of file diff --git a/NextGenSoftware.OASIS.API.Core/Objects/Wallets/ProviderWallet.cs b/NextGenSoftware.OASIS.API.Core/Objects/Wallets/ProviderWallet.cs index 77762367c..14f7d79a2 100644 --- a/NextGenSoftware.OASIS.API.Core/Objects/Wallets/ProviderWallet.cs +++ b/NextGenSoftware.OASIS.API.Core/Objects/Wallets/ProviderWallet.cs @@ -1,8 +1,10 @@  using NextGenSoftware.OASIS.API.Core.Enums; +using NextGenSoftware.OASIS.API.Core.Helpers; using NextGenSoftware.OASIS.API.Core.Holons; using NextGenSoftware.OASIS.API.Core.Interfaces; using System.Collections.Generic; +using System.Threading.Tasks; namespace NextGenSoftware.OASIS.API.Core.Objects { @@ -16,5 +18,25 @@ public class ProviderWallet : HolonBase, IProviderWallet public List Transactions {get;set;} public ProviderType ProviderType { get; set; } public int Balance { get; set; } + + public OASISResult SendNFT(IWalletTransaction transation) + { + throw new System.NotImplementedException(); + } + + public Task> SendNFTAsync(IWalletTransaction transation) + { + throw new System.NotImplementedException(); + } + + public OASISResult SendTrasaction(IWalletTransaction transation) + { + throw new System.NotImplementedException(); + } + + public Task> SendTrasactionAsync(IWalletTransaction transation) + { + throw new System.NotImplementedException(); + } } } diff --git a/NextGenSoftware.OASIS.API.DNA/OASISDNA.cs b/NextGenSoftware.OASIS.API.DNA/OASISDNA.cs index 9a0e0f361..d1409bf61 100644 --- a/NextGenSoftware.OASIS.API.DNA/OASISDNA.cs +++ b/NextGenSoftware.OASIS.API.DNA/OASISDNA.cs @@ -74,6 +74,7 @@ public class StorageProviderSettings public Neo4jOASISSettings Neo4jOASIS { get; set; } public SolanaOASISSettings SolanaOASIS { get; set; } public CargoOASISSettings CargoOASIS { get; set; } + public LocalFileOASISSettings LocalFileOASIS { get; set; } } public class EmailSettings @@ -153,4 +154,9 @@ public class Neo4jOASISSettings : ProviderSettingsBase public string Username { get; set; } public string Password { get; set; } } + + public class LocalFileOASISSettings + { + public string FilePath { get; set; } + } } diff --git a/NextGenSoftware.OASIS.API.ONODE.WebAPI/OASIS_DNA.json b/NextGenSoftware.OASIS.API.ONODE.WebAPI/OASIS_DNA.json index b74550630..8140ce89f 100644 --- a/NextGenSoftware.OASIS.API.ONODE.WebAPI/OASIS_DNA.json +++ b/NextGenSoftware.OASIS.API.ONODE.WebAPI/OASIS_DNA.json @@ -7,8 +7,8 @@ "AllowedHosts": "*", "OASIS": { "Terms": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.\n\n", - "CurrentStagingVersion": "v0.19.1", - "CurrentLiveVersion": "v0.19.1", + "CurrentStagingVersion": "v2.2.0", + "CurrentLiveVersion": "v2.1.0", "Logging": { "LoggingFramework": "NLog" }, @@ -100,6 +100,19 @@ "IPFSOASIS": { "ConnectionString": "http://localhost:5001", "LookUpIPFSAddress": "" + }, + "SolanaOASIS": { + "WalletMnemonicWords": "bullet nothing diamond universe detail east dinner code plunge charge poem ball cable clog spray purpose renew above clay brand control shallow turtle similar", + "ConnectionString": "https://api.mainnet-beta.solana.com" + }, + "CargoOASIS": { + "ConnectionString": "", + "SingingMessage": "", + "PrivateKey": "", + "HostUrl": "" + }, + "LocalFileOASIS": { + "FilePath": "wallets.json" } } } diff --git a/NextGenSoftware.OASIS.API.Providers.AcitvityPub/AcitvityPubOASIS.cs b/NextGenSoftware.OASIS.API.Providers.AcitvityPub/AcitvityPubOASIS.cs index 598b7fe89..88e37fa45 100644 --- a/NextGenSoftware.OASIS.API.Providers.AcitvityPub/AcitvityPubOASIS.cs +++ b/NextGenSoftware.OASIS.API.Providers.AcitvityPub/AcitvityPubOASIS.cs @@ -84,6 +84,26 @@ public override Task> DeleteHolonAsync(string providerKey, boo throw new NotImplementedException(); } + public override Task>> ExportAll(int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByEmail(string avatarEmailAddress, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarById(Guid avatarId, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByUsername(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + public OASISResult> GetHolonsNearMe(HolonType Type) { throw new NotImplementedException(); @@ -94,6 +114,11 @@ public OASISResult> GetPlayersNearMe() throw new NotImplementedException(); } + public override Task> Import(IEnumerable holons) + { + throw new NotImplementedException(); + } + public override OASISResult> LoadAllAvatarDetails(int version = 0) { throw new NotImplementedException(); diff --git a/NextGenSoftware.OASIS.API.Providers.BlockStackOASIS/BlockStackOASIS.cs b/NextGenSoftware.OASIS.API.Providers.BlockStackOASIS/BlockStackOASIS.cs index fef9fcc89..e861fa935 100644 --- a/NextGenSoftware.OASIS.API.Providers.BlockStackOASIS/BlockStackOASIS.cs +++ b/NextGenSoftware.OASIS.API.Providers.BlockStackOASIS/BlockStackOASIS.cs @@ -78,6 +78,26 @@ public override Task> DeleteHolonAsync(string providerKey, boo throw new NotImplementedException(); } + public override Task>> ExportAll(int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByEmail(string avatarEmailAddress, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarById(Guid avatarId, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByUsername(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + public OASISResult> GetHolonsNearMe(HolonType Type) { throw new NotImplementedException(); @@ -88,6 +108,11 @@ public OASISResult> GetPlayersNearMe() throw new NotImplementedException(); } + public override Task> Import(IEnumerable holons) + { + throw new NotImplementedException(); + } + public override OASISResult> LoadAllAvatarDetails(int version = 0) { throw new NotImplementedException(); @@ -292,5 +317,25 @@ public override Task> SearchAsync(ISearchParams sear { throw new NotImplementedException(); } + + public OASISResult SendNFT(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public Task> SendNFTAsync(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public OASISResult SendTrasaction(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public Task> SendTrasactionAsync(IWalletTransaction transation) + { + throw new NotImplementedException(); + } } } diff --git a/NextGenSoftware.OASIS.API.Providers.ChainLinkOASIS/ChainLinkOASIS.cs b/NextGenSoftware.OASIS.API.Providers.ChainLinkOASIS/ChainLinkOASIS.cs index c2dd22bf5..680e68a1e 100644 --- a/NextGenSoftware.OASIS.API.Providers.ChainLinkOASIS/ChainLinkOASIS.cs +++ b/NextGenSoftware.OASIS.API.Providers.ChainLinkOASIS/ChainLinkOASIS.cs @@ -79,6 +79,26 @@ public override Task> DeleteHolonAsync(string providerKey, boo throw new NotImplementedException(); } + public override Task>> ExportAll(int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByEmail(string avatarEmailAddress, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarById(Guid avatarId, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByUsername(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + public OASISResult> GetHolonsNearMe(HolonType Type) { throw new NotImplementedException(); @@ -89,6 +109,11 @@ public OASISResult> GetPlayersNearMe() throw new NotImplementedException(); } + public override Task> Import(IEnumerable holons) + { + throw new NotImplementedException(); + } + public override OASISResult> LoadAllAvatarDetails(int version = 0) { throw new NotImplementedException(); @@ -293,5 +318,25 @@ public override Task> SearchAsync(ISearchParams sear { throw new NotImplementedException(); } + + public OASISResult SendNFT(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public Task> SendNFTAsync(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public OASISResult SendTrasaction(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public Task> SendTrasactionAsync(IWalletTransaction transation) + { + throw new NotImplementedException(); + } } } diff --git a/NextGenSoftware.OASIS.API.Providers.EOSIOOASIS/EOSIOOASIS.cs b/NextGenSoftware.OASIS.API.Providers.EOSIOOASIS/EOSIOOASIS.cs index c81dc9ff6..91e197877 100644 --- a/NextGenSoftware.OASIS.API.Providers.EOSIOOASIS/EOSIOOASIS.cs +++ b/NextGenSoftware.OASIS.API.Providers.EOSIOOASIS/EOSIOOASIS.cs @@ -473,5 +473,50 @@ public IAvatar GetAvatarForEOSIOAccountName(string eosioAccountName) //TODO: Handle OASISResult Properly. return KeyManager.GetAvatarForProviderPublicKey(eosioAccountName, Core.Enums.ProviderType.EOSIOOASIS).Result; } + + public override Task> Import(IEnumerable holons) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarById(Guid avatarId, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByUsername(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByEmail(string avatarEmailAddress, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAll(int version = 0) + { + throw new NotImplementedException(); + } + + public OASISResult SendTrasaction(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public Task> SendTrasactionAsync(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public OASISResult SendNFT(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public Task> SendNFTAsync(IWalletTransaction transation) + { + throw new NotImplementedException(); + } } } diff --git a/NextGenSoftware.OASIS.API.Providers.EthereumOASIS/EthereumOASIS.cs b/NextGenSoftware.OASIS.API.Providers.EthereumOASIS/EthereumOASIS.cs index 38435d84e..3823e324f 100644 --- a/NextGenSoftware.OASIS.API.Providers.EthereumOASIS/EthereumOASIS.cs +++ b/NextGenSoftware.OASIS.API.Providers.EthereumOASIS/EthereumOASIS.cs @@ -1101,5 +1101,30 @@ public OASISResult> GetHolonsNearMe(HolonType Type) { throw new NotImplementedException(); } + + public override Task> Import(IEnumerable holons) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarById(Guid avatarId, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByUsername(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByEmail(string avatarEmailAddress, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAll(int version = 0) + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/NextGenSoftware.OASIS.API.Providers.HashgraphOASIS/HashgraphOASIS.cs b/NextGenSoftware.OASIS.API.Providers.HashgraphOASIS/HashgraphOASIS.cs index 23bfa4ee2..cd33fe6b6 100644 --- a/NextGenSoftware.OASIS.API.Providers.HashgraphOASIS/HashgraphOASIS.cs +++ b/NextGenSoftware.OASIS.API.Providers.HashgraphOASIS/HashgraphOASIS.cs @@ -78,6 +78,26 @@ public override Task> DeleteHolonAsync(string providerKey, boo throw new NotImplementedException(); } + public override Task>> ExportAll(int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByEmail(string avatarEmailAddress, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarById(Guid avatarId, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByUsername(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + public OASISResult> GetHolonsNearMe(HolonType Type) { throw new NotImplementedException(); @@ -88,6 +108,11 @@ public OASISResult> GetPlayersNearMe() throw new NotImplementedException(); } + public override Task> Import(IEnumerable holons) + { + throw new NotImplementedException(); + } + public override OASISResult> LoadAllAvatarDetails(int version = 0) { throw new NotImplementedException(); @@ -292,5 +317,25 @@ public override Task> SearchAsync(ISearchParams sear { throw new NotImplementedException(); } + + public OASISResult SendNFT(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public Task> SendNFTAsync(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public OASISResult SendTrasaction(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public Task> SendTrasactionAsync(IWalletTransaction transation) + { + throw new NotImplementedException(); + } } } diff --git a/NextGenSoftware.OASIS.API.Providers.HoloOASIS.Core/HoloOASISBase.cs b/NextGenSoftware.OASIS.API.Providers.HoloOASIS.Core/HoloOASISBase.cs index 7f2058322..4b644c8c9 100644 --- a/NextGenSoftware.OASIS.API.Providers.HoloOASIS.Core/HoloOASISBase.cs +++ b/NextGenSoftware.OASIS.API.Providers.HoloOASIS.Core/HoloOASISBase.cs @@ -13,7 +13,7 @@ namespace NextGenSoftware.OASIS.API.Providers.HoloOASIS.Core { - public abstract class HoloOASISBase : OASISStorageProviderBase, IOASISNETProvider, IOASISBlockchainStorageProvider, IOASISSmartContractProvider, IOASISNFTProvider, IOASISSuperStar + public abstract class HoloOASISBase : OASISStorageProviderBase, IOASISNETProvider, IOASISBlockchainStorageProvider, IOASISLocalStorageProvider, IOASISSmartContractProvider, IOASISNFTProvider, IOASISSuperStar { private const string OURWORLD_ZOME = "our_world_core"; private const string LOAD_Avatar_FUNC = "load_Avatar"; @@ -51,8 +51,8 @@ public HoloOASISBase(HoloNETClientBase holoNETClient) { this.ProviderName = "HoloOASIS"; this.ProviderDescription = "Holochain Provider"; - this.ProviderType = new API.Core.Helpers.EnumValue(API.Core.Enums.ProviderType.HoloOASIS); - this.ProviderCategory = new API.Core.Helpers.EnumValue(API.Core.Enums.ProviderCategory.StorageAndNetwork); + this.ProviderType = new EnumValue(API.Core.Enums.ProviderType.HoloOASIS); + this.ProviderCategory = new EnumValue(API.Core.Enums.ProviderCategory.StorageLocalAndNetwork); this.HoloNETClient = holoNETClient; // _holochainURI = holochainURI; Initialize(); @@ -627,5 +627,86 @@ public bool NativeCodeGenesis(ICelestialBody celestialBody) { throw new NotImplementedException(); } + + public OASISResult SendTrasaction(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public Task> SendTrasactionAsync(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public OASISResult SendNFT(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public Task> SendNFTAsync(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public OASISResult>> LoadProviderWallets() + { + OASISResult>> result = new OASISResult>>(); + + //TODO: Finish Implementing. + + return result; + } + + public async Task>>> LoadProviderWalletsAsync() + { + OASISResult>> result = new OASISResult>>(); + + //TODO: Finish Implementing. + + return result; + } + + public OASISResult SaveProviderWallets(Dictionary> providerWallets) + { + OASISResult result = new OASISResult(); + + //TODO: Finish Implementing. + + return result; + } + + public async Task> SaveProviderWalletsAsync(Dictionary> providerWallets) + { + OASISResult result = new OASISResult(); + + //TODO: Finish Implementing. + + return result; + } + + public override Task>> ExportAll(int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByEmail(string avatarEmailAddress, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarById(Guid avatarId, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByUsername(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task> Import(IEnumerable holons) + { + throw new NotImplementedException(); + } } } diff --git a/NextGenSoftware.OASIS.API.Providers.HoloOASIS.Unity/HoloOASIS.cs b/NextGenSoftware.OASIS.API.Providers.HoloOASIS.Unity/HoloOASIS.cs index 5abfd2050..90c46df01 100644 --- a/NextGenSoftware.OASIS.API.Providers.HoloOASIS.Unity/HoloOASIS.cs +++ b/NextGenSoftware.OASIS.API.Providers.HoloOASIS.Unity/HoloOASIS.cs @@ -1,7 +1,11 @@ using NextGenSoftware.Holochain.HoloNET.Client.Core; using NextGenSoftware.Holochain.HoloNET.Client.Unity; +using NextGenSoftware.OASIS.API.Core.Helpers; +using NextGenSoftware.OASIS.API.Core.Interfaces; using NextGenSoftware.OASIS.API.Providers.HoloOASIS.Core; - +using System; +using System.Collections.Generic; +using System.Threading.Tasks; namespace NextGenSoftware.OASIS.API.Providers.HoloOASIS.Unity { diff --git a/NextGenSoftware.OASIS.API.Providers.IPFSOASIS/IPFSOASIS.cs b/NextGenSoftware.OASIS.API.Providers.IPFSOASIS/IPFSOASIS.cs index eaa59d502..cb9fac733 100644 --- a/NextGenSoftware.OASIS.API.Providers.IPFSOASIS/IPFSOASIS.cs +++ b/NextGenSoftware.OASIS.API.Providers.IPFSOASIS/IPFSOASIS.cs @@ -22,7 +22,7 @@ namespace NextGenSoftware.OASIS.API.Providers.IPFSOASIS { //TODO: Implement OASISResult properly on below methods! :) - public class IPFSOASIS : OASISStorageProviderBase, IOASISBlockchainStorageProvider, IOASISNETProvider + public class IPFSOASIS : OASISStorageProviderBase, IOASISNETProvider { public IpfsClient IPFSClient; public IpfsEngine IPFSEngine; //= new IpfsEngine(); @@ -782,5 +782,30 @@ OASISResult> IOASISNETProvider.GetHolonsNearMe(HolonType Typ { throw new NotImplementedException(); } + + public override Task> Import(IEnumerable holons) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarById(Guid avatarId, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByUsername(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByEmail(string avatarEmailAddress, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAll(int version = 0) + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/NextGenSoftware.OASIS.API.Providers.LocalFileOASIS/LocalFileOASIS.cs b/NextGenSoftware.OASIS.API.Providers.LocalFileOASIS/LocalFileOASIS.cs new file mode 100644 index 000000000..0ca060a23 --- /dev/null +++ b/NextGenSoftware.OASIS.API.Providers.LocalFileOASIS/LocalFileOASIS.cs @@ -0,0 +1,373 @@ +using System.Text.Json; +using NextGenSoftware.OASIS.API.Core; +using NextGenSoftware.OASIS.API.Core.Enums; +using NextGenSoftware.OASIS.API.Core.Helpers; +using NextGenSoftware.OASIS.API.Core.Interfaces; + +namespace NextGenSoftware.OASIS.API.Providers.LocalFileOASIS +{ + public class LocalFileOASIS : OASISStorageProviderBase, IOASISLocalStorageProvider + { + private string _filePath = "wallets.json"; + + public LocalFileOASIS(string filePath) + { + this.ProviderName = "LocalFileOASIS"; + this.ProviderDescription = "LocalFile Provider"; + this.ProviderType = new EnumValue(Core.Enums.ProviderType.LocalFileOASIS); + this.ProviderCategory = new EnumValue(Core.Enums.ProviderCategory.StorageLocal); + + if (!string.IsNullOrEmpty(filePath)) + _filePath = filePath; + } + + public OASISResult>> LoadProviderWallets() + { + OASISResult>> result = new OASISResult>>(); + + try + { + string json = File.ReadAllText(_filePath); + result.Result = JsonSerializer.Deserialize>>(json); + } + catch (Exception ex) + { + ErrorHandling.HandleError(ref result, $"Error occured in LoadProviderWallets method in LocalFileOASIS Provider loading wallets. Reason: {ex.Message}", ex); + } + + return result; + } + + public async Task>>> LoadProviderWalletsAsync() + { + OASISResult>> result = new OASISResult>>(); + + try + { + using FileStream openStream = File.OpenRead(_filePath); + result.Result = await JsonSerializer.DeserializeAsync>>(openStream); + } + catch (Exception ex) + { + ErrorHandling.HandleError(ref result, $"Error occured in LoadProviderWalletsAsync method in LocalFileOASIS Provider loading wallets. Reason: {ex.Message}", ex); + } + + return result; + } + + public OASISResult SaveProviderWallets(Dictionary> providerWallets) + { + OASISResult result = new OASISResult(); + + try + { + string jsonString = JsonSerializer.Serialize(providerWallets); + File.WriteAllText(_filePath, jsonString); + } + catch (Exception ex) + { + ErrorHandling.HandleError(ref result, $"Error occured in SaveProviderWalletsAsync method in LocalFileOASIS Provider saving wallets. Reason: {ex.Message}", ex); + } + + return result; + } + + public async Task> SaveProviderWalletsAsync(Dictionary> providerWallets) + { + OASISResult result = new OASISResult(); + + try + { + using FileStream createStream = File.Create(_filePath); + await JsonSerializer.SerializeAsync(createStream, providerWallets); + await createStream.DisposeAsync(); + } + catch (Exception ex) + { + ErrorHandling.HandleError(ref result, $"Error occured in SaveProviderWalletsAsync method in LocalFileOASIS Provider saving wallets. Reason: {ex.Message}", ex); + } + + return result; + } + + public override OASISResult DeleteAvatar(Guid id, bool softDelete = true) + { + throw new NotImplementedException(); + } + + public override OASISResult DeleteAvatar(string providerKey, bool softDelete = true) + { + throw new NotImplementedException(); + } + + public override Task> DeleteAvatarAsync(Guid id, bool softDelete = true) + { + throw new NotImplementedException(); + } + + public override Task> DeleteAvatarAsync(string providerKey, bool softDelete = true) + { + throw new NotImplementedException(); + } + + public override OASISResult DeleteAvatarByEmail(string avatarEmail, bool softDelete = true) + { + throw new NotImplementedException(); + } + + public override Task> DeleteAvatarByEmailAsync(string avatarEmail, bool softDelete = true) + { + throw new NotImplementedException(); + } + + public override OASISResult DeleteAvatarByUsername(string avatarUsername, bool softDelete = true) + { + throw new NotImplementedException(); + } + + public override Task> DeleteAvatarByUsernameAsync(string avatarUsername, bool softDelete = true) + { + throw new NotImplementedException(); + } + + public override OASISResult DeleteHolon(Guid id, bool softDelete = true) + { + throw new NotImplementedException(); + } + + public override OASISResult DeleteHolon(string providerKey, bool softDelete = true) + { + throw new NotImplementedException(); + } + + public override Task> DeleteHolonAsync(Guid id, bool softDelete = true) + { + throw new NotImplementedException(); + } + + public override Task> DeleteHolonAsync(string providerKey, bool softDelete = true) + { + throw new NotImplementedException(); + } + + public override OASISResult> LoadAllAvatarDetails(int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> LoadAllAvatarDetailsAsync(int version = 0) + { + throw new NotImplementedException(); + } + + public override OASISResult> LoadAllAvatars(int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> LoadAllAvatarsAsync(int version = 0) + { + throw new NotImplementedException(); + } + + public override OASISResult> LoadAllHolons(HolonType type = HolonType.All, bool loadChildren = true, bool recursive = true, int maxChildDepth = 0, int curentChildDepth = 0, bool continueOnError = true, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> LoadAllHolonsAsync(HolonType type = HolonType.All, bool loadChildren = true, bool recursive = true, int maxChildDepth = 0, int curentChildDepth = 0, bool continueOnError = true, int version = 0) + { + throw new NotImplementedException(); + } + + public override OASISResult LoadAvatar(Guid Id, int version = 0) + { + throw new NotImplementedException(); + } + + public override OASISResult LoadAvatar(string username, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task> LoadAvatarAsync(Guid Id, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task> LoadAvatarAsync(string username, int version = 0) + { + throw new NotImplementedException(); + } + + public override OASISResult LoadAvatarByEmail(string avatarEmail, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task> LoadAvatarByEmailAsync(string avatarEmail, int version = 0) + { + throw new NotImplementedException(); + } + + public override OASISResult LoadAvatarByUsername(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task> LoadAvatarByUsernameAsync(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + + public override OASISResult LoadAvatarDetail(Guid id, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task> LoadAvatarDetailAsync(Guid id, int version = 0) + { + throw new NotImplementedException(); + } + + public override OASISResult LoadAvatarDetailByEmail(string avatarEmail, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task> LoadAvatarDetailByEmailAsync(string avatarEmail, int version = 0) + { + throw new NotImplementedException(); + } + + public override OASISResult LoadAvatarDetailByUsername(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task> LoadAvatarDetailByUsernameAsync(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + + public override OASISResult LoadAvatarForProviderKey(string providerKey, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task> LoadAvatarForProviderKeyAsync(string providerKey, int version = 0) + { + throw new NotImplementedException(); + } + + public override OASISResult LoadHolon(Guid id, bool loadChildren = true, bool recursive = true, int maxChildDepth = 0, bool continueOnError = true, int version = 0) + { + throw new NotImplementedException(); + } + + public override OASISResult LoadHolon(string providerKey, bool loadChildren = true, bool recursive = true, int maxChildDepth = 0, bool continueOnError = true, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task> LoadHolonAsync(Guid id, bool loadChildren = true, bool recursive = true, int maxChildDepth = 0, bool continueOnError = true, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task> LoadHolonAsync(string providerKey, bool loadChildren = true, bool recursive = true, int maxChildDepth = 0, bool continueOnError = true, int version = 0) + { + throw new NotImplementedException(); + } + + public override OASISResult> LoadHolonsForParent(Guid id, HolonType type = HolonType.All, bool loadChildren = true, bool recursive = true, int maxChildDepth = 0, int curentChildDepth = 0, bool continueOnError = true, int version = 0) + { + throw new NotImplementedException(); + } + + public override OASISResult> LoadHolonsForParent(string providerKey, HolonType type = HolonType.All, bool loadChildren = true, bool recursive = true, int maxChildDepth = 0, int curentChildDepth = 0, bool continueOnError = true, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> LoadHolonsForParentAsync(Guid id, HolonType type = HolonType.All, bool loadChildren = true, bool recursive = true, int maxChildDepth = 0, int curentChildDepth = 0, bool continueOnError = true, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> LoadHolonsForParentAsync(string providerKey, HolonType type = HolonType.All, bool loadChildren = true, bool recursive = true, int maxChildDepth = 0, int curentChildDepth = 0, bool continueOnError = true, int version = 0) + { + throw new NotImplementedException(); + } + + public override OASISResult SaveAvatar(IAvatar Avatar) + { + throw new NotImplementedException(); + } + + public override Task> SaveAvatarAsync(IAvatar Avatar) + { + throw new NotImplementedException(); + } + + public override OASISResult SaveAvatarDetail(IAvatarDetail Avatar) + { + throw new NotImplementedException(); + } + + public override Task> SaveAvatarDetailAsync(IAvatarDetail Avatar) + { + throw new NotImplementedException(); + } + + public override OASISResult SaveHolon(IHolon holon, bool saveChildren = true, bool recursive = true, int maxChildDepth = 0, bool continueOnError = true) + { + throw new NotImplementedException(); + } + + public override Task> SaveHolonAsync(IHolon holon, bool saveChildren = true, bool recursive = true, int maxChildDepth = 0, bool continueOnError = true) + { + throw new NotImplementedException(); + } + + public override OASISResult> SaveHolons(IEnumerable holons, bool saveChildren = true, bool recursive = true, int maxChildDepth = 0, int curentChildDepth = 0, bool continueOnError = true) + { + throw new NotImplementedException(); + } + + public override Task>> SaveHolonsAsync(IEnumerable holons, bool saveChildren = true, bool recursive = true, int maxChildDepth = 0, int curentChildDepth = 0, bool continueOnError = true) + { + throw new NotImplementedException(); + } + + public override Task> SearchAsync(ISearchParams searchParams, bool loadChildren = true, bool recursive = true, int maxChildDepth = 0, bool continueOnError = true, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task> Import(IEnumerable holons) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarById(Guid avatarId, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByUsername(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByEmail(string avatarEmailAddress, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAll(int version = 0) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/NextGenSoftware.OASIS.API.Providers.LocalFileOASIS/NextGenSoftware.OASIS.API.Providers.LocalFileOASIS.csproj b/NextGenSoftware.OASIS.API.Providers.LocalFileOASIS/NextGenSoftware.OASIS.API.Providers.LocalFileOASIS.csproj new file mode 100644 index 000000000..75223c9bd --- /dev/null +++ b/NextGenSoftware.OASIS.API.Providers.LocalFileOASIS/NextGenSoftware.OASIS.API.Providers.LocalFileOASIS.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/NextGenSoftware.OASIS.API.Providers.MongoOASIS/Entities/Avatar.cs b/NextGenSoftware.OASIS.API.Providers.MongoOASIS/Entities/Avatar.cs index 0a548ee6e..100e0be44 100644 --- a/NextGenSoftware.OASIS.API.Providers.MongoOASIS/Entities/Avatar.cs +++ b/NextGenSoftware.OASIS.API.Providers.MongoOASIS/Entities/Avatar.cs @@ -12,7 +12,7 @@ namespace NextGenSoftware.OASIS.API.Providers.MongoDBOASIS.Entities public class Avatar : HolonBase { [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] - public Dictionary> ProviderWallets { get; set; } = new Dictionary>(); + public Dictionary> ProviderWallets { get; set; } = new Dictionary>(); //[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] //public Dictionary ProviderPrivateKey { get; set; } = new Dictionary(); //Unique private key used by each provider (part of private/public key pair). diff --git a/NextGenSoftware.OASIS.API.Providers.MongoOASIS/Entities/AvatarDetail.cs b/NextGenSoftware.OASIS.API.Providers.MongoOASIS/Entities/AvatarDetail.cs index 07fb6959e..1a9cf5381 100644 --- a/NextGenSoftware.OASIS.API.Providers.MongoOASIS/Entities/AvatarDetail.cs +++ b/NextGenSoftware.OASIS.API.Providers.MongoOASIS/Entities/AvatarDetail.cs @@ -36,17 +36,17 @@ public class AvatarDetail : Holon //public EnumValue AvatarType { get; set; } public int Karma { get; set; } - [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] - public Dictionary ProviderPrivateKey { get; set; } = new Dictionary(); //Unique private key used by each provider (part of private/public key pair). + //[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] + //public Dictionary ProviderPrivateKey { get; set; } = new Dictionary(); //Unique private key used by each provider (part of private/public key pair). - [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] - public Dictionary ProviderPublicKey { get; set; } = new Dictionary(); + //[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] + //public Dictionary ProviderPublicKey { get; set; } = new Dictionary(); - [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] - public Dictionary ProviderUsername { get; set; } = new Dictionary(); // This is only really needed when we need to store BOTH a id and username for a provider (ProviderUniqueStorageKey on Holon already stores either id/username etc). // public Dictionary ProviderId { get; set; } = new Dictionary(); // The ProviderUniqueStorageKey property on the base Holon object can store ids, usernames, etc that uniqueliy identity that holon in the provider (although the Guid is globally unique we still need to map the Holons the unique id/username/etc for each provider). + //[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] + //public Dictionary ProviderUsername { get; set; } = new Dictionary(); // This is only really needed when we need to store BOTH a id and username for a provider (ProviderUniqueStorageKey on Holon already stores either id/username etc). // public Dictionary ProviderId { get; set; } = new Dictionary(); // The ProviderUniqueStorageKey property on the base Holon object can store ids, usernames, etc that uniqueliy identity that holon in the provider (although the Guid is globally unique we still need to map the Holons the unique id/username/etc for each provider). - [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] - public Dictionary ProviderWalletAddress { get; set; } = new Dictionary(); + //[BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] + //public Dictionary ProviderWalletAddress { get; set; } = new Dictionary(); public ConsoleColor FavouriteColour { get; set; } public ConsoleColor STARCLIColour { get; set; } diff --git a/NextGenSoftware.OASIS.API.Providers.MongoOASIS/MongoDBOASIS.cs b/NextGenSoftware.OASIS.API.Providers.MongoOASIS/MongoDBOASIS.cs index 865b6c3bf..aff810980 100644 --- a/NextGenSoftware.OASIS.API.Providers.MongoOASIS/MongoDBOASIS.cs +++ b/NextGenSoftware.OASIS.API.Providers.MongoOASIS/MongoDBOASIS.cs @@ -11,6 +11,7 @@ using Avatar = NextGenSoftware.OASIS.API.Providers.MongoDBOASIS.Entities.Avatar; using AvatarDetail = NextGenSoftware.OASIS.API.Providers.MongoDBOASIS.Entities.AvatarDetail; using Holon = NextGenSoftware.OASIS.API.Providers.MongoDBOASIS.Entities.Holon; +using NextGenSoftware.OASIS.API.Core.Objects; namespace NextGenSoftware.OASIS.API.Providers.MongoDBOASIS { @@ -586,9 +587,21 @@ private OASISResult ConvertMongoEntityToOASISAvatar(OASISResult result.Result.IsNewHolon = false; result.Result.Id = avatarResult.Result.HolonId; result.Result.ProviderUniqueStorageKey = avatarResult.Result.ProviderUniqueStorageKey; - result.Result.ProviderWallets = avatarResult.Result.ProviderWallets; - // result.Result.ProviderPrivateKey = avatarResult.Result.ProviderPrivateKey; - // result.Result.ProviderPublicKey = avatarResult.Result.ProviderPublicKey; + //result.Result.ProviderWallets = avatarResult.Result.ProviderWallets; + + List wallets; + foreach (ProviderType providerType in avatarResult.Result.ProviderWallets.Keys) + { + wallets = new List(); + + foreach (IProviderWallet wallet in avatarResult.Result.ProviderWallets[providerType]) + wallets.Add(wallet); + + result.Result.ProviderWallets[providerType] = wallets; + } + + // result.Result.ProviderPrivateKey = avatarResult.Result.ProviderPrivateKey; + // result.Result.ProviderPublicKey = avatarResult.Result.ProviderPublicKey; result.Result.ProviderUsername = avatarResult.Result.ProviderUsername; // result.Result.ProviderWalletAddress = avatarResult.Result.ProviderWalletAddress; result.Result.PreviousVersionId = avatarResult.Result.PreviousVersionId; @@ -763,7 +776,19 @@ private Avatar ConvertOASISAvatarToMongoEntity(IAvatar avatar) mongoAvatar.HolonId = avatar.Id; // mongoAvatar.AvatarId = avatar.Id; mongoAvatar.ProviderUniqueStorageKey = avatar.ProviderUniqueStorageKey; - mongoAvatar.ProviderWallets = avatar.ProviderWallets; + + foreach (ProviderType providerType in avatar.ProviderWallets.Keys) + { + foreach (IProviderWallet wallet in avatar.ProviderWallets[providerType]) + { + if (!mongoAvatar.ProviderWallets.ContainsKey(providerType)) + mongoAvatar.ProviderWallets[providerType] = new List(); + + mongoAvatar.ProviderWallets[providerType].Add((ProviderWallet)wallet); + } + } + + //mongoAvatar.ProviderWallets = avatar.ProviderWallets; // mongoAvatar.ProviderPrivateKey = avatar.ProviderPrivateKey; //mongoAvatar.ProviderPublicKey = avatar.ProviderPublicKey; mongoAvatar.ProviderUsername = avatar.ProviderUsername; @@ -1140,5 +1165,30 @@ OASISResult> IOASISNETProvider.GetHolonsNearMe(HolonType Typ { throw new NotImplementedException(); } + + public override Task> Import(IEnumerable holons) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarById(Guid avatarId, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByUsername(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByEmail(string avatarEmailAddress, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAll(int version = 0) + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/NextGenSoftware.OASIS.API.Providers.Neo4jOASIS/Neo4jOASIS.cs b/NextGenSoftware.OASIS.API.Providers.Neo4jOASIS/Neo4jOASIS.cs index 36ee4c59e..3dcd19c6c 100644 --- a/NextGenSoftware.OASIS.API.Providers.Neo4jOASIS/Neo4jOASIS.cs +++ b/NextGenSoftware.OASIS.API.Providers.Neo4jOASIS/Neo4jOASIS.cs @@ -449,6 +449,31 @@ public override Task> DeleteHolonAsync(string providerKey, boo throw new NotImplementedException(); } + public override Task> Import(IEnumerable holons) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarById(Guid avatarId, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByUsername(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByEmail(string avatarEmailAddress, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAll(int version = 0) + { + throw new NotImplementedException(); + } + //public override OASISResult DeleteAvatar(Guid id, bool softDelete = true) //{ // throw new NotImplementedException(); diff --git a/NextGenSoftware.OASIS.API.Providers.PLANOASIS/PLANOASIS.cs b/NextGenSoftware.OASIS.API.Providers.PLANOASIS/PLANOASIS.cs index aad0212c8..0962dc6cc 100644 --- a/NextGenSoftware.OASIS.API.Providers.PLANOASIS/PLANOASIS.cs +++ b/NextGenSoftware.OASIS.API.Providers.PLANOASIS/PLANOASIS.cs @@ -78,6 +78,26 @@ public override Task> DeleteHolonAsync(string providerKey, boo throw new NotImplementedException(); } + public override Task>> ExportAll(int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByEmail(string avatarEmailAddress, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarById(Guid avatarId, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByUsername(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + public OASISResult> GetHolonsNearMe(HolonType Type) { throw new NotImplementedException(); @@ -88,6 +108,11 @@ public OASISResult> GetPlayersNearMe() throw new NotImplementedException(); } + public override Task> Import(IEnumerable holons) + { + throw new NotImplementedException(); + } + public override OASISResult> LoadAllAvatarDetails(int version = 0) { throw new NotImplementedException(); diff --git a/NextGenSoftware.OASIS.API.Providers.SOLANAOASIS/SolanaOasis.cs b/NextGenSoftware.OASIS.API.Providers.SOLANAOASIS/SolanaOasis.cs index f70b5d0cf..617ce6b10 100644 --- a/NextGenSoftware.OASIS.API.Providers.SOLANAOASIS/SolanaOasis.cs +++ b/NextGenSoftware.OASIS.API.Providers.SOLANAOASIS/SolanaOasis.cs @@ -505,5 +505,50 @@ public OASISResult> GetHolonsNearMe(HolonType Type) { throw new NotImplementedException(); } + + public override Task> Import(IEnumerable holons) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarById(Guid avatarId, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByUsername(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByEmail(string avatarEmailAddress, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAll(int version = 0) + { + throw new NotImplementedException(); + } + + public OASISResult SendTrasaction(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public Task> SendTrasactionAsync(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public OASISResult SendNFT(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public Task> SendNFTAsync(IWalletTransaction transation) + { + throw new NotImplementedException(); + } } } diff --git a/NextGenSoftware.OASIS.API.Providers.SOLIDOASIS/SOLIDOASIS.cs b/NextGenSoftware.OASIS.API.Providers.SOLIDOASIS/SOLIDOASIS.cs index 4d8aeef3e..a114c9e3a 100644 --- a/NextGenSoftware.OASIS.API.Providers.SOLIDOASIS/SOLIDOASIS.cs +++ b/NextGenSoftware.OASIS.API.Providers.SOLIDOASIS/SOLIDOASIS.cs @@ -80,6 +80,26 @@ public override Task> DeleteHolonAsync(string providerKey, boo throw new NotImplementedException(); } + public override Task>> ExportAll(int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByEmail(string avatarEmailAddress, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarById(Guid avatarId, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByUsername(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + public OASISResult> GetHolonsNearMe(HolonType Type) { throw new NotImplementedException(); @@ -90,6 +110,11 @@ public OASISResult> GetPlayersNearMe() throw new NotImplementedException(); } + public override Task> Import(IEnumerable holons) + { + throw new NotImplementedException(); + } + public override OASISResult> LoadAllAvatarDetails(int version = 0) { throw new NotImplementedException(); diff --git a/NextGenSoftware.OASIS.API.Providers.SQLLiteDBOASIS/Entities/AvatarEntity.cs b/NextGenSoftware.OASIS.API.Providers.SQLLiteDBOASIS/Entities/AvatarEntity.cs index a40d46ae2..f50bfab9b 100644 --- a/NextGenSoftware.OASIS.API.Providers.SQLLiteDBOASIS/Entities/AvatarEntity.cs +++ b/NextGenSoftware.OASIS.API.Providers.SQLLiteDBOASIS/Entities/AvatarEntity.cs @@ -137,12 +137,17 @@ public IAvatar Save() return (ProviderManager.CurrentStorageProvider).SaveAvatar(this).Result; } - OASISResult IAvatar.Save() + public OASISResult Save(ProviderType providerType = ProviderType.Default) { throw new NotImplementedException(); } - Task> IAvatar.SaveAsync() + public Task> SaveAsync(ProviderType providerType = ProviderType.Default) + { + throw new NotImplementedException(); + } + + public OASISResult SaveProviderWallets(ProviderType providerType = ProviderType.Default) { throw new NotImplementedException(); } diff --git a/NextGenSoftware.OASIS.API.Providers.SQLLiteDBOASIS/SQLLiteDBOASIS.cs b/NextGenSoftware.OASIS.API.Providers.SQLLiteDBOASIS/SQLLiteDBOASIS.cs index 9112d536e..e6839661e 100644 --- a/NextGenSoftware.OASIS.API.Providers.SQLLiteDBOASIS/SQLLiteDBOASIS.cs +++ b/NextGenSoftware.OASIS.API.Providers.SQLLiteDBOASIS/SQLLiteDBOASIS.cs @@ -10,7 +10,7 @@ namespace NextGenSoftware.OASIS.API.Providers.SQLLiteDBOASIS { - public class SQLLiteDBOASIS : OASISStorageProviderBase, IOASISDBStorageProvider, IOASISNETProvider, IOASISSuperStar + public class SQLLiteDBOASIS : OASISStorageProviderBase, IOASISDBStorageProvider, IOASISLocalStorageProvider, IOASISNETProvider, IOASISSuperStar { private DataContext appDataContext; @@ -24,7 +24,7 @@ public SQLLiteDBOASIS(string connectionString) this.ProviderName = "SQLLiteDBOASIS"; this.ProviderDescription = "SQLLiteDBOASIS Provider"; this.ProviderType = new EnumValue(Core.Enums.ProviderType.SQLLiteDBOASIS); - this.ProviderCategory = new EnumValue(Core.Enums.ProviderCategory.StorageAndNetwork); + this.ProviderCategory = new EnumValue(Core.Enums.ProviderCategory.StorageLocalAndNetwork); appDataContext = new DataContext(connectionString); //appDataContext = new DataContext(); @@ -382,5 +382,66 @@ public override Task> SearchAsync(ISearchParams sear { throw new NotImplementedException(); } + + public OASISResult>> LoadProviderWallets() + { + OASISResult>> result = new OASISResult>>(); + + //TODO: Finish Implementing. + + return result; + } + + public async Task>>> LoadProviderWalletsAsync() + { + OASISResult>> result = new OASISResult>>(); + + //TODO: Finish Implementing. + + return result; + } + + public OASISResult SaveProviderWallets(Dictionary> providerWallets) + { + OASISResult result = new OASISResult(); + + //TODO: Finish Implementing. + + return result; + } + + public async Task> SaveProviderWalletsAsync(Dictionary> providerWallets) + { + OASISResult result = new OASISResult(); + + //TODO: Finish Implementing. + + return result; + } + + public override Task> Import(IEnumerable holons) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarById(Guid avatarId, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByUsername(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByEmail(string avatarEmailAddress, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAll(int version = 0) + { + throw new NotImplementedException(); + } } } diff --git a/NextGenSoftware.OASIS.API.Providers.ScuttlebuttOASIS/ScuttlebuttOASIS.cs b/NextGenSoftware.OASIS.API.Providers.ScuttlebuttOASIS/ScuttlebuttOASIS.cs index c0083d236..7f6456543 100644 --- a/NextGenSoftware.OASIS.API.Providers.ScuttlebuttOASIS/ScuttlebuttOASIS.cs +++ b/NextGenSoftware.OASIS.API.Providers.ScuttlebuttOASIS/ScuttlebuttOASIS.cs @@ -79,6 +79,26 @@ public override Task> DeleteHolonAsync(string providerKey, boo throw new NotImplementedException(); } + public override Task>> ExportAll(int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByEmail(string avatarEmailAddress, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarById(Guid avatarId, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByUsername(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + public OASISResult> GetHolonsNearMe(HolonType Type) { throw new NotImplementedException(); @@ -89,6 +109,11 @@ public OASISResult> GetPlayersNearMe() throw new NotImplementedException(); } + public override Task> Import(IEnumerable holons) + { + throw new NotImplementedException(); + } + public override OASISResult> LoadAllAvatarDetails(int version = 0) { throw new NotImplementedException(); diff --git a/NextGenSoftware.OASIS.API.Providers.TRONOASIS/TRONOASIS.cs b/NextGenSoftware.OASIS.API.Providers.TRONOASIS/TRONOASIS.cs index a3816fb5a..53401e6aa 100644 --- a/NextGenSoftware.OASIS.API.Providers.TRONOASIS/TRONOASIS.cs +++ b/NextGenSoftware.OASIS.API.Providers.TRONOASIS/TRONOASIS.cs @@ -78,6 +78,26 @@ public override Task> DeleteHolonAsync(string providerKey, boo throw new NotImplementedException(); } + public override Task>> ExportAll(int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByEmail(string avatarEmailAddress, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarById(Guid avatarId, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByUsername(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + public OASISResult> GetHolonsNearMe(HolonType Type) { throw new NotImplementedException(); @@ -88,6 +108,11 @@ public OASISResult> GetPlayersNearMe() throw new NotImplementedException(); } + public override Task> Import(IEnumerable holons) + { + throw new NotImplementedException(); + } + public override OASISResult> LoadAllAvatarDetails(int version = 0) { throw new NotImplementedException(); @@ -292,5 +317,25 @@ public override Task> SearchAsync(ISearchParams sear { throw new NotImplementedException(); } + + public OASISResult SendNFT(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public Task> SendNFTAsync(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public OASISResult SendTrasaction(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public Task> SendTrasactionAsync(IWalletTransaction transation) + { + throw new NotImplementedException(); + } } } diff --git a/NextGenSoftware.OASIS.API.Providers.TelosOASIS/TelosOASIS.cs b/NextGenSoftware.OASIS.API.Providers.TelosOASIS/TelosOASIS.cs index 1598c8f1f..f9d4065d4 100644 --- a/NextGenSoftware.OASIS.API.Providers.TelosOASIS/TelosOASIS.cs +++ b/NextGenSoftware.OASIS.API.Providers.TelosOASIS/TelosOASIS.cs @@ -388,5 +388,50 @@ public OASISResult> GetHolonsNearMe(HolonType Type) { throw new NotImplementedException(); } + + public OASISResult SendTrasaction(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public Task> SendTrasactionAsync(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public OASISResult SendNFT(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public Task> SendNFTAsync(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public override Task> Import(IEnumerable holons) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarById(Guid avatarId, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByUsername(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByEmail(string avatarEmailAddress, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAll(int version = 0) + { + throw new NotImplementedException(); + } } } diff --git a/NextGenSoftware.OASIS.API.Providers.ThreeFoldOASIS/ThreeFoldOASIS.cs b/NextGenSoftware.OASIS.API.Providers.ThreeFoldOASIS/ThreeFoldOASIS.cs index 069905bc4..2c419ab42 100644 --- a/NextGenSoftware.OASIS.API.Providers.ThreeFoldOASIS/ThreeFoldOASIS.cs +++ b/NextGenSoftware.OASIS.API.Providers.ThreeFoldOASIS/ThreeFoldOASIS.cs @@ -295,5 +295,50 @@ public OASISResult> GetHolonsNearMe(HolonType Type) { throw new NotImplementedException(); } + + public OASISResult SendTrasaction(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public Task> SendTrasactionAsync(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public OASISResult SendNFT(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public Task> SendNFTAsync(IWalletTransaction transation) + { + throw new NotImplementedException(); + } + + public override Task> Import(IEnumerable holons) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarById(Guid avatarId, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByUsername(string avatarUsername, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAllDataForAvatarByEmail(string avatarEmailAddress, int version = 0) + { + throw new NotImplementedException(); + } + + public override Task>> ExportAll(int version = 0) + { + throw new NotImplementedException(); + } } } diff --git a/NextGenSoftware.OASIS.OASISBootLoader/NextGenSoftware.OASIS.OASISBootLoader.csproj b/NextGenSoftware.OASIS.OASISBootLoader/NextGenSoftware.OASIS.OASISBootLoader.csproj index 0ab1090eb..d09dfcb6a 100644 --- a/NextGenSoftware.OASIS.OASISBootLoader/NextGenSoftware.OASIS.OASISBootLoader.csproj +++ b/NextGenSoftware.OASIS.OASISBootLoader/NextGenSoftware.OASIS.OASISBootLoader.csproj @@ -17,6 +17,7 @@ + diff --git a/NextGenSoftware.OASIS.OASISBootLoader/OASISBootLoader.cs b/NextGenSoftware.OASIS.OASISBootLoader/OASISBootLoader.cs index b5aca7123..1c573b349 100644 --- a/NextGenSoftware.OASIS.OASISBootLoader/OASISBootLoader.cs +++ b/NextGenSoftware.OASIS.OASISBootLoader/OASISBootLoader.cs @@ -19,7 +19,7 @@ using NextGenSoftware.OASIS.API.Providers.ThreeFoldOASIS; using NextGenSoftware.OASIS.API.Providers.SOLANAOASIS; using NextGenSoftware.Holochain.HoloNET.Client.Core; - +using NextGenSoftware.OASIS.API.Providers.LocalFileOASIS; namespace NextGenSoftware.OASIS.OASISBootLoader { @@ -367,6 +367,13 @@ public static OASISResult GetAndActivateDefaultProvider() registeredProvider = ThreeFoldOASIS; } break; + + case ProviderType.LocalFileOASIS: + { + LocalFileOASIS localFileOASIS = new LocalFileOASIS(OASISDNA.OASIS.StorageProviders.LocalFileOASIS.FilePath); + localFileOASIS.StorageProviderError += LocalFileOASIS_StorageProviderError; + registeredProvider = localFileOASIS; + }break; } if (registeredProvider != null) @@ -382,17 +389,22 @@ public static OASISResult GetAndActivateDefaultProvider() return registeredProvider; } - private static void ThreeFoldOASIS_StorageProviderError(object sender, AvatarManagerErrorEventArgs e) + private static void LocalFileOASIS_StorageProviderError(object sender, OASISErrorEventArgs e) { throw new NotImplementedException(); } - private static void EthereumOASIS_StorageProviderError(object sender, AvatarManagerErrorEventArgs e) + private static void ThreeFoldOASIS_StorageProviderError(object sender, OASISErrorEventArgs e) { throw new NotImplementedException(); } - private static void TelosOASIS_StorageProviderError(object sender, AvatarManagerErrorEventArgs e) + private static void EthereumOASIS_StorageProviderError(object sender, OASISErrorEventArgs e) + { + throw new NotImplementedException(); + } + + private static void TelosOASIS_StorageProviderError(object sender, OASISErrorEventArgs e) { throw new NotImplementedException(); } @@ -534,49 +546,51 @@ private static void LoadProviderLists() ProviderManager.SetAutoFailOverForProviders(true, GetProviderTypesFromDNA("AutoFailOverProviders", OASISDNA.OASIS.StorageProviders.AutoFailOverProviders)); + ProviderManager.SetAutoLoadBalanceForProviders(true, GetProviderTypesFromDNA("AutoLoadBalanceProviders", OASISDNA.OASIS.StorageProviders.AutoLoadBalanceProviders)); + ProviderManager.SetAutoReplicationForProviders(true, GetProviderTypesFromDNA("AutoReplicationProviders", OASISDNA.OASIS.StorageProviders.AutoReplicationProviders)); } - private static void IPFSOASIS_StorageProviderError(object sender, AvatarManagerErrorEventArgs e) + private static void IPFSOASIS_StorageProviderError(object sender, OASISErrorEventArgs e) { throw new NotImplementedException(); } - private static void Neo4jOASIS_StorageProviderError(object sender, AvatarManagerErrorEventArgs e) + private static void Neo4jOASIS_StorageProviderError(object sender, OASISErrorEventArgs e) { throw new NotImplementedException(); } - private static void SQLLiteDBOASIS_StorageProviderError(object sender, AvatarManagerErrorEventArgs e) + private static void SQLLiteDBOASIS_StorageProviderError(object sender, OASISErrorEventArgs e) { //TODO: {URGENT} Handle Errors properly here (log, etc) // throw new Exception(string.Concat("ERROR: MongoOASIS_StorageProviderError. EndPoint: ", e.EndPoint, "Reason: ", e.Reason, ". Error Details: ", e.ErrorDetails)); } - private static void EOSIOOASIS_StorageProviderError(object sender, AvatarManagerErrorEventArgs e) + private static void EOSIOOASIS_StorageProviderError(object sender, OASISErrorEventArgs e) { //TODO: {URGENT} Handle Errors properly here (log, etc) // throw new Exception(string.Concat("ERROR: EOSIOOASIS_StorageProviderError. EndPoint: ", e.EndPoint, "Reason: ", e.Reason, ". Error Details: ", e.ErrorDetails)); } - private static void MongoOASIS_StorageProviderError(object sender, AvatarManagerErrorEventArgs e) + private static void MongoOASIS_StorageProviderError(object sender, OASISErrorEventArgs e) { //TODO: {URGENT} Handle Errors properly here (log, etc) // throw new Exception(string.Concat("ERROR: MongoOASIS_StorageProviderError. EndPoint: ", e.EndPoint, "Reason: ", e.Reason, ". Error Details: ", e.ErrorDetails)); } - private static void SolanaOASIS_StorageProviderError(object sender, AvatarManagerErrorEventArgs e) + private static void SolanaOASIS_StorageProviderError(object sender, OASISErrorEventArgs e) { //TODO: {URGENT} Handle Errors properly here (log, etc) // throw new Exception(string.Concat("ERROR: MongoOASIS_StorageProviderError. EndPoint: ", e.EndPoint, "Reason: ", e.Reason, ". Error Details: ", e.ErrorDetails)); } - private static void HoloOASIS_StorageProviderError(object sender, AvatarManagerErrorEventArgs e) + private static void HoloOASIS_StorageProviderError(object sender, OASISErrorEventArgs e) { //TODO: {URGENT} Handle Errors properly here (log, etc) // throw new Exception(string.Concat("ERROR: HoloOASIS_StorageProviderError. EndPoint: ", e.EndPoint, "Reason: ", e.Reason, ". Error Details: ", e.ErrorDetails)); diff --git a/NextGenSoftware.OASIS.STAR/DNA/OASIS_DNA.json b/NextGenSoftware.OASIS.STAR/DNA/OASIS_DNA.json index a7e1b1aba..a72efa89d 100644 --- a/NextGenSoftware.OASIS.STAR/DNA/OASIS_DNA.json +++ b/NextGenSoftware.OASIS.STAR/DNA/OASIS_DNA.json @@ -7,8 +7,8 @@ "AllowedHosts": "*", "OASIS": { "Terms": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.\n\n", - "CurrentStagingVersion": "v0.19.1", - "CurrentLiveVersion": "v0.19.1", + "CurrentStagingVersion": "v2.2.0", + "CurrentLiveVersion": "v2.1.0", "Logging": { "LoggingFramework": "NLog" }, @@ -53,7 +53,7 @@ "AutoLoadBalanceReadPollIntervalMins": "10", "AutoLoadBalanceWritePollIntervalMins": "10", "ProviderMethodCallTimeOutSeconds": "10", - "AutoReplicationProviders": "MongoDBOASIS, SQLLiteDBOASIS, Neo4jOASIS, IPFSOASIS, HoloOASIS, TelosOASIS, EOSIOOASIS, EthereumOASIS, ThreeFoldOASIS", + "AutoReplicationProviders": "MongoDBOASIS, LocalFileOASIS, SQLLiteDBOASIS, Neo4jOASIS, IPFSOASIS, HoloOASIS, TelosOASIS, EOSIOOASIS, EthereumOASIS, ThreeFoldOASIS", "AutoFailOverProviders": "MongoDBOASIS, SQLLiteDBOASIS, Neo4jOASIS, IPFSOASIS, HoloOASIS, TelosOASIS, EOSIOOASIS, EthereumOASIS, ThreeFoldOASIS", "AutoLoadBalanceProviders": "MongoDBOASIS, SQLLiteDBOASIS, Neo4jOASIS, IPFSOASIS, HoloOASIS, TelosOASIS, EOSIOOASIS, EthereumOASIS, ThreeFoldOASIS", @@ -89,7 +89,10 @@ "ConnectionString": "" }, "EthereumOASIS": { - "ConnectionString": "http://localhost:7545" + "ConnectionString": "http://testchain.nethereum.com:8545", + "ChainPrivateKey": "0x7580e7fb49df1c861f0050fae31c2224c6aba908e116b8da44ee8cd927b990b0", + "ChainId": 444444444500, + "ContractAddress": "0x06a2dabf7fec27d27f9283cb2de1cd328685510c" }, "Neo4JOASIS": { "ConnectionString": "http://localhost:7474", @@ -99,6 +102,19 @@ "IPFSOASIS": { "ConnectionString": "http://localhost:5001", "LookUpIPFSAddress": "" + }, + "SolanaOASIS": { + "WalletMnemonicWords": "bullet nothing diamond universe detail east dinner code plunge charge poem ball cable clog spray purpose renew above clay brand control shallow turtle similar", + "ConnectionString": "https://api.mainnet-beta.solana.com" + }, + "CargoOASIS": { + "ConnectionString": "", + "SingingMessage": "", + "PrivateKey": "", + "HostUrl": "" + }, + "LocalFileOASIS": { + "FilePath": "wallets.json" } } } diff --git a/The OASIS.sln b/The OASIS.sln index e318f31f5..54bc412e3 100644 --- a/The OASIS.sln +++ b/The OASIS.sln @@ -205,7 +205,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NextGenSoftware.OASIS.API.P EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NextGenSoftware.OASIS.API.Providers.SQLLiteDBOASIS.TestHarness", "NextGenSoftware.OASIS.API.Providers.SQLLiteDBOASIS.TestHarness\NextGenSoftware.OASIS.API.Providers.SQLLiteDBOASIS.TestHarness.csproj", "{BF70AEBD-22A3-4A31-8680-6580BEF8AD60}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NextGenSoftware.OASIS.API.Providers.EthereumOASIS.TestHarness", "NextGenSoftware.OASIS.API.Providers.EthereumOASIS.TestHarness\NextGenSoftware.OASIS.API.Providers.EthereumOASIS.TestHarness.csproj", "{5F56C3D3-EE6C-4864-A346-600E99C1519D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NextGenSoftware.OASIS.API.Providers.EthereumOASIS.TestHarness", "NextGenSoftware.OASIS.API.Providers.EthereumOASIS.TestHarness\NextGenSoftware.OASIS.API.Providers.EthereumOASIS.TestHarness.csproj", "{5F56C3D3-EE6C-4864-A346-600E99C1519D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NextGenSoftware.OASIS.API.Providers.LocalFileOASIS", "NextGenSoftware.OASIS.API.Providers.LocalFileOASIS\NextGenSoftware.OASIS.API.Providers.LocalFileOASIS.csproj", "{B24E62D6-C8CB-4D74-98A7-289468940F8A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -1675,6 +1677,24 @@ Global {5F56C3D3-EE6C-4864-A346-600E99C1519D}.Release|x64.Build.0 = Release|Any CPU {5F56C3D3-EE6C-4864-A346-600E99C1519D}.Release|x86.ActiveCfg = Release|Any CPU {5F56C3D3-EE6C-4864-A346-600E99C1519D}.Release|x86.Build.0 = Release|Any CPU + {B24E62D6-C8CB-4D74-98A7-289468940F8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B24E62D6-C8CB-4D74-98A7-289468940F8A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B24E62D6-C8CB-4D74-98A7-289468940F8A}.Debug|x64.ActiveCfg = Debug|Any CPU + {B24E62D6-C8CB-4D74-98A7-289468940F8A}.Debug|x64.Build.0 = Debug|Any CPU + {B24E62D6-C8CB-4D74-98A7-289468940F8A}.Debug|x86.ActiveCfg = Debug|Any CPU + {B24E62D6-C8CB-4D74-98A7-289468940F8A}.Debug|x86.Build.0 = Debug|Any CPU + {B24E62D6-C8CB-4D74-98A7-289468940F8A}.Linux|Any CPU.ActiveCfg = Debug|Any CPU + {B24E62D6-C8CB-4D74-98A7-289468940F8A}.Linux|Any CPU.Build.0 = Debug|Any CPU + {B24E62D6-C8CB-4D74-98A7-289468940F8A}.Linux|x64.ActiveCfg = Debug|Any CPU + {B24E62D6-C8CB-4D74-98A7-289468940F8A}.Linux|x64.Build.0 = Debug|Any CPU + {B24E62D6-C8CB-4D74-98A7-289468940F8A}.Linux|x86.ActiveCfg = Debug|Any CPU + {B24E62D6-C8CB-4D74-98A7-289468940F8A}.Linux|x86.Build.0 = Debug|Any CPU + {B24E62D6-C8CB-4D74-98A7-289468940F8A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B24E62D6-C8CB-4D74-98A7-289468940F8A}.Release|Any CPU.Build.0 = Release|Any CPU + {B24E62D6-C8CB-4D74-98A7-289468940F8A}.Release|x64.ActiveCfg = Release|Any CPU + {B24E62D6-C8CB-4D74-98A7-289468940F8A}.Release|x64.Build.0 = Release|Any CPU + {B24E62D6-C8CB-4D74-98A7-289468940F8A}.Release|x86.ActiveCfg = Release|Any CPU + {B24E62D6-C8CB-4D74-98A7-289468940F8A}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE