Click here to Skip to main content
15,885,030 members
Articles / Programming Languages / C#

Service Bus Architecture based on WCF (3): Build your ESB

Rate me:
Please Sign up or sign in to vote.
4.87/5 (18 votes)
10 Feb 2011CPOL4 min read 76.8K   8.3K   52  
Service Bus Architecture based on WCF (3): build your ESB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Trilobita.SAOT.Receiver;
using Trilobita.SAOT.Object;

namespace Trilobita.SAOT.ServiceBus
{
    public static class BusEngine
    {
        static BusEngine()
        {
        }
        public static event EventHandler<Message> MessageDelivered;
        public static event EventHandler Disconnected;
        public static event EventHandler HeartBeatMessage;
        private static List<SAOTServiceStructre<ISAOTService>> ServiceList = new List<SAOTServiceStructre<ISAOTService>>();
        public static void RegisterNewService(string name,string address)
        {
            SAOTServiceStructre<ISAOTService> service =
                new SAOTServiceStructre<ISAOTService>(name, address);
            service.MessageService.MessageDelivered += new EventHandler<Message>(messageDelivered);
            service.MessageService.ServerDisconnectedEvent += new EventHandler(MessageService_ServerDisconnectedEvent);
            service.MessageService.HeartBeatFromServer += new EventHandler(MessageService_HeartBeatFromServer);
            ServiceList.Add(service);

        }

        static void MessageService_HeartBeatFromServer(object sender, EventArgs e)
        {
            if (HeartBeatMessage != null) HeartBeatMessage(sender, e);
        }

        static void MessageService_ServerDisconnectedEvent(object sender, EventArgs e)
        {
            if (Disconnected != null) Disconnected(sender, e);
        }

        static void messageDelivered(object sender, Message e)
        {
            if (MessageDelivered != null) MessageDelivered(sender, e);
        }
        public static SAOTServiceStructre<ISAOTService> GetService(string name)
        {
            return ServiceList.FirstOrDefault
                (s => string.Equals(s.ServiceName, name, StringComparison.InvariantCultureIgnoreCase));
        }
        public static void RemoveService(string name)
        {
            SAOTServiceStructre<ISAOTService> service = GetService(name);
            if (service != null)
            {
                service.CloseService();
            }
        }
        public static SAOTServiceStructre<ISAOTService>[] GetServiceList()
        {
            return ServiceList.ToArray();
        }
    }
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions