示例#1
0
        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            var nav = section.CreateNavigator();

            // load configuration type explicitly
            var typeName = nav.Evaluate("string(@type)") as string;

            if (string.IsNullOrWhiteSpace(typeName?.Trim()))
            {
                // Not specified, use element name to lookup known configuration objects
                var elementName = nav.Name;

                if (KnownConfigurationObjectsByLowerCaseSectionName.ContainsKey(elementName.ToLowerInvariant()))
                {
                    typeName = KnownConfigurationObjectsByLowerCaseSectionName[elementName.ToLowerInvariant()];
                }
                else
                {
                    typeName = TypeResolver.Resolve(elementName).AssemblyQualifiedName;
                    //throw new SoftwareException("No known configuration object for '{0}'", elementName);
                }
            }
            var configurationObjectType = TypeResolver.Resolve(typeName);
            var ser = new XmlSerializer(configurationObjectType);

            return(ser.Deserialize(new XmlNodeReader(section)));
        }
        /// <summary>
        /// Creates the object representing the configuration section. The section will
        /// be serialized into the type specified by the type attribute in the xml.
        /// 
        /// This method is called by the framework, for example when ConfiguratinManager.GetSection() 
        /// is called. It should not be called directly by client code. 
        /// </summary>
        /// <param name="parent">Parent object</param>
        /// <param name="configContext">Configuration context object</param>
        /// <param name="section">Section XML node</param>
        /// <returns></returns>
        public object Create(object parent, object configContext, XmlNode section)
        {
            XPathNavigator nav = section.CreateNavigator();
            string typename = (string)nav.Evaluate("string(@type)");
            Type type = Type.GetType(typename);

            if (type == null)
            {
                throw new ConfigurationErrorsException(
                    string.Format("Type '{0}' specified with the XmlSerializerSectionHandler could not be resolved.", typename)
                    );
            }

            try
            {
                using (XmlNodeReader xmlNodeReader = new XmlNodeReader(section))
                {
                    XmlSerializer xmlSerializer = new XmlSerializer(type);
                    return xmlSerializer.Deserialize(xmlNodeReader);
                }
            }
            catch (InvalidOperationException ex)
            {
                // Unwrap any exception
                if (ex.InnerException != null)
                    throw ex.InnerException;
                throw;
            }
        }
        /// <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(DropDownEditorProperty))
            {
                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);

            // expression 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);

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

            // create and return
            DropDownEditorProperty dropDownEditorPropertyValue = new DropDownEditorProperty();

            dropDownEditorPropertyValue.SampleBoolean = sampleBoolean;
            dropDownEditorPropertyValue.SampleString  = sampleString;
            return(dropDownEditorPropertyValue);
        }
        /// <summary>
        /// Implement IConfigurationSectionHandler Create interface
        /// </summary>
        /// <remarks>
        /// Implemented by all configuration section handlers to parse the XML of the configuration section.
        /// The returned object is added to the configuration collection and is accessed by System.Configuration.ConfigurationSettings.GetConfig(System.String).
        /// </remarks>
        /// <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)
        {
            Object settings = null;

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

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

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

            try
            {
                settings = xs.Deserialize(reader);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            finally
            {
                xs = null;
            }

            return(settings);
        }
示例#5
0
        public static void TransformNode(XmlNode element, XmlReader xslTemplate)
        {
            XmlReader reader = new XmlNodeReader(element);

              XmlReader transformResultReader = TransformXml(reader, xslTemplate, null);
              element.CreateNavigator().ReplaceSelf(transformResultReader);
        }
        public object Create( object parent, object configContext, XmlNode section )
        {
            XPathNavigator navigator = section.CreateNavigator();
            string typeName = ( string )navigator.Evaluate( "string(@type)" );

            if( string.IsNullOrEmpty( typeName ) )
                throw new ConfigurationErrorsException( string.Format( MISSING_TYPE_MSG, section.Name ), section );

            Type type = Type.GetType( typeName );
            if( type == null )
                throw new ConfigurationErrorsException( string.Format( NULL_TYPE_MSG, typeName, section.Name ), section );

            XmlSerializer serializer = new XmlSerializer( type );
            XmlNodeReader reader = new XmlNodeReader( section );

            try
            {
                return serializer.Deserialize( reader );
            }
            catch( Exception ex )
            {
                throw new ConfigurationErrorsException(
                    string.Format( FAILED_DESERIALIZE_MSG, typeName, section.Name, FormattedInnerExceptions( ex ) ),
                    ex, section );
            }
        }
 public object Create(object parent, object configContext, XmlNode section)
 {
     XPathNavigator nav = section.CreateNavigator();
     var typename = (string)nav.Evaluate("string(@type)");
     Type t = Type.GetType(typename);
     var ser = new XmlSerializer(t);
     return ser.Deserialize(new XmlNodeReader(section));
 }
示例#8
0
        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 configuration section handler.
 /// </summary>
 /// <returns>
 /// The created section handler object.
 /// </returns>
 /// <param name="parent">Parent object.</param><param name="configContext">Configuration context object.</param><param name="section">Section XML node.</param><filterpriority>2</filterpriority>
 public object Create(object parent, object configContext, XmlNode section)
 {
     var navigator = section.CreateNavigator();
     var typeOfObject = (string)navigator.Evaluate("string(@type)");
     var type = Type.GetType(typeOfObject);
     var xmlSerializer = new XmlSerializer(type);
     var nodeReader = new XmlNodeReader(section);
     return xmlSerializer.Deserialize(nodeReader);
 }
示例#10
0
文件: Settings.cs 项目: zibler/zibler
 public object Create(object parent, object configContext, XmlNode section)
 {
     if (section == null)
     {
         return null;
     }
     _config = section.CreateNavigator();
     return this;
 }
        /// <summary>
        /// Creates a configuration section handler.
        /// </summary>
        /// <param name="parent">Parent object.</param>
        /// <param name="configContext">Configuration context object.</param>
        /// <param name="section">Section XML node.</param>
        /// <returns>The created section handler object.</returns>
        public virtual object Create(
            object parent,
            object configContext,
            System.Xml.XmlNode section)
        {
            XPathNavigator nav      = section.CreateNavigator();
            string         typename = (string)nav.Evaluate("string(@type)");

            return(CreateInternal(parent, configContext, section, typename));
        }
        object IConfigurationSectionHandler.Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            XPathNavigator xNav         = section.CreateNavigator();
            string         typeOfObject = (string)xNav.Evaluate("string(@type)");
            Type           t            = Type.GetType(typeOfObject);
            XmlSerializer  ser          = new XmlSerializer(t);
            XmlNodeReader  xNodeReader  = new XmlNodeReader(section);

            return(ser.Deserialize(xNodeReader));
        }
        //������ض�����ǰ���ýڵķ���
        object IConfigurationSectionHandler.Create(object parent, object configContext, XmlNode section)
        {
            //XPathNavigator��ʹ���α�ģ�ʹ��������ݴ洢����ȡ���ݡ�
            XPathNavigator navigator = section.CreateNavigator();
            string text = (string)navigator.Evaluate("string(@type)");
            Type type = Type.GetType(text);
            XmlSerializer serializer = new XmlSerializer(type);

            return serializer.Deserialize(new XmlNodeReader(section));
        }
 private static void DoPostMerge(string outputPath, XmlNode mergedNode)
 {
     foreach (XmlNode partNode in mergedNode.SafeSelectNodes("layout/generate"))
     {
         partNode.Attributes.Remove(partNode.Attributes["combinedkey"]);
     }
     using (var writer = XmlWriter.Create(outputPath, CanonicalXmlSettings.CreateXmlWriterSettings()))
     {
         writer.WriteNode(mergedNode.CreateNavigator(), true);
     }
 }
 public XmlDocument ApplyChanges(BaseDiffResultObjectList results, XmlNode originalDocument)
 {
     XmlDocument resultDocument = new XmlDocument();
     XPathNavigator navigator = originalDocument.CreateNavigator();
     foreach (var item in results.Items)
     {
         GetCommonNode(item, ref navigator);
     }
     resultDocument.LoadXml(navigator.OuterXml);
     return resultDocument;
 }
示例#16
0
        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            if (section == null)
            {
                return(null);
            }
            Type          sectionType = Type.GetType((string)(section.CreateNavigator()).Evaluate("string(@configType)"));
            XmlSerializer xs          = new XmlSerializer(sectionType);

            return(xs.Deserialize(new XmlNodeReader(section)));
        }
        /// <summary>
        /// Create the configuration section.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="configContext"></param>
        /// <param name="section"></param>
        /// <returns></returns>
        public object Create(object parent,
                            object configContext,
                            XmlNode section) {
            XPathNavigator nav = section.CreateNavigator();
            String typename = (String) nav.Evaluate("string(@type)");
            Type type = Type.GetType(typename);
            object theObject = this.GetConfigObject (type,
                            section.SelectSingleNode ("//" + SharpCvsLibConfig.SUB_SECTION));

            return theObject;
        }
示例#18
0
        public object Create(object parent, object configContext, XmlNode section)
        {
            XPathNavigator nav = section.CreateNavigator();
            string typeName = (string)nav.Evaluate("string(@type)");
            Type t = Type.GetType(typeName);
            XmlSerializer ser = new XmlSerializer(t);
            XmlNodeReader xnr = new XmlNodeReader(section);
            object deSerialised = null;

            deSerialised = ser.Deserialize(xnr);

            return deSerialised;
        }
		/// <summary>
		/// Returns an object deserialized from an Xml Configuration Section.
		/// </summary>
		/// <param name="section">The configuration section containing the settings.</param>
		/// <param name="settingsTarget">The existing settings object to copy the new settings to.</param>
		/// <returns></returns>
		static object DeserializeSection(XmlNode section)
		{
			XPathNavigator navigator = section.CreateNavigator(); 

			string typename = (string)navigator.Evaluate("string(@type)");

			Type type = Type.GetType(typename);
			if(type == null)
				throw new ConfigurationException("The type '" + typename + "' is not a valid type. Double check the type parameter.");
			XmlSerializer serializer = new XmlSerializer(type); 

			return serializer.Deserialize(new XmlNodeReader(section));
		}
示例#20
0
文件: PlugConfig.cs 项目: kcitwm/dova
 public object Create(object parent, object configContext, XmlNode section)
 {
     try
     {
         string typeName = (string)section.CreateNavigator().Evaluate("string(@type)");
         string configSouce = (string)section.CreateNavigator().Evaluate("string(@configSouce)");
         XmlSerializer serializer = new XmlSerializer(Type.GetType(typeName), new XmlRootAttribute(section.Name));
         if (!string.IsNullOrEmpty(configSouce))
         {
             using (XmlTextReader tr = new XmlTextReader(Config.BasePath + configSouce))
             {
                 return serializer.Deserialize(tr);
             }
         }
         return serializer.Deserialize(new XmlNodeReader(section));
     }
     catch (Exception e)
     {
         Log.Error("ReadServiceConfig.Create;" + e.Message);
     }
     return null;
 }
示例#21
0
 public object Create(object parent, object configContext, XmlNode section)
 {
     try
     {
         string typeName = (string) section.CreateNavigator().Evaluate("string(@type)");
         XmlSerializer serializer = new XmlSerializer(Type.GetType(typeName));
         return serializer.Deserialize(new XmlNodeReader(section));
     }
     catch(Exception e)
     {
         Log.Error("WriteServiceConfig.Create;" + e.Message);
     }
     return null;
 }
示例#22
0
        public ReisDeel(XmlNode node)
        {
            var navigator = node.CreateNavigator();
            Vervoerder = navigator.Evaluate("string(Vervoerder)").ToString();
            VervoerType = navigator.Evaluate("string(VervoerType)").ToString();
            RitNummer = Convert.ToInt32(navigator.Evaluate("number(RitNummer)").ToString());
            GeplandeSoringId = navigator.Evaluate("string(GeplandeSoringId)").ToString();
            OngeplandeStoringId = navigator.Evaluate("string(OngeplandeStoringId)").ToString();

            ReisStops = new List<ReisStop>();
            foreach (XmlNode n in node.SelectNodes("ReisStop"))
            {
                ReisStops.Add(new ReisStop(n));
            }
        }
        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);
            }
        }
        /// <summary>
        /// Get the type of the configuration object that will be returned by the
        /// <see cref="Create"/> method.
        /// </summary>
        /// <param name="section">An xml node that represents configuration object in the *.config file.</param>
        /// <returns>The type of the configuration object that will be returned by the <see cref="Create"/> method.</returns>
        protected virtual Type GetConfigType(XmlNode section)
        {
            var xPathNavigator = section.CreateNavigator();
            var typeName = (string)xPathNavigator.Evaluate("string(@type)");

            if (string.IsNullOrEmpty(typeName))
            {
                throw new InvalidConfigurationException(string.Format("A 'type' attribute must be provided for the '{0}' element.", section.Name), section.OuterXml);
            }

            var configType = Type.GetType(typeName);

            if (configType == null)
            {
                throw new InvalidConfigurationException(string.Format("The value of the 'type' attribute, '{0}', is invalid for the '{1}' element. Hint: use the type's assembly qualified name.", typeName, section.Name), section.OuterXml);
            }

            return configType;
        }
        /// <summary>
        ///     Creates a configuration section handler.
        /// </summary>
        /// <param name="parent">Parent object.</param>
        /// <param name="configContext">Configuration context object.</param>
        /// <param name="section">Section XML node.</param>
        /// <returns>The created section handler object.</returns>
        /// <exception cref="System.ArgumentNullException">
        ///     configContext
        ///     or
        ///     section
        /// </exception>
        public object Create(object parent, object configContext, XmlNode section) {
            if (configContext == null) throw new ArgumentNullException("configContext");
            if (section == null) throw new ArgumentNullException("section");

            var xNav = section.CreateNavigator();

            var type = (string)xNav.Evaluate("string(@type)");

            if (type == null) return null;

            var t = Type.GetType(type);

            if (t == null) return null;

            var ser = new XmlSerializer(t);

            var xNodeReader = new XmlNodeReader(section);

            return ser.Deserialize(xNodeReader);
        }
        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            XPathNavigator navigator     = section.CreateNavigator();
            string         attributeName = "type";
            string         typeName      = (string)navigator.Evaluate("string(@" + attributeName + ")");

            if (typeName.Length == 0)
            {
                throw new ConfigurationErrorsException(string.Format("Attribute \'{0}\' not found for section \'{1}\'", attributeName, section.Name));
            }
            Type type = Type.GetType(typeName);

            if (type == null)
            {
                throw new ConfigurationErrorsException(string.Format("Type \'{0}\' couldn\'t be found. Section \'{1}\'", typeName, section.Name));
            }
            XmlSerializer ser        = new XmlSerializer(type);
            XmlNodeReader nodeReader = new XmlNodeReader(section);

            return(ser.Deserialize(nodeReader));
        }
        public object Create(
            object parent,
            object configContext,
            System.Xml.XmlNode section)
        {
            string callingAssemblyName = System.Reflection.Assembly.GetCallingAssembly().GetName().Name;
            string timeStamp           = DateTime.Now.ToString();
            string message             = "";

            try
            {
                message = "Attempting to deserialize a configuration object based on a configuration section node.";
                //Ram
                _avaLog.Debug(string.Format(GetDateTimeStamp() + ",DEBUG," + message));
                //Debug.WriteLine(GetDateTimeStamp()+ ",DEBUG," + message);

                XPathNavigator nav      = section.CreateNavigator();
                string         typename = ( string )nav.Evaluate("string(@type)");

                message = "Object to deserialize: " + typename;
                //Debug.WriteLine(GetDateTimeStamp()+ ",DEBUG," + message);
                _avaLog.Debug(string.Format(GetDateTimeStamp() + ",DEBUG," + message));

                Type          t   = Type.GetType(typename);
                XmlSerializer ser = new XmlSerializer(t);
                return(ser.Deserialize(new XmlNodeReader(section)));
            }
            catch (Exception ex)
            {
#if DEBUG
                Console.WriteLine(ex);
#endif
                message = "Failed to deserialize object. " + ex.Message;
                //Trace.WriteLine(GetDateTimeStamp()+ ",ERROR," + message);
                _avaLog.Error(GetDateTimeStamp() + ",ERROR," + message);
                throw;
            }
        }
示例#28
0
        public ValidationRule(XmlNode parent)
        {
            XPathNavigator nav = parent.CreateNavigator();

            this.name = XmlUtility.GetString(nav, NAME);

            this.length = XmlUtility.GetInteger(nav, LENGTH);
            string s = XmlUtility.GetString(nav, MIN);
            this.min = (s != null && s.Length > 0) ? s : "-1";
            s = XmlUtility.GetString(nav, MAX);
            this.max = (s != null && s.Length > 0) ? s : "-1";

            this.precision = XmlUtility.GetInteger(nav, PRECISION);

            this.required = XmlUtility.GetString(nav, REQUIRED);
            this.regex = XmlUtility.GetString(nav, REG_EXP);
            this.separator = XmlUtility.GetString(nav, SEPARATOR);
            this.mask = XmlUtility.GetString(nav, MASK);
            this.full = XmlUtility.GetInteger(nav, FULL);
            this.protocol = XmlUtility.GetString(nav, PROTOCOL);
            this.invalidhost = XmlUtility.GetString(nav, INVALIDHOST);
            this.invalidhostoverride = XmlUtility.GetString(nav, INVALIDHOSTOVERRIDE);
        }
示例#29
0
        public VertrekkendeTrein(XmlNode node)
        {
            var navigator = node.CreateNavigator();

            RitNummer = Convert.ToInt32(navigator.Evaluate("number(RitNummer)"));
            VertrekTijd = DateTime.ParseExact(navigator.Evaluate("string(VertrekTijd)").ToString(), "yyyy-MM-ddTHH:mm:sszzz", null);

            var vertrekVertraging = navigator.Evaluate("string(VertrekVertraging)").ToString();
            if (!String.IsNullOrEmpty(vertrekVertraging))
            {
                VertrekVertraging = new Vertraging()
                {
                    Duur = XmlConvert.ToTimeSpan(vertrekVertraging),
                    Tekst = navigator.Evaluate("string(VertrekVertragingTekst)").ToString()
                };
            }

            EindBestemming = navigator.Evaluate("string(EindBestemming)").ToString();
            TreinSoort = navigator.Evaluate("string(TreinSoort)").ToString();
            Route = navigator.Evaluate("string(RouteTekst)").ToString();
            Vervoerder = navigator.Evaluate("string(Vervoerder)").ToString();

            VertrekSpoor = new Spoor()
            {
                Gewijzigd = bool.Parse(navigator.Evaluate("string(VertrekSpoor/@wijziging)").ToString()),
                Nummer = navigator.Evaluate("string(VertrekSpoor)").ToString()
            };

            Opmerkingen = new List<string>();
            foreach (XmlNode a in node.SelectNodes("Opmerkingen/Opmerking"))
            {
                Opmerkingen.Add(a.InnerText.Trim());
            }

            ReisTip = navigator.Evaluate("string(ReisTip)").ToString();
        }
        public object ReadPropertyXml(PropertySerializerContext context, XmlNode propertyValue)
        {
            if (context.PropertyInfo.PropertyType != typeof(TableConfigurationCollection))
            {
                return null;
            }

            XPathNavigator navigator = propertyValue.CreateNavigator();
            XmlNamespaceManager oManager = new XmlNamespaceManager(navigator.NameTable);
            TableConfigurationCollection collection = new TableConfigurationCollection();
            TableConfigurationSerializer itemSerializer = new TableConfigurationSerializer();

            // Add the CodeSmith namespace
            oManager.AddNamespace("cs", CodeSmithProject.DefaultNamespace);

            // Loop through items
            XPathNodeIterator oIterator = navigator.Select("cs:TableConfiguration", oManager);
            while (oIterator.MoveNext())
            {
                collection.Add(itemSerializer.ReadPropertyXmlInner(context, ((IHasXmlNode)oIterator.Current).GetNode()));
            }

            return collection;
        }
示例#31
0
        private string GetXPathFromNode(XmlNode node) {
            // IM TODO review this algorithm - tidy up
            XPathNavigator nav = node.CreateNavigator();

            string xpath = "";
            int index = 0;

            while (nav.NodeType.ToString(CultureInfo.InvariantCulture) != "Root") {
                // loop thru children until we find ourselves
                XPathNavigator navParent = nav.Clone();
                navParent.MoveToParent();
                int parentIndex = 0;
                navParent.MoveToFirstChild();
                if (navParent.IsSamePosition(nav)) {
                    index = parentIndex;
                }
                while (navParent.MoveToNext()) {
                    parentIndex++;
                    if (navParent.IsSamePosition(nav)) {
                        index = parentIndex;
                    }
                }

                nav.MoveToParent(); // do loop condition here
                index++; // Convert to 1 based index

                string thisNode = "child::node()[" + index.ToString(CultureInfo.InvariantCulture) + "]";

                if (xpath.Length == 0) {
                    xpath = thisNode;
                } else {
                    // build xpath string
                    xpath = thisNode + "/" + xpath;
                }
            }

            // prepend slash to ...
            xpath = "/" + xpath;

            return xpath;
        }
示例#32
0
 // NOTE: should be protected internal virtual
 // but for ml-pnet's System.Data the internal modifier has to be removed
 protected virtual XPathNavigator CreateNavigator(XmlNode node)
 {
     return(node.CreateNavigator());
 }
示例#33
0
 /// <summary>
 /// Selects a node set using the specified XPath expression.
 /// </summary>
 public static XmlNodeList SelectNodesSorted(string expression, XmlNode source,
     object sortExpression, XmlSortOrder order, XmlCaseOrder caseOrder, string lang, XmlDataType dataType,
     XmlPrefix[] prefixes, params XPathVariable[] variables)
 {
     return XmlNodeListFactory.CreateNodeList(
         SelectSorted(expression, source.CreateNavigator(), sortExpression,
         order, caseOrder, lang, dataType, prefixes, variables));
 }
示例#34
0
 /// <summary>
 /// Selects a node set using the specified XPath expression.
 /// </summary>
 public static XmlNodeList SelectNodesSorted(string expression, XmlNode source,
     object sortExpression, XmlSortOrder order, XmlCaseOrder caseOrder, string lang, XmlDataType dataType,
     XmlNamespaceManager context)
 {
     return XmlNodeListFactory.CreateNodeList(
         SelectSorted(expression, source.CreateNavigator(), sortExpression,
         order, caseOrder, lang, dataType, context));
 }
示例#35
0
        /// <summary>
        /// This is used to load the reflection information file and to load
        /// the root namespace nodes into the tree view.
        /// </summary>
        /// <remarks>The namespace nodes and type nodes are loaded on demand
        /// to reduce the time needed to create the tree view and to conserve
        /// some memory for extremely large builds.
        /// <p/>Documented APIs are loaded into the first root node.  Inherited
        /// APIs are loaded into the second node.  By splitting the inherited
        /// stuff out, we can optimize the API filter and allow the user to get
        /// rid of unwanted inherited members with a single selection.</remarks>
        private void LoadNamespaces()
        {
            TreeNode node, rootNode = tvApiList.Nodes[0];
            NodeInfo nodeInfo;
            ApiFilter filter;
            List<NodeInfo> nodeList = new List<NodeInfo>();
            HashSet<string> existingIds = new HashSet<string>();
            string fullName;

            reflectionInfo = new XmlDocument();
            reflectionInfo.Load(reflectionFile);

            // Get the root APIs node as that's all we'll ever search
            apisNode = reflectionInfo.SelectSingleNode("reflection/apis");
            navigator = apisNode.CreateNavigator();

            try
            {
                this.Cursor = Cursors.WaitCursor;
                lblProgress.Text = "Loading namespaces...";
                Application.DoEvents();
                tvApiList.BeginUpdate();

                // Build a set of nodes to store the necessary information and sort it
                foreach(XmlNode nsNode in apisNode.SelectNodes("api[starts-with(@id, 'N:') or " +
                  "(starts-with(@id, 'G:') and not(apidata/@subgroup='rootGroup'))]"))
                {
                    string apiID = nsNode.Attributes["id"].Value, namespaceText = apiID.Substring(2);

                    if(apiID.StartsWith("G:", StringComparison.Ordinal))
                        namespaceText += " (Group)";

                    nodeInfo = new NodeInfo(namespaceText, apiID.Substring(2));
                    nodeInfo.ApiNode = nsNode;

                    nodeList.Add(nodeInfo);

                    // Classes with extension methods can show up in the system types too so we'll filter them
                    // out below.
                    existingIds.Add(nodeInfo.NodeText);
                }

                nodeList.Sort((x, y) =>
                {
                    var rVal = String.Compare(x.Id, y.Id, StringComparison.CurrentCulture);

                    // Sometimes group namespace ID is same as normal namespace, return group namespace first
                    return rVal == 0 ? -String.Compare(x.NodeText, y.NodeText, StringComparison.CurrentCulture) : rVal;
                });

                // Load the tree view with the namespaces for documented APIs as children of the first root node
                foreach(NodeInfo ni in nodeList)
                {
                    // The text is the namespace name and we'll store a reference to the node info in the tag
                    node = new TreeNode(ni.NodeText);
                    node.Tag = ni;
                    node.ImageIndex = node.SelectedImageIndex = (int)ApiEntryType.Namespace;

                    // This node may be namespace or namespace group
                    bool isNamespace = (ni.EntryType == ApiEntryType.Namespace);

                    // See if it's in the current filter
                    if(!buildFilterEntries.TryGetValue(ni.Id, out filter))
                    {
                        node.Checked = true;

                        if(isNamespace)
                        {
                            // Add a placeholder node for expansion on demand
                            node.Nodes.Add(String.Empty);
                        }
                    }
                    else
                    {
                        if(filter.IsProjectExclude && !filter.IsExposed)
                        {
                            ni.IsProjectExclude = true;
                            node.Checked = false;
                            node.NodeFont = italicFont;
                            node.ToolTipText = "Excluded via namespace comments or an <exclude /> tag.";
                        }
                        else
                            node.Checked = filter.IsExposed;

                        // Simple tristate workaround
                        if(filter.Children.Count != 0 && !filter.IsExposed)
                            node.BackColor = Color.LightBlue;

                        if(isNamespace)
                        {
                            // Add children now as it contains filtered entries and we'll need to keep them in
                            // synch with the parent.
                            this.AddTypes(node);
                        }
                    }

                    rootNode.Nodes.Add(node);
                }

                // Load inherited namespaces found in dependent assemblies and the .NET Framework itself
                lblProgress.Text = "Loading inherited namespaces...";
                Application.DoEvents();

                nodeList.Clear();
                rootNode = tvApiList.Nodes[1];

                // Build a set of nodes to store the necessary information and sort it
                foreach(XmlNode nsNode in apisNode.SelectNodes("api/elements/element/containers/namespace"))
                {
                    fullName = nsNode.Attributes["api"].Value.Substring(2);

                    // Ignore existing IDs as noted above
                    if(existingIds.Add(fullName))
                    {
                        nodeInfo = new NodeInfo(fullName, fullName);
                        nodeInfo.ApiNode = nsNode;
                        nodeInfo.IsProjectExclude = true;
                        nodeList.Add(nodeInfo);
                    }
                }

                nodeList.Sort((x, y) => String.Compare(x.NodeText, y.NodeText, StringComparison.CurrentCulture));

                // Load the tree view with the namespaces of inherited APIs as children of the second root node
                foreach(NodeInfo ni in nodeList)
                {
                    // The text is the namespace name and we'll store a reference to the node info in the tag
                    node = new TreeNode(ni.NodeText);
                    node.Tag = ni;
                    node.NodeFont = italicFont;
                    node.ToolTipText = "Namespace contains inherited types";
                    node.ImageIndex = node.SelectedImageIndex = (int)ApiEntryType.Namespace;

                    // See if it's in the current filter
                    if(!buildFilterEntries.TryGetValue(ni.Id, out filter))
                    {
                        node.Checked = true;

                        // Add a placeholder node for expansion on demand
                        node.Nodes.Add(String.Empty);
                    }
                    else
                    {
                        node.Checked = filter.IsExposed;

                        // Simple tri-state workaround
                        if(filter.Children.Count != 0 && !filter.IsExposed)
                            node.BackColor = Color.LightBlue;

                        // Add children now as it contains filtered entries and we'll need to keep them in synch
                        // with the parent.
                        this.AddBaseTypes(node);
                    }

                    rootNode.Nodes.Add(node);
                }

                if(tvApiList.Nodes[0].Nodes.Count != 0)
                    tvApiList.Nodes[0].Expand();

                if(tvApiList.Nodes[1].Nodes.Count != 0)
                    tvApiList.Nodes[1].Expand();

                tvApiList.SelectedNode = tvApiList.Nodes[0];
            }
            finally
            {
                tvApiList.EndUpdate();
                lblProgress.Text = null;
                this.Cursor = Cursors.Default;
            }
        }
示例#36
0
 /// <summary>
 /// Selects a list of nodes matching the XPath expression.
 /// </summary>
 public static XmlNodeList SelectNodes(string expression, XmlNode source, XmlNamespaceManager context, params XPathVariable[] variables)
 {
     XPathNodeIterator it = Select(expression, source.CreateNavigator(), context, variables);
     return XmlNodeListFactory.CreateNodeList(it);
 }
示例#37
0
 /// <summary>
 /// Selects a list of nodes matching the XPath expression.
 /// </summary>
 public static XmlNodeList SelectNodes(string expression, XmlNode source)
 {
     XPathNodeIterator it = Select(expression, source.CreateNavigator());
     return XmlNodeListFactory.CreateNodeList(it);
 }
示例#38
0
 /// <summary>
 /// Selects a node set using the specified XPath expression.
 /// </summary>
 public static XmlNodeList SelectNodesSorted(string expression, XmlNode source,
     object sortExpression, IComparer comparer,
     XmlPrefix[] prefixes, params XPathVariable[] variables)
 {
     return XmlNodeListFactory.CreateNodeList(
         SelectSorted(expression, source.CreateNavigator(), sortExpression,
         comparer, prefixes, variables));
 }
示例#39
0
 /// <summary>
 /// Selects a list of nodes matching the XPath expression.
 /// </summary>
 public static XmlNodeList SelectNodes(string expression, XmlNode source, XmlPrefix[] prefixes, params XPathVariable[] variables)
 {
     XPathNodeIterator it = Select(expression, source.CreateNavigator(), prefixes, variables);
     return XmlNodeListFactory.CreateNodeList(it);
 }
示例#40
0
 public XPathNavigator CreateNavigator()
 {
     return(_node.CreateNavigator());
 }
示例#41
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        ///   AddPortal manages the Installation of a new DotNetNuke Portal
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        ///   [cnurse]	11/06/2004	created
        /// </history>
        /// -----------------------------------------------------------------------------
        public static int AddPortal(XmlNode node, bool status, int indent)
        {

            int portalId = -1;
            try
            {
                string hostMapPath = Globals.HostMapPath;
                string childPath = "";
                string domain = "";

                if ((HttpContext.Current != null))
                {
                    domain = Globals.GetDomainName(HttpContext.Current.Request, true).ToLowerInvariant().Replace("/install", "");
                }
                DnnInstallLogger.InstallLogInfo(Localization.Localization.GetString("LogStart", Localization.Localization.GlobalResourceFile) + "AddPortal:" + domain);
                string portalName = XmlUtils.GetNodeValue(node.CreateNavigator(), "portalname");
                if (status)
                {
                    if (HttpContext.Current != null)
                    {
                        HtmlUtils.WriteFeedback(HttpContext.Current.Response, indent, "Creating Site: " + portalName + "<br>");
                    }
                }

                XmlNode adminNode = node.SelectSingleNode("administrator");
                if (adminNode != null)
                {
                    string firstName = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "firstname");
                    string lastName = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "lastname");
                    string username = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "username");
                    string password = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "password");
                    string email = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "email");
                    string description = XmlUtils.GetNodeValue(node.CreateNavigator(), "description");
                    string keyWords = XmlUtils.GetNodeValue(node.CreateNavigator(), "keywords");
                    string templateFileName = XmlUtils.GetNodeValue(node.CreateNavigator(), "templatefile");
                    string serverPath = Globals.ApplicationMapPath + "\\";
                    bool isChild = bool.Parse(XmlUtils.GetNodeValue(node.CreateNavigator(), "ischild"));
                    string homeDirectory = XmlUtils.GetNodeValue(node.CreateNavigator(), "homedirectory");

                    //Get the Portal Alias
                    XmlNodeList portalAliases = node.SelectNodes("portalaliases/portalalias");
                    string strPortalAlias = domain;
                    if (portalAliases != null)
                    {
                        if (portalAliases.Count > 0)
                        {
                            if (!string.IsNullOrEmpty(portalAliases[0].InnerText))
                            {
                                strPortalAlias = portalAliases[0].InnerText;
                            }
                        }
                    }

                    //Create default email
                    if (string.IsNullOrEmpty(email))
                    {
                        email = "admin@" + domain.Replace("www.", "");
                        //Remove any domain subfolder information ( if it exists )
                        if (email.IndexOf("/") != -1)
                        {
                            email = email.Substring(0, email.IndexOf("/"));
                        }
                    }

                    if (isChild)
                    {
                        childPath = PortalController.GetPortalFolder(strPortalAlias);
                    }

                    var template = FindBestTemplate(templateFileName);
                    var userInfo = CreateUserInfo(firstName, lastName, username, password, email);

                    //Create Portal
                    portalId = PortalController.Instance.CreatePortal(portalName,
                                                             userInfo,
                                                             description,
                                                             keyWords,
                                                             template,
                                                             homeDirectory,
                                                             strPortalAlias,
                                                             serverPath,
                                                             serverPath + childPath,
                                                             isChild);

                    if (portalId > -1)
                    {
                        //Add Extra Aliases
                        if (portalAliases != null)
                        {
                            foreach (XmlNode portalAlias in portalAliases)
                            {
                                if (!string.IsNullOrEmpty(portalAlias.InnerText))
                                {
                                    if (status)
                                    {
                                        if (HttpContext.Current != null)
                                        {
                                            HtmlUtils.WriteFeedback(HttpContext.Current.Response, indent, "Creating Site Alias: " + portalAlias.InnerText + "<br>");
                                        }
                                    }
                                    PortalController.Instance.AddPortalAlias(portalId, portalAlias.InnerText);
                                }
                            }
                        }

                        //Force Administrator to Update Password on first log in
                        PortalInfo portal = PortalController.Instance.GetPortal(portalId);
                        UserInfo adminUser = UserController.GetUserById(portalId, portal.AdministratorId);
                        adminUser.Membership.UpdatePassword = true;
                        UserController.UpdateUser(portalId, adminUser);
                    }


                    return portalId;
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);

                if (HttpContext.Current != null)
                {
                    HtmlUtils.WriteFeedback(HttpContext.Current.Response, indent, "<font color='red'>Error: " + ex.Message + ex.StackTrace + "</font><br>");
                    DnnInstallLogger.InstallLogError(ex);
                }
                // failure
                portalId = -1;
            }
            return portalId;
        }
示例#42
0
 /// <summary>
 /// Selects a node set using the specified XPath expression and sort.
 /// </summary>
 /// <remarks>
 /// See <see cref="XPathExpression.AddSort(object, IComparer)"/>.
 /// </remarks>
 public static XmlNodeList SelectNodesSorted(string expression, XmlNode source,
     object sortExpression, IComparer comparer)
 {
     return XmlNodeListFactory.CreateNodeList(
         SelectSorted(expression, source.CreateNavigator(), sortExpression, comparer));
 }