view Messaging/Server/UI/MainWindowViewModel.cs @ 27:96fdf58e05b4

Server working with sockets and rabbitmq
author adminsh@apollo
date Wed, 21 Mar 2012 19:00:59 +0000
parents 045dac571339
children 4c0dea4760c5
line wrap: on
line source

using System;
using System.Windows.Input;
using Common;
using Common.Logger;
using Common.Messages;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System.Windows;
using GalaSoft.MvvmLight.Messaging;
using Server.EndPoints;
using Server.Interfaces;
using Server.Listeners;

namespace Server.UI
{
    public class MainWindowViewModel : ViewModelBase
    {
        #region Properties

        #region OverrideSwitch

        public const string OverrideSwitchPropertyName = "OverrideSwitch";
        private bool? _overrideSwitch = false;
        public bool? OverrideSwitch
        {
            get { return _overrideSwitch; }
            set
            {
                if (_overrideSwitch == value) return;
                var oldValue = _overrideSwitch;
                _overrideSwitch = value;
                RaisePropertyChanged(() => OverrideSwitch, oldValue, value, false);
            }
        }

        #endregion

        #endregion

        public ICommand CloseCommand { get; set; }

        public BaseEndPoint SocketEndPoint { get; set; }
        public BaseEndPoint RabbitEndPoint { get; set; }
        public BaseEndPoint RabbitProtoEndPoint { get; set; }

        #region Constructor

        public MainWindowViewModel()
        {
            InitSocketEndPoint(Settings.SocketsPortNumber);
            InitRabbitEndPoint(Settings.RabbitPortNumber);
            InitRabbitProtoEndPoint(Settings.RabbitProtoPortNumber);

            CloseCommand = new RelayCommand(CloseCommandExecute);

        }

        private void InitSocketEndPoint(int port)
        {
            IListener listener = new AsyncSocketListener(port);
            SocketEndPoint = new SocketEndPoint(listener)
            {
                DisplayText = "Async Sockets",
                ToolTip = "Listening over TCP/IP on socket localhost:" + port
            };
        }

        private void InitRabbitEndPoint(int port)
        {
            IListener listener = new RabbitQueueListener(port);
            RabbitEndPoint = new RabbitEndPoint(listener)
            {
                DisplayText = "RabbitMQ",
                ToolTip = "Listening..." + port
            };
        }

        private void InitRabbitProtoEndPoint(int port)
        {
            IListener listener = null;
            RabbitProtoEndPoint = new RabbitProtoEndPoint(listener)
            {
                DisplayText = "RabbitMQ with Protobuf-net",
                ToolTip = "Listening...." + port
            };
        }
        private void CloseCommandExecute()
        {
            Log.Write("Closing command executed");
            Application.Current.Shutdown();
        }

        #endregion
    }
}