# SolidFire .NET SDK Examples
These examples walk through all interactions with an Account on the SolidFire cluster.
Examples for:
Further documentation for each method and type can be found at our .NET documentation site.
ListAllAccounts method documentation
To list all Accounts on a cluster:
// Create connection to SF Cluster
var sfe = ElementFactory.Create("ip-address-of-cluster", "username", "password");
// create the request object but leave all properties as default
var request = new ListAccountsRequest();
// send the request and gather the result
var listAccountsResult = sfe.ListAccounts(request);
// iterate the accounts array on the result object and display each account
foreach(Account account in listAccountsResult.Accounts)
{
Console.WriteLine(account.ToString());
}
GetAccountByID method documentation
To get a single Account by ID
:
// Create connection to SF Cluster
var sfe = ElementFactory.Create("ip-address-of-cluster", "username", "password");
// send the request and gather the result
var getAccountResult = sfe.GetAccountByID(1);
// display the account from the result object
Console.WriteLine(getAccountResult.Account.ToString());
GetAccountByName method documentation
To get a single Account by Username
:
// Create connection to SF Cluster
var sfe = ElementFactory.Create("ip-address-of-cluster", "username", "password");
// send the request and gather the result
var getAccountResult = sfe.GetAccountByName("username-of-account");
// display the account from the result object
Console.WriteLine(getAccountResult.Account.ToString());
AddAccount method documentation
To add an Account you must specify the Username
in the AddAccountRequest object. Optionally, you can also specify the InitiatorSecret
and TargetSecret
which are CHAPSecret objects. If those secrets are not specified, they will be auto-generated by the API.
First, we add an Account with only a Username
:
// Create connection to SF Cluster
var sfe = ElementFactory.Create("ip-address-of-cluster", "username", "password");
// create a request object and set the username property
var request = new AddAccountRequest()
{
Username = "my-new-account"
};
// send the request and gather the result
var addAccountResult = sfe.AddAccount(request);
// grab the account ID from the result object
var newAccountId = addAccountResult.AccountID;
Now we add an Account and specify the Username
and InitiatorSecret
in the AddAccountRequest object. Notice we created a new CHAPSecret object and set the string value for the IntitiatorSecret
property. The TargetSecret
will be auto-generated during the process on the cluster:
// Create connection to SF Cluster
var sfe = ElementFactory.Create("ip-address-of-cluster", "username", "password");
// create a request object and set the username property
var request = new AddAccountRequest()
{
Username = "my-new-account",
InitiatorSecret = new CHAPSecret("a12To16charvalue")
};
// send the request and gather the result
var addAccountResult = sfe.AddAccount(request);
// grab the account ID from the result object
var newAccountId = addAccountResult.AccountID;
ModifyAccount method documentation
To modify an Account, all you need is the AccountID
and the values you want to change present in the ModifyAccountRequest object. Any values you leave off will remain as they were before this call is made.
In this example, we will instruct the API to autogenerate a new TargetSecret
value for an account. In order to do so we need to call the static AutoGenerate()
method on the CHAPSecret class.
// Create connection to SF Cluster
var sfe = ElementFactory.Create("ip-address-of-cluster", "username", "password");
// create a request object and set the username property
var request = new ModifyAccountRequest()
{
AccountID = 1,
TargetSecret = CHAPSecret.AutoGenerate()
};
// send the request
sfe.ModifyAccount(request);