コード例 #1
0
        public A2ARetrievableAccount SavePluginVaultAccount(ISafeguardConnection sgConnection, string name, AssetAccount sppAccount)
        {
            var plugin = _configDb.GetPluginByName(name);

            if (plugin == null)
            {
                throw LogAndException($"Plugin {name} not found.");
            }
            if (sppAccount == null)
            {
                throw LogAndException("Invalid account.");
            }

            var account = _safeguardLogic.GetAssetAccount(sgConnection, sppAccount.Id);

            if (account == null)
            {
                throw LogAndException($"Account {sppAccount.Id} not found.");
            }

            // Make sure that the vault account isn't being used by another plugin before we delete it.
            if (plugin.VaultAccountId != null && (VaultAccountUsage(plugin.VaultAccountId.Value) <= 1))
            {
                _safeguardLogic.DeleteA2ARetrievableAccount(sgConnection, plugin.VaultAccountId.Value, A2ARegistrationType.Vault);
            }

            var accounts = _safeguardLogic.AddA2ARetrievableAccounts(sgConnection, new List <SppAccount>()
            {
                new SppAccount()
                {
                    Id = account.Id, Name = account.Name
                }
            }, A2ARegistrationType.Vault);

            var a2aAccount = accounts.FirstOrDefault(x => x.AccountId == account.Id);

            if (a2aAccount != null)
            {
                plugin.VaultAccountId = a2aAccount.AccountId;
                _configDb.SavePluginConfiguration(plugin);
            }
            else
            {
                throw LogAndException($"Failed to add the account to the A2A vault registration.  {account.Id} - {account.Name}.");
            }

            return(a2aAccount);
        }