diff --git a/src/CosmosDB/CosmosDB/ChangeLog.md b/src/CosmosDB/CosmosDB/ChangeLog.md index 56a02c6464d9..3b20819ebcaa 100644 --- a/src/CosmosDB/CosmosDB/ChangeLog.md +++ b/src/CosmosDB/CosmosDB/ChangeLog.md @@ -19,7 +19,7 @@ --> ## Upcoming Release -* Use invariant culture to serialize timestamp into query string when call Restore-AzCosmosDBAccount. +* Serialized timestamp into query string by invariant culture for `Restore-AzCosmosDBAccount` and `Restore-AzCosmosDBTable`. ## Version 1.15.0 * Added new parameter `DisableTtl` to `Restore-AzCosmosDBAccount`. diff --git a/src/CosmosDB/CosmosDB/CosmosDBAccount/RestoreAzCosmosDBAccount.cs b/src/CosmosDB/CosmosDB/CosmosDBAccount/RestoreAzCosmosDBAccount.cs index 72423c0aa09d..fed4c99d098b 100644 --- a/src/CosmosDB/CosmosDB/CosmosDBAccount/RestoreAzCosmosDBAccount.cs +++ b/src/CosmosDB/CosmosDB/CosmosDBAccount/RestoreAzCosmosDBAccount.cs @@ -12,19 +12,20 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using System; -using System.Collections; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Globalization; -using System.Linq; -using System.Management.Automation; +using Microsoft.Azure.Commands.Common; using Microsoft.Azure.Commands.CosmosDB.Helpers; using Microsoft.Azure.Commands.CosmosDB.Models; using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; using Microsoft.Azure.Management.CosmosDB.Models; -using Microsoft.Extensions.Azure; + using Newtonsoft.Json.Converters; + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Management.Automation; + using SDKModel = Microsoft.Azure.Management.CosmosDB.Models; namespace Microsoft.Azure.Commands.CosmosDB @@ -139,7 +140,7 @@ public override void ExecuteCmdlet() sourceAccountToRestore.Location, sourceAccountToRestore.Name, Location, - utcRestoreDateTime.ToString("M/dd/yyyy h:mm:ss tt")).GetAwaiter().GetResult().Body; + utcRestoreDateTime.ToInvariantString()).GetAwaiter().GetResult().Body; restorableResourcesNotFound = restorableResources == null || !restorableResources.Any(); } @@ -157,7 +158,7 @@ public override void ExecuteCmdlet() sourceAccountToRestore.Location, sourceAccountToRestore.Name, Location, - utcRestoreDateTime.ToString("M/dd/yyyy h:mm:ss tt")).GetAwaiter().GetResult().Body; + utcRestoreDateTime.ToInvariantString()).GetAwaiter().GetResult().Body; restorableResourcesNotFound = restorableResources == null || !restorableResources.Any(); } @@ -175,7 +176,7 @@ public override void ExecuteCmdlet() sourceAccountToRestore.Location, sourceAccountToRestore.Name, Location, - utcRestoreDateTime.ToString("M/dd/yyyy h:mm:ss tt")).GetAwaiter().GetResult().Body; + utcRestoreDateTime.ToInvariantString()).GetAwaiter().GetResult().Body; restorableResourcesNotFound = restorableResources == null || !restorableResources.Any(); } @@ -193,7 +194,7 @@ public override void ExecuteCmdlet() sourceAccountToRestore.Location, sourceAccountToRestore.Name, Location, - utcRestoreDateTime.ToString("M/dd/yyyy h:mm:ss tt")).GetAwaiter().GetResult().Body; + utcRestoreDateTime.ToInvariantString()).GetAwaiter().GetResult().Body; restorableResourcesNotFound = restorableResources == null || !restorableResources.Any(); } diff --git a/src/CosmosDB/CosmosDB/Table/RestoreAzCosmosDBTable.cs b/src/CosmosDB/CosmosDB/Table/RestoreAzCosmosDBTable.cs index bf48d702228f..4c92ae9e5187 100644 --- a/src/CosmosDB/CosmosDB/Table/RestoreAzCosmosDBTable.cs +++ b/src/CosmosDB/CosmosDB/Table/RestoreAzCosmosDBTable.cs @@ -15,6 +15,7 @@ using System; using System.Collections.Generic; using System.Management.Automation; +using Microsoft.Azure.Commands.Common; using Microsoft.Azure.Commands.CosmosDB.Models; using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; using Microsoft.Azure.Management.CosmosDB.Models; @@ -169,7 +170,7 @@ public override void ExecuteCmdlet() string accountInstanceId = databaseAccount.Name; - IEnumerable restorableTables = CosmosDBManagementClient.RestorableTables.ListWithHttpMessagesAsync(databaseAccount.Location, accountInstanceId, databaseAccount.CreationTime?.ToString("M/dd/yyyy h:mm:ss tt"), DateTime.MaxValue.ToString("M/dd/yyyy h:mm:ss tt")).GetAwaiter().GetResult().Body; + IEnumerable restorableTables = CosmosDBManagementClient.RestorableTables.ListWithHttpMessagesAsync(databaseAccount.Location, accountInstanceId, databaseAccount.CreationTime?.ToInvariantString(), DateTime.MaxValue.ToInvariantString()).GetAwaiter().GetResult().Body; (DateTime latestDatabaseDeleteTime, DateTime latestDatabaseCreateOrRecreateTime, string databaseRid) = ProcessRestorableDatabases(restorableTables); if (databaseRid == null) diff --git a/src/Monitor/Monitor.Test/CustomPrinterTests.cs b/src/Monitor/Monitor.Test/CustomPrinterTests.cs index c41544f83ee2..17e06c66d358 100644 --- a/src/Monitor/Monitor.Test/CustomPrinterTests.cs +++ b/src/Monitor/Monitor.Test/CustomPrinterTests.cs @@ -12,13 +12,15 @@ // limitations under the License. // ---------------------------------------------------------------------------------- +using Microsoft.Azure.Commands.Common; +using Microsoft.Azure.ServiceManagement.Common.Models; +using Microsoft.WindowsAzure.Commands.ScenarioTest; + using System; -using System.Globalization; using System.Collections.Generic; using System.Diagnostics; using System.Xml; -using Microsoft.Azure.ServiceManagement.Common.Models; -using Microsoft.WindowsAzure.Commands.ScenarioTest; + using Xunit; using Xunit.Abstractions; @@ -51,10 +53,10 @@ public void CustomPrinterTest_SimpleTypes() Assert.Equal(" : " + XmlConvert.ToString(ts) + Environment.NewLine, OutputClasses.CustomPrinter.Print(ts)); // Must be dt.ToUniversalTime().ToString("O") in the future - Assert.Equal(" : " + dt.ToString(CultureInfo.InvariantCulture) + Environment.NewLine, OutputClasses.CustomPrinter.Print(dt)); + Assert.Equal(" : " + dt.ToInvariantString() + Environment.NewLine, OutputClasses.CustomPrinter.Print(dt)); // Must be dtUtc.ToString("O") in the future - Assert.Equal(" : " + dtUtc.ToString(CultureInfo.InvariantCulture) + Environment.NewLine, OutputClasses.CustomPrinter.Print(dtUtc)); + Assert.Equal(" : " + dtUtc.ToInvariantString() + Environment.NewLine, OutputClasses.CustomPrinter.Print(dtUtc)); // Both must be string.Empty in the future Assert.Equal($" :{Environment.NewLine}", OutputClasses.CustomPrinter.Print(null)); @@ -87,7 +89,7 @@ public void CustomPrinterTest_ComplexTypes() // Must be [\r\nAuthorization : [\r\n Action : PUT\r\n Role : Sender\r\n Scope : None\r\n ]\r\nClaims : {\r\n [aud, https://management.core.windows.net/]\r\n [iss, https://sts.windows.net/123456/]\r\n [iat, h123445]\r\n }\r\nCaller : caller\r\nDescription : fake event\r\nId : ac7d2ab5-698a-4c33-9c19-0a93d3d7f527\r\nEventDataId : \r\nCorrelationId : correlation\r\nEventName : [\r\n Value : Start request\r\n LocalizedValue : Start request\r\n ]\r\nCategory : [\r\n Value : Microsoft Resources\r\n LocalizedValue : Microsoft Resources\r\n ]\r\nHttpRequest : [\r\n ClientRequestId : 1234\r\n ClientIpAddress : 123.123.123.123\r\n Method : PUT\r\n Uri : http://path/subscriptions/ffce8037-a374-48bf-901d-dac4e3ea8c09/resourcegroups/foo/deployments/testdeploy\r\n ]\r\nLevel : Informational\r\nResourceGroupName : Default-Web-EastUS\r\nResourceProviderName : [\r\n Value : Microsoft Resources\r\n LocalizedValue : Microsoft Resources\r\n ]\r\nResourceId : /subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/garyyang1\r\nResourceType : \r\nOperationId : c0f2e85f-efb0-47d0-bf90-f983ec8be91d\r\nOperationName : [\r\n Value : Microsoft.Resources/subscriptions/resourcegroups/deployments/write\r\n LocalizedValue : Microsoft.Resources/subscriptions/resourcegroups/deployments/write\r\n ]\r\nProperties : {}\r\nStatus : [\r\n Value : Succeeded\r\n LocalizedValue : Succeeded\r\n ]\r\nSubStatus : [\r\n Value : Created\r\n LocalizedValue : Created\r\n ]\r\nEventTimestamp : 2017-06-07T22:54:00.0000000Z\r\nSubmissionTimestamp : 2017-06-07T22:54:00.0000000Z\r\nSubscriptionId : \r\nTenantId : \r\n] in the future Assert.Equal( - expected: $"Authorization {Environment.NewLine}Action : PUT{Environment.NewLine}Role : Sender{Environment.NewLine}Scope : None{Environment.NewLine}{Environment.NewLine}Claims {Environment.NewLine} : [aud, https://management.core.windows.net/]{Environment.NewLine} : [iss, https://sts.windows.net/123456/]{Environment.NewLine} : [iat, h123445]{Environment.NewLine}Caller : caller{Environment.NewLine}Description : fake event{Environment.NewLine}Id : ac7d2ab5-698a-4c33-9c19-0a93d3d7f527{Environment.NewLine}EventDataId :{Environment.NewLine}CorrelationId : correlation{Environment.NewLine}EventName {Environment.NewLine}Value : Start request{Environment.NewLine}LocalizedValue : Start request{Environment.NewLine}{Environment.NewLine}Category {Environment.NewLine}Value : Microsoft Resources{Environment.NewLine}LocalizedValue : Microsoft Resources{Environment.NewLine}{Environment.NewLine}HttpRequest {Environment.NewLine}ClientRequestId : 1234{Environment.NewLine}ClientIpAddress : 123.123.123.123{Environment.NewLine}Method : PUT{Environment.NewLine}Uri : http://path/subscriptions/ffce8037-a374-48bf-901d-dac4e3ea8c09/resourcegroups/foo/deployments/testdeploy{Environment.NewLine}{Environment.NewLine}Level : Informational{Environment.NewLine}ResourceGroupName : Default-Web-EastUS{Environment.NewLine}ResourceProviderName{Environment.NewLine}Value : Microsoft Resources{Environment.NewLine}LocalizedValue : Microsoft Resources{Environment.NewLine}{Environment.NewLine}ResourceId : /subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/garyyang1{Environment.NewLine}ResourceType :{Environment.NewLine}OperationId : c0f2e85f-efb0-47d0-bf90-f983ec8be91d{Environment.NewLine}OperationName {Environment.NewLine}Value : Microsoft.Resources/subscriptions/resourcegroups/deployments/write{Environment.NewLine}LocalizedValue : Microsoft.Resources/subscriptions/resourcegroups/deployments/write{Environment.NewLine}{Environment.NewLine}Properties {Environment.NewLine}Status {Environment.NewLine}Value : Succeeded{Environment.NewLine}LocalizedValue : Succeeded{Environment.NewLine}{Environment.NewLine}SubStatus {Environment.NewLine}Value : Created{Environment.NewLine}LocalizedValue : Created{Environment.NewLine}{Environment.NewLine}EventTimestamp : 06/07/{year} 22:54:00{Environment.NewLine}SubmissionTimestamp : 06/07/{year} 22:54:00{Environment.NewLine}SubscriptionId :{Environment.NewLine}TenantId :{Environment.NewLine}{Environment.NewLine}", + expected: $"Authorization {Environment.NewLine}Action : PUT{Environment.NewLine}Role : Sender{Environment.NewLine}Scope : None{Environment.NewLine}{Environment.NewLine}Claims {Environment.NewLine} : [aud, https://management.core.windows.net/]{Environment.NewLine} : [iss, https://sts.windows.net/123456/]{Environment.NewLine} : [iat, h123445]{Environment.NewLine}Caller : caller{Environment.NewLine}Description : fake event{Environment.NewLine}Id : ac7d2ab5-698a-4c33-9c19-0a93d3d7f527{Environment.NewLine}EventDataId :{Environment.NewLine}CorrelationId : correlation{Environment.NewLine}EventName {Environment.NewLine}Value : Start request{Environment.NewLine}LocalizedValue : Start request{Environment.NewLine}{Environment.NewLine}Category {Environment.NewLine}Value : Microsoft Resources{Environment.NewLine}LocalizedValue : Microsoft Resources{Environment.NewLine}{Environment.NewLine}HttpRequest {Environment.NewLine}ClientRequestId : 1234{Environment.NewLine}ClientIpAddress : 123.123.123.123{Environment.NewLine}Method : PUT{Environment.NewLine}Uri : http://path/subscriptions/ffce8037-a374-48bf-901d-dac4e3ea8c09/resourcegroups/foo/deployments/testdeploy{Environment.NewLine}{Environment.NewLine}Level : Informational{Environment.NewLine}ResourceGroupName : Default-Web-EastUS{Environment.NewLine}ResourceProviderName{Environment.NewLine}Value : Microsoft Resources{Environment.NewLine}LocalizedValue : Microsoft Resources{Environment.NewLine}{Environment.NewLine}ResourceId : /subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/garyyang1{Environment.NewLine}ResourceType :{Environment.NewLine}OperationId : c0f2e85f-efb0-47d0-bf90-f983ec8be91d{Environment.NewLine}OperationName {Environment.NewLine}Value : Microsoft.Resources/subscriptions/resourcegroups/deployments/write{Environment.NewLine}LocalizedValue : Microsoft.Resources/subscriptions/resourcegroups/deployments/write{Environment.NewLine}{Environment.NewLine}Properties {Environment.NewLine}Status {Environment.NewLine}Value : Succeeded{Environment.NewLine}LocalizedValue : Succeeded{Environment.NewLine}{Environment.NewLine}SubStatus {Environment.NewLine}Value : Created{Environment.NewLine}LocalizedValue : Created{Environment.NewLine}{Environment.NewLine}EventTimestamp : 6/7/{year} 10:54:00 PM{Environment.NewLine}SubmissionTimestamp : 6/7/{year} 10:54:00 PM{Environment.NewLine}SubscriptionId :{Environment.NewLine}TenantId :{Environment.NewLine}{Environment.NewLine}", actual: result); dictionarySS.Add("k1", "v1"); diff --git a/src/Monitor/Monitor/OutputClasses/CustomPrinter.cs b/src/Monitor/Monitor/OutputClasses/CustomPrinter.cs index 035753fc9bc5..fd197363ab41 100644 --- a/src/Monitor/Monitor/OutputClasses/CustomPrinter.cs +++ b/src/Monitor/Monitor/OutputClasses/CustomPrinter.cs @@ -19,6 +19,8 @@ using System.Text; using System.Xml; +using Microsoft.Azure.Commands.Common; + namespace Microsoft.Azure.Commands.Insights.OutputClasses { public static class CustomPrinter @@ -73,7 +75,7 @@ private static void Print(object obj, string name, string currentIndent, StringB sb.Append(" : "); if (obj is DateTime dateTime) { - sb.AppendLine(dateTime.ToString(System.Globalization.CultureInfo.InvariantCulture)); + sb.AppendLine(dateTime.ToInvariantString()); } else {