Beispiel #1
0
        object DoPSPassThroughConversion <T>(T objectToConvert)
        {
            string content       = PSSerializer.Serialize(objectToConvert, 10);
            var    reconstituted = PSSerializer.Deserialize(content);
            var    converter     = new AzureContextConverter();

            Assert.True(converter.CanConvertFrom(reconstituted, typeof(IAzureContextContainer)));
            return(converter.ConvertFrom(reconstituted, typeof(IAzureContextContainer), CultureInfo.InvariantCulture, true));
        }
        static IAzureContext GetDefaultContext(IProfileProvider provider, System.Management.Automation.InvocationInfo invocationInfo)
        {
            IAzureContextContainer context;
            var contextConverter = new AzureContextConverter();

            if (invocationInfo.BoundParameters.ContainsKey("DefaultContext") &&
                contextConverter.CanConvertFrom(invocationInfo.BoundParameters["DefaultContext"], typeof(IAzureContextContainer)))
            {
                context = contextConverter.ConvertFrom(invocationInfo.BoundParameters["DefaultContext"], typeof(IAzureContextContainer), CultureInfo.InvariantCulture, true) as IAzureContextContainer;
            }
            else
            {
                context = provider.Profile;
            }

            return(context?.DefaultContext);
        }
        private static IAzureContext GetDefaultContext(IProfileProvider provider, InvocationInfo invocationInfo)
        {
            IAzureContextContainer profile;
            var contextConverter = new AzureContextConverter();

            if (invocationInfo.BoundParameters.ContainsKey("DefaultContext") &&
                contextConverter.CanConvertFrom(invocationInfo.BoundParameters["DefaultContext"], typeof(IAzureContextContainer)))
            {
                profile = contextConverter.ConvertFrom(invocationInfo.BoundParameters["DefaultContext"], typeof(IAzureContextContainer), CultureInfo.InvariantCulture, true) as IAzureContextContainer;
            }
            else
            {
                profile = provider.Profile;
            }

            return(profile?.DefaultContext);
        }