public static SecureString GetSecureString(NSM.ResourceExtensionParameterValue item)
        {
            SecureString secureStr = null;

            bool isPrivate = string.Equals(
                item.Type,
                PrivateTypeStr,
                StringComparison.OrdinalIgnoreCase);

            if (item != null && isPrivate)
            {
                secureStr = GetSecureString(item.Value);
            }

            return secureStr;
        }
        public static string GetPlainString(NSM.ResourceExtensionParameterValue item)
        {
            string str = null;

            bool isPublic = string.Equals(
                item.Type,
                PublicTypeStr,
                StringComparison.OrdinalIgnoreCase);

            if (item != null && isPublic)
            {
                str = item.Value;
            }

            return str;
        }
        /// <summary>
        /// Creates dsc extension status object for a virtual machine
        /// </summary>
        /// <param name="vmRole">Details of a role in the deployment</param>
        /// <param name="roleInstance">Details of a specific role instance</param>
        /// <returns></returns>
        internal VirtualMachineDscExtensionStatusContext CreateDscStatusContext(NSM.Role vmRole, NSM.RoleInstance roleInstance) 
        {
            var message = string.Empty;
            var extension = VirtualMachineDscExtensionCmdletBase.ExtensionPublishedNamespace + "." 
                               + VirtualMachineDscExtensionCmdletBase.ExtensionPublishedName;
            NSM.ResourceExtensionConfigurationStatus extensionSettingStatus = null;
            
            if (roleInstance != null && roleInstance.ResourceExtensionStatusList != null)
            {
                foreach (var resourceExtensionStatus in 
                    roleInstance.ResourceExtensionStatusList.Where(
                    resourceExtensionStatus => resourceExtensionStatus.HandlerName.Equals(
                        extension, StringComparison.InvariantCultureIgnoreCase)).
                        Where(resourceExtensionStatus => resourceExtensionStatus.ExtensionSettingStatus != null))
                {
                    extensionSettingStatus = resourceExtensionStatus.ExtensionSettingStatus;

                    if (extensionSettingStatus.SubStatusList == null) continue;
                    var resourceExtensionSubStatusList = extensionSettingStatus.SubStatusList;
                    var resourceExtensionSubStatus = resourceExtensionSubStatusList.FirstOrDefault();
                    if (resourceExtensionSubStatus == null || resourceExtensionSubStatus.FormattedMessage == null ||
                        resourceExtensionSubStatus.FormattedMessage.Message == null) continue;
                    message = resourceExtensionSubStatus.FormattedMessage.Message.ToString(CultureInfo.CurrentUICulture);
                    break;
                }
            }

            if (extensionSettingStatus == null)
                return null;

            var dscStatusContext = new VirtualMachineDscExtensionStatusContext
            {
                ServiceName = Service,
                Name = vmRole == null ? string.Empty : vmRole.RoleName,
                Status = extensionSettingStatus.Status ?? string.Empty,
                StatusCode = extensionSettingStatus.Code ?? -1,
                StatusMessage = (extensionSettingStatus.FormattedMessage == null || 
                    extensionSettingStatus.FormattedMessage.Message == null) ? string.Empty : 
                    extensionSettingStatus.FormattedMessage.Message.ToString(CultureInfo.CurrentUICulture),
                DscConfigurationLog = !string.Empty.Equals(message) ? message.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None) : new List<String>().ToArray(),
                Timestamp = extensionSettingStatus.Timestamp == null ? DateTime.MinValue : extensionSettingStatus.Timestamp.Value
            };
            return dscStatusContext;
        }
        /// <summary>
        /// Retrieves dsc extension status for all virtual machine's in a cloud service or a given virtual machine from the deployment object
        /// </summary>
        /// <param name="deployment">Deployment that exists in the service</param>
        /// <returns></returns>
        internal List<VirtualMachineDscExtensionStatusContext> GetVirtualMachineDscStatusContextList(NSM.DeploymentGetResponse deployment)
        {
            var vmDscStatusContexts = new List<VirtualMachineDscExtensionStatusContext>();
            
            //filter the deployment info for a vm, if specified. 
            var vmRoles = new List<NSM.Role>(deployment.Roles.Where(
                r => (string.IsNullOrEmpty(Name) && string.IsNullOrEmpty(VmName))
                  || r.RoleName.Equals(Name, StringComparison.InvariantCultureIgnoreCase) 
                  || r.RoleName.Equals(VmName, StringComparison.InvariantCultureIgnoreCase)));

            foreach (var vm in vmRoles)
            {
                var roleInstance = deployment.RoleInstances.FirstOrDefault(
                    r => r.RoleName == vm.RoleName);

                if (roleInstance == null)
                {
                    WriteWarning(
                        string.Format(CultureInfo.CurrentUICulture, Resources.RoleInstanceCanNotBeFoundWithName, vm.RoleName));
                }

                var vmDscStatusContext = CreateDscStatusContext(
                    vm,
                    roleInstance);

                if (vmDscStatusContext != null)
                    vmDscStatusContexts.Add(vmDscStatusContext);
            }

            return vmDscStatusContexts;
        }
 private List<NSM.ResourceExtensionSubStatus> CreateResourceExtensionSubStatus(int code,
     NSM.GuestAgentFormattedMessage formattedMessage)
 {
     var resourceExtensionSubStatusList = new List<NSM.ResourceExtensionSubStatus>();
     var resourceExtensionSubStatus = new NSM.ResourceExtensionSubStatus
     {
         Code = code,
         FormattedMessage = formattedMessage,
         Status = "Success",
         Name = "DSC Status"
     };
     resourceExtensionSubStatusList.Add(resourceExtensionSubStatus);
     return resourceExtensionSubStatusList;
 }