Exemplo n.º 1
0
 public MainViewVm(IQuoteSource source)
 {
     Quotes = new ObservableCollection<Quote>();
     _source = source;
     _currentDispatcher = Dispatcher.CurrentDispatcher;
     _source.QuoteArrived += new Action<Quote>(_source_QuoteArrived);
 }
Exemplo n.º 2
0
 public WatchListViewModel(IQuoteSource source)
 {
     this.Quotes               = new ObservableCollection <Quote>();
     this.currentDispatcher    = Dispatcher.CurrentDispatcher;
     this.source               = source;
     this.source.QuoteArrived += new Action <Quote>(source_QuoteArrived);
 }
Exemplo n.º 3
0
        public QuoteServer(IQuoteSource quoteSource, IQuoteTransportServer transportServer, IQuoteStore quoteStore)
        {
            this.quoteSource = quoteSource;
            this.server = transportServer;
            this.quoteStore = quoteStore;

            timer.Elapsed += TimerOnElapsed;
            timer.Interval = 2000;
            timer.Start();

            quoteSource.NewQuoteAvailable += QuoteSourceOnNewQuoteAvailable;
            server.OnNewClientConnected += ServerOnOnNewClientConnected;
        }
Exemplo n.º 4
0
        public QuoteServer(IQuoteSource quoteSource, IQuoteTransportServer transportServer, IQuoteStore quoteStore)
        {
            this.quoteSource = quoteSource;
            this.server      = transportServer;
            this.quoteStore  = quoteStore;

            timer.Elapsed += TimerOnElapsed;
            timer.Interval = 2000;
            timer.Start();

            quoteSource.NewQuoteAvailable += QuoteSourceOnNewQuoteAvailable;
            server.OnNewClientConnected   += ServerOnOnNewClientConnected;
        }
Exemplo n.º 5
0
        public void Listen(int port, IQuoteSource quoteSource)
        {
            _quoteSource = quoteSource;
            _server      = new UdpClient(port);

            while (true)
            {
                var remoteEP = new IPEndPoint(IPAddress.Any, port);
                _server.Receive(ref remoteEP);

                Log.Information("Request from {RemoteEndPoint}", remoteEP);

                Quote  quote      = quoteSource.GetQuote();
                byte[] quoteBytes = Encoding.ASCII.GetBytes(quote + "\n");
                _server.Send(quoteBytes, quoteBytes.Length, remoteEP);

                Log.Information("Sent quote {Quote} to {RemoteEndPoint}", quote, remoteEP);
            }
        }
Exemplo n.º 6
0
        public void Listen(int port, IQuoteSource quoteSource)
        {
            _quoteSource = quoteSource;
            _server      = new TcpListener(IPAddress.Any, port);
            _server.Start();

            while (true)
            {
                var client = _server.AcceptTcpClient();

                Log.Information("Request from {RemoteEndPoint}", client.Client.RemoteEndPoint);

                Quote  quote      = quoteSource.GetQuote();
                byte[] quoteBytes = Encoding.ASCII.GetBytes(quote + "\n");
                client.GetStream().Write(quoteBytes, 0, quoteBytes.Length);

                Log.Information("Sent quote {Quote} to {RemoteEndPoint}", quote, client.Client.RemoteEndPoint);

                client.Close();
            }
        }