protected override void ValidateConfiguration() { using (StreamReader sr = new StreamReader(DiagnosticsConfigurationPath)) { string header = sr.ReadLine(); // make sure it is the header if (!header.Trim().StartsWith("<?xml")) { throw new ArgumentException(Resources.PaaSDiagnosticsWrongHeader); } PublicConfiguration = sr.ReadToEnd(); } // the element <StorageAccount> is not meant to be set by teh user in the public config. // Make sure it matches the storage account in the private config. XmlDocument doc = new XmlDocument(); XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable); ns.AddNamespace("ns", XmlNamespace); doc.Load(DiagnosticsConfigurationPath); var node = doc.SelectSingleNode("//ns:StorageAccount", ns); if (node != null) { if (node.InnerText == null) { throw new ArgumentException(Resources.PaaSDiagnosticsNullStorageAccount); } if (string.Compare(node.InnerText, StorageContext.StorageAccountName, true) != 0) { throw new ArgumentException(Resources.PassDiagnosticsNoMatchStorageAccount); } } else { // the StorageAccount is not there. we must set it string storageAccountElem = "\n<StorageAccount>" + StorageContext.StorageAccountName + "</StorageAccount>\n"; // insert it after </WadCfg> int wadCfgEndIndex = PublicConfiguration.IndexOf("</WadCfg>"); PublicConfiguration = PublicConfiguration.Insert(wadCfgEndIndex + "</WadCfg>".Length, storageAccountElem); } PrivateConfigurationXml = new XDocument(PrivateConfigurationXmlTemplate); SetPrivateConfigAttribute(StorageAccountElemStr, PrivConfNameAttr, StorageContext.StorageAccountName); SetPrivateConfigAttribute(StorageAccountElemStr, PrivConfKeyAttr, StorageKey); SetPrivateConfigAttribute(StorageAccountElemStr, PrivConfEndpointAttr, Endpoint); PrivateConfiguration = PrivateConfigurationXml.ToString(); }
protected override void ValidateConfiguration() { using (StreamReader sr = new StreamReader(DiagnosticsConfigurationPath)) { string header = sr.ReadLine(); // make sure it is the header if (!header.Trim().StartsWith("<?xml")) { throw new ArgumentException(Resources.DiagnosticsExtensionWrongHeader); } } var publicConfigElem = DiagnosticsHelper.GetPublicConfigXElementFromXmlFile(this.DiagnosticsConfigurationPath); if (publicConfigElem == null) { throw new ArgumentException(Resources.DiagnosticsExtensionNullPublicConfig); } publicConfigElem.SetAttributeValue("xmlns", XmlNamespace); PublicConfiguration = publicConfigElem.ToString(); // The element <StorageAccount> is not meant to be set by the user in the public config. // Make sure it matches the storage account in the private config. XmlDocument doc = new XmlDocument(); XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable); ns.AddNamespace("ns", XmlNamespace); doc.Load(DiagnosticsConfigurationPath); var node = doc.SelectSingleNode("//ns:StorageAccount", ns); if (node != null) { // The StorageAccount is empty, we must set it if (string.IsNullOrEmpty(node.InnerText)) { var insertIndex = PublicConfiguration.IndexOf("</StorageAccount>"); PublicConfiguration = PublicConfiguration.Insert(insertIndex, StorageAccountName); } else if (!string.IsNullOrEmpty(node.InnerText) && string.Compare(node.InnerText, StorageAccountName, true) != 0) { throw new ArgumentException(Resources.DiagnosticsExtensionNoMatchStorageAccount); } } else { // the StorageAccount is not there. we must set it string storageAccountElem = "\n<StorageAccount>" + StorageAccountName + "</StorageAccount>\n"; // insert it after </WadCfg> int wadCfgEndIndex = PublicConfiguration.IndexOf("</WadCfg>"); PublicConfiguration = PublicConfiguration.Insert(wadCfgEndIndex + "</WadCfg>".Length, storageAccountElem); } // Make sure the storage account name in PrivateConfig matches. var privateConfigStorageAccountName = DiagnosticsHelper.GetStorageAccountInfoFromPrivateConfig(this.DiagnosticsConfigurationPath, DiagnosticsHelper.PrivConfNameAttr); if (!string.IsNullOrEmpty(privateConfigStorageAccountName) && !string.Equals(StorageAccountName, privateConfigStorageAccountName, StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException(Resources.DiagnosticsExtensionNoMatchPrivateStorageAccount); } PrivateConfigurationXml = new XDocument(PrivateConfigurationXmlTemplate); SetPrivateConfigAttribute(DiagnosticsHelper.StorageAccountElemStr, DiagnosticsHelper.PrivConfNameAttr, StorageAccountName); SetPrivateConfigAttribute(DiagnosticsHelper.StorageAccountElemStr, DiagnosticsHelper.PrivConfKeyAttr, StorageAccountKey); SetPrivateConfigAttribute(DiagnosticsHelper.StorageAccountElemStr, DiagnosticsHelper.PrivConfEndpointAttr, StorageAccountEndpoint); PrivateConfiguration = PrivateConfigurationXml.ToString(); }