Skip to content

Commit

Permalink
(fix): Build error due to missing dispose
Browse files Browse the repository at this point in the history
  • Loading branch information
vinagesh committed Feb 3, 2021
1 parent c418ac3 commit f2979e1
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 6 deletions.
2 changes: 1 addition & 1 deletion iothub/device/src/AuthenticationWithTokenRefresh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.Azure.Devices.Client
/// <summary>
/// Authentication method that uses a shared access signature token and allows for token refresh.
/// </summary>
public abstract class AuthenticationWithTokenRefresh : IAuthenticationMethod, IDisposable
public abstract class AuthenticationWithTokenRefresh : IAuthenticationMethod
{
private readonly int _suggestedTimeToLiveSeconds;
private readonly int _timeBufferPercentage;
Expand Down
4 changes: 3 additions & 1 deletion iothub/device/src/ClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ public static InternalClient Create(string hostname, string gatewayHostname, IAu
throw new ArgumentException("No certificate was found. To use certificate authentication certificate must be present.");
}

#pragma warning disable CA2000 // This is returned to client so cannot be disposed here.
InternalClient dc = CreateFromConnectionString(connectionStringBuilder.ToString(), PopulateCertificateInTransportSettings(connectionStringBuilder, transportType), options);
#pragma warning restore CA2000
dc.Certificate = connectionStringBuilder.Certificate;

// Install all the intermediate certificates in the chain if specified.
Expand Down Expand Up @@ -158,7 +160,7 @@ public static InternalClient Create(string hostname, string gatewayHostname, IAu
throw new ArgumentNullException(nameof(authenticationMethod));
}

var connectionStringBuilder = IotHubConnectionStringBuilder.Create(hostname, gatewayHostname, authenticationMethod);
IotHubConnectionStringBuilder connectionStringBuilder = IotHubConnectionStringBuilder.Create(hostname, gatewayHostname, authenticationMethod);

// Make sure client options is initialized with the correct transport setting.
EnsureOptionsIsSetup(connectionStringBuilder.Certificate, ref options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public IotHubConnectionStringBuilder Populate(IotHubConnectionStringBuilder iotH
throw new ArgumentNullException(nameof(iotHubConnectionStringBuilder));
}

iotHubConnectionStringBuilder.DeviceId = this.DeviceId;
iotHubConnectionStringBuilder.SharedAccessKey = this.KeyAsBase64String;
iotHubConnectionStringBuilder.DeviceId = DeviceId;
iotHubConnectionStringBuilder.SharedAccessKey = KeyAsBase64String;
iotHubConnectionStringBuilder.SharedAccessKeyName = null;
iotHubConnectionStringBuilder.SharedAccessSignature = null;

Expand Down Expand Up @@ -106,5 +106,11 @@ private void SetDeviceId(string deviceId)

_deviceId = deviceId;
}

/// <inheritdoc />

public void Dispose()
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public string PolicyName
set => SetPolicyName(value);
}

/// <inheritdoc />

public void Dispose()
{
}

/// <summary>
/// Populates an <see cref="IotHubConnectionStringBuilder"/> instance based on the properties of the current instance.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions iothub/device/src/DeviceAuthenticationWithToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public string Token
set => SetToken(value);
}

/// <inheritdoc />

public void Dispose()
{
}

/// <summary>
/// Populates an <see cref="IotHubConnectionStringBuilder"/> instance based on the properties of the current instance.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions iothub/device/src/DeviceAuthenticationWithX509Certificate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public string DeviceId
/// </summary>
public X509Certificate2Collection ChainCertificates { get; }

/// <inheritdoc />

public void Dispose()
{
}

/// <summary>
/// Populates an <see cref="IotHubConnectionStringBuilder"/> instance based on the properties of the current instance.
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion iothub/device/src/IAuthenticationMethod.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

namespace Microsoft.Azure.Devices.Client
{
/// <summary>
/// Authentication interface to use for device communications.
/// </summary>
public interface IAuthenticationMethod
public interface IAuthenticationMethod : IDisposable
{
/// <summary>
/// Populates an <see cref="IotHubConnectionStringBuilder"/> instance based on the properties of the current instance.
Expand Down
3 changes: 2 additions & 1 deletion iothub/device/src/IAuthorizationProvider.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Threading.Tasks;

namespace Microsoft.Azure.Devices.Client
{
internal interface IAuthorizationProvider
internal interface IAuthorizationProvider : IDisposable
{
Task<string> GetPasswordAsync();
}
Expand Down
7 changes: 7 additions & 0 deletions iothub/device/src/InternalClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1974,11 +1974,18 @@ internal void ValidateModuleTransportHandler(string apiName)
public void Dispose()
{
InnerHandler?.Dispose();
InnerHandler = null;
_methodsDictionarySemaphore?.Dispose();
_moduleReceiveMessageSemaphore?.Dispose();
_fileUploadHttpTransportHandler?.Dispose();
_deviceReceiveMessageSemaphore?.Dispose();
_twinDesiredPropertySemaphore?.Dispose();
#if !NET451
Certificate?.Dispose();
Certificate = null;
#endif
IotHubConnectionString?.Dispose();
IotHubConnectionString = null;
}

internal bool IsE2EDiagnosticSupportedProtocol()
Expand Down
6 changes: 6 additions & 0 deletions iothub/device/src/IotHubConnectionString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,11 @@ public IotHubConnectionString(IotHubConnectionStringBuilder builder)
public string SharedAccessKey { get; private set; }

public string SharedAccessSignature { get; private set; }

public void Dispose()
{
TokenRefresher?.Dispose();
TokenRefresher = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,11 @@ private void SetModuleId(string moduleId)

_moduleId = moduleId;
}

/// <inheritdoc />

public void Dispose()
{
}
}
}
6 changes: 6 additions & 0 deletions iothub/device/src/ModuleAuthenticationWithToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public string Token
set => SetToken(value);
}

/// <inheritdoc />

public void Dispose()
{
}

/// <summary>
/// Populates an <see cref="IotHubConnectionStringBuilder"/> instance based on the properties of the current instance.
/// </summary>
Expand Down

0 comments on commit f2979e1

Please sign in to comment.