Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Question : As of now the broadcaster gets value from UIbroadcastlistener. We need this to be done by the coordinator.
We shouldn’t use static variable to assign
No cyclic references as advised by the Architect
Here is the Code:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Timers;
namespace FicTestConsole
{
    class UIbroadcasterlistener
    {
        private System.Timers.Timer UITimeout;
        public static DateTime UIHB;

        // A list of clients that are interested in knowing about updates in state of browser.
        private List<ibrowserstatelistener> browserStateListeners =
            new List<ibrowserstatelistener>();

        public UIbroadcasterlistener()
        {
            this.UITimeout = new System.Timers.Timer(1000);
            this.UITimeout.Elapsed += _UITimeoutElapsed;
            UITimeout.Start();
        }
        public void _UITimeoutElapsed(object source, ElapsedEventArgs e)
        {
            UIHB = DateTime.Now;
            NotifyListeners(UIHB);
            Console.WriteLine("IN UIbroadcasterlistener UIHB : " + UIHB.ToString());
        
        }
        public void AddUIBroadcastListener(IBrowserStateListener listener)
        {
            this.browserStateListeners.Add(listener);
        }
        private void NotifyListeners(DateTime param)
        {
            foreach (IBrowserStateListener listener in
                this.browserStateListeners)
            {
                listener.OnNewState(param);
            }
        }
    }
class broadcaster:IBrowserStateListener
    {
        private DateTime UIHrtBt;
        public broadcaster()
        {          
        }
        public void OnNewState(DateTime param)
        {
            UIHrtBt = param;
            Console.WriteLine("In broadcaster UIHrtBt =" + UIHrtBt.ToString());
        }
    }
class Coordinator
    {
        private UIbroadcasterlistener uiBroadcastListener = new UIbroadcasterlistener();
        private broadcaster obj = new broadcaster();
        public Coordinator()
        {           
        }
    }
public interface IBrowserStateListener
        {
            void OnNewState(DateTime param);
        }
}
Posted
Updated 16-Jun-14 22:58pm
v2
Comments
Sunasara Imdadhusen 17-Jun-14 4:59am    
Please do not post your entire code, it may reduce chance to get answer quickly.
gggustafson 17-Jun-14 9:14am    
Where is your Socket code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900