diff --git a/Azure.IoT.Edge.DotSettings b/Azure.IoT.Edge.DotSettings index cc659ed0e33..5bfdad9d9f4 100644 --- a/Azure.IoT.Edge.DotSettings +++ b/Azure.IoT.Edge.DotSettings @@ -100,7 +100,7 @@ DO_NOT_SHOW SUGGESTION HINT - <?xml version="1.0" encoding="utf-16"?><Profile name="Azure.IoT.Edge"><AspOptimizeRegisterDirectives>True</AspOptimizeRegisterDirectives><HtmlReformatCode>True</HtmlReformatCode><CSArrangeThisQualifier>True</CSArrangeThisQualifier><CSRemoveCodeRedundancies>True</CSRemoveCodeRedundancies><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSUpdateFileHeader>True</CSUpdateFileHeader><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSShortenReferences>True</CSShortenReferences><CSReformatCode>True</CSReformatCode><VBOptimizeImports>True</VBOptimizeImports><VBShortenReferences>True</VBShortenReferences><VBReformatCode>True</VBReformatCode><JsInsertSemicolon>True</JsInsertSemicolon><JsReformatCode>True</JsReformatCode><CssAlphabetizeProperties>True</CssAlphabetizeProperties><CssReformatCode>True</CssReformatCode><CSUseVar><BehavourStyle>CAN_CHANGE_TO_EXPLICIT</BehavourStyle><LocalVariableStyle>IMPLICIT_EXCEPT_SIMPLE_TYPES</LocalVariableStyle><ForeachVariableStyle>IMPLICIT_EXCEPT_SIMPLE_TYPES</ForeachVariableStyle></CSUseVar><XMLReformatCode>True</XMLReformatCode><StyleCop.Documentation><SA1600ElementsMustBeDocumented>False</SA1600ElementsMustBeDocumented><SA1604ElementDocumentationMustHaveSummary>False</SA1604ElementDocumentationMustHaveSummary><SA1609PropertyDocumentationMustHaveValueDocumented>False</SA1609PropertyDocumentationMustHaveValueDocumented><SA1611ElementParametersMustBeDocumented>False</SA1611ElementParametersMustBeDocumented><SA1615ElementReturnValueMustBeDocumented>True</SA1615ElementReturnValueMustBeDocumented><SA1617VoidReturnValueMustNotBeDocumented>True</SA1617VoidReturnValueMustNotBeDocumented><SA1618GenericTypeParametersMustBeDocumented>False</SA1618GenericTypeParametersMustBeDocumented><SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes>True</SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes><SA1628DocumentationTextMustBeginWithACapitalLetter>True</SA1628DocumentationTextMustBeginWithACapitalLetter><SA1629DocumentationTextMustEndWithAPeriod>True</SA1629DocumentationTextMustEndWithAPeriod><SA1633SA1641UpdateFileHeader>Ignore</SA1633SA1641UpdateFileHeader><SA1639FileHeaderMustHaveSummary>False</SA1639FileHeaderMustHaveSummary><SA1642ConstructorSummaryDocumentationMustBeginWithStandardText>True</SA1642ConstructorSummaryDocumentationMustBeginWithStandardText><SA1643DestructorSummaryDocumentationMustBeginWithStandardText>True</SA1643DestructorSummaryDocumentationMustBeginWithStandardText><SA1644DocumentationHeadersMustNotContainBlankLines>True</SA1644DocumentationHeadersMustNotContainBlankLines></StyleCop.Documentation><CSReorderTypeMembers>True</CSReorderTypeMembers><CSArrangeQualifiers>True</CSArrangeQualifiers><FormatAttributeQuoteDescriptor>True</FormatAttributeQuoteDescriptor><PublicModifierStyleTs>True</PublicModifierStyleTs><ExplicitAnyTs>True</ExplicitAnyTs><TypeAnnotationStyleTs>True</TypeAnnotationStyleTs><RelativePathStyleTs>True</RelativePathStyleTs><OptimizeReferenceCommentsTs>True</OptimizeReferenceCommentsTs><OptimizeImportsTs>True</OptimizeImportsTs><RemoveRedundantQualifiersTs>True</RemoveRedundantQualifiersTs><CSFixBuiltinTypeReferences>True</CSFixBuiltinTypeReferences><CSCodeStyleAttributes ArrangeTypeAccessModifier="True" ArrangeTypeMemberAccessModifier="True" SortModifiers="True" RemoveRedundantParentheses="False" AddMissingParentheses="True" ArrangeAttributes="True" /></Profile> + <?xml version="1.0" encoding="utf-16"?><Profile name="Azure.IoT.Edge"><AspOptimizeRegisterDirectives>True</AspOptimizeRegisterDirectives><HtmlReformatCode>True</HtmlReformatCode><CSArrangeThisQualifier>True</CSArrangeThisQualifier><CSRemoveCodeRedundancies>True</CSRemoveCodeRedundancies><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSUpdateFileHeader>True</CSUpdateFileHeader><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSReformatCode>True</CSReformatCode><VBOptimizeImports>True</VBOptimizeImports><VBShortenReferences>True</VBShortenReferences><VBReformatCode>True</VBReformatCode><JsInsertSemicolon>True</JsInsertSemicolon><JsReformatCode>True</JsReformatCode><CssAlphabetizeProperties>True</CssAlphabetizeProperties><CssReformatCode>True</CssReformatCode><CSUseVar><BehavourStyle>CAN_CHANGE_TO_EXPLICIT</BehavourStyle><LocalVariableStyle>IMPLICIT_EXCEPT_SIMPLE_TYPES</LocalVariableStyle><ForeachVariableStyle>IMPLICIT_EXCEPT_SIMPLE_TYPES</ForeachVariableStyle></CSUseVar><XMLReformatCode>True</XMLReformatCode><StyleCop.Documentation><SA1600ElementsMustBeDocumented>False</SA1600ElementsMustBeDocumented><SA1604ElementDocumentationMustHaveSummary>False</SA1604ElementDocumentationMustHaveSummary><SA1609PropertyDocumentationMustHaveValueDocumented>False</SA1609PropertyDocumentationMustHaveValueDocumented><SA1611ElementParametersMustBeDocumented>False</SA1611ElementParametersMustBeDocumented><SA1615ElementReturnValueMustBeDocumented>True</SA1615ElementReturnValueMustBeDocumented><SA1617VoidReturnValueMustNotBeDocumented>True</SA1617VoidReturnValueMustNotBeDocumented><SA1618GenericTypeParametersMustBeDocumented>False</SA1618GenericTypeParametersMustBeDocumented><SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes>True</SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes><SA1628DocumentationTextMustBeginWithACapitalLetter>True</SA1628DocumentationTextMustBeginWithACapitalLetter><SA1629DocumentationTextMustEndWithAPeriod>True</SA1629DocumentationTextMustEndWithAPeriod><SA1633SA1641UpdateFileHeader>Ignore</SA1633SA1641UpdateFileHeader><SA1639FileHeaderMustHaveSummary>False</SA1639FileHeaderMustHaveSummary><SA1642ConstructorSummaryDocumentationMustBeginWithStandardText>True</SA1642ConstructorSummaryDocumentationMustBeginWithStandardText><SA1643DestructorSummaryDocumentationMustBeginWithStandardText>True</SA1643DestructorSummaryDocumentationMustBeginWithStandardText><SA1644DocumentationHeadersMustNotContainBlankLines>True</SA1644DocumentationHeadersMustNotContainBlankLines></StyleCop.Documentation><CSReorderTypeMembers>True</CSReorderTypeMembers><CSArrangeQualifiers>True</CSArrangeQualifiers><FormatAttributeQuoteDescriptor>True</FormatAttributeQuoteDescriptor><PublicModifierStyleTs>True</PublicModifierStyleTs><ExplicitAnyTs>True</ExplicitAnyTs><TypeAnnotationStyleTs>True</TypeAnnotationStyleTs><RelativePathStyleTs>True</RelativePathStyleTs><OptimizeReferenceCommentsTs>True</OptimizeReferenceCommentsTs><OptimizeImportsTs>True</OptimizeImportsTs><RemoveRedundantQualifiersTs>True</RemoveRedundantQualifiersTs><CSFixBuiltinTypeReferences>True</CSFixBuiltinTypeReferences><CSCodeStyleAttributes ArrangeTypeAccessModifier="True" ArrangeTypeMemberAccessModifier="True" SortModifiers="True" RemoveRedundantParentheses="False" AddMissingParentheses="True" ArrangeAttributes="True" /></Profile> True @@ -121,6 +121,7 @@ True True False + False NEXT_LINE 0 1 diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/logs/LogsProcessor.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/logs/LogsProcessor.cs index b6575a3bc33..429a3036f6e 100644 --- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/logs/LogsProcessor.cs +++ b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/logs/LogsProcessor.cs @@ -9,13 +9,13 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Core.Logs using System.Linq; using System.Text; using System.Threading.Tasks; - using akka::Akka; - using akka::Akka.Actor; - using akka::Akka.IO; using Akka.Streams; using Akka.Streams.Dsl; using Microsoft.Azure.Devices.Edge.Storage; using Microsoft.Azure.Devices.Edge.Util; + using AkkaActor = akka::Akka.Actor; + using AkkaIO = akka::Akka.IO; + using AkkaNet = akka::Akka; // Processes incoming logs stream and converts to the required format // @@ -29,20 +29,20 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Core.Logs // unused public class LogsProcessor : ILogsProcessor, IDisposable { - static readonly Flow FramingFlow - = Framing.LengthField(4, int.MaxValue, 4, ByteOrder.BigEndian); + static readonly Flow FramingFlow + = Framing.LengthField(4, int.MaxValue, 4, AkkaIO.ByteOrder.BigEndian); - static readonly Flow SimpleLengthFraming + static readonly Flow SimpleLengthFraming = Framing.SimpleFramingProtocolEncoder(int.MaxValue); - readonly ActorSystem system; + readonly AkkaActor.ActorSystem system; readonly ActorMaterializer materializer; readonly ILogMessageParser logMessageParser; public LogsProcessor(ILogMessageParser logMessageParser) { this.logMessageParser = Preconditions.CheckNotNull(logMessageParser, nameof(logMessageParser)); - this.system = ActorSystem.Create("LogsProcessor"); + this.system = AkkaActor.ActorSystem.Create("LogsProcessor"); this.materializer = this.system.Materializer(); } @@ -106,7 +106,7 @@ ArraySegment BasicMapper(ModuleLogMessageData l) ? new ArraySegment(l.FullText.ToBytes()) : new ArraySegment(l.ToBytes()); - var sourceMappers = new List, NotUsed>, Source, NotUsed>>>(); + var sourceMappers = new List, AkkaNet.NotUsed>, Source, AkkaNet.NotUsed>>>(); if (logOptions.ContentEncoding == LogsContentEncoding.Gzip) { @@ -134,15 +134,15 @@ public void Dispose() this.materializer?.Dispose(); } - static Source, NotUsed> SimpleLengthFramingMapper(Source, NotUsed> s) => - s.Select(ByteString.FromBytes) + static Source, AkkaNet.NotUsed> SimpleLengthFramingMapper(Source, AkkaNet.NotUsed> s) => + s.Select(AkkaIO.ByteString.FromBytes) .Via(SimpleLengthFraming) .Select(b => new ArraySegment(b.ToArray())); - static Source, NotUsed> NonGroupingGzipMapper(Source, NotUsed> s) => + static Source, AkkaNet.NotUsed> NonGroupingGzipMapper(Source, AkkaNet.NotUsed> s) => s.Select(m => new ArraySegment(Compression.CompressToGzip(m.Array))); - static Source, NotUsed> GroupingGzipMapper(Source, NotUsed> s, LogsOutputGroupingConfig outputGroupingConfig) => + static Source, AkkaNet.NotUsed> GroupingGzipMapper(Source, AkkaNet.NotUsed> s, LogsOutputGroupingConfig outputGroupingConfig) => s.GroupedWithin(outputGroupingConfig.MaxFrames, outputGroupingConfig.MaxDuration) .Select( b => @@ -154,20 +154,20 @@ static Source, NotUsed> GroupingGzipMapper(Source parsingGraphSource; + Source parsingGraphSource; - GraphBuilder(Source parsingGraphSource) + GraphBuilder(Source parsingGraphSource) { this.parsingGraphSource = parsingGraphSource; } - public static GraphBuilder CreateParsingGraphBuilder(Stream stream, Func parserFunc) + public static GraphBuilder CreateParsingGraphBuilder(Stream stream, Func parserFunc) { var source = StreamConverters.FromInputStream(() => stream); var graph = source .Via(FramingFlow) .Select(parserFunc) - .MapMaterializedValue(_ => NotUsed.Instance); + .MapMaterializedValue(_ => AkkaNet.NotUsed.Instance); return new GraphBuilder(graph); } @@ -199,14 +199,14 @@ public IRunnableGraph>> GetMaterializingGraph(Func GetStreamingGraph( Func> callback, Func basicMapper, - List, Source>> mappers) + List, Source>> mappers) { - Source streamingGraphSource = this.parsingGraphSource + Source streamingGraphSource = this.parsingGraphSource .Select(basicMapper); if (mappers?.Count > 0) { - foreach (Func, Source> mapper in mappers) + foreach (Func, Source> mapper in mappers) { streamingGraphSource = mapper(streamingGraphSource); } diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/requests/LogsUploadRequestHandler.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/requests/LogsUploadRequestHandler.cs index 11e7a8f305d..b32a6e0178a 100644 --- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/requests/LogsUploadRequestHandler.cs +++ b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/requests/LogsUploadRequestHandler.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. namespace Microsoft.Azure.Devices.Edge.Agent.Core.Requests { - extern alias akka; using System; using System.Collections.Generic; using System.Linq; diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/AssemblyInfo.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/AssemblyInfo.cs index 301be82783d..3aba00a71ca 100644 --- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/AssemblyInfo.cs +++ b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/AssemblyInfo.cs @@ -1,4 +1,4 @@ // Copyright (c) Microsoft. All rights reserved. using System.Runtime.CompilerServices; -[assembly: InternalsVisibleTo("Microsoft.Azure.Devices.Edge.Agent.Docker.Test")] \ No newline at end of file +[assembly: InternalsVisibleTo("Microsoft.Azure.Devices.Edge.Agent.Docker.Test")] diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/DockerModule.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/DockerModule.cs index d75ab1bde1f..8b70fd4ffe4 100644 --- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/DockerModule.cs +++ b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/DockerModule.cs @@ -75,13 +75,13 @@ public virtual bool Equals(IModule other) } return string.Equals(this.Name, other.Name) && - string.Equals(this.Version, other.Version) && - string.Equals(this.Type, other.Type) && - this.DesiredStatus == other.DesiredStatus && - this.Config.Equals(other.Config) && - this.RestartPolicy == other.RestartPolicy && - this.ImagePullPolicy == other.ImagePullPolicy && - EnvDictionaryComparer.Equals(this.Env, other.Env); + string.Equals(this.Version, other.Version) && + string.Equals(this.Type, other.Type) && + this.DesiredStatus == other.DesiredStatus && + this.Config.Equals(other.Config) && + this.RestartPolicy == other.RestartPolicy && + this.ImagePullPolicy == other.ImagePullPolicy && + EnvDictionaryComparer.Equals(this.Env, other.Env); } public virtual bool IsOnlyModuleStatusChanged(IModule other) diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/EdgeAgentDockerRuntimeModule.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/EdgeAgentDockerRuntimeModule.cs index 11df7a031ca..cea954af2df 100644 --- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/EdgeAgentDockerRuntimeModule.cs +++ b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/EdgeAgentDockerRuntimeModule.cs @@ -4,7 +4,6 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker using System; using System.Collections.Generic; using Microsoft.Azure.Devices.Edge.Agent.Core; - using Microsoft.Azure.Devices.Edge.Util; using Newtonsoft.Json; public class EdgeAgentDockerRuntimeModule : DockerRuntimeModule, IEdgeAgentModule diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/commands/CreateCommand.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/commands/CreateCommand.cs index 44344d99cb2..1caac25a2d8 100644 --- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/commands/CreateCommand.cs +++ b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/commands/CreateCommand.cs @@ -15,15 +15,15 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Docker.Commands public class CreateCommand : ICommand { - readonly CreateContainerParameters createContainerParameters; - readonly IDockerClient client; - static readonly Dictionary EdgeHubPortBinding = new Dictionary { { "8883/tcp", new PortBinding { HostPort = "8883" } }, { "443/tcp", new PortBinding { HostPort = "443" } } }; + readonly CreateContainerParameters createContainerParameters; + readonly IDockerClient client; + readonly Lazy id; public CreateCommand(IDockerClient client, CreateContainerParameters createContainerParameters) diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/commands/RemoveCommand.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/commands/RemoveCommand.cs index 6f63999d2c8..1dfc5a0ab65 100644 --- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/commands/RemoveCommand.cs +++ b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Docker/commands/RemoveCommand.cs @@ -18,6 +18,7 @@ public class RemoveCommand : ICommand static readonly ILogger Logger = Util.Logger.Factory.CreateLogger(); readonly IDockerClient client; readonly DockerModule module; + public RemoveCommand(IDockerClient client, DockerModule module) { this.client = Preconditions.CheckNotNull(client, nameof(client)); diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Edgelet/version_2018_06_28/ModuleManagementHttpClient.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Edgelet/version_2018_06_28/ModuleManagementHttpClient.cs index 1ce481945f5..c4f7cf0ff20 100644 --- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Edgelet/version_2018_06_28/ModuleManagementHttpClient.cs +++ b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Edgelet/version_2018_06_28/ModuleManagementHttpClient.cs @@ -10,8 +10,8 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Edgelet.Version_2018_06_28 using System.Threading; using System.Threading.Tasks; using Microsoft.Azure.Devices.Edge.Agent.Core; - using Microsoft.Azure.Devices.Edge.Agent.Edgelet.Versioning; using Microsoft.Azure.Devices.Edge.Agent.Edgelet.Version_2018_06_28.GeneratedCode; + using Microsoft.Azure.Devices.Edge.Agent.Edgelet.Versioning; using Microsoft.Azure.Devices.Edge.Util; using Microsoft.Azure.Devices.Edge.Util.Edged; using Microsoft.Azure.Devices.Edge.Util.TransientFaultHandling; diff --git a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Edgelet/version_2019_01_30/ModuleManagementHttpClient.cs b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Edgelet/version_2019_01_30/ModuleManagementHttpClient.cs index 60247163262..a02de05b982 100644 --- a/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Edgelet/version_2019_01_30/ModuleManagementHttpClient.cs +++ b/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Edgelet/version_2019_01_30/ModuleManagementHttpClient.cs @@ -10,8 +10,8 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Edgelet.Version_2019_01_30 using System.Threading; using System.Threading.Tasks; using Microsoft.Azure.Devices.Edge.Agent.Core; - using Microsoft.Azure.Devices.Edge.Agent.Edgelet.Versioning; using Microsoft.Azure.Devices.Edge.Agent.Edgelet.Version_2019_01_30.GeneratedCode; + using Microsoft.Azure.Devices.Edge.Agent.Edgelet.Versioning; using Microsoft.Azure.Devices.Edge.Util; using Microsoft.Azure.Devices.Edge.Util.Edged; using Microsoft.Azure.Devices.Edge.Util.TransientFaultHandling; diff --git a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/AgentTests.cs b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/AgentTests.cs index 836d33104b3..774967d0cfc 100644 --- a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/AgentTests.cs +++ b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/AgentTests.cs @@ -91,7 +91,7 @@ public async void AgentCreateSuccessWhenDecryptFails() [Unit] public async void ReconcileAsyncOnEmptyPlan() { - var token = new CancellationToken(); + var token = default(CancellationToken); var serde = Mock.Of>(); var mockConfigSource = new Mock(); var mockEnvironment = new Mock(); @@ -146,7 +146,7 @@ public async void ReconcileAsyncAbortsWhenConfigSourceThrows() var mockPlanner = new Mock(); var mockPlanRunner = new Mock(); var mockReporter = new Mock(); - var token = new CancellationToken(); + var token = default(CancellationToken); var currentSet = ModuleSet.Empty; var mockModuleIdentityLifecycleManager = new Mock(); var configStore = Mock.Of>(); @@ -182,7 +182,7 @@ public async void ReconcileAsyncAbortsWhenConfigSourceReturnsKnownExceptions( var mockPlanner = new Mock(); var mockPlanRunner = new Mock(); var mockReporter = new Mock(); - var token = new CancellationToken(); + var token = default(CancellationToken); var currentSet = ModuleSet.Empty; var mockModuleIdentityLifecycleManager = new Mock(); var configStore = Mock.Of>(); @@ -217,7 +217,7 @@ public async void ReconcileAsyncAbortsWhenEnvironmentSourceThrows() var mockPlanner = new Mock(); var mockPlanRunner = new Mock(); var mockReporter = new Mock(); - var token = new CancellationToken(); + var token = default(CancellationToken); var mockModuleIdentityLifecycleManager = new Mock(); var configStore = Mock.Of>(); var mockEnvironmentProvider = Mock.Of(m => m.Create(It.IsAny()) == mockEnvironment.Object); @@ -251,7 +251,7 @@ public async void ReconcileAsyncAbortsWhenModuleIdentityLifecycleManagerThrows() var mockPlanner = new Mock(); var mockPlanRunner = new Mock(); var mockReporter = new Mock(); - var token = new CancellationToken(); + var token = default(CancellationToken); var mockModuleIdentityLifecycleManager = new Mock(); var configStore = Mock.Of>(); var mockEnvironmentProvider = Mock.Of(m => m.Create(It.IsAny()) == mockEnvironment.Object); @@ -290,7 +290,7 @@ public async void ReconcileAsyncAbortsWhenModuleIdentityLifecycleManagerThrows() [Unit] public async void ReconcileAsyncReportsFailedWhenEncryptProviderThrows() { - var token = new CancellationToken(); + var token = default(CancellationToken); var serde = Mock.Of>(); var mockConfigSource = new Mock(); var mockEnvironment = new Mock(); @@ -364,9 +364,7 @@ public async void ReconcileAsyncOnSetPlan() new TestCommand(TestCommandType.TestRemove, currentModule, recordKeeper) }; var testPlan = new Plan(commandList); - - var token = new CancellationToken(); - + var token = default(CancellationToken); var runtimeInfo = Mock.Of(); var deploymentConfig = new DeploymentConfig("1.0", runtimeInfo, new SystemModules(null, null), new Dictionary { ["desired"] = desiredModule }); var deploymentConfigInfo = new DeploymentConfigInfo(0, deploymentConfig); @@ -418,7 +416,7 @@ public async Task DesiredIsNotNullBecauseCurrentThrew() var mockReporter = new Mock(); var runtimeInfo = new Mock(); var mockModuleIdentityLifecycleManager = new Mock(); - var token = new CancellationToken(); + var token = default(CancellationToken); var configStore = Mock.Of>(); var mockEnvironmentProvider = Mock.Of(m => m.Create(It.IsAny()) == mockEnvironment.Object); var serde = Mock.Of>(); @@ -449,7 +447,7 @@ public async Task CurrentIsNotNullBecauseDesiredThrew() var mockPlanRunner = new Mock(); var mockReporter = new Mock(); var mockModuleIdentityLifecycleManager = new Mock(); - var token = new CancellationToken(); + var token = default(CancellationToken); var configStore = Mock.Of>(); var mockEnvironmentProvider = Mock.Of(m => m.Create(It.IsAny()) == mockEnvironment.Object); var serde = Mock.Of>(); @@ -492,7 +490,7 @@ public async Task ReportShutdownAsyncConfigTest() { "mod1", new TestModule("mod1", "1.0", "docker", ModuleStatus.Running, new TestConfig("boo"), RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, new ConfigurationInfo("1"), null) } }); var deploymentConfigInfo = new DeploymentConfigInfo(0, deploymentConfig); - var token = new CancellationToken(); + var token = default(CancellationToken); mockConfigSource.Setup(cs => cs.GetDeploymentConfigInfoAsync()) .ReturnsAsync(deploymentConfigInfo); @@ -555,7 +553,7 @@ public async Task HandleShutdownTest() var encryptionDecryptionProvider = Mock.Of(); var deploymentConfig = new DeploymentConfig("1.0", Mock.Of(), new SystemModules(null, null), modules); var deploymentConfigInfo = new DeploymentConfigInfo(0, deploymentConfig); - var token = new CancellationToken(); + var token = default(CancellationToken); mockConfigSource.Setup(cs => cs.GetDeploymentConfigInfoAsync()) .ReturnsAsync(deploymentConfigInfo); diff --git a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/NullEnvironmentTest.cs b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/NullEnvironmentTest.cs index 606dab19bed..d1395b06a81 100644 --- a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/NullEnvironmentTest.cs +++ b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/NullEnvironmentTest.cs @@ -14,7 +14,7 @@ public async void TestNullEnvironment() NullEnvironment testNullEnvironment = NullEnvironment.Instance; Assert.NotNull(testNullEnvironment); - var token = new CancellationToken(); + var token = default(CancellationToken); ModuleSet testModuleSet = await testNullEnvironment.GetModulesAsync(token); Assert.NotNull(testModuleSet); diff --git a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/OrderedPlanRunnerTest.cs b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/OrderedPlanRunnerTest.cs index bec3f4e9165..10888a3b735 100644 --- a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/OrderedPlanRunnerTest.cs +++ b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/OrderedPlanRunnerTest.cs @@ -46,7 +46,7 @@ public async void TestPlanExecution() Assert.True(Plan.Empty.IsEmpty); Assert.True(plan2.IsEmpty); - var token = new CancellationToken(); + var token = default(CancellationToken); var planRunner = new OrderedPlanRunner(); await planRunner.ExecuteAsync(1, plan1, token); @@ -85,7 +85,7 @@ await factory.StartAsync(moduleExecutionList[3].Module), await factory.StopAsync(moduleExecutionList[4].Module), }; var plan1 = new Plan(commandList); - var token = new CancellationToken(); + var token = default(CancellationToken); var planRunner = new OrderedPlanRunner(); await planRunner.ExecuteAsync(1, plan1, token); Assert.All( @@ -129,7 +129,7 @@ await failureFactory.StopAsync(moduleExecutionList[4].Module), await factory.StopAsync(moduleExecutionList[4].Module), }; var plan1 = new Plan(commandList); - var token = new CancellationToken(); + var token = default(CancellationToken); var planRunner = new OrderedPlanRunner(); AggregateException ex = await Assert.ThrowsAsync(async () => await planRunner.ExecuteAsync(1, plan1, token)); diff --git a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/commands/GroupCommandTest.cs b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/commands/GroupCommandTest.cs index 67afe861f2f..373065a3dde 100644 --- a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/commands/GroupCommandTest.cs +++ b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/commands/GroupCommandTest.cs @@ -31,7 +31,7 @@ public async Task TestCreate( { var g = new GroupCommand(commandList.ToArray()); - var token = new CancellationToken(); + var token = default(CancellationToken); await g.ExecuteAsync(token); @@ -48,7 +48,7 @@ public async Task TestUndoAsync( { ICommand g = new GroupCommand(commandList.ToArray()); - var token = new CancellationToken(); + var token = default(CancellationToken); await g.UndoAsync(token); diff --git a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/commands/LoggingCommandFactoryTest.cs b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/commands/LoggingCommandFactoryTest.cs index 8b1dc3eea51..58b2e7a11a0 100644 --- a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/commands/LoggingCommandFactoryTest.cs +++ b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/commands/LoggingCommandFactoryTest.cs @@ -78,7 +78,7 @@ public async Task ExecuteSuccessfulTests( Task commandBeingDecorated, TestExecutionExpr testExpr) { - var token = new CancellationToken(); + var token = default(CancellationToken); var logFactoryMock = new Mock(); var logMock = new Mock>(); @@ -114,7 +114,7 @@ public async Task ExecuteFailureTests( Task commandBeingDecorated, TestExecutionExpr testExpr) { - var token = new CancellationToken(); + var token = default(CancellationToken); var logFactoryMock = new Mock(); var logMock = new Mock>(); @@ -144,7 +144,7 @@ public async Task UndoSuccessTests( Task commandBeingDecorated, TestExecutionExpr testExpr) { - var token = new CancellationToken(); + var token = default(CancellationToken); var logFactoryMock = new Mock(); var logMock = new Mock>(); @@ -174,7 +174,7 @@ public async Task UndoFailureTests( Task commandBeingDecorated, TestExecutionExpr testExpr) { - var token = new CancellationToken(); + var token = default(CancellationToken); var logFactoryMock = new Mock(); var logMock = new Mock>(); var factoryMock = new Mock(); diff --git a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/commands/NullCommandTest.cs b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/commands/NullCommandTest.cs index dd3b3df1ddb..371019d3499 100644 --- a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/commands/NullCommandTest.cs +++ b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/commands/NullCommandTest.cs @@ -13,7 +13,7 @@ public class NullCommandTest public async void NullCommandTestAll() { NullCommand n = NullCommand.Instance; - var token = new CancellationToken(); + var token = default(CancellationToken); await n.ExecuteAsync(token); diff --git a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/commands/ParallelGroupCommandTest.cs b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/commands/ParallelGroupCommandTest.cs index d46831aa485..853371f5e4a 100644 --- a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/commands/ParallelGroupCommandTest.cs +++ b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/commands/ParallelGroupCommandTest.cs @@ -31,7 +31,7 @@ public async Task TestCreate( { var g = new ParallelGroupCommand(commandList.ToArray()); - var token = new CancellationToken(); + var token = default(CancellationToken); await g.ExecuteAsync(token); @@ -48,7 +48,7 @@ public async Task TestUndoAsync( { ICommand g = new ParallelGroupCommand(commandList.ToArray()); - var token = new CancellationToken(); + var token = default(CancellationToken); await g.UndoAsync(token); diff --git a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/planners/HealthRestartPlannerTest.cs b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/planners/HealthRestartPlannerTest.cs index ed830ccbc62..1b380ffc785 100644 --- a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/planners/HealthRestartPlannerTest.cs +++ b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/planners/HealthRestartPlannerTest.cs @@ -43,7 +43,7 @@ public async void TestMinimalTest() { // Arrange (TestCommandFactory factory, _, _, HealthRestartPlanner planner) = CreatePlanner(); - var token = new CancellationToken(); + var token = default(CancellationToken); var expectedExecutionList = new List(); // Act diff --git a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/planners/RestartPlannerTest.cs b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/planners/RestartPlannerTest.cs index 187beef560e..07df8186aeb 100644 --- a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/planners/RestartPlannerTest.cs +++ b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Core.Test/planners/RestartPlannerTest.cs @@ -26,7 +26,7 @@ public async void RestartPlannerMinimalTest() { var factory = new TestCommandFactory(); var planner = new RestartPlanner(factory); - var token = new CancellationToken(); + var token = default(CancellationToken); var addExecutionList = new List(); Plan addPlan = await planner.PlanAsync(ModuleSet.Empty, ModuleSet.Empty, RuntimeInfo, ImmutableDictionary.Empty); @@ -47,7 +47,7 @@ public async void RestartPlannerAdd1RunningModule() IImmutableDictionary moduleIdentities = GetModuleIdentities(new List() { addModule }); var planner = new RestartPlanner(factory); - var token = new CancellationToken(); + var token = default(CancellationToken); ModuleSet addRunning = ModuleSet.Create(addModule); var addExecutionList = new List @@ -73,7 +73,7 @@ public async void RestartPlannerAdd1StoppedModule() IImmutableDictionary moduleIdentities = GetModuleIdentities(new List() { stoppedModule }); var planner = new RestartPlanner(factory); - var token = new CancellationToken(); + var token = default(CancellationToken); var addStoppedExecutionList = new List { @@ -97,7 +97,7 @@ public async void RestartPlannerUpdate1Module() IImmutableDictionary moduleIdentities = GetModuleIdentities(new List() { desiredModule }); var planner = new RestartPlanner(factory); - var token = new CancellationToken(); + var token = default(CancellationToken); ModuleSet currentSet = ModuleSet.Create(currentModule); ModuleSet desiredSet = ModuleSet.Create(desiredModule); @@ -120,7 +120,7 @@ public async void RestartPlannerRemove1Module() { var factory = new TestCommandFactory(); var planner = new RestartPlanner(factory); - var token = new CancellationToken(); + var token = default(CancellationToken); IModule removeModule = new TestModule("mod1", "version1", "test", ModuleStatus.Running, Config1, RestartPolicy.OnUnhealthy, ImagePullPolicy.OnCreate, DefaultConfigurationInfo, EnvVars); ModuleSet removeRunning = ModuleSet.Create(removeModule); @@ -141,7 +141,7 @@ public async void RestartPlannerRemove1Module() public async void RestartPlannerAddRemoveUpdate() { var factory = new TestCommandFactory(); - var token = new CancellationToken(); + var token = default(CancellationToken); DateTime lastStartTime = DateTime.Parse("2017-08-04T17:52:13.0419502Z", null, DateTimeStyles.RoundtripKind); DateTime lastExitTime = lastStartTime.AddDays(1); diff --git a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Test/KubernetesCommandFactoryTest.cs b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Test/KubernetesCommandFactoryTest.cs index 2c5039545fd..29cc3411893 100644 --- a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Test/KubernetesCommandFactoryTest.cs +++ b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Test/KubernetesCommandFactoryTest.cs @@ -3,9 +3,9 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Test { using System.Threading; using System.Threading.Tasks; - using Microsoft.Azure.Devices.Edge.Util.Test.Common; using Microsoft.Azure.Devices.Edge.Agent.Core; using Microsoft.Azure.Devices.Edge.Agent.Core.Commands; + using Microsoft.Azure.Devices.Edge.Util.Test.Common; using Moq; using Xunit; @@ -31,7 +31,7 @@ public async void KubernetesCommandFactoryIsReallyBasic() Assert.Equal(NullCommand.Instance, await kcf.RestartAsync(mockModule)); var newCommand = await kcf.WrapAsync(mockCommand); await newCommand.ExecuteAsync(ct); - Mock.Get(mockCommand).Verify( c => c.ExecuteAsync(ct), Times.Once); + Mock.Get(mockCommand).Verify(c => c.ExecuteAsync(ct), Times.Once); } -} + } } diff --git a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Test/commands/KubernetesCrdCommandTest.cs b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Test/commands/KubernetesCrdCommandTest.cs index c70e8e28174..80c49ea9307 100644 --- a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Test/commands/KubernetesCrdCommandTest.cs +++ b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Test/commands/KubernetesCrdCommandTest.cs @@ -8,16 +8,16 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Test.Commands using System.Threading; using System.Threading.Tasks; using global::Docker.DotNet.Models; - using Microsoft.Azure.Devices.Edge.Agent.Core; - using Microsoft.Azure.Devices.Edge.Agent.Docker; - using Microsoft.Azure.Devices.Edge.Util.Test.Common; - using Moq; using k8s; using k8s.Models; + using Microsoft.Azure.Devices.Edge.Agent.Core; + using Microsoft.Azure.Devices.Edge.Agent.Docker; using Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Commands; - using Xunit; using Microsoft.Azure.Devices.Edge.Util; + using Microsoft.Azure.Devices.Edge.Util.Test.Common; + using Moq; using Newtonsoft.Json; + using Xunit; using Constants = Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Constants; public class KubernetesCrdCommandTest @@ -62,7 +62,7 @@ public async void CrdCommandExecuteAsyncInvalidModule() var configProvider = new Mock>(); configProvider.Setup(cp => cp.GetCombinedConfig(km1, Runtime)).Returns(() => null); - var token = new CancellationToken(); + var token = default(CancellationToken); var cmd = new KubernetesCrdCommand(Ns, Hostname, DeviceId, DefaultClient, modules, runtimeOption, DefaultConfigProvider); await Assert.ThrowsAsync(() => cmd.ExecuteAsync(token)); } @@ -74,7 +74,7 @@ public async void CrdCommandExecuteWithAuthCreateNewObjects() IModule m1 = new DockerModule("module1", "v1", ModuleStatus.Running, Core.RestartPolicy.Always, Config1, ImagePullPolicy.OnCreate, DefaultConfigurationInfo, EnvVars); var km1 = new KubernetesModule((IModule)m1); KubernetesModule[] modules = { km1 }; - var token = new CancellationToken(); + var token = default(CancellationToken); Option runtimeOption = Option.Maybe(Runtime); var auth = new AuthConfig() { Username = "username", Password = "password", ServerAddress = "docker.io" }; var configProvider = new Mock>(); @@ -145,7 +145,7 @@ public async void CrdCommandExecuteWithAuthReplaceObjects() IModule m1 = new DockerModule("module1", "v1", ModuleStatus.Running, Core.RestartPolicy.Always, Config1, ImagePullPolicy.OnCreate, DefaultConfigurationInfo, EnvVars); var km1 = new KubernetesModule((IModule)m1); KubernetesModule[] modules = { km1 }; - var token = new CancellationToken(); + var token = default(CancellationToken); Option runtimeOption = Option.Maybe(Runtime); var auth = new AuthConfig() { Username = "username", Password = "password", ServerAddress = "docker.io" }; var configProvider = new Mock>(); @@ -217,7 +217,7 @@ public async void CrdCommandExecuteTwoModulesWithSamePullSecret() IModule m2 = new DockerModule("module2", "v1", ModuleStatus.Running, Core.RestartPolicy.Always, Config2, ImagePullPolicy.OnCreate, DefaultConfigurationInfo, EnvVars); var km2 = new KubernetesModule((IModule)m2); KubernetesModule[] modules = { km1, km2 }; - var token = new CancellationToken(); + var token = default(CancellationToken); Option runtimeOption = Option.Maybe(Runtime); var auth = new AuthConfig() { Username = "username", Password = "password", ServerAddress = "docker.io" }; var configProvider = new Mock>(); diff --git a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Test/planners/KubernetesPlannerTest.cs b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Test/planners/KubernetesPlannerTest.cs index e409816b537..a24002c83d4 100644 --- a/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Test/planners/KubernetesPlannerTest.cs +++ b/edge-agent/test/Microsoft.Azure.Devices.Edge.Agent.Kubernetes.Test/planners/KubernetesPlannerTest.cs @@ -64,7 +64,8 @@ public async void KubernetesPlannerPlanFailsWithNonDistinctModules() var planner = new KubernetesPlanner(Ns, Hostname, DeviceId, DefaultClient, DefaultCommandFactory, DefaultConfigProvider); - await Assert.ThrowsAsync( () => planner.PlanAsync(addRunning, ModuleSet.Empty, RuntimeInfo, ImmutableDictionary.Empty)); + await Assert.ThrowsAsync( + () => planner.PlanAsync(addRunning, ModuleSet.Empty, RuntimeInfo, ImmutableDictionary.Empty)); } [Fact] diff --git a/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.CloudProxy/ClientTokenCloudConnection.cs b/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.CloudProxy/ClientTokenCloudConnection.cs index 5da5e7abca5..c7fae6a50b3 100644 --- a/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.CloudProxy/ClientTokenCloudConnection.cs +++ b/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.CloudProxy/ClientTokenCloudConnection.cs @@ -13,7 +13,7 @@ namespace Microsoft.Azure.Devices.Edge.Hub.CloudProxy using static System.FormattableString; /// - /// This class creates and manages cloud connections (CloudProxy instances) + /// This class creates and manages cloud connections (CloudProxy instances). /// class ClientTokenCloudConnection : CloudConnection, IClientTokenCloudConnection { @@ -298,40 +298,40 @@ public static void TokenNotUsable(IIdentity identity, string newToken) Log.LogDebug((int)EventIds.ObtainedNewToken, Invariant($"Token received for client {identity.Id} expires in {timeRemaining}, and so is not usable. Getting a fresh token...")); } - internal static void GetNewToken(string id) + internal static void CreateException(Exception ex, IIdentity identity) { - Log.LogDebug((int)EventIds.CreateNewToken, Invariant($"Getting new token for {id}.")); + Log.LogError((int)EventIds.CloudConnectError, ex, Invariant($"Error creating or updating the cloud proxy for client {identity.Id}")); } - internal static void UsingExistingToken(string id) + internal static void ErrorRenewingToken(Exception ex) { - Log.LogInformation((int)EventIds.CreateNewToken, Invariant($"New token requested by client {id}, but using existing token as it is usable.")); + Log.LogDebug((int)EventIds.ErrorRenewingToken, ex, "Critical Error trying to renew Token."); } - internal static void SafeCreateNewToken(string id) + internal static void GetNewToken(string id) { - Log.LogInformation((int)EventIds.CreateNewToken, Invariant($"Existing token not found for {id}. Getting new token from the client...")); + Log.LogDebug((int)EventIds.CreateNewToken, Invariant($"Getting new token for {id}.")); } - internal static void CreateException(Exception ex, IIdentity identity) + internal static void NewTokenObtained(IIdentity identity, string newToken) { - Log.LogError((int)EventIds.CloudConnectError, ex, Invariant($"Error creating or updating the cloud proxy for client {identity.Id}")); + TimeSpan timeRemaining = TokenHelper.GetTokenExpiryTimeRemaining(identity.IotHubHostName, newToken); + Log.LogInformation((int)EventIds.ObtainedNewToken, Invariant($"Obtained new token for client {identity.Id} that expires in {timeRemaining}")); } - internal static void UpdatedCloudConnection(IIdentity identity) + internal static void SafeCreateNewToken(string id) { - Log.LogDebug((int)EventIds.UpdatedCloudConnection, Invariant($"Updated cloud connection for client {identity.Id}")); + Log.LogInformation((int)EventIds.CreateNewToken, Invariant($"Existing token not found for {id}. Getting new token from the client...")); } - internal static void NewTokenObtained(IIdentity identity, string newToken) + internal static void UpdatedCloudConnection(IIdentity identity) { - TimeSpan timeRemaining = TokenHelper.GetTokenExpiryTimeRemaining(identity.IotHubHostName, newToken); - Log.LogInformation((int)EventIds.ObtainedNewToken, Invariant($"Obtained new token for client {identity.Id} that expires in {timeRemaining}")); + Log.LogDebug((int)EventIds.UpdatedCloudConnection, Invariant($"Updated cloud connection for client {identity.Id}")); } - internal static void ErrorRenewingToken(Exception ex) + internal static void UsingExistingToken(string id) { - Log.LogDebug((int)EventIds.ErrorRenewingToken, ex, "Critical Error trying to renew Token."); + Log.LogInformation((int)EventIds.CreateNewToken, Invariant($"New token requested by client {id}, but using existing token as it is usable.")); } } } diff --git a/edge-hub/src/Microsoft.Azure.Devices.Routing.Core/endpoints/StoringAsyncEndpointExecutorFactory.cs b/edge-hub/src/Microsoft.Azure.Devices.Routing.Core/endpoints/StoringAsyncEndpointExecutorFactory.cs index 49f130912da..1208b619439 100644 --- a/edge-hub/src/Microsoft.Azure.Devices.Routing.Core/endpoints/StoringAsyncEndpointExecutorFactory.cs +++ b/edge-hub/src/Microsoft.Azure.Devices.Routing.Core/endpoints/StoringAsyncEndpointExecutorFactory.cs @@ -2,8 +2,8 @@ namespace Microsoft.Azure.Devices.Routing.Core.Endpoints { using System.Threading.Tasks; - using Microsoft.Azure.Devices.Routing.Core.Checkpointers; using Microsoft.Azure.Devices.Edge.Util; + using Microsoft.Azure.Devices.Routing.Core.Checkpointers; public class StoringAsyncEndpointExecutorFactory : IEndpointExecutorFactory { diff --git a/edge-hub/src/Microsoft.Azure.Devices.Routing.Core/query/Null.cs b/edge-hub/src/Microsoft.Azure.Devices.Routing.Core/query/Null.cs index 469e3313654..e49fcfffb67 100644 --- a/edge-hub/src/Microsoft.Azure.Devices.Routing.Core/query/Null.cs +++ b/edge-hub/src/Microsoft.Azure.Devices.Routing.Core/query/Null.cs @@ -3,7 +3,7 @@ namespace Microsoft.Azure.Devices.Routing.Core.Query { public struct Null { - public static Null Instance { get; } = new Null(); + public static Null Instance { get; } = default(Null); // Equal public static Bool operator ==(Null x, Null y) => Bool.True; diff --git a/edge-hub/src/Microsoft.Azure.Devices.Routing.Core/query/Undefined.cs b/edge-hub/src/Microsoft.Azure.Devices.Routing.Core/query/Undefined.cs index 018fb3a79da..b86830f2934 100644 --- a/edge-hub/src/Microsoft.Azure.Devices.Routing.Core/query/Undefined.cs +++ b/edge-hub/src/Microsoft.Azure.Devices.Routing.Core/query/Undefined.cs @@ -9,7 +9,7 @@ public struct Undefined static readonly Bool UndefinedBool = Bool.Undefined; static readonly double UndefinedDouble = double.NaN; - public static Undefined Instance { get; } = new Undefined(); + public static Undefined Instance { get; } = default(Undefined); // Equal public static Bool operator ==(Undefined x, Undefined y) => Bool.Undefined; diff --git a/edge-hub/test/Microsoft.Azure.Devices.Routing.Core.Test/query/NullTest.cs b/edge-hub/test/Microsoft.Azure.Devices.Routing.Core.Test/query/NullTest.cs index 971d2363803..bae4386e784 100644 --- a/edge-hub/test/Microsoft.Azure.Devices.Routing.Core.Test/query/NullTest.cs +++ b/edge-hub/test/Microsoft.Azure.Devices.Routing.Core.Test/query/NullTest.cs @@ -24,13 +24,11 @@ public void SmokeTest() [Unit] public void TestEquals() { - var d1 = new Null(); - var d2 = new Null(); + var d1 = default(Null); + var d2 = default(Null); Assert.True(d1 == d2); Assert.False(d1 != d2); - Assert.Equal(Bool.Undefined, Bool.True == d1); - Assert.Equal(Bool.Undefined, Bool.False == d1); Assert.Equal(Bool.Undefined, d1 == Bool.True); Assert.Equal(Bool.Undefined, d1 == Bool.False); } @@ -39,8 +37,8 @@ public void TestEquals() [Unit] public void TestArthimetic() { - var d1 = new Null(); - var d2 = new Null(); + var d1 = default(Null); + var d2 = default(Null); Assert.Equal(12.34, d1 + 12.34); Assert.Equal(12.34, 12.34 + d1); @@ -64,39 +62,39 @@ public void TestArthimetic() [Unit] public void TestComparison() { - var d1 = new Null(); - var d2 = new Null(); + var d1 = default(Null); + var d2 = default(Null); Assert.Equal(Bool.Undefined, d1 < 12.34); - Assert.Equal(Bool.Undefined, 12.34 < d1); + Assert.Equal(Bool.Undefined, d1 > 12.34); Assert.Equal(Bool.Undefined, d1 < "string"); - Assert.Equal(Bool.Undefined, "string" < d1); + Assert.Equal(Bool.Undefined, d1 > "string"); Assert.Equal(Bool.Undefined, d1 < Bool.True); - Assert.Equal(Bool.Undefined, Bool.True < d1); + Assert.Equal(Bool.Undefined, d1 > Bool.True); Assert.Equal(Bool.False, d1 < d2); Assert.Equal(Bool.Undefined, d1 > 12.34); - Assert.Equal(Bool.Undefined, 12.34 > d1); + Assert.Equal(Bool.Undefined, d1 < 12.34); Assert.Equal(Bool.Undefined, d1 > "string"); - Assert.Equal(Bool.Undefined, "string" > d1); + Assert.Equal(Bool.Undefined, d1 < "string"); Assert.Equal(Bool.Undefined, d1 > Bool.True); - Assert.Equal(Bool.Undefined, Bool.True > d1); + Assert.Equal(Bool.Undefined, d1 < Bool.True); Assert.Equal(Bool.False, d1 > d2); Assert.Equal(Bool.Undefined, d1 <= 12.34); - Assert.Equal(Bool.Undefined, 12.34 <= d1); + Assert.Equal(Bool.Undefined, d1 >= 12.34); Assert.Equal(Bool.Undefined, d1 <= "string"); - Assert.Equal(Bool.Undefined, "string" <= d1); + Assert.Equal(Bool.Undefined, d1 >= "string"); Assert.Equal(Bool.Undefined, d1 <= Bool.True); - Assert.Equal(Bool.Undefined, Bool.True <= d1); + Assert.Equal(Bool.Undefined, d1 >= Bool.True); Assert.Equal(Bool.True, d1 <= d2); Assert.Equal(Bool.Undefined, d1 >= 12.34); - Assert.Equal(Bool.Undefined, 12.34 >= d1); + Assert.Equal(Bool.Undefined, d1 <= 12.34); Assert.Equal(Bool.Undefined, d1 >= "string"); - Assert.Equal(Bool.Undefined, "string" >= d1); + Assert.Equal(Bool.Undefined, d1 <= "string"); Assert.Equal(Bool.Undefined, d1 >= Bool.True); - Assert.Equal(Bool.Undefined, Bool.True >= d1); + Assert.Equal(Bool.Undefined, d1 <= Bool.True); Assert.Equal(Bool.True, d1 >= d2); } diff --git a/edge-hub/test/Microsoft.Azure.Devices.Routing.Core.Test/query/UndefinedTest.cs b/edge-hub/test/Microsoft.Azure.Devices.Routing.Core.Test/query/UndefinedTest.cs index 5cc5d34b677..6edd3444984 100644 --- a/edge-hub/test/Microsoft.Azure.Devices.Routing.Core.Test/query/UndefinedTest.cs +++ b/edge-hub/test/Microsoft.Azure.Devices.Routing.Core.Test/query/UndefinedTest.cs @@ -24,13 +24,11 @@ public void SmokeTest() [Unit] public void TestEquals() { - var d1 = new Undefined(); - var d2 = new Undefined(); + var d1 = default(Undefined); + var d2 = default(Undefined); Assert.Equal(Bool.Undefined, d1 == d2); Assert.Equal(Bool.Undefined, d1 != d2); - Assert.Equal(Bool.Undefined, Bool.True == d1); - Assert.Equal(Bool.Undefined, Bool.False == d1); Assert.Equal(Bool.Undefined, d1 == Bool.True); Assert.Equal(Bool.Undefined, d1 == Bool.False); } @@ -47,8 +45,8 @@ public void TestTypes() [Unit] public void TestArthimetic() { - var d1 = new Undefined(); - var d2 = new Undefined(); + var d1 = default(Undefined); + var d2 = default(Undefined); Assert.Equal(double.NaN, d1 + 12.34); Assert.Equal(double.NaN, 12.34 + d1); @@ -71,23 +69,23 @@ public void TestArthimetic() [Unit] public void TestComparison() { - var d1 = new Undefined(); - var d2 = new Undefined(); + var d1 = default(Undefined); + var d2 = default(Undefined); Assert.Equal(Bool.Undefined, d1 < 12.34); - Assert.Equal(Bool.Undefined, 12.34 < d1); + Assert.Equal(Bool.Undefined, d1 > 12.34); Assert.Equal(Bool.Undefined, d1 < d2); Assert.Equal(Bool.Undefined, d1 > 12.34); - Assert.Equal(Bool.Undefined, 12.34 > d1); + Assert.Equal(Bool.Undefined, d1 < 12.34); Assert.Equal(Bool.Undefined, d1 > d2); Assert.Equal(Bool.Undefined, d1 <= 12.34); - Assert.Equal(Bool.Undefined, 12.34 <= d1); + Assert.Equal(Bool.Undefined, d1 >= 12.34); Assert.Equal(Bool.Undefined, d1 <= d2); Assert.Equal(Bool.Undefined, d1 >= 12.34); - Assert.Equal(Bool.Undefined, 12.34 >= d1); + Assert.Equal(Bool.Undefined, d1 <= 12.34); Assert.Equal(Bool.Undefined, d1 >= d2); } diff --git a/edge-modules/DirectMethodCloudSender/src/Program.cs b/edge-modules/DirectMethodCloudSender/src/Program.cs index 0047cc4c88f..e8225e0dfca 100644 --- a/edge-modules/DirectMethodCloudSender/src/Program.cs +++ b/edge-modules/DirectMethodCloudSender/src/Program.cs @@ -9,10 +9,10 @@ namespace DirectMethodCloudSender using System.Threading.Tasks; using Microsoft.Azure.Devices; using Microsoft.Azure.Devices.Client; + using Microsoft.Azure.Devices.Edge.ModuleUtil; using Microsoft.Azure.Devices.Edge.Util; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; - using Microsoft.Azure.Devices.Edge.ModuleUtil; using IotHubConnectionStringBuilder = Microsoft.Azure.Devices.IotHubConnectionStringBuilder; using Message = Microsoft.Azure.Devices.Client.Message; using TransportType = Microsoft.Azure.Devices.Client.TransportType; diff --git a/edge-modules/DirectMethodReceiver/src/Program.cs b/edge-modules/DirectMethodReceiver/src/Program.cs index 63486cba311..8aaf476c97b 100644 --- a/edge-modules/DirectMethodReceiver/src/Program.cs +++ b/edge-modules/DirectMethodReceiver/src/Program.cs @@ -7,10 +7,10 @@ namespace DirectMethodReceiver using System.Threading; using System.Threading.Tasks; using Microsoft.Azure.Devices.Client; + using Microsoft.Azure.Devices.Edge.ModuleUtil; using Microsoft.Azure.Devices.Edge.Util; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; - using Microsoft.Azure.Devices.Edge.ModuleUtil; class Program { diff --git a/edge-modules/DirectMethodSender/src/Program.cs b/edge-modules/DirectMethodSender/src/Program.cs index b19f50c8906..1fc0f3b822b 100644 --- a/edge-modules/DirectMethodSender/src/Program.cs +++ b/edge-modules/DirectMethodSender/src/Program.cs @@ -8,10 +8,10 @@ namespace DirectMethodSender using System.Threading; using System.Threading.Tasks; using Microsoft.Azure.Devices.Client; + using Microsoft.Azure.Devices.Edge.ModuleUtil; using Microsoft.Azure.Devices.Edge.Util; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; - using Microsoft.Azure.Devices.Edge.ModuleUtil; class Program { diff --git a/edge-modules/SimulatedTemperatureSensor/src/Program.cs b/edge-modules/SimulatedTemperatureSensor/src/Program.cs index e4c5b7362e4..9fe1190d76f 100644 --- a/edge-modules/SimulatedTemperatureSensor/src/Program.cs +++ b/edge-modules/SimulatedTemperatureSensor/src/Program.cs @@ -8,12 +8,11 @@ namespace SimulatedTemperatureSensor using System.Threading; using System.Threading.Tasks; using Microsoft.Azure.Devices.Client; + using Microsoft.Azure.Devices.Edge.ModuleUtil; using Microsoft.Azure.Devices.Edge.Util; using Microsoft.Azure.Devices.Edge.Util.Concurrency; using Microsoft.Azure.Devices.Shared; using Microsoft.Extensions.Configuration; - using Microsoft.Extensions.Logging; - using Microsoft.Azure.Devices.Edge.ModuleUtil; using Newtonsoft.Json; class Program diff --git a/edge-modules/TemperatureFilter/Program.cs b/edge-modules/TemperatureFilter/Program.cs index 905d236cd84..d741ef0f52b 100644 --- a/edge-modules/TemperatureFilter/Program.cs +++ b/edge-modules/TemperatureFilter/Program.cs @@ -8,11 +8,11 @@ namespace TemperatureFilter using System.Threading; using System.Threading.Tasks; using Microsoft.Azure.Devices.Client; + using Microsoft.Azure.Devices.Edge.ModuleUtil; using Microsoft.Azure.Devices.Edge.Util; using Microsoft.Azure.Devices.Shared; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; - using Microsoft.Azure.Devices.Edge.ModuleUtil; using Newtonsoft.Json; class Program diff --git a/edge-modules/load-gen/Program.cs b/edge-modules/load-gen/Program.cs index 43f8c4f8d75..18c34c3d7f3 100644 --- a/edge-modules/load-gen/Program.cs +++ b/edge-modules/load-gen/Program.cs @@ -6,12 +6,11 @@ namespace LoadGen using System.Threading; using System.Threading.Tasks; using Microsoft.Azure.Devices.Client; + using Microsoft.Azure.Devices.Edge.ModuleUtil; using Microsoft.Azure.Devices.Edge.Util; using Microsoft.Azure.Devices.Shared; using Microsoft.Extensions.Logging; - using Microsoft.Azure.Devices.Edge.ModuleUtil; using Newtonsoft.Json; - using ILogger = Microsoft.Extensions.Logging.ILogger; class Program { diff --git a/edge-util/src/Microsoft.Azure.Devices.Edge.Util/concurrency/AsyncLock.cs b/edge-util/src/Microsoft.Azure.Devices.Edge.Util/concurrency/AsyncLock.cs index 93cdc2dd2dc..37d36b2bc1d 100644 --- a/edge-util/src/Microsoft.Azure.Devices.Edge.Util/concurrency/AsyncLock.cs +++ b/edge-util/src/Microsoft.Azure.Devices.Edge.Util/concurrency/AsyncLock.cs @@ -52,7 +52,7 @@ public Releaser(AsyncLock toRelease) public void Dispose() { - if (0 == Interlocked.Exchange(ref this.disposed, 1)) + if (Interlocked.Exchange(ref this.disposed, 1) == 0) { this.toRelease.semaphore.Release(); } diff --git a/edge-util/src/Microsoft.Azure.Devices.Edge.Util/uds/UnixDomainSocketEndPoint.cs b/edge-util/src/Microsoft.Azure.Devices.Edge.Util/uds/UnixDomainSocketEndPoint.cs index d3ae7f70430..0ab9af42e49 100644 --- a/edge-util/src/Microsoft.Azure.Devices.Edge.Util/uds/UnixDomainSocketEndPoint.cs +++ b/edge-util/src/Microsoft.Azure.Devices.Edge.Util/uds/UnixDomainSocketEndPoint.cs @@ -11,17 +11,17 @@ sealed class UnixDomainSocketEndPoint : EndPoint { const AddressFamily EndPointAddressFamily = AddressFamily.Unix; - static readonly Encoding s_pathEncoding = Encoding.UTF8; + static readonly Encoding PathEncoding = Encoding.UTF8; - static readonly int s_nativePathOffset = 2; // = offsetof(struct sockaddr_un, sun_path). It's the same on Linux and OSX + static readonly int NativePathOffset = 2; // = offsetof(struct sockaddr_un, sun_path). It's the same on Linux and OSX - static readonly int s_nativePathLength = 91; // sockaddr_un.sun_path at http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_un.h.html, -1 for terminator + static readonly int NativePathLength = 91; // sockaddr_un.sun_path at http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_un.h.html, -1 for terminator - static readonly int s_nativeAddressSize = s_nativePathOffset + s_nativePathLength; + static readonly int NativeAddressSize = NativePathOffset + NativePathLength; - readonly string _path; + readonly string path; - readonly byte[] _encodedPath; + readonly byte[] encodedPath; public UnixDomainSocketEndPoint(string path) { @@ -30,10 +30,10 @@ public UnixDomainSocketEndPoint(string path) throw new ArgumentNullException(nameof(path)); } - this._path = path; - this._encodedPath = s_pathEncoding.GetBytes(this._path); + this.path = path; + this.encodedPath = PathEncoding.GetBytes(this.path); - if (path.Length == 0 || this._encodedPath.Length > s_nativePathLength) + if (path.Length == 0 || this.encodedPath.Length > NativePathLength) { throw new ArgumentOutOfRangeException(nameof(path), path); } @@ -47,25 +47,25 @@ internal UnixDomainSocketEndPoint(SocketAddress socketAddress) } if (socketAddress.Family != EndPointAddressFamily || - socketAddress.Size > s_nativeAddressSize) + socketAddress.Size > NativeAddressSize) { throw new ArgumentOutOfRangeException(nameof(socketAddress)); } - if (socketAddress.Size > s_nativePathOffset) + if (socketAddress.Size > NativePathOffset) { - this._encodedPath = new byte[socketAddress.Size - s_nativePathOffset]; - for (int i = 0; i < this._encodedPath.Length; i++) + this.encodedPath = new byte[socketAddress.Size - NativePathOffset]; + for (int i = 0; i < this.encodedPath.Length; i++) { - this._encodedPath[i] = socketAddress[s_nativePathOffset + i]; + this.encodedPath[i] = socketAddress[NativePathOffset + i]; } - this._path = s_pathEncoding.GetString(this._encodedPath, 0, this._encodedPath.Length); + this.path = PathEncoding.GetString(this.encodedPath, 0, this.encodedPath.Length); } else { - this._encodedPath = Array.Empty(); - this._path = string.Empty; + this.encodedPath = Array.Empty(); + this.path = string.Empty; } } @@ -73,21 +73,21 @@ internal UnixDomainSocketEndPoint(SocketAddress socketAddress) public override SocketAddress Serialize() { - var result = new SocketAddress(AddressFamily.Unix, s_nativeAddressSize); - Debug.Assert(this._encodedPath.Length + s_nativePathOffset <= result.Size, "Expected path to fit in address"); + var result = new SocketAddress(AddressFamily.Unix, NativeAddressSize); + Debug.Assert(this.encodedPath.Length + NativePathOffset <= result.Size, "Expected path to fit in address"); - for (int index = 0; index < this._encodedPath.Length; index++) + for (int index = 0; index < this.encodedPath.Length; index++) { - result[s_nativePathOffset + index] = this._encodedPath[index]; + result[NativePathOffset + index] = this.encodedPath[index]; } - result[s_nativePathOffset + this._encodedPath.Length] = 0; // path must be null-terminated + result[NativePathOffset + this.encodedPath.Length] = 0; // path must be null-terminated return result; } public override EndPoint Create(SocketAddress socketAddress) => new UnixDomainSocketEndPoint(socketAddress); - public override string ToString() => this._path; + public override string ToString() => this.path; } } diff --git a/stylecop.ruleset b/stylecop.ruleset index 5cb7a821677..23f5b0a55b9 100644 --- a/stylecop.ruleset +++ b/stylecop.ruleset @@ -1,36 +1,29 @@ - + - - + - - - - - - - - - - - - - - + + + + + + + + - + - + - + - + \ No newline at end of file diff --git a/test/Microsoft.Azure.Devices.Edge.Test.Common/EdgeLogs.cs b/test/Microsoft.Azure.Devices.Edge.Test.Common/EdgeLogs.cs index 13174954cbc..ab5a2f499f2 100644 --- a/test/Microsoft.Azure.Devices.Edge.Test.Common/EdgeLogs.cs +++ b/test/Microsoft.Azure.Devices.Edge.Test.Common/EdgeLogs.cs @@ -2,9 +2,9 @@ namespace Microsoft.Azure.Devices.Edge.Test.Common { using System; - using System.Linq; using System.Collections.Generic; using System.IO; + using System.Linq; using System.Threading; using System.Threading.Tasks;