Skip to content

Commit 90c0e3d

Browse files
committed
added new functionality for demos
1 parent 5a0de72 commit 90c0e3d

11 files changed

+194
-53
lines changed

Elastacloud.FluentExamples/App.config

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
<add key="dbname" value="stacked"/>
55
<add key="username" value="azurecoder"/>
66
<add key="password" value="Password101!"/>
7-
<add key="sql_db_username" value="azurecoder_db"/>
8-
<add key="default_storage" value="stackedstorage"/>
9-
<add key="mobile_service_name" value="stackedmobile"/>
10-
<add key="deployment_name" value="stacked deployment"/>
7+
<add key="sqldbusername" value="azurecoder_db"/>
8+
<add key="defaultstorage" value="stackedstorage"/>
9+
<add key="mobileservicename" value="stackedmobile"/>
10+
<add key="deploymentname" value="stacked deployment"/>
1111
<add key="publishsettings" value="C:\Users\Richard\Desktop\Engagements\AllAccounts.publishsettings"/>
1212
<add key="rdpfile" value="C:\Users\Richard\Desktop\Engagements\stackedliverpool.rdp"/>
1313
<add key="vmroleservice" value="stackedliverpool"/>
1414
<add key="cloudservice" value="stackedliverpoolpaas"/>
1515
<add key="rolename" value="ExampleWebRole"/>
16+
<add key="deploymentpath" value="C:\Users\Richard\Documents\Fluent Examples\Elastacloud.FluentExamples\TestCloudInstall\bin\Release\app.publish"/>
1617
</appSettings>
1718
<startup>
1819
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />

Elastacloud.FluentExamples/BuildGetBlobRequest.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void PreActionSteps()
2727
{
2828
// use AMS to transfer file
2929
var storageClient = new StorageClient(_subscriptionId, _managementCertificate);
30-
var keys = storageClient.GetStorageAccountKeys("stackedstorage");
30+
var keys = storageClient.GetStorageAccountKeys(Settings.DefaultStorage);
3131
StorageKey = keys[0];
3232
}
3333

@@ -43,8 +43,8 @@ public void DoWork()
4343
var builder = new StringBuilder("GET");
4444
builder.Append(lineEndings);
4545
builder.AppendFormat("x-ms-date:{0}\n", date);
46-
builder.AppendFormat("x-ms-version:2011-08-18\n");
47-
builder.Append("/stackedstorage/docs/test.txt\n");
46+
builder.Append("x-ms-version:2011-08-18\n");
47+
builder.AppendFormat("/{0}/docs/test.txt\n",Settings.DefaultStorage);
4848
builder.Append("timeout:90");
4949

5050
string signature;
@@ -56,7 +56,8 @@ public void DoWork()
5656

5757
var authValue = "SharedKey stackedstorage:" + signature;
5858

59-
var request = (HttpWebRequest)WebRequest.Create("http://stackedstorage.blob.core.windows.net/docs/test.txt?timeout=90");
59+
var request = (HttpWebRequest)WebRequest.Create(
60+
String.Format("http://{0}.blob.core.windows.net/docs/test.txt?timeout=90", Settings.DefaultStorage));
6061
request.Method = "GET";
6162
request.ContentLength = 0;
6263
request.Headers.Add("x-ms-date", date);

Elastacloud.FluentExamples/BuildMobileService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public BuildMobileService(string subscriptionId, X509Certificate2 managementCert
2222
public void SpinUp()
2323
{
2424
var client = new MobileServiceClient(SubscriptionId, ManagementCertificate);
25-
client.CreateMobileServiceWithNewDb("mobilestacked", "azurecoder", "Password101!");
25+
client.CreateMobileServiceWithNewDb(Settings.MobileServiceName, Settings.Username, Settings.Password);
2626
Console.WriteLine("Yeah, we created a mobile service using the Service Management API - even though it hasn't been published yet!");
2727

2828
// Display some details about the mobile service
@@ -45,7 +45,7 @@ public void TearDown()
4545

4646
public void DoSomething()
4747
{
48-
var client = new MobileServiceClient(SubscriptionId, ManagementCertificate, "mobilestacked");
48+
var client = new MobileServiceClient(SubscriptionId, ManagementCertificate, Settings.MobileServiceName);
4949
if (!client.Tables.Exists(a => a.TableName == "Speakers"))
5050
client.AddTable("Speakers");
5151
client.AddTableScript(CrudOperation.Insert, "Speakers", "function insert(item, user, request){ /*Another fluent success!*/request.execute();}", Roles.User);

Elastacloud.FluentExamples/BuildVirtualMachine.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,21 @@ public class BuildVirtualMachine : IBuilder
2121
private readonly string _subscriptionId;
2222
private readonly string _rdpFile;
2323

24-
public BuildVirtualMachine(string subscriptionId, string publishSettingsFile, string rdpFile)
24+
public BuildVirtualMachine(string subscriptionId, X509Certificate2 certificate)
2525
{
26-
var settings = PublishSettingsExtractor.GetFromFile(publishSettingsFile);
27-
_certificate = settings.AddPublishSettingsToPersonalMachineStore();
26+
_certificate = certificate;
2827
_subscriptionId = subscriptionId;
29-
_rdpFile = rdpFile;
28+
_rdpFile = Settings.RemoteDesktopFilePath;
3029
_properties = new WindowsVirtualMachineProperties()
3130
{
32-
AdministratorPassword = "Password101!",
33-
RoleName = "stackedliverpool",
34-
DeploymentName = "stackedliverpool",
31+
AdministratorPassword = Settings.Password,
32+
RoleName = Settings.VmRoleAndServiceName,
33+
DeploymentName = Settings.VmRoleAndServiceName,
3534
Certificate = _certificate,
3635
Location = LocationConstants.NorthEurope,
3736
UseExistingCloudService = false,
3837
SubscriptionId = subscriptionId,
39-
CloudServiceName = "stackedliverpool",
38+
CloudServiceName = Settings.VmRoleAndServiceName,
4039
PublicEndpoints = new List<InputEndpoint>(new[]
4140
{
4241
new InputEndpoint()
@@ -49,7 +48,7 @@ public BuildVirtualMachine(string subscriptionId, string publishSettingsFile, st
4948
}),
5049
VirtualMachineType = VirtualMachineTemplates.WindowsServer2012,
5150
VmSize = VmSize.Medium,
52-
StorageAccountName = "stackedstorage",
51+
StorageAccountName = Settings.DefaultStorage,
5352
DataDisks = new List<DataVirtualHardDisk>(new[] {
5453
new DataVirtualHardDisk(){LogicalDiskSizeInGB = 100}
5554
})
@@ -59,7 +58,7 @@ public BuildVirtualMachine(string subscriptionId, string publishSettingsFile, st
5958
void IBuilder.SpinUp()
6059
{
6160
var storageClient = new StorageClient(_subscriptionId, _certificate);
62-
storageClient.CreateNewStorageAccount("stackedstorage");
61+
storageClient.CreateNewStorageAccount(Settings.DefaultStorage);
6362
var client = new WindowsVirtualMachineClient(_subscriptionId, _certificate);
6463
var newClient = client.CreateNewVirtualMachineFromTemplateGallery(_properties);
6564
Console.WriteLine("Virtual machine now created - with diskname {0}",

Elastacloud.FluentExamples/Elastacloud.FluentExamples.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
<Compile Include="BuildGetBlobRequest.cs" />
7777
<Compile Include="BuildMobileService.cs" />
7878
<Compile Include="BuildVirtualMachine.cs" />
79+
<Compile Include="WorkflowLoadConfig.cs" />
80+
<Compile Include="Settings.cs" />
81+
<Compile Include="WorkflowPublishSettings.cs" />
7982
<Compile Include="WorkflowFluentDeploymentWithSSL.cs" />
8083
<Compile Include="WorkflowRoleSystemWatcher.cs" />
8184
<Compile Include="WorkflowFluentDeployment.cs" />

Elastacloud.FluentExamples/Program.cs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4+
using System.IO;
45
using System.Linq;
56
using System.Text;
67
using System.Threading;
@@ -10,47 +11,52 @@ namespace Elastacloud.FluentExamples
1011
{
1112
class Program
1213
{
14+
static readonly List<IBuilder> Builders = new List<IBuilder>();
15+
static readonly List<IWorkflow> Workflows = new List<IWorkflow>();
1316
// args 0 - the subscription id
1417
// args 1 - the path to the publishsettings file
1518
// args 2 - the path to the rdp output file
1619
static void Main(string[] args)
1720
{
18-
var builders = new List<IBuilder>();
19-
var workflows = new List<IWorkflow>();
20-
// create a virtual machine
21-
IBuilder virtualMachine = new BuildVirtualMachine(args[0], args[1], args[2]);
22-
builders.Add(virtualMachine);
21+
if (args.Length < 1)
22+
throw new ApplicationException("need a single argument to proceed");
23+
24+
// manipulate and transform config files
25+
IWorkflow getConfig = new WorkflowLoadConfig(Path.Combine(Settings.DeploymentPath, "TestCloudInstall.cscfg"));
26+
getConfig.PreActionSteps();
27+
28+
// do the publishsettings
29+
IWorkflow getSettings = new WorkflowPublishSettings(args[0], Settings.PublishSettingsFilePath);
30+
getSettings.PreActionSteps();
2331

2432
// Add the test get blob API - before running this create a storage account using AMS called stackedstorage
25-
IWorkflow getBlob = new BuildGetBlobRequest(virtualMachine.SubscriptionId, virtualMachine.ManagementCertificate);
26-
workflows.Add(getBlob);
33+
IWorkflow getBlob = new BuildGetBlobRequest(Settings.SubscriptionId, Settings.ManagementCertificate);
34+
Workflows.Add(getBlob);
35+
36+
// create a virtual machine
37+
IBuilder virtualMachine = new BuildVirtualMachine(args[0], Settings.ManagementCertificate);
38+
Builders.Add(virtualMachine);
2739

2840
// test linq to azure with storage
29-
IWorkflow linqToStorage = new WorkflowLinqToStorage(virtualMachine.SubscriptionId, virtualMachine.ManagementCertificate);
30-
workflows.Add(linqToStorage);
41+
IWorkflow linqToStorage = new WorkflowLinqToStorage(Settings.SubscriptionId, Settings.ManagementCertificate);
42+
Workflows.Add(linqToStorage);
3143

3244
// test create a mobile services deployment
33-
IBuilder mobileService = new BuildMobileService(virtualMachine.SubscriptionId, virtualMachine.ManagementCertificate);
34-
builders.Add(mobileService);
45+
IBuilder mobileService = new BuildMobileService(Settings.SubscriptionId, Settings.ManagementCertificate);
46+
Builders.Add(mobileService);
3547

3648
// test paas deployment
3749
// test linq to azure with cloud services
3850
// test paas orchestration
39-
IWorkflow fluentDeployment = new WorkflowFluentDeployment(virtualMachine.SubscriptionId, virtualMachine.ManagementCertificate);
40-
workflows.Add(fluentDeployment);
51+
IWorkflow fluentDeployment = new WorkflowFluentDeployment(Settings.SubscriptionId, Settings.ManagementCertificate);
52+
Workflows.Add(fluentDeployment);
4153

4254
// test role system watcher
4355
var watcher = new WorkflowRoleSystemWatcher(virtualMachine.SubscriptionId, virtualMachine.ManagementCertificate);
44-
workflows.Add(watcher);
45-
watcher.DoWork();
56+
Workflows.Add(watcher);
4657

4758
// test paas build
48-
4959

50-
51-
52-
53-
// manipulate and transform config files
5460
Console.WriteLine("Press [ENTER] to exit");
5561
Console.Read();
5662
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Linq;
5+
using System.Security.Cryptography.X509Certificates;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace Elastacloud.FluentExamples
10+
{
11+
public static class Settings
12+
{
13+
public static string DatabaseName { get { return ConfigurationManager.AppSettings["dbname"]; } }
14+
public static string Username { get { return ConfigurationManager.AppSettings["username"]; } }
15+
public static string Password { get { return ConfigurationManager.AppSettings["password"]; } }
16+
public static string SqlDatabaseUsername { get { return ConfigurationManager.AppSettings["sqldbusername"]; } }
17+
public static string DefaultStorage { get { return ConfigurationManager.AppSettings["defaultStorage"]; } }
18+
public static string MobileServiceName { get { return ConfigurationManager.AppSettings["mobileservicename"]; } }
19+
public static string DeplopymentName { get { return ConfigurationManager.AppSettings["deploymentname"]; } }
20+
public static string PublishSettingsFilePath { get { return ConfigurationManager.AppSettings["publishsettings"]; } }
21+
public static string RemoteDesktopFilePath { get { return ConfigurationManager.AppSettings["rdpfile"]; } }
22+
public static string VmRoleAndServiceName { get { return ConfigurationManager.AppSettings["vmservicerole"]; } }
23+
public static string CloudServiceName { get { return ConfigurationManager.AppSettings["cloudservice"]; } }
24+
public static string RoleName { get { return ConfigurationManager.AppSettings["rolename"]; } }
25+
public static string DeploymentPath { get { return ConfigurationManager.AppSettings["deploymentpath"]; } }
26+
public static string SubscriptionId { get; set; }
27+
public static X509Certificate2 ManagementCertificate { get; set; }
28+
}
29+
}

Elastacloud.FluentExamples/WorkflowFluentDeployment.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,22 @@ public void PreActionSteps()
4949
.AddCertificate(_managementCertificate)
5050
.AddNewFirewallRuleForWindowsAzureHostedService()
5151
.AddNewFirewallRuleWithMyIp("my ip rule - for stacked")
52-
.WithSqlAzureCredentials("azurecoder", "Password101!")
53-
.AddNewDatabase("stacked")
54-
.AddNewDatabaseAdminUser("azurecoder_db", "Password101!")
52+
.WithSqlAzureCredentials(Settings.Username, Settings.Password)
53+
.AddNewDatabase(Settings.DatabaseName)
54+
.AddNewDatabaseAdminUser(Settings.SqlDatabaseUsername, Settings.Password)
5555
.Go();
5656
_orchestrator.AddDeploymentStep(serviceTransactionSql);
5757
var serviceTransactionDeployment = manager.GetDeploymentManager()
5858
.AddCertificate(_managementCertificate)
59-
.ForNewDeployment("stacked deployment")
60-
.SetCspkgEndpoint(@"C:\Users\Richard\Documents\Fluent Examples\Elastacloud.FluentExamples\TestCloudInstall\bin\Release\app.publish")
61-
.WithNewHostedService("stackedliverpoolpaas")
59+
.ForNewDeployment(Settings.DeplopymentName)
60+
.SetCspkgEndpoint(Settings.DeploymentPath)
61+
.WithNewHostedService(Settings.CloudServiceName)
6262
.WithStorageAccount(_accountName)
6363
.AddDescription("Fluent management @ Stacked")
6464
.AddEnvironment(DeploymentSlot.Production)
6565
.AddLocation(LocationConstants.NorthEurope)
6666
.AddParams(DeploymentParams.StartImmediately|DeploymentParams.WarningsAsErrors)
67-
.ForRole("ExampleWebRole")
67+
.ForRole(Settings.RoleName)
6868
.WithInstanceCount(4)
6969
.WaitUntilAllRoleInstancesAreRunning()
7070
.Go();

Elastacloud.FluentExamples/WorkflowFluentDeploymentWithSSL.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ public void PreActionSteps()
3434
var manager = new SubscriptionManager(_subscriptionId);
3535
_context = manager.GetDeploymentManager()
3636
.AddCertificate(_managementCertificate)
37-
.ForNewDeployment("stacked deployment")
37+
.ForNewDeployment(Settings.DeplopymentName)
3838
.SetBuildDirectoryRoot("builddirectory")
39-
.EnableRemoteDesktopAndSslForRole("ExampleWebRole")
40-
.WithUsernameAndPassword("azurecoder", "Password101!")
41-
.GenerateAndAddServiceCertificate("stackedliverpoolpaas")
42-
.WithNewHostedService("stackedliverpoolpaas")
43-
.WithStorageAccount("stackedstorage")
39+
.EnableRemoteDesktopAndSslForRole(Settings.RoleName)
40+
.WithUsernameAndPassword(Settings.Username, Settings.Password)
41+
.GenerateAndAddServiceCertificate(Settings.CloudServiceName + ".cloudapp.net")
42+
.WithNewHostedService(Settings.CloudServiceName)
43+
.WithStorageAccount(Settings.DefaultStorage)
4444
.AddDescription("Created by fluent management")
4545
.AddEnvironment(DeploymentSlot.Production)
4646
.AddLocation(LocationConstants.NorthEurope)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.Helpers.PublishSettings;
10+
using Elastacloud.AzureManagement.Fluent.Linq;
11+
using Elastacloud.AzureManagement.Fluent.Types;
12+
13+
namespace Elastacloud.FluentExamples
14+
{
15+
public class WorkflowLoadConfig : IWorkflow
16+
{
17+
private readonly string _configFile;
18+
private List<string> roleList;
19+
private int instanceCount;
20+
private CscfgFile configFile;
21+
22+
public WorkflowLoadConfig(string configFile)
23+
{
24+
_configFile = configFile;
25+
}
26+
27+
#region Implementation of IWorkflow
28+
29+
public void PreActionSteps()
30+
{
31+
Console.WriteLine("getting configuration settings for role");
32+
configFile = (CscfgFile)CscfgFile.GetInstance(_configFile);
33+
roleList = configFile.GetRoleNameList();
34+
}
35+
36+
public void DoWork()
37+
{
38+
foreach (var role in roleList)
39+
Console.WriteLine("Found role with name: {0}, has {1} instances", role, configFile.GetInstanceCountForRole(role));
40+
}
41+
42+
public void PostActionSteps()
43+
{
44+
Console.WriteLine("Finished reading .cscfg file");
45+
}
46+
47+
#endregion
48+
}
49+
}

0 commit comments

Comments
 (0)