Click here to Skip to main content
15,885,914 members
Articles / Hosted Services / Serverless

Peer Graph - Search Criteria Helper

Rate me:
Please Sign up or sign in to vote.
4.17/5 (2 votes)
16 Jan 20067 min read 35.9K   510   14  
Expression conversion to XML search criteria for a Peer Graph, using Microsoft's Peer-to-Peer technology.
using System;
using System.Xml;
using System.Reflection;
using System.Xml.Schema;

namespace Peer.Graph
{
	public class PeerSearch
	{
		private static XmlSchema schema;
		static PeerSearch()
		{
			schema = XmlSchema.Read(Assembly.GetExecutingAssembly().GetManifestResourceStream("Graph.SearchCriteria.xsd"), null);
			schema.Compile(null);
		}

		private PeerGraph graph;
		private string xml;

		public PeerSearch(PeerGraph Graph)
		{
			graph = Graph;
		}

		public PeerGraph Graph
		{
			get { return graph; }
		}

		public string Xml
		{
			get
			{
				return xml;
			}
			set
			{
				xml = value;
			}
		}

		public virtual PeerRecordCollection Search()
		{
			return Graph.Search(xml);
		}

		public override string ToString()
		{
			return Xml;
		}

		public bool Validate()
		{
			XmlValidatingReader vr = new XmlValidatingReader(Xml, XmlNodeType.Element, null);
			vr.Schemas.Add(schema,null);
			bool valid;
			try
			{
				while (vr.Read()) { }
				valid = true;
			}
			catch (XmlSchemaException ex)
			{
				valid = false;
			}
			catch (XmlException ex)
			{
				valid = false;
			}
			return valid;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Canada Canada
Adrian Moore is the Development Manager for the SCADA Vision system developed by ABB Inc in Calgary, Alberta.

He has been interested in compilers, parsers, real-time database systems and peer-to-peer solutions since the early 90's. In his spare time, he is currently working on a SQL parser for querying .NET DataSets (http://www.queryadataset.com).

Adrian is a Microsoft MVP for Windows Networking.

Comments and Discussions