Skip() public method

public Skip ( ) : void
return void
Esempio n. 1
0
        public static DatabaseConfiguration Read(string file)
        {
            DatabaseConfiguration config = new DatabaseConfiguration ();

            StreamReader s = new StreamReader (file);
            using (s) {
                XmlTextReader tr = new XmlTextReader (s);
                tr.MoveToContent ();
                if (tr.IsEmptyElement)
                    return config;

                tr.ReadStartElement ("Configuration");
                tr.MoveToContent ();

                while (tr.NodeType != XmlNodeType.EndElement) {

                    if (tr.NodeType != XmlNodeType.Element || tr.IsEmptyElement) {
                        tr.Skip ();
                    }
                    else if (tr.LocalName == "DisabledAddins") {
                        // For back compatibility
                        tr.ReadStartElement ();
                        tr.MoveToContent ();
                        while (tr.NodeType != XmlNodeType.EndElement) {
                            if (tr.NodeType == XmlNodeType.Element && tr.LocalName == "Addin")
                                config.addinStatus [tr.ReadElementString ()] = null;
                            else
                                tr.Skip ();
                            tr.MoveToContent ();
                        }
                        tr.ReadEndElement ();
                    }
                    else if (tr.LocalName == "AddinStatus") {
                        tr.ReadStartElement ();
                        tr.MoveToContent ();
                        while (tr.NodeType != XmlNodeType.EndElement) {
                            if (tr.NodeType == XmlNodeType.Element && tr.LocalName == "Addin") {
                                string aid = tr.GetAttribute ("id");
                                string senabled = tr.GetAttribute ("enabled");
                                if (senabled.Length == 0 || senabled == "True")
                                    config.addinStatus [aid] = config;
                                else
                                    config.addinStatus [aid] = null;
                            }
                            tr.Skip ();
                            tr.MoveToContent ();
                        }
                        tr.ReadEndElement ();
                    }
                    tr.MoveToContent ();
                }
            }
            return config;
        }
		public static DatabaseConfiguration Read (string file)
		{
			DatabaseConfiguration config = new DatabaseConfiguration ();
			
			StreamReader s = new StreamReader (file);
			using (s) {
				XmlTextReader tr = new XmlTextReader (s);
				tr.MoveToContent ();
				tr.ReadStartElement ("Configuration");
				tr.MoveToContent ();
				tr.ReadStartElement ("DisabledAddins");
				tr.MoveToContent ();
				if (!tr.IsEmptyElement) {
					while (tr.NodeType != XmlNodeType.EndElement) {
						if (tr.NodeType == XmlNodeType.Element) {
							if (tr.LocalName == "Addin")
								config.DisabledAddins.Add (tr.ReadElementString ());
						}
						else
							tr.Skip ();
						tr.MoveToContent ();
					}
				}
			}
			return config;
		}
Esempio n. 3
0
 /// <summary> Loads any XML case file with it's Elements, Attributes and Values. </summary>
 /// <param name="fileURL"> Which file to load. </param>
 /// <returns> Load succeeded? </returns>
 bool LoadXML(string fileURL)
 {
     reader = new XmlTextReader(fileURL);
     if (reader.Read() && reader.NodeType == XmlNodeType.XmlDeclaration)
     {
         reader.Skip();
         while (reader.Read())
         {
             switch (reader.NodeType)
             {
                 case XmlNodeType.Element:
                     Program.form1.labelTest.Text += "+"+reader.Name;
                     Program.form1.labelTest.Text += reader.AttributeCount;
                     //Program.form1.labelTest.Text += "-"+reader.Value;
                     for (int i = 0; i < reader.AttributeCount; i++)
                         Program.form1.labelTest.Text += "#" + reader.GetAttribute(i);
                     break;
                 case XmlNodeType.Text:
                     //Program.form1.labelTest.Text += " TEXT  " + reader.Name;
                     Program.form1.labelTest.Text += " TEXT  " + reader.Value;
                     break;
                 case XmlNodeType.EndElement:
                     Program.form1.labelTest.Text += ">" + reader.Name;
                     //Program.form1.labelTest.Text += ">" + reader.Value;
                     break;
                 default:
                     if (reader.NodeType != XmlNodeType.Whitespace)
                         Program.form1.labelTest.Text += "     F A L S E ! ! ! ! !     ";
                     break;
             }
         }
     }
     return true;
 }
        public CAGCategory( CAGCategory parent, XmlTextReader xml )
        {
            m_Parent = parent;

            if ( xml.MoveToAttribute( "title" ) )
                m_Title = xml.Value;
            else
                m_Title = "empty";

            if ( m_Title == "Docked" )
                m_Title = "Docked 2";

            if ( xml.IsEmptyElement )
            {
                m_Nodes = new CAGNode[0];
            }
            else
            {
                ArrayList nodes = new ArrayList();

                while ( xml.Read() && xml.NodeType != XmlNodeType.EndElement )
                {
                    if ( xml.NodeType == XmlNodeType.Element && xml.Name == "object" )
                        nodes.Add( new CAGObject( this, xml ) );
                    else if ( xml.NodeType == XmlNodeType.Element && xml.Name == "category" )
                        nodes.Add( new CAGCategory( this, xml ) );
                    else
                        xml.Skip();
                }

                m_Nodes = (CAGNode[])nodes.ToArray( typeof( CAGNode ) );
            }
        }
Esempio n. 5
0
        public DataTable readXML(string qID, string xmlPath)
        {
            DataTable dt = new DataTable();
            string quest = "";
            string part = "";
            dt.Columns.Add("name");
            dt.Columns.Add("id");
            try
            {
                XmlTextReader reader = new XmlTextReader(xmlPath);
                while (reader.Read())
                {
                    switch (reader.Name)
                    {
                        case "question":

                            if (reader.AttributeCount > 0 && qID.ToUpper() == reader.GetAttribute("value").ToUpper())//OM DETR FINN 
                            {
                                part = reader.GetAttribute("part").ToUpper();
                            }
                            else
                            {
                                reader.Skip();
                            }
                            break;
                        case "txt":
                            quest = reader.ReadString(); //Frågan sparas till en string behöver ha en tupple
                            break;
                        case "qone": 
                            dt.Rows.Add();//Nedan är svarsalternativen 
                            dt.Rows[dt.Rows.Count - 1]["id"] = reader.GetAttribute("id").ToUpper();
                            dt.Rows[dt.Rows.Count - 1]["name"] = reader.ReadString();
                            break;
                        case "qtwo":
                            dt.Rows.Add();
                            dt.Rows[dt.Rows.Count - 1]["id"] = reader.GetAttribute("id").ToUpper();
                            dt.Rows[dt.Rows.Count - 1]["name"] = reader.ReadString();                           
                            break;
                        case "qthree":
                            dt.Rows.Add();
                            dt.Rows[dt.Rows.Count - 1]["id"] = reader.GetAttribute("id").ToUpper();
                            dt.Rows[dt.Rows.Count - 1]["name"] = reader.ReadString();                           
                            break;
                        case "qfour":
                            dt.Rows.Add();
                            dt.Rows[dt.Rows.Count - 1]["id"] = reader.GetAttribute("id").ToUpper();
                            dt.Rows[dt.Rows.Count - 1]["name"] = reader.ReadString();                            
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                return null;
            }
            return dt;
        }
Esempio n. 6
0
 public static string XmlDocumentationToText(string xmlDoc)
 {
     System.Diagnostics.Debug.WriteLine(xmlDoc);
     StringBuilder b = new StringBuilder();
     try {
         using (XmlTextReader reader = new XmlTextReader(new StringReader("<root>" + xmlDoc + "</root>"))) {
             reader.XmlResolver = null;
             while (reader.Read()) {
                 switch (reader.NodeType) {
                     case XmlNodeType.Text:
                         b.Append(reader.Value);
                         break;
                     case XmlNodeType.Element:
                         switch (reader.Name) {
                             case "filterpriority":
                                 reader.Skip();
                                 break;
                             case "returns":
                                 b.AppendLine();
                                 b.Append("Returns: ");
                                 break;
                             case "param":
                                 b.AppendLine();
                                 b.Append(reader.GetAttribute("name") + ": ");
                                 break;
                             case "remarks":
                                 b.AppendLine();
                                 b.Append("Remarks: ");
                                 break;
                             case "see":
                                 if (reader.IsEmptyElement) {
                                     b.Append(reader.GetAttribute("cref"));
                                 } else {
                                     reader.MoveToContent();
                                     if (reader.HasValue) {
                                         b.Append(reader.Value);
                                     } else {
                                         b.Append(reader.GetAttribute("cref"));
                                     }
                                 }
                                 break;
                         }
                         break;
                 }
             }
         }
         return b.ToString();
     } catch (XmlException) {
         return xmlDoc;
     }
 }
        public XmlAddCAGCategory( XmlAddCAGCategory parent, XmlTextReader xml )
        {
            m_Parent = parent;

            if ( xml.MoveToAttribute( "title" ) )
            {
                if(xml.Value == "Add Menu")
                    m_Title = "XmlAdd Menu";
                else
                    m_Title = xml.Value;

            }
            else
                m_Title = "empty";

            if ( m_Title == "Docked" )
                m_Title = "Docked 2";

            if ( xml.IsEmptyElement )
            {
                m_Nodes = new XmlAddCAGNode[0];
            }
            else
            {
                ArrayList nodes = new ArrayList();

                try{
                while ( xml.Read() && xml.NodeType != XmlNodeType.EndElement )
                {

                    if ( xml.NodeType == XmlNodeType.Element && xml.Name == "object" )
                        nodes.Add( new XmlAddCAGObject( this, xml ) );
                    else if ( xml.NodeType == XmlNodeType.Element && xml.Name == "category" )
                        nodes.Add( new XmlAddCAGCategory( this, xml ) );
                    else
                        xml.Skip();

                }
                } catch (Exception ex){
                    Console.WriteLine("XmlCategorizedAddGump: Corrupted Data/objects.xml file detected. Not all XmlCAG objects loaded. {0}", ex);
                }

                m_Nodes = (XmlAddCAGNode[])nodes.ToArray( typeof( XmlAddCAGNode ) );

            }
        }
Esempio n. 8
0
		public override void ReadGen(APGen gen, string streamName, XmlTextReader reader)
		{
			StreamName = streamName;
			GenHost = gen.GenHost;

			while (reader.MoveToNextAttribute())
			{
				switch (reader.Name)
				{
					case "type": TypeName = reader.Value; break;
					case "name": Name = reader.Value; break;
					default: ThrowException(APResource.GetString(APResource.APGen_UnrecognizedAttribute, reader.Name), reader); break;
				}
			}

			if (Name == null || TypeName == null)
				ThrowException(APResource.GetString(APResource.APGen_MissingRequiredAttribute, "section", "name or type"), reader);

			reader.MoveToElement();
			reader.Skip();
		}
Esempio n. 9
0
        public DataTable read(string testID)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("name"); //Fråga 1, Fråga 2---
            dt.Columns.Add("id"); //Fråge id:et
            dt.Columns.Add("order");
            try
            {
                XmlTextReader reader = new XmlTextReader(new StringReader(getXml(testID)));
                while (reader.Read())
                {
                    switch (reader.Name)
                    {
                        case "question":
                            dt.Rows.Add();
                            dt.Rows[dt.Rows.Count - 1]["order"] = reader.GetAttribute("order").ToUpper();
                            dt.Rows[dt.Rows.Count - 1]["id"] = reader.GetAttribute("value").ToUpper();
                           // Random random = new Random();

                            reader.Skip();
                            break;
                    }
                }

            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }

            dt.DefaultView.Sort = "order";
            dt = dt.DefaultView.ToTable();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dt.Rows[i]["name"] = (i + 1).ToString();
            }

            return dt;
        }
		static string ReadGenericProjectType (string file)
		{
			using (XmlTextReader tr = new XmlTextReader (file)) {
				tr.MoveToContent ();
				if (tr.LocalName != "Project")
					return null;
				if (tr.IsEmptyElement)
					return null;
				tr.ReadStartElement ();
				tr.MoveToContent ();
				if (tr.LocalName != "PropertyGroup")
					return null;
				if (tr.IsEmptyElement)
					return null;
				tr.ReadStartElement ();
				tr.MoveToContent ();
				while (tr.NodeType != XmlNodeType.EndElement) {
					if (tr.NodeType == XmlNodeType.Element && !tr.IsEmptyElement && tr.LocalName == "ItemType")
						return tr.ReadElementString ();
					tr.Skip ();
				}
				return null;
			}
		}
Esempio n. 11
0
		private void ParseSettingString (string source)
		{
			XmlTextReader xtr = new XmlTextReader (source,
				XmlNodeType.Element, null);

			xtr.Read ();
			if (xtr.Name != "DataViewSettingCollectionString")
				// easy way to throw the expected exception ;-)
			xtr.ReadStartElement ("DataViewSettingCollectionString");
			if (xtr.IsEmptyElement)
				return; // MS does not change the value.

			xtr.Read ();
			do {
				xtr.MoveToContent ();
				if (xtr.NodeType == XmlNodeType.EndElement)
					break;
				if (xtr.NodeType == XmlNodeType.Element)
					ReadTableSetting (xtr);
				else
					xtr.Skip ();
			} while (!xtr.EOF);
			if (xtr.NodeType == XmlNodeType.EndElement)
				xtr.ReadEndElement ();
		}
Esempio n. 12
0
		private void ReadConfigFile (XmlTextReader reader)
		{
			//int depth = reader.Depth;
			for (reader.MoveToContent ();
			     !reader.EOF && reader.NodeType != XmlNodeType.EndElement;
			     reader.MoveToContent ()) {
				string name = reader.Name;
				if (name == "configSections") {
					if (reader.HasAttributes)
						ThrowException ("Unrecognized attribute in <configSections>.", reader);
					if (reader.IsEmptyElement)
						reader.Skip ();
					else {
						reader.Read ();
						reader.MoveToContent ();
						if (reader.NodeType != XmlNodeType.EndElement)
							ReadSections (reader, null);
						reader.ReadEndElement ();
					}
				} else if (name != null && name != "") {
					StorePending (name, reader);
					MoveToNextElement (reader);
				} else {
					MoveToNextElement (reader);
				}
			}
		}
Esempio n. 13
0
		private void ReadSection (XmlTextReader reader, string sectionName)
		{
			string attName;
			string nameValue = null;
			string typeValue = null;
			string allowLoc = null, allowDef = null;
			bool requirePermission = false;
			string requirePer = null;
			bool allowLocation = true;
			AllowDefinition allowDefinition = AllowDefinition.Everywhere;

			while (reader.MoveToNextAttribute ()) {
				attName = reader.Name;
				if (attName == null)
					continue;

				if (attName == "allowLocation") {
					if (allowLoc != null)
						ThrowException ("Duplicated allowLocation attribute.", reader);

					allowLoc = reader.Value;
					allowLocation = (allowLoc == "true");
					if (!allowLocation && allowLoc != "false")
						ThrowException ("Invalid attribute value", reader);

					continue;
				}

				if (attName == "requirePermission") {
					if (requirePer != null)
						ThrowException ("Duplicated requirePermission attribute.", reader);
					requirePer = reader.Value;
					requirePermission = (requirePer == "true");
					if (!requirePermission && requirePer != "false")
						ThrowException ("Invalid attribute value", reader);
					continue;
				}

				if (attName == "allowDefinition") {
					if (allowDef != null)
						ThrowException ("Duplicated allowDefinition attribute.", reader);

					allowDef = reader.Value;
					try {
						allowDefinition = (AllowDefinition) Enum.Parse (
								   typeof (AllowDefinition), allowDef);
					} catch {
						ThrowException ("Invalid attribute value", reader);
					}

					continue;
				}

				if (attName == "type")  {
					if (typeValue != null)
						ThrowException ("Duplicated type attribute.", reader);
					typeValue = reader.Value;
					continue;
				}
				
				if (attName == "name")  {
					if (nameValue != null)
						ThrowException ("Duplicated name attribute.", reader);
					nameValue = reader.Value;
					if (nameValue == "location")
						ThrowException ("location is a reserved section name", reader);
					continue;
				}

				ThrowException ("Unrecognized attribute.", reader);
			}

			if (nameValue == null || typeValue == null)
				ThrowException ("Required attribute missing", reader);

			if (sectionName != null)
				nameValue = sectionName + '/' + nameValue;

			reader.MoveToElement();
			object o = LookForFactory (nameValue);
			if (o != null && o != removedMark)
				ThrowException ("Already have a factory for " + nameValue, reader);
			SectionData section = new SectionData (nameValue, typeValue, allowLocation,
				allowDefinition, requirePermission);
			section.FileName = fileName;
			factories [nameValue] = section;

			if (reader.IsEmptyElement)
				reader.Skip ();
			else {
				reader.Read ();
				reader.MoveToContent ();
				if (reader.NodeType != XmlNodeType.EndElement)
					// sub-section inside a section
					ReadSections (reader, nameValue);
				reader.ReadEndElement ();
			}
			reader.MoveToContent ();
		}
Esempio n. 14
0
        /// <summary>
        /// Converts the xml documentation string into a plain text string.
        /// </summary>
        private static string GetDocumentation(string ExtendedData)
        {
            System.IO.StringReader reader = new System.IO.StringReader("<docroot>" + ExtendedData + "</docroot>");
            XmlTextReader xml = new XmlTextReader(reader);
            StringBuilder ret = new StringBuilder();
            ////Regex whitespace    = new Regex(@"\s+");
            bool blnExceptionStarted = false;

            try
            {
                xml.Read();
                do
                {
                    if (xml.NodeType == XmlNodeType.Element)
                    {
                        string elname = xml.Name.ToLowerInvariant();
                        switch (elname)
                        {
                            case "filterpriority":
                                xml.Skip();
                                break;
                            case "remarks":
                                ret.Append(Environment.NewLine);
                                ret.Append("Remarks:");
                                ret.Append(Environment.NewLine);
                                break;
                            case "example":
                                ret.Append(Environment.NewLine);
                                ret.Append("Example:");
                                ret.Append(Environment.NewLine);
                                break;
                            case "exception":
                                ret.Append(Environment.NewLine);
                                if (blnExceptionStarted == false)
                                {
                                    ret.Append("Exception:");
                                    ret.Append(Environment.NewLine);
                                    blnExceptionStarted = true;
                                }
                                ret.Append(GetCref(xml["cref"]));
                                ret.Append(": ");
                                xml.Skip();
                                break;
                            case "returns":
                                xml.Skip();
                                //ret.Append(Environment.NewLine);
                                //ret.Append("Returns: ");
                                break;
                            case "see":
                                ret.Append(GetCref(xml["cref"]));
                                ret.Append(xml["langword"]);
                                break;
                            case "seealso":
                                ret.Append(Environment.NewLine);
                                ret.Append("See also: ");
                                ret.Append(GetCref(xml["cref"]));
                                break;
                            case "paramref":
                                ret.Append(xml["name"]);
                                break;
                            case "param":
                                ret.Append(Environment.NewLine);
                                ret.Append(whitespace.Replace(xml["name"].Trim(), " "));
                                ret.Append(": ");
                                break;
                            case "value":
                                ret.Append(Environment.NewLine);
                                ret.Append("Value: ");
                                ret.Append(Environment.NewLine);
                                break;
                            case "br":
                            case "para":
                                ret.Append(Environment.NewLine);
                                break;
                        }
                    }
                    else if (xml.NodeType == XmlNodeType.Text)
                    {
                        ret.Append(whitespace.Replace(xml.Value, " "));
                    }
                } while (xml.Read());
            }
            catch (Exception e)
            {
                e.ToString();
                return ExtendedData;
            }
            return ret.ToString();
        }
Esempio n. 15
0
        /// <summary>
        /// GetLineNumber is used when reporting errors in Animation XML
        /// descriptions. It will find the line number of the first top level
        /// node whose tag matches the provided value.
        /// </summary>
        /// <param name="source">Animation XML description</param>
        /// <param name="tag">Tag of the node to find</param>
        /// <returns>Line number of the tag, or the first line if nothing found</returns>
        private static int GetLineNumber(string source, string tag)
        {
            // We'll manually walk through the source using an XmlTextReader
            // so we can get the line number
            using (XmlTextReader reader = new XmlTextReader(new StringReader(source)))
            {
                // Move to the document element
                if (reader.Read())
                {
                    // Loop though all the top level children
                    while (reader.Read())
                    {
                        // If this node matches, return its line number
                        if (string.Compare(reader.Name, tag, StringComparison.OrdinalIgnoreCase) == 0)
                            return reader.LineNumber;
                        // If this node has children, ignore them all 
                        if (reader.NodeType == XmlNodeType.Element && !reader.IsEmptyElement)
                            reader.Skip();
                    }
                }
            }

            // If we can't find it, just use the first line
            return 1;   
        }
Esempio n. 16
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="filename"></param>
        private void Read(string filename)
        {
            XmlTextReader xmlReader = new XmlTextReader(filename);
            xmlReader.WhitespaceHandling = WhitespaceHandling.None;

            xmlReader.Read();
            xmlReader.Read();
            xmlReader.Read();
            xmlReader.Skip();

            int i = 0;

            if (xmlReader.Name == "members")
            {
                List<Entity> entities = new List<Entity>();
                Hashtable classTable = new Hashtable();
                xmlReader.Read();
                while (!(xmlReader.Name == "members" && xmlReader.NodeType == XmlNodeType.EndElement))
                {
                    i++;
                    ReadMember(xmlReader, entities);
                    xmlReader.Read();
                    //if (i > 3) break;
                }
                foreach (Entity e in entities)
                {
                    if (e.Name.StartsWith("XamlGeneratedNamespace") ||
                        e.Name.StartsWith("Stoffi.Properties.")) continue;

                    if (e is Class)
                    {
                        string[] name = ParseName(e.Name);
                        e.Name = name[0];
                        classTable[name[0]] = e;
                    }
                }
                foreach (Entity e in entities)
                {
                    if (e.Name.StartsWith("XamlGeneratedNamespace") ||
                        e.Name.StartsWith("Stoffi.Properties.")) continue;

                    if (e is Method)
                    {
                        string[] name = ParseName(e.Name, true);
                        e.Name = name[1];
                        Class c = classTable[name[0]] as Class;
                        c.Methods.Add(e as Method);
                    }
                    else if (e is Delegate)
                    {
                        string[] name = ParseName(e.Name, true);
                        if (name[1] == null)
                        {
                            e.Name = name[0];
                            delegates.Add(e as Delegate);
                        }
                        else
                        {
                            e.Name = name[1];
                            Class c = classTable[name[0]] as Class;
                            c.Delegates.Add(e as Delegate);
                        }
                    }
                    else if (e is Event)
                    {
                        string[] name = ParseName(e.Name, true);
                        e.Name = name[1];
                        Class c = classTable[name[0]] as Class;
                        c.Events.Add(e as Event);
                    }
                    else if (e is Field)
                    {
                        string[] name = ParseName(e.Name, true);
                        e.Name = name[1];
                        Class c = classTable[name[0]] as Class;
                        c.Fields.Add(e as Field);
                    }
                    else if (e is Property)
                    {
                        string[] name = ParseName(e.Name, true);
                        e.Name = name[1];
                        Class c = classTable[name[0]] as Class;
                        c.Properties.Add(e as Property);
                    }
                    else if (!(e is Class))
                    {
                        Console.WriteLine("Unknown type of entity: " + e.Name);
                    }
                }

                foreach (DictionaryEntry o in classTable)
                {
                    Class c = o.Value as Class;

                    if (c.Fields.Count > 0 && c.Methods.Count == 0 && c.Events.Count == 0 && c.Properties.Count == 0)
                    {
                        Enum e = new Enum();
                        e.Name = c.Name;
                        e.Summary = c.Summary;
                        e.SeeAlsos = c.SeeAlsos;
                        e.Remarks = c.Remarks;

                        foreach (Field f in c.Fields)
                        {
                            Value v = new Value();
                            v.Name = f.Name;
                            v.Summary = f.Summary;
                            v.SeeAlsos = f.SeeAlsos;
                            v.Remarks = f.Remarks;
                            e.Values.Add(v);
                        }
                        enums.Add(e);
                    }
                    else
                    {
                        foreach (Method m in c.Methods)
                        {
                            if (m.Name.StartsWith("#cctor") || m.Name.StartsWith("#ctor"))
                                c.Constructor = m;
                            else if (m.Name == "Finalize")
                                c.Destructor = m;
                        }
                        c.Methods.Remove(c.Constructor);
                        c.Methods.Remove(c.Destructor);
                        classes.Add(c);
                    }
                }

                Generate();
            }
            else
            {
                Console.WriteLine("Expected element <members> but got <" + xmlReader.Name + "> instead");
            }
        }
Esempio n. 17
0
        public void ScanAddinsFile(IProgressStatus monitor, string file, string domain, AddinScanResult scanResult)
        {
            XmlTextReader r = null;
            ArrayList directories = new ArrayList ();
            ArrayList directoriesWithSubdirs = new ArrayList ();
            string basePath = Path.GetDirectoryName (file);

            try {
                r = new XmlTextReader (fs.OpenTextFile (file));
                r.MoveToContent ();
                if (r.IsEmptyElement)
                    return;
                r.ReadStartElement ();
                r.MoveToContent ();
                while (r.NodeType != XmlNodeType.EndElement) {
                    if (r.NodeType == XmlNodeType.Element && r.LocalName == "Directory") {
                        string subs = r.GetAttribute ("include-subdirs");
                        string sdom;
                        string share = r.GetAttribute ("shared");
                        if (share == "true")
                            sdom = AddinDatabase.GlobalDomain;
                        else if (share == "false")
                            sdom = null;
                        else
                            sdom = domain; // Inherit the domain

                        string path = r.ReadElementString ().Trim ();
                        if (path.Length > 0) {
                            path = Util.NormalizePath (path);
                            if (subs == "true")
                                directoriesWithSubdirs.Add (new string[] {path, sdom});
                            else
                                directories.Add (new string[] {path, sdom});
                        }
                    }
                    else if (r.NodeType == XmlNodeType.Element && r.LocalName == "GacAssembly") {
                        string aname = r.ReadElementString ().Trim ();
                        if (aname.Length > 0) {
                            aname = Util.NormalizePath (aname);
                            aname = Util.GetGacPath (aname);
                            if (aname != null) {
                                // Gac assemblies always use the global domain
                                directories.Add (new string[] {aname, AddinDatabase.GlobalDomain});
                            }
                        }
                    }
                    else if (r.NodeType == XmlNodeType.Element && r.LocalName == "Exclude") {
                        string path = r.ReadElementString ().Trim ();
                        if (path.Length > 0) {
                            path = Util.NormalizePath (path);
                            if (!Path.IsPathRooted (path))
                                path = Path.Combine (basePath, path);
                            scanResult.AddPathToIgnore (Path.GetFullPath (path));
                        }
                    }
                    else
                        r.Skip ();
                    r.MoveToContent ();
                }
            } catch (Exception ex) {
                monitor.ReportError ("Could not process addins file: " + file, ex);
                return;
            } finally {
                if (r != null)
                    r.Close ();
            }

            foreach (string[] d in directories) {
                string dir = d[0];
                if (!Path.IsPathRooted (dir))
                    dir = Path.Combine (basePath, dir);
                ScanFolder (monitor, dir, d[1], scanResult);
            }
            foreach (string[] d in directoriesWithSubdirs) {
                string dir = d[0];
                if (!Path.IsPathRooted (dir))
                    dir = Path.Combine (basePath, dir);
                ScanFolderRec (monitor, dir, d[1], scanResult);
            }
        }
Esempio n. 18
0
        private void ParseActionXml(String XML, int startLine)
        {
            UPnPAction action = new UPnPAction();
            UPnPArgument arg;

            StringReader MyString = new StringReader(XML);
            XmlTextReader XMLDoc = new XmlTextReader(MyString);

            try
            {
                XMLDoc.Read();
                XMLDoc.MoveToContent();
                XMLDoc.Read();
                XMLDoc.MoveToContent();
                while (XMLDoc.LocalName != "action")
                {
                    switch (XMLDoc.LocalName)
                    {
                        case "name":
                            action.Name = XMLDoc.ReadString().Trim();
                            break;
                        case "argumentList":
                            if (XMLDoc.IsEmptyElement)
                            {
                                break;
                            }
                            XMLDoc.Read();
                            XMLDoc.MoveToContent();
                            while (XMLDoc.LocalName != "argumentList" && XMLDoc.EOF == false)
                            {
                                if (XMLDoc.LocalName == "argument")
                                {
                                    arg = new UPnPArgument();
                                    XMLDoc.Read();
                                    XMLDoc.MoveToContent();
                                    while (XMLDoc.LocalName != "argument")
                                    {
                                        switch (XMLDoc.LocalName)
                                        {
                                            case "name":
                                                arg.Name = XMLDoc.ReadString().Trim();
                                                break;
                                            case "retval":
                                                arg.IsReturnValue = true;
                                                break;
                                            case "direction":
                                                arg.Direction = XMLDoc.ReadString().Trim();
                                                break;
                                            case "relatedStateVariable":
                                                arg.StateVarName = XMLDoc.ReadString().Trim();
                                                break;
                                        }
                                        XMLDoc.Read();
                                        XMLDoc.MoveToContent();
                                    }
                                    action.AddArgument(arg);
                                    XMLDoc.Read();
                                    XMLDoc.MoveToContent();
                                }
                                else
                                {
                                    XMLDoc.Skip();
                                }
                            }
                            break;
                    }
                    // End of Switch
                    XMLDoc.Read();
                    XMLDoc.MoveToContent();
                }
                // End of While

                AddAction(action);
            }
            catch (Exception ex)
            {
                throw new XMLParsingException("Invalid Action XML", startLine + XMLDoc.LineNumber, XMLDoc.LinePosition, ex);
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Converts the xml documentation string into a plain text string.
        /// </summary>
        public static string ConvertDocumentation(string xmlDocumentation)
        {
            if (string.IsNullOrEmpty(xmlDocumentation))
                return string.Empty;

            var reader = new System.IO.StringReader("<docroot>" + xmlDocumentation + "</docroot>");
            var xml = new XmlTextReader(reader);
            var ret = new StringBuilder();

            try
            {
                xml.Read();
                do
                {
                    if (xml.NodeType == XmlNodeType.Element)
                    {
                        string elname = xml.Name.ToLowerInvariant();
                        switch (elname)
                        {
                            case "filterpriority":
                                xml.Skip();
                                break;
                            case "remarks":
                                ret.Append(Environment.NewLine);
                                ret.Append("Remarks:");
                                ret.Append(Environment.NewLine);
                                break;
                            case "example":
                                ret.Append(Environment.NewLine);
                                ret.Append("Example:");
                                ret.Append(Environment.NewLine);
                                break;
                            case "exception":
                                ret.Append(Environment.NewLine);
                                ret.Append(GetCref(xml["cref"]));
                                ret.Append(": ");
                                break;
                            case "returns":
                                ret.Append(Environment.NewLine);
                                ret.Append("Returns: ");
                                break;
                            case "see":
                                ret.Append(GetCref(xml["cref"]));
                                ret.Append(xml["langword"]);
                                break;
                            case "seealso":
                                ret.Append(Environment.NewLine);
                                ret.Append("See also: ");
                                ret.Append(GetCref(xml["cref"]));
                                break;
                            case "paramref":
                                ret.Append(xml["name"]);
                                break;
                            case "param":
                                ret.Append(Environment.NewLine);
                                ret.Append(Whitespace.Replace(xml["name"].Trim(), " "));
                                ret.Append(": ");
                                break;
                            case "value":
                                ret.Append(Environment.NewLine);
                                ret.Append("Value: ");
                                ret.Append(Environment.NewLine);
                                break;
                            case "br":
                            case "para":
                                ret.Append(Environment.NewLine);
                                break;
                        }
                    }
                    else if (xml.NodeType == XmlNodeType.Text)
                    {
                        ret.Append(Whitespace.Replace(xml.Value, " "));
                    }
                } while (xml.Read());
            }
            catch (Exception)
            {
                return xmlDocumentation;
            }
            return ret.ToString();
        }
        internal void ParseSCPD(String XML)
        {
            OpenSource.Utilities.EventLogger.Log (this, System.Diagnostics.EventLogEntryType.SuccessAudit,"Embarking on an xml journey");

            bool loadSchema = false;
            string schemaUrn = "";
            if (XML == "")
            {
                return;
            }

            string evented = "no";
            string multicast = "no";
            StringReader MyString = new StringReader(XML);
            XmlTextReader XMLDoc = new XmlTextReader(MyString);

            XMLDoc.Read();
            XMLDoc.MoveToContent();

            if (XMLDoc.LocalName == "scpd")
            {
                if (XMLDoc.HasAttributes)
                {
                    // May be UPnP/1.1 SCPD
                    for (int i = 0; i < XMLDoc.AttributeCount; i++)
                    {
                        XMLDoc.MoveToAttribute(i);
                        if (XMLDoc.Prefix == "xmlns")
                        {
                            loadSchema = true;
                            schemaUrn = XMLDoc.Value;
                        }
                        // ToDo: Try to load the schema from the network first
                        //						if (XMLDoc.LocalName=="schemaLocation")
                        //						{
                        //							if (XMLDoc.Value=="http://www.vendor.org/Schemas/Sample.xsd")
                        //							{
                        //								schemaUrn = XMLDoc.LookupNamespace(XMLDoc.Prefix);
                        //							}
                        //						}
                    }
                    XMLDoc.MoveToElement();

                    if (loadSchema)
                    {
                        // Prompt Application for local Schema Location
                        System.Windows.Forms.OpenFileDialog fd = new System.Windows.Forms.OpenFileDialog();
                        fd.Multiselect = false;
                        fd.Title = schemaUrn;
                        if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            FileStream fs = (FileStream)fd.OpenFile();
                            System.Text.UTF8Encoding U = new System.Text.UTF8Encoding();
                            byte[] buffer = new byte[(int)fs.Length];
                            fs.Read(buffer, 0, buffer.Length);
                            UPnPComplexType[] complexTypes = UPnPComplexType.Parse(U.GetString(buffer));
                            fs.Close();
                            foreach (UPnPComplexType complexType in complexTypes)
                            {
                                this.AddComplexType(complexType);
                            }
                        }
                    }
                }

                // TODO This parsing is hideous. We should use a proper parser!
                XMLDoc.Read();
                XMLDoc.MoveToContent();
                while ((XMLDoc.LocalName != "scpd") && (XMLDoc.EOF == false))
                {
                    if (XMLDoc.LocalName == "actionList" && !XMLDoc.IsEmptyElement)
                    {
                        XMLDoc.Read();
                        XMLDoc.MoveToContent();
                        while ((XMLDoc.LocalName != "actionList") && (XMLDoc.EOF == false))
                        {
                            if (XMLDoc.LocalName == "action")
                            {
                                OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.SuccessAudit, "Found an action, lets parse it!");
                                ParseActionXml("<action>\r\n" + XMLDoc.ReadInnerXml() + "</action>");
                            }
                            if (!XMLDoc.IsStartElement())
                            {
                                if (XMLDoc.LocalName != "actionList")
                                {
                                    XMLDoc.Read();
                                    XMLDoc.MoveToContent();
                                }
                            }
                        }
                    }
                    else
                    {
                        if (XMLDoc.LocalName == "serviceStateTable")
                        {
                            XMLDoc.Read();
                            XMLDoc.MoveToContent();

                            while ((XMLDoc.LocalName != "serviceStateTable") &&
                                (XMLDoc.EOF == false))
                            {
                                if (XMLDoc.LocalName == "stateVariable")
                                {
                                    evented = "no";
                                    multicast = "no";

                                    XMLDoc.MoveToAttribute("sendEvents");
                                    if (XMLDoc.LocalName == "sendEvents")
                                    {
                                        evented = XMLDoc.GetAttribute("sendEvents");
                                    }
                                    XMLDoc.MoveToAttribute("multicast");
                                    if (XMLDoc.LocalName == "multicast")
                                    {
                                        multicast = XMLDoc.GetAttribute("multicast");
                                    }
                                    XMLDoc.MoveToContent();
                                    ParseStateVarXml(evented, multicast, XMLDoc);
                                }
                                if (!XMLDoc.IsStartElement())
                                {
                                    if (XMLDoc.LocalName != "serviceStateTable")
                                    {
                                        XMLDoc.Read();
                                        XMLDoc.MoveToContent();
                                    }
                                }
                            }
                        }
                        else
                        {
                            XMLDoc.Skip();
                        }

                    }
                    if (!XMLDoc.IsStartElement())
                    {
                        XMLDoc.Read();
                        XMLDoc.MoveToContent();
                    }
                }
                // End of While

                // Add Associations
                foreach (UPnPAction A in this.Actions)
                {
                    foreach (UPnPArgument G in A.Arguments)
                    {
                        if (G.RelatedStateVar == null)
                        {
                            OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.FailureAudit, "About to throw an exception");
                            throw (new InvalidRelatedStateVariableException("Action: " + A.Name + " Arg: " + G.Name + " Contains invalid reference: " + G.StateVarName));
                        }
                        G.RelatedStateVar.AddAssociation(A.Name, G.Name);
                    }
                }
            }
            // End of If
        }
Esempio n. 21
0
		private bool InitRead (XmlTextReader reader)
		{
			reader.MoveToContent ();
			if (reader.NodeType != XmlNodeType.Element || reader.Name != "configuration")
				ThrowException ("Configuration file does not have a valid root element", reader);

			if (reader.HasAttributes)
				ThrowException ("Unrecognized attribute in root element", reader);
			if (reader.IsEmptyElement) {
				reader.Skip ();
				return false;
			}
			reader.Read ();
			reader.MoveToContent ();
			return reader.NodeType != XmlNodeType.EndElement;
		}
        private void ParseActionXml(String XML)
        {
            UPnPAction action = new UPnPAction();
            UPnPArgument arg;

            StringReader MyString = new StringReader(XML);
            XmlTextReader XMLDoc = new XmlTextReader(MyString);

            XMLDoc.Read();
            XMLDoc.MoveToContent();
            XMLDoc.Read();
            XMLDoc.MoveToContent();
            while (XMLDoc.LocalName != "action")
            {
                switch (XMLDoc.LocalName)
                {
                    case "name":
                        OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.SuccessAudit, "I've found an action");
                        action.Name = XMLDoc.ReadString().Trim();
                        OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.SuccessAudit, "Its called " + action.Name);
                        break;
                    case "argumentList":
                        if (XMLDoc.IsEmptyElement)
                        {
                            break;
                        }
                        XMLDoc.Read();
                        XMLDoc.MoveToContent();
                        while (XMLDoc.LocalName != "argumentList" && XMLDoc.EOF == false)
                        {
                            if (XMLDoc.LocalName == "argument")
                            {
                                arg = new UPnPArgument();
                                XMLDoc.Read();
                                XMLDoc.MoveToContent();
                                while (XMLDoc.LocalName != "argument")
                                {
                                    switch (XMLDoc.LocalName)
                                    {
                                        case "name":
                                            arg.Name = XMLDoc.ReadString().Trim();
                                            break;
                                        case "retval":
                                            arg.IsReturnValue = true;
                                            break;
                                        case "direction":
                                            arg.Direction = XMLDoc.ReadString().Trim();
                                            break;
                                        case "relatedStateVariable":
                                            OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.SuccessAudit, "I've found a related state variable");
                                            arg.StateVarName = XMLDoc.ReadString().Trim();
                                            OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.SuccessAudit, "Its called " + arg.StateVarName);
                                            break;
                                    }
                                    XMLDoc.Read();
                                    XMLDoc.MoveToContent();
                                }
                                action.AddArgument(arg);
                                XMLDoc.Read();
                                XMLDoc.MoveToContent();
                            }
                            else
                            {
                                XMLDoc.Skip();
                            }
                        }
                        break;
                }
                // End of Switch
                XMLDoc.Read();
                XMLDoc.MoveToContent();
            }
            // End of While

            AddAction(action);
        }
Esempio n. 23
0
		private void ReadSectionGroup (XmlTextReader reader, string configSection)
		{
			if (!reader.MoveToNextAttribute ())
				ThrowException ("sectionGroup must have a 'name' attribute.", reader);

			string value = null;
			do {
				if (reader.Name == "name") {
					if (value != null)
						ThrowException ("Duplicate 'name' attribute.", reader);
					value = reader.Value;
				}
				else
				if (reader.Name != "type")
					ThrowException ("Unrecognized attribute.", reader);
			} while (reader.MoveToNextAttribute ());

			if (value == null)
				ThrowException ("No 'name' attribute.", reader);
			
			if (value == "location")
				ThrowException ("location is a reserved section name", reader);

			if (configSection != null)
				value = configSection + '/' + value;

			object o = LookForFactory (value);
			if (o != null && o != removedMark && o != groupMark)
				ThrowException ("Already have a factory for " + value, reader);

			factories [value] = groupMark;

			if (reader.IsEmptyElement) {
				reader.Skip ();
				reader.MoveToContent ();
			} else {
				reader.Read ();
				reader.MoveToContent ();
				if (reader.NodeType != XmlNodeType.EndElement)
					ReadSections (reader, value);
				reader.ReadEndElement ();
				reader.MoveToContent ();
			}
		}
        private UPnPCustomException ParseErrorBody(String XML)
        {
            StringReader sr = new StringReader(XML);
            XmlTextReader XMLDoc = new XmlTextReader(sr);
            UPnPCustomException RetVal = null;

            int ec = 0;
            String ed = "";

            XMLDoc.Read();
            XMLDoc.MoveToContent();

            if (XMLDoc.LocalName == "Envelope")
            {
                XMLDoc.Read();
                XMLDoc.MoveToContent();
                while ((XMLDoc.LocalName != "Envelope") && (XMLDoc.EOF == false))
                {
                    switch (XMLDoc.LocalName)
                    {
                        case "Body":
                            XMLDoc.Read();
                            XMLDoc.MoveToContent();
                            while ((XMLDoc.LocalName != "Body") && (XMLDoc.EOF == false))
                            {
                                if (XMLDoc.LocalName == "Fault")
                                {
                                    XMLDoc.Read();
                                    XMLDoc.MoveToContent();
                                    while ((XMLDoc.LocalName != "Fault") && (XMLDoc.EOF == false))
                                    {
                                        switch (XMLDoc.LocalName)
                                        {
                                            case "detail":
                                                XMLDoc.Read();
                                                XMLDoc.MoveToContent();
                                                while ((XMLDoc.LocalName != "detail") && (XMLDoc.EOF == false))
                                                {
                                                    if (XMLDoc.LocalName == "UPnPError")
                                                    {
                                                        XMLDoc.Read();
                                                        XMLDoc.MoveToContent();
                                                        while ((XMLDoc.LocalName != "UPnPError") && (XMLDoc.EOF == false))
                                                        {
                                                            switch (XMLDoc.LocalName)
                                                            {
                                                                case "errorCode":
                                                                    ec = int.Parse(XMLDoc.ReadString());
                                                                    break;
                                                                case "errorDescription":
                                                                    ed = XMLDoc.ReadString();
                                                                    break;
                                                            }
                                                            XMLDoc.Read();
                                                            XMLDoc.MoveToContent();
                                                        }

                                                        RetVal = new UPnPCustomException(ec, ed);
                                                    }
                                                    else
                                                    {
                                                        XMLDoc.Skip();
                                                    }
                                                    XMLDoc.Read();
                                                    XMLDoc.MoveToContent();
                                                }
                                                break;
                                            default:
                                                XMLDoc.Skip();
                                                break;
                                        }
                                        XMLDoc.Read();
                                        XMLDoc.MoveToContent();
                                    }

                                }
                                else
                                {
                                    XMLDoc.Skip();
                                }
                                XMLDoc.Read();
                                XMLDoc.MoveToContent();
                            }
                            break;
                        default:
                            XMLDoc.Skip();
                            break;
                    }
                    XMLDoc.Read();
                    XMLDoc.MoveToContent();
                }
            }
            return (RetVal);
        }
Esempio n. 25
0
        public void SelfInit(EventArgs e)
        {
            //ǿ�������������ԣ�ʹ��������������ֵʧЧ
            this.AutoGenerateColumns = false;

            XmlTextReader reader = new XmlTextReader(HttpContext.Current.Server.MapPath(this.XmlGridFile));
            try
            {
                while(reader.Read())
                {
                    if(!reader.IsStartElement("XmlGrid"))
                        continue;
                    else
                    {
                        //�ж�ָ����XmlGrid���ƺ������е��Ƿ�һ�¡�
                        if(this.GetItemAttribute(reader.GetAttribute("Name"), "").ToLower() != this.XmlGridName.ToLower())
                        {
                            reader.Skip();      //������һ��XmlGrid
                            continue;
                        }
                        else
                        {
                            _table = this.GetItemAttribute(reader.GetAttribute("Table"), "");     //��ȡ����
                            _orderby = this.GetItemAttribute(reader.GetAttribute("OrderBy"), "");     //��ȡ����
                            _dataKeyField = this.GetItemAttribute(reader.GetAttribute("DataKeyField"), "");
                            if(_dataKeyField.Length > 0) this.DataKeyField = _dataKeyField.Replace('.', '_');
                        }

                        // ��ȡ��
                        while(reader.Read())
                        {
                            if(reader.LocalName == "XmlGrid") break;      //��XmlGrid�Ľ�β������
                            else if(reader.LocalName == "Columns")
                            {
                                _columnsStart = this.GetItemAttribute(reader.GetAttribute("Start"), 0);     //��ȡ�ӵڼ��п�ʼ������
                                this.InitColumns(reader);     //��ʼ����
                            }
                            else if(reader.LocalName == "Clauses")
                            {
                                _clausesHiddenDefault = this.GetItemAttribute(reader.GetAttribute("HiddenDefault"), false);     //��ȡClause��HiddenĬ��ֵ
                                this.InitClauses(reader);     //��ʼ����ѯ�Ӿ�
                            }
                        }
                        break;
                    }
                }
            }
            finally
            {
                if(reader != null) reader.Close();
            }
        }
		protected void LastChangeSink(CpRenderingControl sender, string LC)
		{
			if(LC=="")return;
			if(LC.Substring(0,1)!="<") LC = UPnPStringFormatter.UnEscapeString(LC);
			if(LC.Substring(0,1)!="<") LC = UPnPStringFormatter.UnEscapeString(LC);


			/*
			if(LC.StartsWith("<?")==true)
			{
				int dx = LC.IndexOf(">");
				LC = LC.Substring(0,dx+1) + "<MYROOT>" + LC.Substring(dx+1) + "</MYROOT>";
			}
			else
			{
				LC = "<MYROOT>" + LC + "</MYROOT>";
			}*/

			StringReader MyString = new StringReader(LC);
			XmlTextReader XMLDoc = new XmlTextReader(MyString);

			Hashtable T = new Hashtable();

			int ID = -1;
			string VarName = "";
			string VarValue = "";
			string AttrName = "";
			string AttrValue = "";

			XMLDoc.Read();
			XMLDoc.MoveToContent();

			XMLDoc.Read();
			XMLDoc.MoveToContent();

			while((XMLDoc.LocalName!="Event")&&(XMLDoc.EOF==false))
			{
				// At Start, should be InstanceID
				if(XMLDoc.LocalName=="InstanceID")
				{
					XMLDoc.MoveToAttribute("val");
					ID = int.Parse(XMLDoc.GetAttribute("val"));
					if(T.ContainsKey(ID)==false) T[ID] = new Hashtable();
					XMLDoc.MoveToContent();

					XMLDoc.Read();
					XMLDoc.MoveToContent();

					while(XMLDoc.LocalName!="InstanceID")
					{
						VarName = XMLDoc.LocalName;
						VarValue = "";
						AttrName = "";
						AttrValue = "";

						for(int a_idx=0;a_idx<XMLDoc.AttributeCount;++a_idx)
						{
							XMLDoc.MoveToAttribute(a_idx);
							if(XMLDoc.LocalName=="val")
							{
								VarValue = XMLDoc.GetAttribute(a_idx);
							}
							else
							{
								AttrName = XMLDoc.LocalName;
								AttrValue = XMLDoc.GetAttribute(a_idx);
							}
						}

						XMLDoc.MoveToContent();

						if(AttrName=="")
						{
							((Hashtable)T[ID])[VarName] = VarValue;
						}
						else
						{
							if(((Hashtable)T[ID]).ContainsKey(VarName)==false)
							{
								((Hashtable)T[ID])[VarName] = new Hashtable();
							}
							if(((Hashtable)((Hashtable)T[ID])[VarName]).ContainsKey(AttrName)==false)
							{
								((Hashtable)((Hashtable)T[ID])[VarName])[AttrName] = new Hashtable();
							}
							((Hashtable)((Hashtable)((Hashtable)T[ID])[VarName])[AttrName])[AttrValue] = VarValue;
						}
						XMLDoc.Read();
						XMLDoc.MoveToContent();
					}
				}
				else
				{
					XMLDoc.Skip();
				}
				XMLDoc.Read();
				XMLDoc.MoveToContent();
			}

			XMLDoc.Close();


			IDictionaryEnumerator inEn = T.GetEnumerator();
			IDictionaryEnumerator EvEn;
			Hashtable TT;
			while(inEn.MoveNext())
			{
				if((int)inEn.Key == InstanceID)
				{
					TT = (Hashtable)inEn.Value;
					EvEn = TT.GetEnumerator();
					while(EvEn.MoveNext())
					{
						switch((string)EvEn.Key)
						{
							case "Mute":
								if(EvEn.Value.GetType().FullName=="System.String")
								{
									MuteByChannel["MASTER"] = (bool)UPnPService.CreateObjectInstance(typeof(bool),(string)EvEn.Value);
								}
								else
								{
									IDictionaryEnumerator E2 = ((Hashtable)EvEn.Value).GetEnumerator();
									while(E2.MoveNext())
									{
										IDictionaryEnumerator E3 = ((Hashtable)((Hashtable)E2.Value)).GetEnumerator();
										while(E3.MoveNext())
										{
											MuteByChannel[E3.Key.ToString()] = (bool)UPnPService.CreateObjectInstance(typeof(bool),E3.Value.ToString());
										}
									}
								}

								if(OnMuteChanged!=null) OnMuteChanged(this);
								break;
							case "Volume":
								if(EvEn.Value.GetType().FullName=="System.String")
								{
									VolumeByChannel["MASTER"] = UInt16.Parse((string)EvEn.Value);
								}
								else
								{
									IDictionaryEnumerator E2 = ((Hashtable)EvEn.Value).GetEnumerator();
									while(E2.MoveNext())
									{
										IDictionaryEnumerator E3 = ((Hashtable)((Hashtable)E2.Value)).GetEnumerator();
										while(E3.MoveNext())
										{
											VolumeByChannel[E3.Key.ToString()] = UInt16.Parse(E3.Value.ToString());
										}
									}
								}
								//_Volume = UInt16.Parse((string)EvEn.Value);
								if(OnVolumeChanged!=null) OnVolumeChanged(this);
								break;
						}
					}
				}
			}
		}
Esempio n. 27
0
        /// <summary>
        /// Reads the stock data from a FIXML file, predicts its trends and save it in the memory.
        /// </summary>
        /// <param name="predictorName">Name of the prediction plugin.</param>
        /// <param name="xmlFilePath">Path to the FIXML file.</param>
        private void UpdateStockData(String predictorName, String xmlFilePath)
        {
            XmlTextReader reader = new XmlTextReader(xmlFilePath);
            reader.WhitespaceHandling = WhitespaceHandling.None;

            String stockName = String.Empty;
            String stockPriceString = String.Empty;
            String stockTransactionTime = String.Empty;

            while (reader.Read())
            {
                if (reader.Name.Equals("Order") && reader.NodeType == XmlNodeType.Element)
                {
                    #region XML parsing
                    // Get the attributes we want from <Order>
                    stockTransactionTime = reader.GetAttribute("TransactTm");
                    stockPriceString = reader.GetAttribute("Px");

                    // Move back to <Order> node
                    reader.MoveToElement();

                    // Move to <Hdr> node and skip it's children
                    reader.Read();
                    reader.Skip();

                    // We are in <Instrmt> node. Get the attribute we want
                    stockName = reader.GetAttribute("Sym");
                    reader.MoveToElement();
                    #endregion XML parsing

                    #region Data manipulation
                    // Convert stockPriceString to uint - discard decimals
                    Debug.Assert(stockPriceString != null);
                    uint stockPrice = Convert.ToUInt32(stockPriceString.Split(',')[0]);

                    // Convert stockTransactionTime to long
                    // Format of stockTransactionTime: YYYY-MM-DDTHH:MM:SS
                    Debug.Assert(stockTransactionTime != null);
                    int year = Convert.ToInt32(stockTransactionTime.Substring(0, 4));
                    int month = Convert.ToInt32(stockTransactionTime.Substring(5, 2));
                    int day = Convert.ToInt32(stockTransactionTime.Substring(8, 2));
                    int hour = Convert.ToInt32(stockTransactionTime.Substring(11, 2));
                    int minute = Convert.ToInt32(stockTransactionTime.Substring(14, 2));
                    int second = Convert.ToInt32(stockTransactionTime.Substring(17, 2));

                    // Get milliseconds since unixStartDate
                    //DateTime unixStartDate = new DateTime(1970, 1, 1);
                    DateTime stockTime = new DateTime(year, month, day, hour, minute, second);
                    //long ticksSinceUnixStartDate = stockTime.Ticks - unixStartDate.Ticks;
                    long stockTimeStampMillis = stockTime.Ticks / 10000000; // 10.000.000 ticks = 1 second

                    // Save the data
                    int i = -1;
                    i = stockGroups.FindIndex(stockGroup => stockGroup.Name.Equals(stockName));
                    if (i != -1)
                    {
                        // stockName already exist in stockGroups
                        // Add new values to stockName's data points
                        List<StockDataPoint> dataPoints = stockGroups[i].DataPoints;
                        dataPoints.Add(new StockDataPoint(stockPrice, stockTimeStampMillis));
                        stockGroups[i].DataPoints = dataPoints;
                    }
                    else
                    {
                        // stockName does not exist in stockGroups
                        // Create new list of data points
                        List<StockDataPoint> dataPoints = new List<StockDataPoint>();
                        // Add the initial stock price to the list
                        dataPoints.Add(new StockDataPoint(stockPrice, stockTimeStampMillis));
                        // Add the new stockName to stockGroups
                        stockGroups.Add(new StockGroup(stockName, dataPoints));
                    }
                    #endregion Data manipulation
                }
            }

            foreach (StockGroup stockGroup in stockGroups)
            {
                Log.Write("Stock name: " + stockGroup.Name);
            }

            Log.Write("Searching for " + predictorName + ".dll in plugins folder");
            Assembly predictionAssembly = Assembly.LoadFrom("./plugins/" + predictorName + ".dll");
            StockPrediction predictor = null;

            foreach (Type type in predictionAssembly.GetTypes())
            {
                Log.Write(" > Found: " + type.Name);
                if (type.IsClass && type.GetInterface("StockPrediction") != null)
                {
                    Log.Write("a Stock predictor was found");
                    predictor = Activator.CreateInstance(type, new object[0]) as StockPrediction;
                }
            }

            if (predictor == null)
                Log.Write("No stock predictor was found in the dll file");

            // Call prediction on all stock groups
            foreach (StockGroup stockGroup in stockGroups)
            {
                predictor.Predict(stockGroup);
            }

            Log.Write("Current time in seconds: " + (DateTime.Now - new DateTime()).TotalSeconds);
        }
Esempio n. 28
0
        /// <summary>
        /// ��ʼ���ؼ�
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
            _fields = new StringCollection();
              _titles = new StringCollection();
              _aliases = new StringCollection();
              _widths = new StringCollection();
              _sorts = new StringCollection();
              _conditions = new NameValueCollection();
              _conditionsUsed = new NameValueCollection();
              _searches = new NameValueCollection();

              XmlTextReader reader = new XmlTextReader(HttpContext.Current.Server.MapPath(this.XmlFile));
              try
              {
            while(reader.Read())
            {
              if(!reader.IsStartElement("list"))
            continue;
              else
              {
            //�ж�ָ����list���ƺ������е��Ƿ�һ�¡�
            if(this.GetItemAttribute(reader.GetAttribute("id"), "").ToLower() != this.ListId.ToLower())
            {
              reader.Skip();
              continue;
            }
            else
            {
              //��ȡ����
              _table = this.GetItemAttribute(reader.GetAttribute("table"), "");
              //��ȡkey��
              _dataKeyField = this.GetItemAttribute(reader.GetAttribute("dataKeyField"), "");
              this.DataKeyField = _dataKeyField.Replace('.', '_');
            }

            // ��ȡ��
            while(reader.Read())
            {
              if(reader.IsStartElement("list")) break;
              else if(reader.IsStartElement("columns"))
              {
                //��ȡ�ӵڼ��п�ʼ������
                _start = this.GetItemAttribute(reader.GetAttribute("start"), 0);
                this.InitColumns(reader);
              }
              else if(reader.IsStartElement("condition"))
              {
                _conditions.Add(this.GetItemAttribute(reader.GetAttribute("value"), ""), this.GetItemAttribute(reader.GetAttribute("type"), "AND"));
                _conditionsUsed.Add(this.GetItemAttribute(reader.GetAttribute("value"), ""), this.GetItemAttribute(reader.GetAttribute("value"), ""));
                reader.Skip();
              }
              else if(reader.IsStartElement("orderby"))
              {
                _orderbyDefault = this.GetItemAttribute(reader.GetAttribute("default"), "").Replace('.', '_');
                reader.Skip();
              }
              else if(reader.IsStartElement("searches"))
              {
                _searchesHidden = this.GetItemAttribute(reader.GetAttribute("hidden"), false);
              }
              else if(reader.IsStartElement("search"))
              {
                _searches.Add(this.GetItemAttribute(reader.GetAttribute("value"), ""), this.GetItemAttribute(reader.GetAttribute("type"), "AND"));
                reader.Skip();
              }
            }

            break;
              }
            }
              }
              finally
              {
            if(reader != null) reader.Close();
              }

              //��Ӱ���
              BoundColumn column;
              for(int i=_titles.Count-1; i>=0; i--)
              {
            if(_widths[i] != "-1")
            {
              column = new BoundColumn();
              column.HeaderText = _titles[i];
              column.DataField = _aliases[i]==""?_fields[i]:_aliases[i];
              if(_widths[i] != "")
              {
            if(_widths[i] == "0")
              column.Visible = false;
            else
              column.HeaderStyle.Width = Unit.Parse(_widths[i]);
              }
              if(this.AllowSorting)
              {
            if(_sorts[i] != "")
              column.SortExpression = column.DataField + " " + _sorts[i];
              }
              this.Columns.AddAt(_start, column);
            }
              }

              // ��ҳʹ��
              if(ViewState["__orderby"]==null || ViewState["__orderby"].ToString().Length==0)
            ViewState["__orderby"] = _orderbyDefault;

              base.OnInit (e);
        }
Esempio n. 29
0
		public object Deserialize(Stream inStream, ISoapMessage soapMessage) 
		{
			ArrayList headers = null;
			xmlReader = new XmlTextReader(inStream);
			xmlReader.WhitespaceHandling = WhitespaceHandling.None;
			mapper = new SoapTypeMapper(_binder);

			try
			{
				// SOAP-ENV:Envelope
				xmlReader.MoveToContent();
				xmlReader.ReadStartElement ();
				xmlReader.MoveToContent();
				
				// Read headers
				while (!(xmlReader.NodeType == XmlNodeType.Element && xmlReader.LocalName == "Body" && xmlReader.NamespaceURI == SoapTypeMapper.SoapEnvelopeNamespace))
				{
					if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.LocalName == "Header" && xmlReader.NamespaceURI == SoapTypeMapper.SoapEnvelopeNamespace)
					{
						if (headers == null) headers = new ArrayList ();
						DeserializeHeaders (headers);
					}
					else
						xmlReader.Skip ();
					xmlReader.MoveToContent();
				}
				
				// SOAP-ENV:Body
				xmlReader.ReadStartElement();
				xmlReader.MoveToContent();

				// The root object
				if (soapMessage != null)
				{
					if (DeserializeMessage (soapMessage)) {
						_topObjectId = NextAvailableId;
						RegisterObject (_topObjectId, soapMessage, null, 0, null, null);
					}
					xmlReader.MoveToContent();
					
					if (headers != null)
						soapMessage.Headers = (Header[]) headers.ToArray (typeof(Header));
				}
				
				while (xmlReader.NodeType != XmlNodeType.EndElement)
					Deserialize();
					
				// SOAP-ENV:Body
				xmlReader.ReadEndElement ();
				xmlReader.MoveToContent();

				// SOAP-ENV:Envelope
				xmlReader.ReadEndElement ();
			}
			finally 
			{
				if(xmlReader != null) xmlReader.Close();
			}

			return TopObject;
		}
 /// <summary>
 /// Read the config file. all data can then be retreived from the <see cref="keys"/> variable.
 /// </summary>
 private static void ParseKeys()
 {
     //read keys from file
     using (XmlReader reader = new XmlTextReader(settingsPath))
     {
         reader.Read();
         while (!reader.EOF)
         {
             if (reader.IsStartElement())
             {
                 if (reader.Name == "keys")
                 {
                     keys.ReadFromXml(reader);
                 }
                 else
                 {
                     reader.Skip();
                 }
             }
             else
             {
                 reader.Read();
                 break;
             }
         }
         reader.Close();
     }
     Console.WriteLine("file " + settingsPath + " has been read. " + keys.Count + " entrie(s) found.");
     Console.WriteLine();
 }