internal void ExecuteCommand()
        {
            List <ResourceExtensionReference> extensionRefs = GetPredicateExtensionList();

            WriteObject(
                extensionRefs == null ? null : extensionRefs.Select(
                    r =>
            {
                GetExtensionValues(r);
                DscPublicSettings publicSettings = null;
                try
                {
                    publicSettings = DscSettingsSerializer.DeserializePublicSettings(PublicConfiguration);
                }
                catch (JsonException e)
                {
                    this.ThrowTerminatingError(
                        new ErrorRecord(
                            new JsonException(
                                String.Format(
                                    CultureInfo.CurrentUICulture,
                                    Properties.Resources.AzureVMDscWrongSettingsFormat,
                                    PublicConfiguration),
                                e),
                            string.Empty,
                            ErrorCategory.ParserError,
                            null));
                }
                var context = new VirtualMachineDscExtensionContext
                {
                    ExtensionName        = r.Name,
                    Publisher            = r.Publisher,
                    ReferenceName        = r.ReferenceName,
                    Version              = r.Version,
                    State                = r.State,
                    RoleName             = VM.GetInstance().RoleName,
                    PublicConfiguration  = PublicConfiguration,
                    PrivateConfiguration = SecureStringHelper.GetSecureString(PrivateConfiguration)
                };

                if (publicSettings == null)
                {
                    context.ModulesUrl            = string.Empty;
                    context.ConfigurationFunction = string.Empty;
                    context.Properties            = null;
                }
                else
                {
                    context.ModulesUrl            = publicSettings.ModulesUrl;
                    context.ConfigurationFunction = publicSettings.ConfigurationFunction;
                    context.Properties            = new Hashtable(publicSettings.Properties.ToDictionary(x => x.Name, x => x.Value));
                }

                return(context);
            }

                    ).FirstOrDefault());
        }
Example #2
0
        /// <summary>
        /// Helper function for tests.
        /// </summary>
        /// <param name="configurationArguments"></param>
        /// <param name="privateSettings"></param>
        /// <returns></returns>
        private static DscPublicSettings GetPublicPrivateAfterDeseriazlization(
            Hashtable configurationArguments,
            out DscPrivateSettings privateSettings)
        {
            Tuple <DscPublicSettings.Property[], Hashtable> separatedSettings =
                DscSettingsSerializer.SeparatePrivateItems(configurationArguments);
            DscPublicSettings publicSettings = new DscPublicSettings();

            privateSettings           = new DscPrivateSettings();
            publicSettings.Properties = separatedSettings.Item1;
            privateSettings.Items     = separatedSettings.Item2;

            string serializedPublic  = DscSettingsSerializer.SerializePublicSettings(publicSettings);
            string serializedPrivate = DscSettingsSerializer.SerializePrivateSettings(privateSettings);

            publicSettings  = DscSettingsSerializer.DeserializePublicSettings(serializedPublic);
            privateSettings = DeserializePrivateSettings(serializedPrivate);
            return(publicSettings);
        }