// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Xml; namespace Chat.Module.Send { using Chat.Framework.Protocol; using Chat.Framework.Provider; using Chat.Framework.Core; public class SendRequestMessage : RequestMessage { public string Receiver { get; set; } public string Text { get; set; } } public class SendResponseMessage : ResponseMessage { } public class SendSerializer : SerializerBase { public SendSerializer() : base("send", typeof(SendRequestMessage), typeof(SendResponseMessage)) { } public override RequestMessage Parse(string strmsg, string id) { SendRequestMessage objmsg = new SendRequestMessage(); objmsg.ClientID = id; XmlDocument doc = new XmlDocument(); doc.LoadXml(strmsg); objmsg.Receiver = doc.SelectSingleNode("//send-request/receiver/text()").Value; objmsg.Text = doc.SelectSingleNode("//send-request/text/text()").Value; return objmsg; } } public class SendProcessor : ProcessorBase { public SendProcessor() : base(typeof(SendRequestMessage), typeof(SendResponseMessage)) { } public override Tuple Process(ClientState prevstate, RequestMessage reqmsg, Server cntx) { if(prevstate == ClientState.SIGNEDIN) { SendRequestMessage reqmsg2 = (SendRequestMessage)reqmsg; cntx.Send(reqmsg2.Receiver, reqmsg2.Text); ClientState nextstate = prevstate; SendResponseMessage respmsg = new SendResponseMessage(); respmsg.Status = true; return Tuple.Create(nextstate, (ResponseMessage)respmsg); } else { throw new IllegalStateChatException(); } } } public class SendProvider : IProvider { public ISerializer GetSerializer() { return new SendSerializer(); } public IProcessor GetProcessor() { return new SendProcessor(); } } }