Skip to content

Commit 44b175f

Browse files
committed
Upgrade to 0.5.0.95 and fix a bug whereby publishing an event always failed if there were no subscribers.
1 parent 6ea34cc commit 44b175f

File tree

3 files changed

+36
-38
lines changed

3 files changed

+36
-38
lines changed

Elastacloud.AzureManagement.Fluent.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
33
<metadata>
44
<id>Elastacloud.AzureManagement.Fluent</id>
5-
<version>0.5.0.94</version>
5+
<version>0.5.0.95</version>
66
<title>Azure Fluent Management Library</title>
77
<authors>Elastacloud Limited (@azurecoder,@andybareweb,@isaac_abraham)</authors>
88
<owners>Elastacloud Limited</owners>

Elastacloud.AzureManagement.Fluent/Clients/LinuxVirtualMachineClient.cs

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
/*****************************************************************`*******************************************
1+
using Elastacloud.AzureManagement.Fluent.Clients.Helpers;
2+
using Elastacloud.AzureManagement.Fluent.Clients.Interfaces;
3+
using Elastacloud.AzureManagement.Fluent.Commands.Services;
4+
using Elastacloud.AzureManagement.Fluent.Commands.VirtualMachines;
5+
using Elastacloud.AzureManagement.Fluent.Commands.VirtualNetworks;
6+
using Elastacloud.AzureManagement.Fluent.Helpers;
7+
using Elastacloud.AzureManagement.Fluent.Types;
8+
using Elastacloud.AzureManagement.Fluent.Types.Exceptions;
9+
using Elastacloud.AzureManagement.Fluent.Types.VirtualMachines;
10+
using Elastacloud.AzureManagement.Fluent.Types.VirtualNetworks;
11+
using Elastacloud.AzureManagement.Fluent.VirtualMachines.Classes;
12+
/*****************************************************************`*******************************************
213
* This software is distributed under a GNU Lesser License by Elastacloud Limited and it is free to *
314
* modify and distribute providing the terms of the license are followed. From the root of the source the *
415
* license can be found in /Resources/license.txt *
@@ -9,24 +20,10 @@
920
using System;
1021
using System.Collections.Generic;
1122
using System.Diagnostics;
12-
using System.IO;
1323
using System.Linq;
14-
using System.Net;
1524
using System.Security.Cryptography.X509Certificates;
1625
using System.Threading;
1726
using System.Threading.Tasks;
18-
using Elastacloud.AzureManagement.Fluent.Clients.Helpers;
19-
using Elastacloud.AzureManagement.Fluent.Clients.Interfaces;
20-
using Elastacloud.AzureManagement.Fluent.Commands.Blobs;
21-
using Elastacloud.AzureManagement.Fluent.Commands.Services;
22-
using Elastacloud.AzureManagement.Fluent.Commands.VirtualMachines;
23-
using Elastacloud.AzureManagement.Fluent.Commands.VirtualNetworks;
24-
using Elastacloud.AzureManagement.Fluent.Helpers;
25-
using Elastacloud.AzureManagement.Fluent.Types;
26-
using Elastacloud.AzureManagement.Fluent.Types.Exceptions;
27-
using Elastacloud.AzureManagement.Fluent.Types.VirtualMachines;
28-
using Elastacloud.AzureManagement.Fluent.Types.VirtualNetworks;
29-
using Elastacloud.AzureManagement.Fluent.VirtualMachines.Classes;
3027

3128
namespace Elastacloud.AzureManagement.Fluent.Clients
3229
{
@@ -37,7 +34,7 @@ public class LinuxVirtualMachineClient : ILinuxVirtualMachineClient
3734

3835
public event EventHandler<LinuxVirtualMachineProperties> LinuxVirtualMachineCreationEvent;
3936
public event EventHandler<VirtualMachineStatus> LinuxVirtualMachineStatusEvent;
40-
37+
4138
/// <summary>
4239
/// Constructs a LinuxVirtualMachineClient and will get the details of a virtual machine given a cloud service
4340
/// </summary>
@@ -96,7 +93,7 @@ private void CheckVmDeploymentIsRunning(List<LinuxVirtualMachineProperties> prop
9693
// 1. Get the number of vms in the role and create a binary list
9794
var linuxProperties = new Dictionary<string, RoleInstanceStatus>();
9895
properties.ForEach(property => linuxProperties.Add(property.HostName, RoleInstanceStatus.RoleStateUnknown));
99-
var vmProperties = new LinuxVirtualMachineProperties() {CloudServiceName = properties[0].CloudServiceName};
96+
var vmProperties = new LinuxVirtualMachineProperties() { CloudServiceName = properties[0].CloudServiceName };
10097
// 2. Set the value to if the vm is running or not
10198
int index = 0;
10299
// time this out just in case after an hour?
@@ -112,24 +109,25 @@ private void CheckVmDeploymentIsRunning(List<LinuxVirtualMachineProperties> prop
112109
{
113110
if (linuxProperties[vm.RoleName] == vm.Status) return;
114111
// raise the event with the old and new status
115-
LinuxVirtualMachineStatusEvent(this, new VirtualMachineStatus()
116-
{
117-
NewStatus = vm.Status,
118-
OldStatus = linuxProperties[vm.RoleName],
119-
VirtualMachineInstanceName = vm.RoleName,
120-
CloudService = vmProperties.CloudServiceName
121-
});
112+
if (LinuxVirtualMachineStatusEvent != null)
113+
LinuxVirtualMachineStatusEvent(this, new VirtualMachineStatus()
114+
{
115+
NewStatus = vm.Status,
116+
OldStatus = linuxProperties[vm.RoleName],
117+
VirtualMachineInstanceName = vm.RoleName,
118+
CloudService = vmProperties.CloudServiceName
119+
});
122120
// update the status in the dictionary
123121
linuxProperties[vm.RoleName] = vm.Status;
124122
});
125-
123+
126124
Task.Delay(TimeSpan.FromSeconds(10)).RunSynchronously();
127125
index++;
128126
}
129127

130128
if (index == 100)
131129
{
132-
throw new FluentManagementException("timed out listening for status changes - check vms are running correctly", "LinuxVirtualMachineClient");
130+
throw new FluentManagementException("timed out listening for status changes - check vms are running correctly", "LinuxVirtualMachineClient");
133131
}
134132
}
135133

@@ -143,9 +141,9 @@ private void CheckVmDeploymentIsRunning(List<LinuxVirtualMachineProperties> prop
143141
/// <param name="affinityGroup">Affinity group that this service will live in</param>
144142
public IVirtualMachineClient CreateNewVirtualMachineDeploymentFromTemplateGallery(List<LinuxVirtualMachineProperties> properties, string cloudServiceName, ServiceCertificateModel serviceCertificate = null, string location = LocationConstants.NorthEurope, string affinityGroup = "")
145143
{
146-
if(String.IsNullOrEmpty(cloudServiceName))
144+
if (String.IsNullOrEmpty(cloudServiceName))
147145
throw new FluentManagementException("Cloud service name cannot be empty", "LinuxVirtualMachineClient");
148-
146+
149147
// if the cloud service doesn't exist we'll create it
150148
// first check that the service is available
151149
var checkCloudServiceAvailabilityCommand = new CheckCloudServiceNameAvailableCommand(cloudServiceName)
@@ -173,10 +171,10 @@ public IVirtualMachineClient CreateNewVirtualMachineDeploymentFromTemplateGaller
173171
Trace.WriteLine("A new service certificate has been added to the cloud service");
174172
ServiceCertificate = serviceCertificate.ServiceCertificate.Export(X509ContentType.Pfx);
175173
}
176-
174+
177175
// This is really unfortunate and not documented anywhere - unable to add multiple roles to a rolelist!!!
178176
// continue to the create the virtual machine in the cloud service
179-
var command = new CreateLinuxVirtualMachineDeploymentCommand(new List<LinuxVirtualMachineProperties>(new[]{properties[0]}), cloudServiceName)
177+
var command = new CreateLinuxVirtualMachineDeploymentCommand(new List<LinuxVirtualMachineProperties>(new[] { properties[0] }), cloudServiceName)
180178
{
181179
SubscriptionId = SubscriptionId,
182180
Certificate = ManagementCertificate
@@ -298,7 +296,7 @@ private void AddServiceCertificateToRoles(ServiceCertificateModel serviceCertifi
298296
FingerPrint = serviceCertificate.ServiceCertificate.GetCertHashString(),
299297
Path = String.Format("/home/{0}/.ssh/id_rsa", linuxVirtualMachineProperty.UserName)
300298
});
301-
299+
302300
linuxVirtualMachineProperty.DisableSSHPasswordAuthentication = true;
303301
}
304302
}
@@ -332,7 +330,7 @@ public void AddRolesToExistingDeployment(List<LinuxVirtualMachineProperties> pro
332330
/// </summary>
333331
protected string SubscriptionId { get; set; }
334332

335-
333+
336334
#region Implementation of IVirtualMachineClient
337335

338336
/// <summary>
@@ -486,21 +484,21 @@ public void Restart()
486484
restartCommand.Execute();
487485
Trace.WriteLine(String.Format("VM restarted with hostname {0}", linuxVirtualMachineProperty.HostName));
488486
}
489-
487+
490488
}
491489

492490
/// <summary>
493491
/// Stops the virtual machine instance
494492
/// </summary>
495493
public void Stop()
496494
{
497-
Trace.WriteLine(String.Format("Stopping {0} virtual machines in deployment {1} in cloud service {2}",
495+
Trace.WriteLine(String.Format("Stopping {0} virtual machines in deployment {1} in cloud service {2}",
498496
Properties.Count, Properties.First().DeploymentName, Properties.First().CloudServiceName));
499497
foreach (LinuxVirtualMachineProperties linuxVirtualMachineProperties in Properties)
500498
{
501499
var stopCommand = new StopVirtualMachineCommand(linuxVirtualMachineProperties)
502500
{
503-
SubscriptionId = SubscriptionId,
501+
SubscriptionId = SubscriptionId,
504502
Certificate = ManagementCertificate
505503
};
506504
stopCommand.Execute();

Elastacloud.AzureManagement.Fluent/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@
4949

5050
// Make internal interfaces visible to Moq and the testing library
5151
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2"), InternalsVisibleTo("Elastacloud.AzureManagement.Fluent.Tests")]
52-
[assembly: AssemblyVersion("0.5.0.94")]
53-
[assembly: AssemblyFileVersion("0.5.0.94")]
52+
[assembly: AssemblyVersion("0.5.0.95")]
53+
[assembly: AssemblyFileVersion("0.5.0.95")]

0 commit comments

Comments
 (0)