Exemple #1
1
        private JsonWebSocket CreateWebSocket(ServerConfig config)
        {
            var websocket = new JsonWebSocket(string.Format("ws://{0}:{1}/", config.Host, config.Port), "ServerManager");
#if SILVERLIGHT
            websocket.Opened += new EventHandler(CreateAsyncOperation<object, EventArgs>(m_WebSocket_Opened));
            websocket.Error += new EventHandler<ClientEngine.ErrorEventArgs>(CreateAsyncOperation<object, ClientEngine.ErrorEventArgs>(m_WebSocket_Error));
            websocket.Closed += new EventHandler(CreateAsyncOperation<object, EventArgs>(m_WebSocket_Closed));
            websocket.On<ServerInfo>(CommandName.UPDATE, CreateAsyncOperation<ServerInfo>(OnServerUpdated));
#else
            websocket.Opened += new EventHandler(m_WebSocket_Opened);
            websocket.Error += new EventHandler<ClientEngine.ErrorEventArgs>(m_WebSocket_Error);
            websocket.Closed += new EventHandler(m_WebSocket_Closed);
            websocket.On<ServerInfo>(CommandName.UPDATE, OnServerUpdated);
#endif

            websocket.Open();
            State = ConnectionState.Connecting;
            m_ErrorPopped = false;

            foreach (var instance in Instances)
            {
                instance.State = InstanceState.Connecting;
            }

            return websocket;
        }
        protected override void ExecuteSaveCommand(object target)
        {
            ServerConfig server = null;

            var exsiting = App.ClientConfig.Servers.Any(s =>
                    s.Name.Equals(Name, StringComparison.OrdinalIgnoreCase));

            if (exsiting)
            {
                Messenger.Default.Send<NewEditServerMessage>(new NewEditServerMessage { Message = "The server with same name already exists!" });
                return;
            }

            server = new ServerConfig();

            server.Name = Name;
            server.Host = Host;
            server.Port = Port.Value;
            server.UserName = UserName;

            var passwordBox = target as PasswordBox;
            server.Password = EncryptPassword(passwordBox.Password);

            Messenger.Default.Send<CloseNewServerMessage>(CloseNewServerMessage.Empty);
            Messenger.Default.Send<NewServerCreatedMessage>(new NewServerCreatedMessage(server));
        }
Exemple #3
0
        public ServerViewModel(ServerConfig config)
        {
            Instances = new List<InstanceViewModel>();
            m_ServerConfig = config;
            Name = config.Name;
            m_WebSocket = CreateWebSocket(config);
            m_ReconnectTimer = new Timer(ReconnectTimerCallback, null, Timeout.Infinite, Timeout.Infinite);

            ConfigCommand = new RelayCommand<object>(ExecuteConfigCommand);
        }