Acme.Northwind.Install.XmlHelper.GetNodeValue C# (CSharp) Method

GetNodeValue() public static method

Get a node's value based on an XPath query
public static GetNodeValue ( this element, string xpath, System.DateTime defaultValue ) : System.DateTime
element this
xpath string
defaultValue System.DateTime
return System.DateTime
		public static DateTime GetNodeValue(this System.Xml.XmlNode element, string xpath, DateTime defaultValue)
		{
			var b = element.GetNodeValue(xpath, (DateTime?)defaultValue);
			if (b == null) return defaultValue;
			else return b.Value;
		}

Same methods

XmlHelper::GetNodeValue ( this element, string xpath, System.DateTime defaultValue ) : DateTime?
XmlHelper::GetNodeValue ( this element, string xpath, System.Single defaultValue ) : System.Single
XmlHelper::GetNodeValue ( this element, string xpath, System.Single defaultValue ) : Single?
XmlHelper::GetNodeValue ( this element, string xpath, bool defaultValue ) : bool
XmlHelper::GetNodeValue ( this element, string xpath, bool defaultValue ) : bool?
XmlHelper::GetNodeValue ( this element, string xpath, double defaultValue ) : double
XmlHelper::GetNodeValue ( this element, string xpath, double defaultValue ) : double?
XmlHelper::GetNodeValue ( this element, string xpath, int defaultValue ) : int
XmlHelper::GetNodeValue ( this element, string xpath, int defaultValue ) : int?
XmlHelper::GetNodeValue ( this document, string xpath, XmlNamespaceManager nsManager, string defaultValue ) : string
XmlHelper::GetNodeValue ( this document, string xpath, string defaultValue ) : string

Usage Example

示例#1
0
        /// <summary />
        public bool Load()
        {
            var fi = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);

            fi = new FileInfo(Path.Combine(fi.DirectoryName, "installsettings.xml"));
            if (!fi.Exists)
            {
                return(false);
            }

            var document = new XmlDocument();

            document.Load(fi.FullName);

            if (document.DocumentElement.Name == "a")
            {
                this.PrimaryServer = XmlHelper.GetNodeValue(document.DocumentElement, "server", string.Empty);
                this.PrimaryUseIntegratedSecurity = XmlHelper.GetNodeValue(document.DocumentElement, "useintegratedsecurity", false);
                this.PrimaryUserName = XmlHelper.GetNodeValue(document.DocumentElement, "username", string.Empty);
                this.PrimaryPassword = XmlHelper.GetNodeValue(document.DocumentElement, "password", string.Empty);

                var v = XmlHelper.GetNodeValue(document.DocumentElement, "username-encrypted", string.Empty).Decrypt();
                if (!string.IsNullOrEmpty(v))
                {
                    this.PrimaryUserName = v;
                }

                v = XmlHelper.GetNodeValue(document.DocumentElement, "password-encrypted", string.Empty).Decrypt();
                if (!string.IsNullOrEmpty(v))
                {
                    this.PrimaryPassword = v;
                }

                this.PrimaryDatabase = XmlHelper.GetNodeValue(document.DocumentElement, "database", string.Empty);
            }
            else
            {
                var node = document.DocumentElement.SelectSingleNode("primary");
                this.PrimaryServer = XmlHelper.GetNodeValue(node, "server", string.Empty);
                this.PrimaryUseIntegratedSecurity = XmlHelper.GetNodeValue(node, "useintegratedsecurity", false);
                this.PrimaryUserName = XmlHelper.GetNodeValue(node, "username", string.Empty);
                this.PrimaryPassword = XmlHelper.GetNodeValue(node, "password", string.Empty);

                var v = XmlHelper.GetNodeValue(node, "username-encrypted", string.Empty).Decrypt();
                if (!string.IsNullOrEmpty(v))
                {
                    this.PrimaryUserName = v;
                }

                v = XmlHelper.GetNodeValue(node, "password-encrypted", string.Empty).Decrypt();
                if (!string.IsNullOrEmpty(v))
                {
                    this.PrimaryPassword = v;
                }

                this.PrimaryDatabase = XmlHelper.GetNodeValue(node, "database", string.Empty);

                node               = document.DocumentElement.SelectSingleNode("cloud");
                this.CloudServer   = XmlHelper.GetNodeValue(node, "server", string.Empty);
                this.CloudUserName = XmlHelper.GetNodeValue(node, "username", string.Empty);
                this.CloudPassword = XmlHelper.GetNodeValue(node, "password", string.Empty);

                v = XmlHelper.GetNodeValue(node, "username-encrypted", string.Empty).Decrypt();
                if (!string.IsNullOrEmpty(v))
                {
                    this.CloudUserName = v;
                }

                v = XmlHelper.GetNodeValue(node, "password-encrypted", string.Empty).Decrypt();
                if (!string.IsNullOrEmpty(v))
                {
                    this.CloudPassword = v;
                }

                this.CloudDatabase = XmlHelper.GetNodeValue(node, "database", string.Empty);
            }

            this.IsLoaded = true;
            return(true);
        }