Skip to content

Commit 4493206

Browse files
committed
added new linq to storage example
1 parent 84efff7 commit 4493206

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

Elastacloud.FluentExamples/Elastacloud.FluentExamples.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
<ItemGroup>
7474
<Compile Include="BuildVirtualMachine.cs" />
7575
<Compile Include="IBuilder.cs" />
76+
<Compile Include="IWorkflow.cs" />
77+
<Compile Include="LinqToStorage.cs" />
7678
<Compile Include="Program.cs" />
7779
<Compile Include="Properties\AssemblyInfo.cs" />
7880
</ItemGroup>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Elastacloud.FluentExamples
8+
{
9+
public interface IWorkflow
10+
{
11+
void PreActionSteps();
12+
void PostActionSteps();
13+
void DoWork();
14+
}
15+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Security.Cryptography.X509Certificates;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using Elastacloud.AzureManagement.Fluent.Clients;
8+
using Elastacloud.AzureManagement.Fluent.Helpers;
9+
using Elastacloud.AzureManagement.Fluent.Linq;
10+
using Elastacloud.AzureManagement.Fluent.Types;
11+
12+
namespace Elastacloud.FluentExamples
13+
{
14+
public class LinqToStorage : IWorkflow
15+
{
16+
private readonly X509Certificate2 _managementCertificate;
17+
private readonly string _subscriptionId;
18+
private string _accountName;
19+
20+
21+
public LinqToStorage(string subscriptionId, X509Certificate2 managementCertificate)
22+
{
23+
_subscriptionId = subscriptionId;
24+
_managementCertificate = managementCertificate;
25+
}
26+
27+
#region Implementation of IWorkflow
28+
29+
public void PreActionSteps()
30+
{
31+
// get a random account name
32+
var namer = new RandomAccountName();
33+
_accountName = namer.GetPureRandomValue();
34+
35+
var client = new StorageClient(_subscriptionId, _managementCertificate);
36+
client.CreateNewStorageAccount(_accountName);
37+
Console.WriteLine("Created new storage account with name {0}", _accountName);
38+
}
39+
40+
public void DoWork()
41+
{
42+
var inputs = new LinqToAzureInputs()
43+
{
44+
ManagementCertificateThumbprint = _managementCertificate.Thumbprint,
45+
SubscriptionId = _subscriptionId
46+
};
47+
var queryableStorage = new LinqToAzureOrderedQueryable<StorageAccount>(inputs);
48+
// build up a filtered query to check the new account
49+
var query = from account in queryableStorage
50+
where account.Name == _accountName
51+
select account;
52+
var myAccount = query.First();
53+
54+
// check that the account count is 1
55+
Console.WriteLine("{0} record returned", query.Count());
56+
Console.WriteLine("Name: {0}", myAccount.Name);
57+
Console.WriteLine("Url: {0}", myAccount.Url);
58+
Console.WriteLine("Primary Key: {0}", myAccount.PrimaryAccessKey);
59+
Console.WriteLine("Secondary Key: {0}", myAccount.SecondaryAccessKey);
60+
61+
// do an unfiltered query and get the names of all of the storage accounts
62+
var unfilteredQuery = from account in queryableStorage
63+
select account;
64+
int storageCount = unfilteredQuery.Count();
65+
var take = unfilteredQuery.Take(storageCount / 2);
66+
// bring back some info we can use
67+
Console.WriteLine("You have {0} storage accounts", storageCount);
68+
var storageAccounts = take.ToList();
69+
foreach (var storageAccount in storageAccounts)
70+
Console.WriteLine("Account name: {0}", storageAccount.Name);
71+
}
72+
73+
public void PostActionSteps()
74+
{
75+
var client = new StorageClient(_subscriptionId, _managementCertificate);
76+
client.DeleteStorageAccount(_accountName);
77+
78+
Console.WriteLine("Deleted storage account with name {0}", _accountName);
79+
}
80+
81+
82+
83+
#endregion
84+
}
85+
}

Elastacloud.FluentExamples/Program.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,29 @@ class Program
1515
// args 2 - the path to the rdp output file
1616
static void Main(string[] args)
1717
{
18+
// create a virtual machine
1819
IBuilder virtualMachine = new BuildVirtualMachine(args[0], args[1], args[2]);
20+
21+
// test linq to azure with storage
22+
IWorkflow linqToStorage = new LinqToStorage(virtualMachine.SubscriptionId, virtualMachine.ManagementCertificate);
23+
linqToStorage.PreActionSteps();
24+
linqToStorage.DoWork();
25+
linqToStorage.PostActionSteps();
26+
Debugger.Break();
27+
28+
// test linq to azure with cloud services
29+
30+
// test role system watcher
31+
32+
// test paas deployment
33+
34+
// test paas orchestration
35+
36+
// test create a mobile services deployment
37+
38+
// manipulate and transform config files
39+
40+
// test virtual machine deployment
1941
virtualMachine.SpinUp();
2042
Debugger.Break();
2143
virtualMachine.TearDown();

0 commit comments

Comments
 (0)