Beispiel #1
0
		public Object Create(
			Object parent,
			Object configContext,
			System.Xml.XmlNode section)
		{
			Object settings = null;
			if (section == null)
				return settings;

			XPathNavigator nav = section.CreateNavigator();
			String typeName = (String) nav.Evaluate("string(@type)");
			Type sectionType = Type.GetType(typeName);

			XmlSerializer s = new XmlSerializer(sectionType);
			XmlNodeReader r = new XmlNodeReader(section);

			try
			{
				settings = s.Deserialize(r);
			}
			catch (Exception e)
			{

				if ( e.InnerException != null )
					Debug.WriteLine( String.Format("exception:\n{0}\n{1}", e.Message, e.InnerException.Message ) );
				else
					Debug.WriteLine( String.Format("exception:\n{0}", e.Message ) );
			}
			finally
			{
				s = null;
			}

			return settings;
		}
 public object Create(object parent, object configContext, System.Xml.XmlNode section)
 {
     XPathNavigator nav = section.CreateNavigator();
     string typename = (string) nav.Evaluate("string(@type)");
     Type t = Type.GetType(typename);
     XmlSerializer ser = new XmlSerializer(t);
     return ser.Deserialize(new XmlNodeReader(section));
 }
 /// <summary>
 /// Creates a new instance of <see cref="ConnectorConfiguration"/> based on the configuration.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="configContext"></param>
 /// <param name="section"></param>
 /// <returns></returns>
 public object Create(object parent, object configContext, System.Xml.XmlNode section)
 {
     var conf = new ConnectorConfiguration();
     XPathNavigator nav = section.CreateNavigator();
     conf.User = GetValue(nav, "user");
     conf.Key = GetValue(nav, "key");
     conf.HostsRaw = GetValue(nav, "hosts");
     conf.MainHostsRaw = GetValue(nav, "mainHosts");
     conf.FastHostsRaw = GetValue(nav, "fastHosts");
     return conf;
 }
        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            // get the name of the type from the type= attribute on the root node
            XPathNavigator xpn = section.CreateNavigator();
            string TypeName = (string)xpn.Evaluate("string(@type)");
            if (TypeName == "")
            {
                throw new ConfigurationErrorsException(
                    "The type attribute is not present on the root node of the <" +
                    section.Name + "> configuration section ", section);
            }

            // make sure this string evaluates to a valid type
            Type t = Type.GetType(TypeName);
            if (t == null)
            {
                throw new ConfigurationErrorsException(
                    "The type attribute \'" + TypeName + "\' specified in the root node of the " +
                    "the <" + section.Name + "> configuration section is not a valid type.",
                    section);
            }
            XmlSerializer xs = new XmlSerializer(t);

            // attempt to deserialize an object of this type from the provided XML section
            XmlNodeReader xnr = new XmlNodeReader(section);
            try
            {
                return xs.Deserialize(xnr);
            }
            catch (Exception ex)
            {
                string s = ex.Message;
                Exception iex = ex.InnerException;
                while (iex != null)
                {
                    s += "; " + iex.Message;
                    iex = iex.InnerException;
                }
                throw new ConfigurationErrorsException(
                    "Unable to deserialize an object of type \'" + TypeName +
                    "\' from  the <" + section.Name + "> configuration section: " +
                    s, ex, section);
            }
        }
        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            Object settings = null;

            if (section == null) { return settings; }

            XPathNavigator navigator = section.CreateNavigator();

            String typeName = (string)navigator.Evaluate("string(@configuratorType)");

            Type sectionType = Type.GetType(typeName);

            XmlSerializer xs = new XmlSerializer(sectionType);
            XmlNodeReader reader = new XmlNodeReader(section);

            settings = xs.Deserialize(reader);

            return settings;
        }
        public static System.Xml.XmlNamespaceManager GetReportNamespaceManager(System.Xml.XmlDocument doc)
        {
            if (doc == null)
                throw new System.ArgumentNullException("doc");

            System.Xml.XmlNamespaceManager nsmgr = new System.Xml.XmlNamespaceManager(doc.NameTable);

            // <Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">

            if (doc.DocumentElement != null)
            {
                // string strNamespace = doc.DocumentElement.NamespaceURI;
                // System.Console.WriteLine(strNamespace);
                // nsmgr.AddNamespace("dft", strNamespace);

                System.Xml.XPath.XPathNavigator xNav = doc.CreateNavigator();
                while (xNav.MoveToFollowing(System.Xml.XPath.XPathNodeType.Element))
                {
                    System.Collections.Generic.IDictionary<string, string> localNamespaces =
                        xNav.GetNamespacesInScope(System.Xml.XmlNamespaceScope.Local);

                    foreach (System.Collections.Generic.KeyValuePair<string, string> kvp in localNamespaces)
                    {
                        string prefix = kvp.Key;
                        if (string.IsNullOrEmpty(prefix))
                            prefix = "dft";

                        nsmgr.AddNamespace(prefix, kvp.Value);
                    } // Next kvp

                } // Whend

                return nsmgr;
            } // End if (doc.DocumentElement != null)

            nsmgr.AddNamespace("dft", "http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");
            // nsmgr.AddNamespace("dft", "http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition");

            return nsmgr;
        }
        /// <summary>
        /// This method will be used when deserializing the property from an XML property set.
        /// </summary>
        /// <param name="context">Information about the target property.</param>
        /// <param name="propertyValue">The XML node to read the property value from.</param>
        /// <returns>The value to be assigned to the template property.</returns>
        public object ReadPropertyXml(PropertySerializerContext context, System.Xml.XmlNode propertyValue)
        {
            if (context.PropertyInfo.PropertyType != typeof(ModalEditorProperty))
                return null;

            // use XPath to select out values
            XPathNavigator navigator = propertyValue.CreateNavigator();
            // we need to import the CodeSmith Namespace
            XmlNamespaceManager manager = new XmlNamespaceManager(navigator.NameTable);
            manager.AddNamespace("cs", CodeSmithProject.DefaultNamespace);

            // expresion to select SampleBoolean value
            XPathExpression sampleBooleanExpression = XPathExpression.Compile("string(cs:SampleBoolean/text())", manager);
            string boolString = navigator.Evaluate(sampleBooleanExpression) as string;
            bool sampleBoolean;
            bool.TryParse(boolString, out sampleBoolean);

            // expresion to select SampleString value
            XPathExpression sampleTextExpression = XPathExpression.Compile("string(cs:SampleString/text())", manager);
            string sampleString = navigator.Evaluate(sampleTextExpression) as string;

            ModalEditorProperty modalEditorPropertyValue = new ModalEditorProperty();
            modalEditorPropertyValue.SampleBoolean = sampleBoolean;
            modalEditorPropertyValue.SampleString = sampleString;
            return modalEditorPropertyValue;
        }
Beispiel #8
0
    private string ValidateXml(System.Xml.XPath.XPathDocument objXmlDocument, System.Xml.Schema.XmlSchemaSet objSchemas)
    {
        System.Xml.XPath.XPathNavigator nav = objXmlDocument.CreateNavigator();
            m_strInvalidMessage = "";

            nav.CheckValidity(objSchemas, new System.Xml.Schema.ValidationEventHandler(ValidationHandler));

            return m_strInvalidMessage;
    }
 public static dynamic Load(System.Xml.XPath.IXPathNavigable doc)
 {
     var xdoc = XDocument.Load(doc.CreateNavigator().ReadSubtree());
     return Load(xdoc);
 }
        private MailMessage CreateMailMessageFromTemplate(System.Xml.XPath.XPathDocument template,
                                                    String email,
                                                    Dictionary<string, string> parameters)
        {
            System.Xml.XPath.XPathNavigator navigator = template.CreateNavigator();

              // Specify the e-mail sender.
              MailAddress from = new MailAddress((string)navigator.Evaluate("string(template/sender)")); ;
              // Set destinations for the e-mail message.
              //MailAddress to = new MailAddress(email);

              MailMessage message = new MailMessage(from.Address, email);

              message.IsBodyHtml = bool.Parse((string)navigator.Evaluate("string(template/body/@html)"));
              message.BodyEncoding = System.Text.Encoding.UTF8;
              message.SubjectEncoding = System.Text.Encoding.UTF8;

              string body = (string)navigator.Evaluate("string(template/body)");
              message.Body = ReplaceParameters(body, parameters);

              string subject = (string)navigator.Evaluate("string(template/subject)");
              message.Subject = ReplaceParameters(subject, parameters);

              return message;
        }
 public object Create(object parent, object configContext, System.Xml.XmlNode section)
 {
     XPathNavigator nav = section.CreateNavigator();
     XmlSerializer ser = new XmlSerializer(typeof(GGCSettings));
     return ser.Deserialize(new XmlNodeReader(section));
 }