protected InstallConfigurationProperties ReadHostnameSetupFile(string setupDir) { if (string.IsNullOrEmpty(setupDir)) { setupDir = this.GetAppRootDir(); } if (!string.IsNullOrEmpty(setupDir)) { string hostname = System.Net.Dns.GetHostName(); string hostConfigFile = setupDir + Path.DirectorySeparatorChar + hostname + ".setup.config"; this.WriteToTrace("Attempting to read host config file " + hostConfigFile); if (File.Exists(hostConfigFile)) { try { return(XmlXPathUtility.Deserialize <InstallConfigurationProperties>(XmlXPathUtility.Parse(hostConfigFile))); } catch (Exception ex) { this.WriteToTrace("Error reading host config file", ex); } } } return(null); }
/// <summary> /// Generates the body of the message based on the template settings and the given object array /// </summary> /// <param name="dataObjects"></param> /// <returns></returns> public string GenerateBody(Dictionary<string, object> dataObjects) { string text = null; if (this.BodyParserType == NetMailTemplateParserType.Text) { if (!string.IsNullOrEmpty(this.MessageBody)) { text = this.MessageBody; } else { text = FileUtility.ReadFileAsStringBuffer(this.MessageBodyFile).ToString(); } text = TemplateTextParser.ParseObjectsIntoString( this.DataStartDelimiter, this.DataEndDelimiter, this.CollectionIndexStart, this.CollectionIndexEnd, this.NullString, this.ForeachKey, this.ForeachKeyEnd, this.ForeachItemKey, dataObjects, text); } else { StringBuilder allObjectsXML = new StringBuilder(); allObjectsXML.Append("<?xml version=\"1.0\"?>"); allObjectsXML.Append(Environment.NewLine).Append("<").Append(this.XslParserRootNodeName).Append(">"); if (dataObjects != null) { foreach (string key in dataObjects.Keys) { allObjectsXML.Append(Environment.NewLine).Append("<"); allObjectsXML.Append(this.XslParserObjectNodeName).Append(" "); allObjectsXML.Append(this.XslParserObjectNameAttributeName).Append("=\"").Append(key).Append("\">"); object obj = dataObjects[key]; XPathDocument objDoc = XmlXPathUtility.SerializeObject(obj); allObjectsXML.Append(Environment.NewLine).Append(objDoc.CreateNavigator().InnerXml); allObjectsXML.Append(Environment.NewLine).Append("</").Append(this.XslParserObjectNodeName).Append(">"); } } allObjectsXML.Append(Environment.NewLine).Append("</").Append(this.XslParserRootNodeName).Append(">"); XPathDocument objsDoc = XmlXPathUtility.ParseFromString(allObjectsXML.ToString()); XPathDocument template = null; if (string.IsNullOrEmpty(this.MessageBody)) { template = XmlXPathUtility.Parse(this.MessageBodyFile); } else { template = XmlXPathUtility.ParseFromString(this.MessageBody); } if (this.BodyStyle == NetMailTemplateTextStyle.Text) { text = XmlUtility.TransformToString(objsDoc, template, null, null); } else { XPathDocument result = XmlXPathUtility.Transform(objsDoc, template); text = result.CreateNavigator().InnerXml; } } return text; }