Skip to content

Commit 84efff7

Browse files
committed
first fluent examples checkin
1 parent 25e4068 commit 84efff7

11 files changed

+2923
-0
lines changed

Elastacloud.FluentExamples.sln

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2012
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elastacloud.FluentExamples", "Elastacloud.FluentExamples\Elastacloud.FluentExamples.csproj", "{2ACCFE36-B097-4658-90C0-79498BFF6EEA}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|Any CPU = Debug|Any CPU
9+
Release|Any CPU = Release|Any CPU
10+
EndGlobalSection
11+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
12+
{2ACCFE36-B097-4658-90C0-79498BFF6EEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13+
{2ACCFE36-B097-4658-90C0-79498BFF6EEA}.Debug|Any CPU.Build.0 = Debug|Any CPU
14+
{2ACCFE36-B097-4658-90C0-79498BFF6EEA}.Release|Any CPU.ActiveCfg = Release|Any CPU
15+
{2ACCFE36-B097-4658-90C0-79498BFF6EEA}.Release|Any CPU.Build.0 = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(SolutionProperties) = preSolution
18+
HideSolutionNode = FALSE
19+
EndGlobalSection
20+
EndGlobal
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue">&lt;data&gt;&lt;IncludeFilters /&gt;&lt;ExcludeFilters /&gt;&lt;/data&gt;</s:String>
3+
<s:String x:Key="/Default/FilterSettingsManager/AttributeFilterXml/@EntryValue">&lt;data /&gt;</s:String></wpf:ResourceDictionary>

Elastacloud.FluentExamples/App.config

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
6+
<runtime>
7+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
8+
<dependentAssembly>
9+
<assemblyIdentity name="BouncyCastle.Crypto" publicKeyToken="a4292a325f69b123" culture="neutral" />
10+
<bindingRedirect oldVersion="0.0.0.0-1.7.4137.9283" newVersion="1.7.4137.9283" />
11+
</dependentAssembly>
12+
</assemblyBinding>
13+
</runtime>
14+
</configuration>
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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.Commands.VirtualMachines;
9+
using Elastacloud.AzureManagement.Fluent.Helpers;
10+
using Elastacloud.AzureManagement.Fluent.Helpers.PublishSettings;
11+
using Elastacloud.AzureManagement.Fluent.Types;
12+
using Elastacloud.AzureManagement.Fluent.Types.VirtualMachines;
13+
using Elastacloud.AzureManagement.Fluent.VirtualMachines.Classes;
14+
15+
namespace Elastacloud.FluentExamples
16+
{
17+
public class BuildVirtualMachine : IBuilder
18+
{
19+
private readonly WindowsVirtualMachineProperties _properties;
20+
private readonly X509Certificate2 _certificate;
21+
private readonly string _subscriptionId;
22+
private readonly string _rdpFile;
23+
24+
public BuildVirtualMachine(string subscriptionId, string publishSettingsFile, string rdpFile)
25+
{
26+
var settings = PublishSettingsExtractor.GetFromFile(publishSettingsFile);
27+
_certificate = settings.AddPublishSettingsToPersonalMachineStore();
28+
_subscriptionId = subscriptionId;
29+
_rdpFile = rdpFile;
30+
_properties = new WindowsVirtualMachineProperties()
31+
{
32+
AdministratorPassword = "Password101!",
33+
RoleName = "stackedliverpool",
34+
DeploymentName = "stackedliverpool",
35+
Certificate = _certificate,
36+
Location = LocationConstants.NorthEurope,
37+
UseExistingCloudService = false,
38+
SubscriptionId = subscriptionId,
39+
CloudServiceName = "stackedliverpool",
40+
PublicEndpoints = new List<InputEndpoint>(new[]
41+
{
42+
new InputEndpoint()
43+
{
44+
EndpointName = "web",
45+
LocalPort = 80,
46+
Port = 80,
47+
Protocol = Protocol.TCP
48+
}
49+
}),
50+
VirtualMachineType = VirtualMachineTemplates.WindowsServer2012,
51+
VmSize = VmSize.Medium,
52+
StorageAccountName = "stackedstorage",
53+
DataDisks = new List<DataVirtualHardDisk>(new[] {
54+
new DataVirtualHardDisk(){LogicalDiskSizeInGB = 100}
55+
})
56+
};
57+
}
58+
59+
void IBuilder.SpinUp()
60+
{
61+
var storageClient = new StorageClient(_subscriptionId, _certificate);
62+
storageClient.CreateNewStorageAccount("stackedstorage");
63+
var client = new WindowsVirtualMachineClient(_subscriptionId, _certificate);
64+
var newClient = client.CreateNewVirtualMachineFromTemplateGallery(_properties);
65+
Console.WriteLine("Virtual machine now created - with diskname {0}",
66+
newClient.VirtualMachine.OSHardDisk.DiskName);
67+
Console.WriteLine("Getting and saving RD file");
68+
client.SaveRemoteDesktopFile(_rdpFile);
69+
}
70+
71+
void IBuilder.TearDown()
72+
{
73+
var client = new WindowsVirtualMachineClient(_properties);
74+
string ipAddress = client.VirtualMachine.NetworkConfigurationSet.InputEndpoints[0].Vip;
75+
76+
Console.WriteLine("The VIP is {0}", ipAddress);
77+
78+
client.DeleteVirtualMachine();
79+
Console.WriteLine("Virtual machine has been deleted, with cloud service and storage");
80+
}
81+
82+
X509Certificate2 IBuilder.ManagementCertificate
83+
{
84+
get { return _certificate; }
85+
}
86+
87+
string IBuilder.SubscriptionId
88+
{
89+
get { return _subscriptionId; }
90+
}
91+
}
92+
}
93+
94+
95+
96+
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{2ACCFE36-B097-4658-90C0-79498BFF6EEA}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Elastacloud.FluentExamples</RootNamespace>
11+
<AssemblyName>Elastacloud.FluentExamples</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="BouncyCastle.Crypto, Version=1.7.4137.9283, Culture=neutral, PublicKeyToken=a4292a325f69b123, processorArchitecture=MSIL">
36+
<SpecificVersion>False</SpecificVersion>
37+
<HintPath>..\packages\BouncyCastle.1.7.0\lib\Net20\BouncyCastle.Crypto.dll</HintPath>
38+
</Reference>
39+
<Reference Include="Elastacloud.AzureManagement.Fluent, Version=0.4.4.0, Culture=neutral, processorArchitecture=MSIL">
40+
<SpecificVersion>False</SpecificVersion>
41+
<HintPath>..\packages\Elastacloud.AzureManagement.Fluent.0.4.4.8\lib\Elastacloud.AzureManagement.Fluent.dll</HintPath>
42+
</Reference>
43+
<Reference Include="Microsoft.SqlServer.ConnectionInfo, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
44+
<Private>True</Private>
45+
<HintPath>..\packages\Elastacloud.AzureManagement.Fluent.0.4.4.8\lib\Microsoft.SqlServer.ConnectionInfo.dll</HintPath>
46+
</Reference>
47+
<Reference Include="Microsoft.SqlServer.Management.Sdk.Sfc, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
48+
<Private>True</Private>
49+
<HintPath>..\packages\Elastacloud.AzureManagement.Fluent.0.4.4.8\lib\Microsoft.SqlServer.Management.Sdk.Sfc.dll</HintPath>
50+
</Reference>
51+
<Reference Include="Microsoft.SqlServer.Smo, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
52+
<Private>True</Private>
53+
<HintPath>..\packages\Elastacloud.AzureManagement.Fluent.0.4.4.8\lib\Microsoft.SqlServer.Smo.dll</HintPath>
54+
</Reference>
55+
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
56+
<SpecificVersion>False</SpecificVersion>
57+
<HintPath>..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath>
58+
</Reference>
59+
<Reference Include="NLog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
60+
<SpecificVersion>False</SpecificVersion>
61+
<HintPath>..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
62+
</Reference>
63+
<Reference Include="System" />
64+
<Reference Include="System.Configuration" />
65+
<Reference Include="System.Core" />
66+
<Reference Include="System.Security" />
67+
<Reference Include="System.Xml.Linq" />
68+
<Reference Include="System.Data.DataSetExtensions" />
69+
<Reference Include="Microsoft.CSharp" />
70+
<Reference Include="System.Data" />
71+
<Reference Include="System.Xml" />
72+
</ItemGroup>
73+
<ItemGroup>
74+
<Compile Include="BuildVirtualMachine.cs" />
75+
<Compile Include="IBuilder.cs" />
76+
<Compile Include="Program.cs" />
77+
<Compile Include="Properties\AssemblyInfo.cs" />
78+
</ItemGroup>
79+
<ItemGroup>
80+
<None Include="App.config" />
81+
<Content Include="NLog.config">
82+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
83+
</Content>
84+
<None Include="NLog.xsd">
85+
<SubType>Designer</SubType>
86+
</None>
87+
<None Include="packages.config" />
88+
</ItemGroup>
89+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
90+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
91+
Other similar extension points exist, see Microsoft.Common.targets.
92+
<Target Name="BeforeBuild">
93+
</Target>
94+
<Target Name="AfterBuild">
95+
</Target>
96+
-->
97+
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Security.Cryptography.X509Certificates;
2+
3+
namespace Elastacloud.FluentExamples
4+
{
5+
interface IBuilder
6+
{
7+
void SpinUp();
8+
void TearDown();
9+
string SubscriptionId { get; }
10+
X509Certificate2 ManagementCertificate { get; }
11+
}
12+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
5+
<!--
6+
See http://nlog-project.org/wiki/Configuration_file
7+
for information on customizing logging rules and outputs.
8+
-->
9+
<targets>
10+
<!-- add your targets here -->
11+
12+
<!--
13+
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
14+
layout="${longdate} ${uppercase:${level}} ${message}" />
15+
-->
16+
</targets>
17+
18+
<rules>
19+
<!-- add your logging rules here -->
20+
21+
<!--
22+
<logger name="*" minlevel="Trace" writeTo="f" />
23+
-->
24+
</rules>
25+
</nlog>

0 commit comments

Comments
 (0)