comparison Xml/Server.cs @ 0:3ab940a0c7a0

Initial commit
author Ivo Smits <Ivo@UCIS.nl>
date Tue, 11 Sep 2012 16:28:53 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:3ab940a0c7a0
1 using System;
2 using System.Collections.Generic;
3 using System.Xml;
4 using UCIS.Net;
5
6 namespace UCIS.Xml {
7 public class XmlServer : TCPServer.IModule {
8 public Dictionary<string, IModule> Modules = new Dictionary<string, IModule>(StringComparer.OrdinalIgnoreCase);
9
10 public bool Accept(TCPStream Stream) {
11 XmlSocket XSocket = new XmlSocket(Stream);
12 Stream.ReadTimeout = 5000;
13 XmlDocument FirstMessage = XSocket.ReadDocument();
14 if (FirstMessage == null) return true;
15 IModule module;
16 if (Modules.TryGetValue(FirstMessage.FirstChild.Name, out module)) {
17 module.Accept(XSocket, FirstMessage);
18 } else {
19 Console.WriteLine("XMLServer.Accept: Module not found: " + FirstMessage.FirstChild.Name);
20 }
21 return true;
22 }
23
24 public interface IModule {
25 void Accept(XmlSocket Socket, XmlDocument FirstMessage);
26 }
27 }
28 }