public void Run(String[] args)         //throws Exception
        {
            if (!ParseCommandLine(args))
            {
                return;
            }

            SessionOptions sessionOptions = new SessionOptions();

            sessionOptions.ServerHost            = d_host;
            sessionOptions.ServerPort            = d_port;
            sessionOptions.AuthenticationOptions = d_authOptions;

            System.Console.WriteLine("Connecting to " + d_host + ":" + d_port);
            ProviderSession session = new ProviderSession(sessionOptions, ProcessEvent);

            if (!session.Start())
            {
                System.Console.WriteLine("Failed to start session");
                return;
            }

            Identity identity = null;

            if (d_authOptions.Length != 0)
            {
                if (!Authorize(out identity, session))
                {
                    return;
                }
            }

            TopicList topicList = new TopicList();

            topicList.Add(
                d_service + "/1245/4/5",
                new CorrelationID(new MyStream("1245/4/5")));
            topicList.Add(
                d_service + "/330/1/1",
                new CorrelationID(new MyStream("330/1/1")));

            session.CreateTopics(
                topicList,
                ResolveMode.AUTO_REGISTER_SERVICES,
                identity);
            // createTopics() is synchronous, topicList will be updated
            // with the results of topic creation (resolution will happen
            // under the covers)

            Publish(topicList, session);
        }
Пример #2
0
 private void FillTopicList()
 {
     foreach (string keyWord in _keyWords.KeyWordList)
     {
         TopicList.Add(keyWord);
     }
 }
        public void Run(String[] args)
        {
            if (!ParseCommandLine(args))
            {
                return;
            }

            SessionOptions sessionOptions = new SessionOptions();

            sessionOptions.ServerHost            = d_serverHost;
            sessionOptions.ServerPort            = d_serverPort;
            sessionOptions.AuthenticationOptions = d_authOptions;

            System.Console.WriteLine("Connecting to " + d_serverHost + ":" + d_serverPort);
            ProviderSession session = new ProviderSession(sessionOptions, ProcessEvent);

            if (!session.Start())
            {
                Console.Error.WriteLine("Failed to start session");
                return;
            }

            Identity identity = null;

            if (d_authOptions.Length != 0)
            {
                if (!Authorize(out identity, session))
                {
                    return;
                }
            }

            TopicList topicList = new TopicList();

            topicList.Add(
                d_serviceName + "/220/660/1",
                new CorrelationID(new MyStream("220/660/1")));

            session.CreateTopics(
                topicList,
                ResolveMode.AUTO_REGISTER_SERVICES,
                identity);

            List <MyStream> myStreams = new List <MyStream>();

            for (int i = 0; i < topicList.Size; ++i)
            {
                if (topicList.StatusAt(i) == TopicList.TopicStatus.CREATED)
                {
                    Topic    topic  = session.GetTopic(topicList.MessageAt(i));
                    MyStream stream = (MyStream)topicList.CorrelationIdAt(i).Object;
                    stream.SetTopic(topic);
                    myStreams.Add(stream);
                }
            }

            PublishEvents(session, myStreams);

            session.Stop();
        }
Пример #4
0
        public async Task Init()
        {
            var list = await _service.GetAll <List <Topic> >(null);

            TopicList.Clear();
            foreach (var topic in list)
            {
                var user = await _userService.GetById <User>(topic.UserId);

                topic.User      = user.FirstName + user.LastName; //User that posted topic
                request.TopicId = topic.Id;
                var _commentList = await _commentService.GetAll <List <Comment> >(request);

                topic.Comments = _commentList.Count;                         // Number of comments
                var _lastComment     = _commentList[_commentList.Count - 1]; // Last comment of topic
                var user_lastComment = await _userService.GetById <User>(_lastComment.UserId);

                topic.LastComment = user_lastComment.FirstName + " " + user_lastComment.LastName;
                TopicList.Add(topic);
            }
        }
Пример #5
0
        public async Task Init()
        {
            if (TopicList.Count > 0)
            {
                TopicList.Clear();
            }
            var list = await _topicService.GetAll <List <Topic> >(null);

            foreach (var topic in list)
            {
                var client = await _userService.GetById <User>(topic.UserID);

                topic.Client    = client.FirstName + " " + client.LastName; //Client that posted topic
                request.TopicID = topic.TopicID;
                var _commentList = await _commentService.GetAll <List <Comment> >(request);

                topic.Comments = _commentList.Count;                           // Number of comments
                var _lastComment       = _commentList[_commentList.Count - 1]; // Last comment of topic
                var client_lastComment = await _userService.GetById <User>(_lastComment.UserID);

                topic.LastComment = client_lastComment.FirstName + " " + client_lastComment.LastName;
                TopicList.Add(topic);
            }
        }
        public void Run(String[] args)         //throws Exception
        {
            if (!ParseCommandLine(args))
            {
                return;
            }

            SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[d_hosts.Count];
            for (int i = 0; i < d_hosts.Count; ++i)
            {
                servers[i] = new SessionOptions.ServerAddress(d_hosts[i], d_port);
            }

            SessionOptions sessionOptions = new SessionOptions();

            sessionOptions.ServerAddresses            = servers;
            sessionOptions.AuthenticationOptions      = d_authOptions;
            sessionOptions.AutoRestartOnDisconnection = true;
            sessionOptions.NumStartAttempts           = servers.Length;

            Console.Write("Connecting to");
            foreach (SessionOptions.ServerAddress server in sessionOptions.ServerAddresses)
            {
                Console.Write(" " + server);
            }
            Console.WriteLine();

            ProviderSession session = new ProviderSession(
                sessionOptions,
                ProcessEvent);

            if (!session.Start())
            {
                Console.WriteLine("Failed to start session");
                return;
            }

            Identity identity = null;

            if (d_authOptions != null)
            {
                bool isAuthorized = false;
                identity = session.CreateIdentity();
                if (session.OpenService("//blp/apiauth"))
                {
                    Service authService = session.GetService("//blp/apiauth");
                    if (Authorize(authService, identity, session, new CorrelationID()))
                    {
                        isAuthorized = true;
                    }
                }
                if (!isAuthorized)
                {
                    System.Console.Error.WriteLine("No authorization");
                    return;
                }
            }

            TopicList topicList = new TopicList();

            topicList.Add(
                d_service + "/1245/4/5",
                new CorrelationID(new MyStream("1245/4/5")));
            topicList.Add(
                d_service + "/330/1/1",
                new CorrelationID(new MyStream("330/1/1")));

            session.CreateTopics(
                topicList,
                ResolveMode.AUTO_REGISTER_SERVICES,
                identity);
            // createTopics() is synchronous, topicList will be updated
            // with the results of topic creation (resolution will happen
            // under the covers)

            Publish(topicList, session);
        }
Пример #7
0
        public void Run(String[] args)
        {
            if (!ParseCommandLine(args))
            {
                return;
            }

            SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[d_serverHosts.Count];
            for (int i = 0; i < d_serverHosts.Count; ++i)
            {
                servers[i] = new SessionOptions.ServerAddress(d_serverHosts[i], d_serverPort);
            }

            SessionOptions sessionOptions = new SessionOptions();

            sessionOptions.ServerAddresses            = servers;
            sessionOptions.AuthenticationOptions      = d_authOptions;
            sessionOptions.AutoRestartOnDisconnection = true;
            sessionOptions.NumStartAttempts           = d_serverHosts.Count;

            System.Console.Write("Connecting to");
            foreach (SessionOptions.ServerAddress server in sessionOptions.ServerAddresses)
            {
                System.Console.Write(" " + server);
            }
            System.Console.WriteLine();
            ProviderSession session = new ProviderSession(sessionOptions, ProcessEvent);

            if (!session.Start())
            {
                Console.Error.WriteLine("Failed to start session");
                return;
            }

            Identity identity = null;

            if (d_authOptions != null)
            {
                bool isAuthorized = false;
                identity = session.CreateIdentity();
                if (session.OpenService("//blp/apiauth"))
                {
                    Service authService = session.GetService("//blp/apiauth");
                    if (Authorize(authService, identity, session, new CorrelationID()))
                    {
                        isAuthorized = true;
                    }
                }
                if (!isAuthorized)
                {
                    System.Console.Error.WriteLine("No authorization");
                    return;
                }
            }

            TopicList topicList = new TopicList();

            topicList.Add(
                d_serviceName + "/" + d_topic,
                new CorrelationID(new MyStream(d_topic)));

            session.CreateTopics(
                topicList,
                ResolveMode.AUTO_REGISTER_SERVICES,
                identity);

            List <MyStream> myStreams = new List <MyStream>();

            for (int i = 0; i < topicList.Size; ++i)
            {
                if (topicList.StatusAt(i) == TopicList.TopicStatus.CREATED)
                {
                    Topic    topic  = session.GetTopic(topicList.MessageAt(i));
                    MyStream stream = (MyStream)topicList.CorrelationIdAt(i).Object;
                    stream.SetTopic(topic);
                    myStreams.Add(stream);
                }
            }

            PublishEvents(session, myStreams);

            session.Stop();
        }
        private void ProcessTopicStatusMsg(ProviderSession session, Event eventObj)
        {
            TopicList topicList = new TopicList();

            foreach (Message msg in eventObj)
            {
                Console.WriteLine(msg);

                if (msg.MessageType == TOPIC_SUBSCRIBED)
                {
                    Topic topic = session.GetTopic(msg);
                    if (topic == null)
                    {
                        CorrelationID cid = new CorrelationID(msg.GetElementAsString(TOPIC));
                        topicList.Add(msg, cid);
                    }
                    else
                    {
                        lock (d_topicSet)
                        {
                            if (!d_topicSet.ContainsKey(topic))
                            {
                                d_topicSet[topic] = topic;
                                Monitor.PulseAll(d_topicSet);
                            }
                        }
                    }
                }
                else if (msg.MessageType == TOPIC_UNSUBSCRIBED)
                {
                    Topic topic = session.GetTopic(msg);
                    lock (d_topicSet)
                    {
                        d_topicSet.Remove(topic);
                    }
                }
                else if (msg.MessageType == TOPIC_CREATED)
                {
                    Topic topic = session.GetTopic(msg);
                    lock (d_topicSet)
                    {
                        if (!d_topicSet.ContainsKey(topic))
                        {
                            d_topicSet[topic] = topic;
                            Monitor.PulseAll(d_topicSet);
                        }
                    }
                }
                else if (msg.MessageType == TOPIC_RECAP)
                {
                    Topic topic = session.GetTopic(msg);
                    lock (d_topicSet)
                    {
                        if (!d_topicSet.ContainsKey(topic))
                        {
                            continue;
                        }
                    }
                    // send initial paint.this should come from app's cache.
                    Service        service        = session.GetService(d_service);
                    Event          recapEvent     = service.CreatePublishEvent();
                    EventFormatter eventFormatter = new EventFormatter(recapEvent);
                    eventFormatter.AppendRecapMessage(topic, msg.CorrelationID);
                    eventFormatter.SetElement("numRows", 25);
                    eventFormatter.SetElement("numCols", 80);
                    eventFormatter.PushElement("rowUpdate");
                    for (int i = 1; i <= 5; ++i)
                    {
                        eventFormatter.AppendElement();
                        eventFormatter.SetElement("rowNum", i);
                        eventFormatter.PushElement("spanUpdate");
                        eventFormatter.AppendElement();
                        eventFormatter.SetElement("startCol", 1);
                        eventFormatter.SetElement("length", 10);
                        eventFormatter.SetElement("text", "RECAP");
                        eventFormatter.PopElement();
                        eventFormatter.PopElement();
                        eventFormatter.PopElement();
                    }
                    eventFormatter.PopElement();
                    session.Publish(recapEvent);
                }
            }

            if (topicList.Size > 0)
            {
                session.CreateTopicsAsync(topicList);
            }
        }
        public void Run(String[] args)
        {
            if (!ParseCommandLine(args))
            {
                return;
            }

            SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[d_serverHosts.Count];
            for (int i = 0; i < d_serverHosts.Count; ++i)
            {
                servers[i] = new SessionOptions.ServerAddress(d_serverHosts[i], d_serverPort);
            }

            SessionOptions sessionOptions = new SessionOptions();

            sessionOptions.ServerAddresses            = servers;
            sessionOptions.AuthenticationOptions      = d_authOptions;
            sessionOptions.AutoRestartOnDisconnection = true;
            sessionOptions.NumStartAttempts           = d_serverHosts.Count;

            System.Console.Write("Connecting to");
            foreach (SessionOptions.ServerAddress server in sessionOptions.ServerAddresses)
            {
                System.Console.Write(" " + server);
            }
            System.Console.WriteLine();
            ProviderSession session = new ProviderSession(sessionOptions, ProcessEvent);

            if (!session.Start())
            {
                Console.Error.WriteLine("Failed to start session");
                return;
            }

            Identity identity = null;

            if (d_authOptions != null)
            {
                bool isAuthorized = false;
                identity = session.CreateIdentity();
                if (session.OpenService("//blp/apiauth"))
                {
                    Service authService = session.GetService("//blp/apiauth");
                    if (Authorize(authService, identity, session, new CorrelationID()))
                    {
                        isAuthorized = true;
                    }
                }
                if (!isAuthorized)
                {
                    System.Console.Error.WriteLine("No authorization");
                    return;
                }
            }

            TopicList topicList = new TopicList();

            topicList.Add(
                d_serviceName + "/ticker/929903DF6 Corp",
                new CorrelationID(new MyStream("AUDEUR Curncy")));
            topicList.Add(
                d_serviceName + "/ticker/EC070336 Corp",
                new CorrelationID(new MyStream("EC070336 Corp")));
            topicList.Add(
                d_serviceName + "/ticker/6832348A9 Corp",
                new CorrelationID(new MyStream("6832348A9 Corp")));

            session.CreateTopics(
                topicList,
                ResolveMode.AUTO_REGISTER_SERVICES,
                identity);

            Service service = session.GetService(d_serviceName);

            if (service == null)
            {
                System.Console.Error.WriteLine("Open service failed: " + d_serviceName);
                return;
            }

            List <MyStream> myStreams = new List <MyStream>();

            for (int i = 0; i < topicList.Size; ++i)
            {
                if (topicList.StatusAt(i) == TopicList.TopicStatus.CREATED)
                {
                    Topic    topic  = session.GetTopic(topicList.MessageAt(i));
                    MyStream stream = (MyStream)topicList.CorrelationIdAt(i).Object;
                    stream.SetTopic(topic);
                    myStreams.Add(stream);
                }
            }

            int iteration = 0;

            while (iteration++ < d_maxEvents)
            {
                if (!d_running)
                {
                    break;
                }
                Event          eventObj       = service.CreatePublishEvent();
                EventFormatter eventFormatter = new EventFormatter(eventObj);

                foreach (MyStream stream in myStreams)
                {
                    eventFormatter.AppendMessage("MarketData", stream.GetTopic());
                    eventFormatter.SetElement(BID, stream.GetBid());
                    eventFormatter.SetElement(ASK, stream.GetAsk());
                    eventFormatter.SetElement(BID_SIZE, 1200);
                    eventFormatter.SetElement(ASK_SIZE, 1400);
                }

                System.Console.WriteLine(System.DateTime.Now.ToString() + " -");

                foreach (Message msg in eventObj)
                {
                    System.Console.WriteLine(msg);
                }

                session.Publish(eventObj);
                Thread.Sleep(10 * 1000);
            }

            session.Stop();
        }
        public void Run(String[] args)
        {
            if (!ParseCommandLine(args))
            {
                return;
            }

            SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[d_hosts.Count];
            for (int i = 0; i < d_hosts.Count; ++i)
            {
                servers[i] = new SessionOptions.ServerAddress(d_hosts[i], d_port);
            }

            SessionOptions sessionOptions = new SessionOptions();

            sessionOptions.ServerAddresses            = servers;
            sessionOptions.AuthenticationOptions      = d_authOptions;
            sessionOptions.AutoRestartOnDisconnection = true;
            sessionOptions.NumStartAttempts           = servers.Length;

            System.Console.Write("Connecting to");
            foreach (SessionOptions.ServerAddress server in sessionOptions.ServerAddresses)
            {
                System.Console.Write(" " + server);
            }
            System.Console.WriteLine();

            ProviderSession session = new ProviderSession(sessionOptions, ProcessEvent);

            if (!session.Start())
            {
                System.Console.Error.WriteLine("Failed to start session");
                return;
            }

            Identity identity = null;

            if (d_authOptions != null)
            {
                if (!Authorize(out identity, session))
                {
                    return;
                }
            }

            if (d_groupId != null)
            {
                // NOTE: will perform explicit service registration here, instead of letting
                //       createTopics do it, as the latter approach doesn't allow for custom
                //       ServiceRegistrationOptions
                ServiceRegistrationOptions serviceRegistrationOptions = new ServiceRegistrationOptions();
                serviceRegistrationOptions.GroupId         = d_groupId;
                serviceRegistrationOptions.ServicePriority = d_priority;

                if (!session.RegisterService(d_service, identity, serviceRegistrationOptions))
                {
                    System.Console.Write("Failed to register " + d_service);
                    return;
                }
            }

            TopicList topicList = new TopicList();

            for (int i = 0; i < d_topics.Count; i++)
            {
                topicList.Add(
                    d_service + "/" + d_topics[i],
                    new CorrelationID(new MyStream(d_topics[i])));
            }

            session.CreateTopics(
                topicList,
                ResolveMode.AUTO_REGISTER_SERVICES,
                identity);
            // createTopics() is synchronous, topicList will be updated
            // with the results of topic creation (resolution will happen
            // under the covers)

            List <MyStream> myStreams = new List <MyStream>();

            for (int i = 0; i < topicList.Size; ++i)
            {
                MyStream stream = (MyStream)topicList.CorrelationIdAt(i).Object;
                if (topicList.StatusAt(i) == TopicList.TopicStatus.CREATED)
                {
                    Message msg = topicList.MessageAt(i);
                    stream.setTopic(session.GetTopic(msg));
                    myStreams.Add(stream);
                    System.Console.WriteLine("Topic created: " + topicList.TopicStringAt(i));
                }
                else
                {
                    System.Console.WriteLine("Stream '" + stream.getId()
                                             + "': topic not resolved, status = " + topicList.StatusAt(i));
                }
            }
            Service service = session.GetService(d_service);

            // Now we will start publishing
            Name eventName = Name.GetName("MarketDataEvents");
            Name high      = Name.GetName("HIGH");
            Name low       = Name.GetName("LOW");
            long tickCount = 1;

            for (int eventCount = 0; eventCount < d_maxEvents; ++eventCount)
            {
                Event          eventObj       = service.CreatePublishEvent();
                EventFormatter eventFormatter = new EventFormatter(eventObj);

                for (int index = 0; index < myStreams.Count; index++)
                {
                    Topic topic = myStreams[index].getTopic();
                    if (!topic.IsActive())
                    {
                        continue;
                    }
                    eventFormatter.AppendMessage(eventName, topic);
                    if (1 == tickCount)
                    {
                        eventFormatter.SetElement("OPEN", 1.0);
                    }
                    else if (2 == tickCount)
                    {
                        eventFormatter.SetElement("BEST_BID", 3.0);
                    }
                    eventFormatter.SetElement(high, tickCount * 1.0);
                    eventFormatter.SetElement(low, tickCount * 0.5);
                    ++tickCount;
                }

                foreach (Message msg in eventObj)
                {
                    System.Console.WriteLine(msg);
                }

                session.Publish(eventObj);
                Thread.Sleep(2 * 1000);
            }

            session.Stop();
        }
        public void Run(String[] args)
        {
            if (!ParseCommandLine(args))
            {
                return;
            }

            SessionOptions sessionOptions = new SessionOptions();

            sessionOptions.ServerHost            = d_serverHost;
            sessionOptions.ServerPort            = d_serverPort;
            sessionOptions.AuthenticationOptions = d_authOptions;

            System.Console.WriteLine("Connecting to " + d_serverHost + ":" + d_serverPort);
            ProviderSession session = new ProviderSession(sessionOptions, ProcessEvent);

            if (!session.Start())
            {
                Console.Error.WriteLine("Failed to start session");
                return;
            }

            Identity identity = null;

            if (d_authOptions.Length != 0)
            {
                if (!Authorize(out identity, session))
                {
                    return;
                }
            }

            TopicList topicList = new TopicList();

            topicList.Add(
                d_serviceName + "/ticker/929903DF6 Corp",
                new CorrelationID(new MyStream("AUDEUR Curncy")));
            topicList.Add(
                d_serviceName + "/ticker/EC070336 Corp",
                new CorrelationID(new MyStream("EC070336 Corp")));
            topicList.Add(
                d_serviceName + "/ticker/6832348A9 Corp",
                new CorrelationID(new MyStream("6832348A9 Corp")));

            session.CreateTopics(
                topicList,
                ResolveMode.AUTO_REGISTER_SERVICES,
                identity);

            Service service = session.GetService(d_serviceName);

            if (service == null)
            {
                System.Console.Error.WriteLine("Open service failed: " + d_serviceName);
                return;
            }

            List <MyStream> myStreams = new List <MyStream>();

            for (int i = 0; i < topicList.Size; ++i)
            {
                if (topicList.StatusAt(i) == TopicList.TopicStatus.CREATED)
                {
                    Topic    topic  = session.GetTopic(topicList.MessageAt(i));
                    MyStream stream = (MyStream)topicList.CorrelationIdAt(i).Object;
                    stream.SetTopic(topic);
                    myStreams.Add(stream);
                }
            }

            int iteration = 0;

            while (iteration++ < d_maxEvents)
            {
                Event          eventObj       = service.CreatePublishEvent();
                EventFormatter eventFormatter = new EventFormatter(eventObj);

                foreach (MyStream stream in myStreams)
                {
                    eventFormatter.AppendMessage("MarketData", stream.GetTopic());
                    eventFormatter.SetElement(BID, stream.GetBid());
                    eventFormatter.SetElement(ASK, stream.GetAsk());
                    eventFormatter.SetElement(BID_SIZE, 1200);
                    eventFormatter.SetElement(ASK_SIZE, 1400);
                }

                System.Console.WriteLine(System.DateTime.Now.ToString() + " -");

                foreach (Message msg in eventObj)
                {
                    System.Console.WriteLine(msg);
                }

                session.Publish(eventObj);
                Thread.Sleep(10 * 1000);
            }

            session.Stop();
        }
Пример #12
0
        public void ProcessEvent(Event eventObj, ProviderSession session)
        {
            if (d_verbose > 0)
            {
                Console.WriteLine("Received event " + eventObj.Type);
                foreach (Message msg in eventObj)
                {
                    Console.WriteLine("cid = " + msg.CorrelationID);
                    Console.WriteLine("Message = " + msg);
                }
            }

            if (eventObj.Type == Event.EventType.SESSION_STATUS)
            {
                foreach (Message msg in eventObj)
                {
                    if (msg.MessageType == SESSION_TERMINATED)
                    {
                        d_running = false;
                        break;
                    }
                }
            }
            else if (eventObj.Type == Event.EventType.TOPIC_STATUS)
            {
                TopicList topicList = new TopicList();
                foreach (Message msg in eventObj)
                {
                    if (msg.MessageType == TOPIC_SUBSCRIBED)
                    {
                        Topic topic = session.GetTopic(msg);
                        lock (d_topicSet)
                        {
                            string topicStr = msg.GetElementAsString(TOPIC);
                            d_subscribedTopics[topicStr] = topicStr;
                            if (topic == null)
                            {
                                CorrelationID cid
                                    = new CorrelationID(msg.GetElementAsString("topic"));
                                topicList.Add(msg, cid);
                            }
                            else
                            {
                                if (!d_topicSet.ContainsKey(topic))
                                {
                                    d_topicSet[topic] = topic;
                                    Monitor.PulseAll(d_topicSet);
                                }
                            }
                        }
                    }
                    else if (msg.MessageType == TOPIC_UNSUBSCRIBED)
                    {
                        lock (d_topicSet)
                        {
                            d_subscribedTopics.Remove(msg.GetElementAsString(TOPIC));
                            Topic topic = session.GetTopic(msg);
                            d_topicSet.Remove(topic);
                        }
                    }
                    else if (msg.MessageType == TOPIC_CREATED)
                    {
                        Topic topic = session.GetTopic(msg);
                        lock (d_topicSet)
                        {
                            if (d_subscribedTopics.ContainsKey(msg.GetElementAsString(TOPIC)) &&
                                !d_topicSet.ContainsKey(topic))
                            {
                                d_topicSet[topic] = topic;
                                Monitor.PulseAll(d_topicSet);
                            }
                        }
                    }
                    else if (msg.MessageType == TOPIC_RECAP)
                    {
                        // Here we send a recap in response to a Recap Request.
                        Topic topic = session.GetTopic(msg);
                        lock (d_topicSet)
                        {
                            if (!d_topicSet.ContainsKey(topic))
                            {
                                continue;
                            }
                        }
                        Service        service        = topic.Service;
                        Event          recapEvent     = service.CreatePublishEvent();
                        EventFormatter eventFormatter = new EventFormatter(recapEvent);
                        eventFormatter.AppendRecapMessage(topic, msg.CorrelationID);
                        eventFormatter.SetElement("OPEN", 100.0);

                        session.Publish(recapEvent);
                        foreach (Message recapMsg in recapEvent)
                        {
                            Console.WriteLine(recapMsg);
                        }
                    }
                }

                // createTopicsAsync will result in RESOLUTION_STATUS, TOPIC_CREATED events.
                if (topicList.Size > 0)
                {
                    session.CreateTopicsAsync(topicList);
                }
            }
            else if (eventObj.Type == Event.EventType.SERVICE_STATUS)
            {
                foreach (Message msg in eventObj)
                {
                    if (msg.MessageType == SERVICE_REGISTERED)
                    {
                        Object registerServiceResponseMonitor = msg.CorrelationID.Object;
                        lock (registerServiceResponseMonitor)
                        {
                            d_registerServiceResponse = true;
                            Monitor.PulseAll(registerServiceResponseMonitor);
                        }
                    }
                    else if (msg.MessageType == SERVICE_REGISTER_FAILURE)
                    {
                        Object registerServiceResponseMonitor = msg.CorrelationID.Object;
                        lock (registerServiceResponseMonitor)
                        {
                            d_registerServiceResponse = false;
                            Monitor.PulseAll(registerServiceResponseMonitor);
                        }
                    }
                }
            }
            else if (eventObj.Type == Event.EventType.RESOLUTION_STATUS)
            {
                foreach (Message msg in eventObj)
                {
                    if (msg.MessageType == RESOLUTION_SUCCESS)
                    {
                        String resolvedTopic
                            = msg.GetElementAsString(Name.GetName("resolvedTopic"));
                        Console.WriteLine("ResolvedTopic: " + resolvedTopic);
                    }
                    else if (msg.MessageType == RESOLUTION_FAILURE)
                    {
                        Console.WriteLine(
                            "Topic resolution failed (cid = " +
                            msg.CorrelationID +
                            ")");
                    }
                }
            }
            else if (eventObj.Type == Event.EventType.REQUEST)
            {
                Service service = session.GetService(d_service);
                foreach (Message msg in eventObj)
                {
                    if (msg.MessageType == PERMISSION_REQUEST)
                    {
                        // Similar to createPublishEvent. We assume just one
                        // service - d_service. A responseEvent can only be
                        // for single request so we can specify the
                        // correlationId - which establishes context -
                        // when we create the Event.
                        Event          response   = service.CreateResponseEvent(msg.CorrelationID);
                        EventFormatter ef         = new EventFormatter(response);
                        int            permission = 1;              // ALLOWED: 0, DENIED: 1
                        if (msg.HasElement("uuid"))
                        {
                            int uuid = msg.GetElementAsInt32("uuid");
                            Console.WriteLine("UUID = " + uuid);
                            permission = 0;
                        }
                        if (msg.HasElement("applicationId"))
                        {
                            int applicationId = msg.GetElementAsInt32("applicationId");
                            Console.WriteLine("APPID = " + applicationId);
                            permission = 0;
                        }
                        // In appendResponse the string is the name of the
                        // operation, the correlationId indicates
                        // which request we are responding to.
                        ef.AppendResponse("PermissionResponse");
                        ef.PushElement("topicPermissions");
                        // For each of the topics in the request, add an entry
                        // to the response
                        Element topicsElement = msg.GetElement(Name.GetName("topics"));
                        for (int i = 0; i < topicsElement.NumValues; ++i)
                        {
                            ef.AppendElement();
                            ef.SetElement("topic", topicsElement.GetValueAsString(i));

                            ef.SetElement("result", permission);                             // ALLOWED: 0, DENIED: 1

                            if (permission == 1)
                            {
                                // DENIED
                                ef.PushElement("reason");
                                ef.SetElement("source", "My Publisher Name");
                                ef.SetElement("category", "NOT_AUTHORIZED");
                                // or BAD_TOPIC, or custom

                                ef.SetElement("subcategory", "Publisher Controlled");
                                ef.SetElement(
                                    "description",
                                    "Permission denied by My Publisher Name");
                                ef.PopElement();
                            }
                            else
                            {
                                // ALLOWED
                                if (d_resolveSubServiceCode != null)
                                {
                                    ef.SetElement("subServiceCode",
                                                  d_resolveSubServiceCode.Value);
                                    Console.WriteLine(
                                        String.Format(
                                            "Mapping topic {0} to "
                                            + "subserviceCode {1}",
                                            topicsElement.GetValueAsString(i),
                                            d_resolveSubServiceCode));
                                }
                                if (d_eids.Count != 0)
                                {
                                    ef.PushElement("permissions");
                                    ef.AppendElement();
                                    ef.SetElement("permissionService", "//blp/blpperm");
                                    ef.PushElement("eids");
                                    for (int j = 0; j < d_eids.Count; ++j)
                                    {
                                        ef.AppendValue(d_eids[j]);
                                    }
                                    ef.PopElement();
                                    ef.PopElement();
                                    ef.PopElement();
                                }
                            }
                            ef.PopElement();
                        }
                        ef.PopElement();
                        // Service is implicit in the Event. sendResponse has a
                        // second parameter - partialResponse -
                        // that defaults to false.
                        session.SendResponse(response);
                    }
                    else
                    {
                        Console.WriteLine("Received unknown request: " + msg);
                    }
                }
            }
            else if (eventObj.Type == Event.EventType.RESPONSE ||
                     eventObj.Type == Event.EventType.PARTIAL_RESPONSE ||
                     eventObj.Type == Event.EventType.REQUEST_STATUS)
            {
                foreach (Message msg in eventObj)
                {
                    if (msg.CorrelationID != null && d_verbose > 1)
                    {
                        Console.Out.WriteLine("cid = " + msg.CorrelationID);
                    }
                    Console.Out.WriteLine("Message = " + msg);

                    if (msg.CorrelationID == null)
                    {
                        continue;
                    }
                    lock (d_authorizationStatus)
                    {
                        if (d_authorizationStatus.ContainsKey(msg.CorrelationID))
                        {
                            if (msg.MessageType == AUTHORIZATION_SUCCESS)
                            {
                                d_authorizationStatus[msg.CorrelationID]
                                    = AuthorizationStatus.AUTHORIZED;
                            }
                            else
                            {
                                d_authorizationStatus[msg.CorrelationID]
                                    = AuthorizationStatus.FAILED;
                            }
                            Monitor.Pulse(d_authorizationStatus);
                        }
                    }
                }
            }
        }