public void ExecuteCommand()
        {
            ValidateParameters();
            ExtensionConfigurationInput context = new ExtensionConfigurationInput
            {
                Version           = Version,
                ProviderNameSpace = ProviderNamespace,
                Type = ExtensionName,
                CertificateThumbprint = CertificateThumbprint,
                ThumbprintAlgorithm   = ThumbprintAlgorithm,
                X509Certificate       = X509Certificate,
                PublicConfiguration   = PublicConfiguration,
                PrivateConfiguration  = PrivateConfiguration,
                Roles = new ExtensionRoleList(Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)) : Enumerable.Repeat(new ExtensionRole(), 1))
            };

            var secondSlotDeployment = GetDeployment(this.Slot == DeploymentSlotType.Production ? DeploymentSlotType.Staging : DeploymentSlotType.Production);

            Microsoft.WindowsAzure.Management.Compute.Models.ExtensionConfiguration secondSlotExtensionConfiguration =
                secondSlotDeployment != null ? secondSlotDeployment.ExtensionConfiguration : null;

            var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration, secondSlotExtensionConfiguration);

            ChangeDeployment(extConfig);
        }
Exemple #2
0
        private void MergeAntimalwareMonitoringIntoExistingConfig(string existingConfigXmlStr)
        {
            // prepare a new xml document to hold the merged config
            XmlDocument mergedConfig = new XmlDocument();

            mergedConfig.LoadXml(existingConfigXmlStr);

            // check if old config already contains a WindowsEventLog section
            string targetNode;
            string mergeXmlStr;

            if (existingConfigXmlStr.Contains(DiagnosticsConfigWindowsEventLogNodeName))
            {
                // inject into the existing windows event log section
                targetNode  = DiagnosticsConfigWindowsEventLogNodeName;
                mergeXmlStr = DiagnosticsDefaultConfigMergeXmlWithExistingEventLogNode;
            }
            else
            {
                // inject a windows event log section with antimalware monitoring into the diagnostics config
                targetNode  = DiagnosticsConfigNodeName;
                mergeXmlStr = DiagnosticsDefaultConfigMergeXmlWithoutExistingEventLogNode;
            }

            // locate the desired target using xpath
            string  diagXPathStr = String.Format("//*[local-name()='{0}' and namespace-uri()='{1}']", targetNode, DiagnosticsConfigXmlNamespace);
            XmlNode diagNode     = mergedConfig.DocumentElement.SelectSingleNode(diagXPathStr);

            // create an import node and then append to the correct location
            XmlDocument diagnosticsConfigXml = new XmlDocument();

            diagnosticsConfigXml.LoadXml(mergeXmlStr);

            XmlNode importNode = mergedConfig.ImportNode(diagnosticsConfigXml.DocumentElement, true);

            diagNode.AppendChild(importNode);

            // Note : Currently any pre-existing user of the diagnostics configuration will be expected
            // to follow convention of specifying storage account name in the xml configuration so that
            // it can be persisted across configuration changes being made by multiple users.

            // remove any stray xmlns="" attribute from xml string prior to use
            string mergedConfiguration = mergedConfig.OuterXml.Replace(@"xmlns=""""", "");

            // set up for reinstall of the extension with the new configuration
            InitializeDiagnosticsSettings();
            AntimalwareMonitoringExtensionConfigurationInput = new ExtensionConfigurationInput
            {
                ProviderNameSpace = ProviderNamespace,
                Type = ExtensionName,
                CertificateThumbprint = CertificateThumbprint,
                ThumbprintAlgorithm   = ThumbprintAlgorithm,
                X509Certificate       = X509Certificate,
                PublicConfiguration   = mergedConfiguration,
                PrivateConfiguration  = PrivateConfiguration,
                Roles = new ExtensionRoleList(Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)) : Enumerable.Repeat(new ExtensionRole(), 1))
            };
        }
Exemple #3
0
        public void ExecuteCommand()
        {
            ValidateParameters();

            bool removeAll = Role == null || !Role.Any();
            ExtensionConfigurationBuilder configBuilder = ExtensionManager.GetBuilder(Deployment != null ? Deployment.ExtensionConfiguration : null);

            if ((UninstallConfiguration || removeAll) && configBuilder.ExistAny(ProviderNamespace, ExtensionName))
            {
                // Remove extension for all roles
                configBuilder.RemoveAny(ProviderNamespace, ExtensionName);
                WriteWarning(string.Format(Resources.ServiceExtensionRemovingFromAllRoles, ExtensionName, ServiceName));

                ChangeDeployment(configBuilder.ToConfiguration());
            }
            else if (!removeAll && configBuilder.Exist(Role, ProviderNamespace, ExtensionName))
            {
                // Remove extension for the specified roles
                bool defaultExists = configBuilder.ExistDefault(ProviderNamespace, ExtensionName);
                foreach (var r in Role)
                {
                    var singleRoleAsArray = new string[] { r };
                    if (configBuilder.Exist(singleRoleAsArray, ProviderNamespace, ExtensionName))
                    {
                        configBuilder.Remove(singleRoleAsArray, ProviderNamespace, ExtensionName);
                        WriteWarning(string.Format(Resources.ServiceExtensionRemovingFromSpecificRoles, ExtensionName, r, ServiceName));
                    }
                    else
                    {
                        WriteWarning(string.Format(Resources.ServiceExtensionNoExistingExtensionsEnabledOnRole, ProviderNamespace, ExtensionName, r));
                    }

                    if (defaultExists)
                    {
                        WriteWarning(string.Format(Resources.ServiceExtensionRemovingSpecificAndApplyingDefault, ExtensionName, r));
                    }
                }

                ChangeDeployment(configBuilder.ToConfiguration());
            }
            else
            {
                WriteWarning(string.Format(Resources.ServiceExtensionNoExistingExtensionsEnabledOnRoles, ProviderNamespace, ExtensionName));
            }

            if (UninstallConfiguration)
            {
                var allConfig      = ExtensionManager.GetBuilder();
                var deploymentList = (from slot in (new string[] { DeploymentSlot.Production.ToString(), DeploymentSlot.Staging.ToString() })
                                      let d = GetDeployment(slot)
                                              where d != null
                                              select d).ToList();
                deploymentList.ForEach(d => allConfig.Add(d.ExtensionConfiguration));
                ExtensionManager.Uninstall(ProviderNamespace, ExtensionName, allConfig.ToConfiguration());
            }
        }
    public void ExecuteCommand()
    {
        ValidateParameters();

        // prepare diagnostics extension
        switch (monitoringAction)
        {
        case MonitoringActionType.Enable: EnableMonitoring(); break;

        case MonitoringActionType.Disable: RemoveExistingAntimalwareMonitoringConfig(); break;

        default: break;
        }

        // prepare antimalware extension
        if (isAntimalwareEnabled)
        {
            InitializeAntimalwareSettings();
            ExtensionConfigurationInput amExtConfigInput = new ExtensionConfigurationInput
            {
                ProviderNameSpace = ProviderNamespace,
                Type = ExtensionName,
                PublicConfiguration  = PublicConfiguration,
                PrivateConfiguration = PrivateConfiguration,
                Roles = new ExtensionRoleList(Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)) : Enumerable.Repeat(new ExtensionRole(), 1))
            };
            AntimalwareExtensionConfigurationInput = amExtConfigInput;
        }

        // update extensions as appropriate
        ExtensionConfigurationInput[] extConfigInputs = null;
        if (AntimalwareExtensionConfigurationInput != null && AntimalwareMonitoringExtensionConfigurationInput != null)
        {
            extConfigInputs    = new ExtensionConfigurationInput[2];
            extConfigInputs[0] = AntimalwareMonitoringExtensionConfigurationInput;
            extConfigInputs[1] = AntimalwareExtensionConfigurationInput;
        }
        else if (AntimalwareExtensionConfigurationInput != null)
        {
            extConfigInputs    = new ExtensionConfigurationInput[1];
            extConfigInputs[0] = AntimalwareExtensionConfigurationInput;
        }
        else if (AntimalwareMonitoringExtensionConfigurationInput != null)
        {
            extConfigInputs    = new ExtensionConfigurationInput[1];
            extConfigInputs[0] = AntimalwareMonitoringExtensionConfigurationInput;
        }

        // process any pending deployment changes
        if (extConfigInputs != null)
        {
            ExtensionConfiguration newExtConfig = ExtensionManager.Add(Deployment, PeerDeployment, extConfigInputs, Slot);
            ChangeDeployment(newExtConfig);
        }
    }
Exemple #5
0
 public void ExecuteCommand()
 {
     ValidateParameters();
     WriteObject(new ExtensionConfigurationInput
     {
         CertificateThumbprint = CertificateThumbprint,
         ThumbprintAlgorithm   = ThumbprintAlgorithm,
         ProviderNameSpace     = ProviderNamespace,
         Type = ExtensionName,
         PublicConfiguration  = PublicConfiguration,
         PrivateConfiguration = PrivateConfiguration,
         X509Certificate      = X509Certificate,
         Roles = new ExtensionRoleList(Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)) : Enumerable.Repeat(new ExtensionRole(), 1))
     });
 }
 public void ExecuteCommand()
 {
     ValidateParameters();
     WriteObject(new ExtensionConfigurationInput
     {
         CertificateThumbprint = CertificateThumbprint,
         ThumbprintAlgorithm   = ThumbprintAlgorithm,
         ProviderNameSpace     = ExtensionNameSpace,
         Type = ExtensionType,
         PublicConfiguration  = string.Format(PublicConfigurationXmlTemplate.ToString(), Credential.UserName, Expiration.ToString("yyyy-MM-dd")),
         PrivateConfiguration = string.Format(PrivateConfigurationXmlTemplate.ToString(), Credential.Password.ConvertToUnsecureString()),
         X509Certificate      = X509Certificate,
         Roles = Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)).ToList() : new ExtensionRole[] { new ExtensionRole() }.ToList()
     });
 }
 public void ExecuteCommand()
 {
     ValidateParameters();
     WriteObject(new ExtensionConfigurationInput
     {
         CertificateThumbprint = CertificateThumbprint,
         ThumbprintAlgorithm = ThumbprintAlgorithm,
         ProviderNameSpace = ExtensionNameSpace,
         Type = ExtensionType,
         PublicConfiguration = string.Format(PublicConfigurationXmlTemplate.ToString(), ConnectionQualifiers, DefaultEndpointsProtocol, StorageAccountName, DiagnosticsConfiguration != null ? DiagnosticsConfiguration.InnerXml : ""),
         PrivateConfiguration = string.Format(PrivateConfigurationXmlTemplate.ToString(), StorageKey),
         X509Certificate = X509Certificate,
         Roles = Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)).ToList() : new ExtensionRole[] { new ExtensionRole() }.ToList()
     });
 }
Exemple #8
0
        protected void RemoveExtension()
        {
            ExtensionConfigurationBuilder configBuilder = ExtensionManager.GetBuilder(Deployment != null ? Deployment.ExtensionConfiguration : null);

            if (UninstallConfiguration && configBuilder.ExistAny(ProviderNamespace, ExtensionName))
            {
                configBuilder.RemoveAny(ProviderNamespace, ExtensionName);
                WriteWarning(string.Format(Resources.ServiceExtensionRemovingFromAllRoles, ExtensionName, ServiceName));
                ChangeDeployment(configBuilder.ToConfiguration());
            }
            else if (configBuilder.Exist(Role, ProviderNamespace, ExtensionName))
            {
                configBuilder.Remove(Role, ProviderNamespace, ExtensionName);
                if (Role == null || !Role.Any())
                {
                    WriteWarning(string.Format(Resources.ServiceExtensionRemovingFromAllRoles, ExtensionName, ServiceName));
                }
                else
                {
                    bool defaultExists = configBuilder.ExistDefault(ProviderNamespace, ExtensionName);
                    foreach (var r in Role)
                    {
                        WriteWarning(string.Format(Resources.ServiceExtensionRemovingFromSpecificRoles, ExtensionName, r, ServiceName));
                        if (defaultExists)
                        {
                            WriteWarning(string.Format(Resources.ServiceExtensionRemovingSpecificAndApplyingDefault, ExtensionName, r));
                        }
                    }
                }

                ChangeDeployment(configBuilder.ToConfiguration());
            }
            else
            {
                WriteWarning(string.Format(Resources.ServiceExtensionNoExistingExtensionsEnabledOnRoles, ProviderNamespace, ExtensionName));
            }

            if (UninstallConfiguration)
            {
                var allConfig      = ExtensionManager.GetBuilder();
                var deploymentList = (from slot in (new string[] { DeploymentSlot.Production.ToString(), DeploymentSlot.Staging.ToString() })
                                      let d = GetDeployment(slot)
                                              where d != null
                                              select d).ToList();
                deploymentList.ForEach(d => allConfig.Add(d.ExtensionConfiguration));
                ExtensionManager.Uninstall(ProviderNamespace, ExtensionName, allConfig.ToConfiguration());
            }
        }
Exemple #9
0
        // Telecom??

        public Classification ToClassification(string scheme, string parent)
        {
            var authorAttribute = new Classification
            {
                ClassificationScheme = scheme,
                ClassifiedObject     = parent,
                ObjectType           = ObjectType.Classification
            };

            if (Person != null)
            {
                authorAttribute.Slots.Add(new Slot
                {
                    Name   = "authorPerson",
                    Values = new List <string> {
                        Person.Hl7Person.Encode()
                    }
                });
            }

            if (Institution != null && Institution.Any())
            {
                authorAttribute.Slots.Add(new Slot
                {
                    Name   = "authorInstitution",
                    Values = Institution.Select(i => i.Hl7Organization.Encode()).ToList()
                });
            }

            if (Role != null && Role.Any(r => !string.IsNullOrEmpty(r)))
            {
                authorAttribute.Slots.Add(new Slot
                {
                    Name   = "authorRole",
                    Values = Role.Where(r => !string.IsNullOrEmpty(r)).ToList()
                });
            }

            if (Specialty != null && Specialty.Any(s => !string.IsNullOrEmpty(s)))
            {
                authorAttribute.Slots.Add(new Slot
                {
                    Name   = "authorSpecialty",
                    Values = Specialty.Where(s => !string.IsNullOrEmpty(s)).ToList()
                });
            }
            return(authorAttribute);
        }
        public void ExecuteCommand()
        {
            ValidateParameters();
            ExtensionConfigurationBuilder configBuilder = ExtensionManager.GetBuilder(Deployment != null ? Deployment.ExtensionConfiguration : null);

            if (UninstallConfiguration && configBuilder.ExistAny(ExtensionNameSpace, ExtensionType))
            {
                configBuilder.RemoveAny(ExtensionNameSpace, ExtensionType);
                WriteVerbose(string.Format(Resources.ServiceExtensionRemovingFromAllRoles, ExtensionType, ServiceName));
                ChangeDeployment(configBuilder.ToConfiguration());
            }
            else if (configBuilder.Exist(Role, ExtensionNameSpace, ExtensionType))
            {
                configBuilder.Remove(Role, ExtensionNameSpace, ExtensionType);
                if (Role == null || !Role.Any())
                {
                    WriteVerbose(string.Format(Resources.ServiceExtensionRemovingFromAllRoles, ExtensionType, ServiceName));
                }
                else
                {
                    bool defaultExists = configBuilder.ExistDefault(ExtensionNameSpace, ExtensionType);
                    foreach (var r in Role)
                    {
                        WriteVerbose(string.Format(Resources.ServiceExtensionRemovingFromSpecificRoles, ExtensionType, r, ServiceName));
                        if (defaultExists)
                        {
                            WriteVerbose(string.Format(Resources.ServiceExtensionRemovingSpecificAndApplyingDefault, ExtensionType, r));
                        }
                    }
                }
                ChangeDeployment(configBuilder.ToConfiguration());
            }
            else
            {
                WriteVerbose(string.Format(Resources.ServiceExtensionNoExistingExtensionsEnabledOnRoles, ExtensionNameSpace, ExtensionType));
            }

            if (UninstallConfiguration)
            {
                var allConfig      = ExtensionManager.GetBuilder();
                var deploymentList = (from slot in (new string[] { DeploymentSlotType.Production, DeploymentSlotType.Staging })
                                      let d = GetDeployment(slot)
                                              where d != null
                                              select d).ToList();
                deploymentList.ForEach(d => allConfig.Add(d.ExtensionConfiguration));
                ExtensionManager.Uninstall(ExtensionNameSpace, ExtensionType, allConfig.ToConfiguration());
            }
        }
        public void ExecuteCommand()
        {
            ValidateParameters();
            ExtensionConfigurationInput context = new ExtensionConfigurationInput
            {
                ProviderNameSpace = ExtensionNameSpace,
                Type = ExtensionType,
                CertificateThumbprint = CertificateThumbprint,
                ThumbprintAlgorithm   = ThumbprintAlgorithm,
                X509Certificate       = X509Certificate,
                PublicConfiguration   = string.Format(PublicConfigurationXmlTemplate.ToString(), ConnectionQualifiers, DefaultEndpointsProtocol, StorageAccountName, DiagnosticsConfiguration != null ? DiagnosticsConfiguration.InnerXml : ""),
                PrivateConfiguration  = string.Format(PrivateConfigurationXmlTemplate.ToString(), StorageKey),
                Roles = Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)).ToList() : new ExtensionRole[] { new ExtensionRole() }.ToList()
            };
            var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration);

            ChangeDeployment(extConfig);
        }
Exemple #12
0
        private void AddNewAntimalwareMonitoringConfig()
        {
            // install diagnostics provider with a new antimalware event monitoring config
            InitializeDiagnosticsSettings();
            ExtensionConfigurationInput diagExtConfigInput = new ExtensionConfigurationInput
            {
                ProviderNameSpace = ProviderNamespace,
                Type = ExtensionName,
                CertificateThumbprint = CertificateThumbprint,
                ThumbprintAlgorithm   = ThumbprintAlgorithm,
                X509Certificate       = X509Certificate,
                PublicConfiguration   = PublicConfiguration,
                PrivateConfiguration  = PrivateConfiguration,
                Roles = new ExtensionRoleList(Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)) : Enumerable.Repeat(new ExtensionRole(), 1))
            };

            AntimalwareMonitoringExtensionConfigurationInput = diagExtConfigInput;
        }
        public void ExecuteCommand()
        {
            ValidateParameters();
            ExtensionConfigurationInput context = new ExtensionConfigurationInput
            {
                ProviderNameSpace = ProviderNamespace,
                Type = ExtensionName,
                CertificateThumbprint = CertificateThumbprint,
                ThumbprintAlgorithm   = ThumbprintAlgorithm,
                X509Certificate       = X509Certificate,
                PublicConfiguration   = PublicConfiguration,
                PrivateConfiguration  = PrivateConfiguration,
                Roles = new ExtensionRoleList(Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)) : Enumerable.Repeat(new ExtensionRole(), 1))
            };
            var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration);

            ChangeDeployment(extConfig);
        }
        public void ExecuteCommand()
        {
            ValidateParameters();
            ExtensionConfigurationInput context = new ExtensionConfigurationInput
            {
                ProviderNameSpace = ExtensionNameSpace,
                Type = ExtensionType,
                CertificateThumbprint = CertificateThumbprint,
                ThumbprintAlgorithm   = ThumbprintAlgorithm,
                X509Certificate       = X509Certificate,
                PublicConfiguration   = string.Format(PublicConfigurationXmlTemplate.ToString(), Credential.UserName, Expiration.ToString("yyyy-MM-dd")),
                PrivateConfiguration  = string.Format(PrivateConfigurationXmlTemplate.ToString(), Credential.Password.ConvertToUnsecureString()),
                Roles = Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)).ToList() : new ExtensionRole[] { new ExtensionRole() }.ToList()
            };
            var extConfig = ExtensionManager.InstallExtension(context, Slot, Deployment.ExtensionConfiguration);

            ChangeDeployment(extConfig);
        }
        protected void RemoveAntimalwareExtension()
        {
            ProviderNamespace = AntimalwareExtensionProviderNamespace;
            ExtensionName     = AntimalwareExtensionName;

            ExtensionConfigurationBuilder configBuilder = ExtensionManager.GetBuilder(Deployment != null ? Deployment.ExtensionConfiguration : null);

            if (UninstallConfiguration && configBuilder.ExistAny(ProviderNamespace, ExtensionName))
            {
                configBuilder.RemoveAny(ProviderNamespace, ExtensionName);
                WriteWarning(string.Format(Resources.ServiceExtensionRemovingFromAllRoles, ExtensionName, ServiceName));
                ChangeDeployment(configBuilder.ToConfiguration());
            }
            else if (configBuilder.Exist(Role, ProviderNamespace, ExtensionName))
            {
                configBuilder.Remove(Role, ProviderNamespace, ExtensionName);
                if (Role == null || !Role.Any())
                {
                    WriteWarning(string.Format(Resources.ServiceExtensionRemovingFromAllRoles, ExtensionName, ServiceName));
                }
                else
                {
                    bool defaultExists = configBuilder.ExistDefault(ProviderNamespace, ExtensionName);
                    foreach (var r in Role)
                    {
                        WriteWarning(string.Format(Resources.ServiceExtensionRemovingFromSpecificRoles, ExtensionName, r, ServiceName));
                        if (defaultExists)
                        {
                            WriteWarning(string.Format(Resources.ServiceExtensionRemovingSpecificAndApplyingDefault, ExtensionName, r));
                        }
                    }
                }

                ChangeDeployment(configBuilder.ToConfiguration());
            }
            else
            {
                WriteWarning(string.Format(Resources.ServiceExtensionNoExistingExtensionsEnabledOnRoles, ProviderNamespace, ExtensionName));
            }
        }
Exemple #16
0
        protected void EnableMonitoring()
        {
            // retrieve any pre-existing diagnostics extension
            var ext = GetDiagnosticsExtension();

            if ((ext == null) &&
                ((monitoringAction == MonitoringActionType.Disable) || (monitoringAction == MonitoringActionType.NoActionRequested)))
            {
                // if there was no pre-existing diagnostics extension there is
                // nothing to do in either of these two cases so exit early

                // note the user may not have provided a storage account either
                // so this check is performed prior to storage account validation
                return;
            }

            // establish the storage account name to be associated with monitoring
            if (!IsValidStorageContext())
            {
                // no valid storage context exists, try to initialize storage context using config value
                InitializeStorageContext(monitoringStorageAccountName);
            }

            if (!IsValidStorageContext())
            {
                // still unable to associate the storage account name with a valid storage context
                ThrowTerminatingError(new ErrorRecord(
                                          new Exception(Resources.ServiceExtensionCannotFindStorageAccountName),
                                          string.Empty,
                                          ErrorCategory.InvalidData,
                                          null));
            }

            if (ext != null)
            {
                // save the current configuration of the diagnostics extension
                // in the event we do not end up needing to modify it but need
                // to persist the config in the final call to change deployment
                InitializeDiagnosticsSettings();
                AntimalwareMonitoringExtensionConfigurationInput = new ExtensionConfigurationInput
                {
                    ProviderNameSpace = ProviderNamespace,
                    Type = ExtensionName,
                    CertificateThumbprint = CertificateThumbprint,
                    ThumbprintAlgorithm   = ThumbprintAlgorithm,
                    X509Certificate       = X509Certificate,
                    PublicConfiguration   = ext.PublicConfiguration,
                    PrivateConfiguration  = PrivateConfiguration,
                    Roles = new ExtensionRoleList(Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)) : Enumerable.Repeat(new ExtensionRole(), 1))
                };
            }

            switch (monitoringAction)
            {
            case (MonitoringActionType.Enable):
                if (ext == null)
                {
                    AddNewAntimalwareMonitoringConfig();
                }
                else
                {
                    // extension already exists, check to see if it already contains antimalware data source
                    if (!ext.PublicConfiguration.Contains(DiagnosticsConfigAntimalwareProviderToken))
                    {
                        // antimalware data source is not already in the configuration, merge it
                        // with existing config (tracking perf counters, other event logs, etc.)
                        MergeAntimalwareMonitoringIntoExistingConfig(ext.PublicConfiguration);
                    }
                    else
                    {
                        // in this case we preserve monitoring configuration but
                        // apply any changes to storage context that may be needed

                        SaveMonitoringConfiguration(ext.PublicConfiguration);
                        InitializeDiagnosticsSettings();
                        AntimalwareMonitoringExtensionConfigurationInput = new ExtensionConfigurationInput
                        {
                            ProviderNameSpace = ProviderNamespace,
                            Type = ExtensionName,
                            CertificateThumbprint = CertificateThumbprint,
                            ThumbprintAlgorithm   = ThumbprintAlgorithm,
                            X509Certificate       = X509Certificate,
                            PublicConfiguration   = PublicConfiguration,
                            PrivateConfiguration  = PrivateConfiguration,
                            Roles = new ExtensionRoleList(Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)) : Enumerable.Repeat(new ExtensionRole(), 1))
                        };
                    }
                }
                break;

            case (MonitoringActionType.Disable):
                if (ext != null)
                {
                    RemoveExistingAntimalwareMonitoringConfig();
                }
                break;

            case (MonitoringActionType.NoActionRequested):
                break;

            default:
                break;
            }
        }
        protected void RemoveExistingAntimalwareMonitoringConfig()
        {
            // this does not remove the diagnostics extension entirely, it only removes the portion of the
            // diagnostics configuration that monitors antimalware events- everything else will remain
            // in order to avoid doing harm to any other users who may be sharing the diagnostics extension

            var ext = GetDiagnosticsExtension();

            if (ext != null)
            {
                string tmpXmlString = ext.PublicConfiguration;
                string AntimalwareDataSourceName     = "System!*[System[Provider[@Name='Microsoft Antimalware']]]";
                string DiagnosticsConfigXmlNamespace = @"http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration";
                string monitoringStorageAccountName  = null; // for temporarily retrieving storage account name when specified in config file

                // remove the data source element with the antimalware event provider
                XmlDocument tmpXmlDoc = new XmlDocument();
                tmpXmlDoc.LoadXml(tmpXmlString);

                // retrieve storage account name from public configuration
                string  stgAcctNameXPath = string.Format(@"//*[local-name()='{0}' and namespace-uri()='{1}']", StorageAccountElemStr, DiagnosticsConfigXmlNamespace);
                XmlNode stgAcctNameNode  = tmpXmlDoc.DocumentElement.SelectSingleNode(stgAcctNameXPath);
                if (stgAcctNameNode != null)
                {
                    monitoringStorageAccountName = stgAcctNameNode.InnerText;
                }
                if (string.IsNullOrWhiteSpace(monitoringStorageAccountName))
                {
                    // do not modify diagnostics config without including the storage account
                    // throw terminating exception since it is not possible to preserve the
                    // existing storage account with the configuration if it doesn't have a
                    // hint to what the last storage account was in the public configuration
                    ThrowTerminatingError(new ErrorRecord(
                                              new Exception(Resources.ServiceExtensionCannotFindStorageAccountName),
                                              string.Empty,
                                              ErrorCategory.InvalidData,
                                              null));

                    return;
                }
                else
                {
                    // check the storage account and initialize for use
                    InitializeStorageContext(monitoringStorageAccountName);
                }

                // locate the antimalware data source node in the document
                string  antimalwareDataSourceXPath = string.Format(@"//*[local-name()='{0}' and @name=""{1}"" and namespace-uri()='{2}']", "DataSource", AntimalwareDataSourceName, DiagnosticsConfigXmlNamespace);
                XmlNode antimalwareDataSourceNode  = tmpXmlDoc.DocumentElement.SelectSingleNode(antimalwareDataSourceXPath);
                if (antimalwareDataSourceNode != null)
                {
                    XmlNode windowsEventLogNode = antimalwareDataSourceNode.ParentNode;
                    if (windowsEventLogNode.RemoveChild(antimalwareDataSourceNode) != null)
                    {
                        // remove the windows event log if there are no other child data sources present
                        // as will be required for schema validation to succeed when sending the new config
                        // any other data sources outside of the windows event log are left untouched
                        if (!windowsEventLogNode.HasChildNodes)
                        {
                            windowsEventLogNode.ParentNode.RemoveChild(windowsEventLogNode);
                        }
                    }

                    // now reinstall the diagnostics extension with the updated configuration
                    InitializeDiagnosticsSettings();
                    ExtensionConfigurationInput diagExtConfigInput = new ExtensionConfigurationInput
                    {
                        ProviderNameSpace = ProviderNamespace,
                        Type = ExtensionName,
                        CertificateThumbprint = CertificateThumbprint,
                        ThumbprintAlgorithm   = ThumbprintAlgorithm,
                        X509Certificate       = X509Certificate,
                        PublicConfiguration   = tmpXmlDoc.OuterXml,
                        PrivateConfiguration  = PrivateConfiguration,
                        Roles = new ExtensionRoleList(Role != null && Role.Any() ? Role.Select(r => new ExtensionRole(r)) : Enumerable.Repeat(new ExtensionRole(), 1))
                    };
                    AntimalwareMonitoringExtensionConfigurationInput = diagExtConfigInput;
                }
                else
                {
                    // no existing antimalware data source was found needing removal
                    return;
                }
            }
        }
        private List <ExtensionConfigurationInput> GetConfigurations()
        {
            var result = new List <ExtensionConfigurationInput>();

            if (ParameterSetName == SetExtensionUsingDiagnosticsConfigurationParameterSetName)
            {
                // If user specified multiple configurations for the same role, we only take the later configuration for that role.
                // This not only improve the efficieny, one more important reason is current InstallExtension() implementation assumes
                // we call change deployment directly after installation. Calling InstallExtension() multiple times for the same role
                // may result in removing the extension which is still working.
                for (var i = 0; i < DiagnosticsConfiguration.Length; i++)
                {
                    var currentConfig = DiagnosticsConfiguration[i];
                    for (var j = i + 1; j < DiagnosticsConfiguration.Length && currentConfig.Roles.Any(); j++)
                    {
                        var followingConfig = DiagnosticsConfiguration[j];

                        // If the following configuration is applied to all roles, we simply ingore the whole current config.
                        if (followingConfig.Roles.Any(r => r.Default))
                        {
                            currentConfig.Roles.Clear();
                        }

                        // If the role appears in following config, we will take the later one and remove the role from current config.
                        foreach (var role in currentConfig.Roles.ToArray())
                        {
                            if (followingConfig.Roles.Any(r => r.RoleName == role.RoleName))
                            {
                                currentConfig.Roles.Remove(role);
                            }
                        }
                    }

                    if (currentConfig.Roles.Any())
                    {
                        result.Add(currentConfig);
                    }
                }
            }
            else
            {
                // If user specified a config file path, then there is only one configuration.
                result.Add(new ExtensionConfigurationInput
                {
                    Id                    = ExtensionId,
                    Version               = Version,
                    ProviderNameSpace     = ProviderNamespace,
                    Type                  = ExtensionName,
                    CertificateThumbprint = CertificateThumbprint,
                    ThumbprintAlgorithm   = ThumbprintAlgorithm,
                    X509Certificate       = X509Certificate,
                    PublicConfiguration   = PublicConfiguration,
                    PrivateConfiguration  = PrivateConfiguration,
                    Roles                 = new ExtensionRoleList(Role != null && Role.Any()
                                                ? Role.Select(r => new ExtensionRole(r))
                                                : Enumerable.Repeat(new ExtensionRole(), 1))
                });
            }

            return(result);
        }