public NodeMasterViewModel(NodeConfig config) { m_Config = config; Name = m_Config.Name; ConnectCommand = new DelegateCommand(ExecuteConnectCommand); ThreadPool.QueueUserWorkItem((c) => InitializeWebSocket((NodeConfig)c), config); }
void InitializeWebSocket(NodeConfig config) { try { m_WebSocket = new AgentWebSocket(config.Uri); } catch (Exception) { ErrorMessage = "Invalid server URI!"; State = NodeState.Offline; return; } #if !SILVERLIGHT m_WebSocket.AllowUnstrustedCertificate = true; m_WebSocket.Closed += new EventHandler(WebSocket_Closed); m_WebSocket.Error += new EventHandler<ClientEngine.ErrorEventArgs>(WebSocket_Error); m_WebSocket.Opened += new EventHandler(WebSocket_Opened); m_WebSocket.On<string>(CommandName.UPDATE, OnServerUpdated); #else m_WebSocket.ClientAccessPolicyProtocol = System.Net.Sockets.SocketClientAccessPolicyProtocol.Tcp; m_WebSocket.Closed += new EventHandler(WebSocket_Closed); m_WebSocket.Error += new EventHandler<ClientEngine.ErrorEventArgs>(WebSocket_Error); m_WebSocket.Opened += new EventHandler(WebSocket_Opened); m_WebSocket.On<string>(CommandName.UPDATE, OnServerUpdatedAsync); #endif StartConnect(); }
public NodeConfigViewModel(NodeConfig node) { IsNew = node is NewNodeConfig; Name = IsNew ? string.Empty : node.Name; Uri = node.Uri; UserName = node.UserName; Password = node.Password; SaveCommand = new DelegateCommand(ExecuteSaveCommand, CanExecuteSaveCommand); RemoveCommand = new DelegateCommand(ExecuteRemoveCommand, CanExecuteRemoveCommand); }
void OnNodeViewModelSaved(object sender, EventArgs e) { var nodeViewMode = sender as NodeConfigViewModel; var node = new { Name = nodeViewMode.Name, Uri = nodeViewMode.Uri, UserName = nodeViewMode.UserName, Password = nodeViewMode.Password }; var currentNode = SelectedNode; var isNew = false; if (currentNode is NewNodeConfig) { var newNode = new NodeConfig(); m_Nodes.Add(newNode); SelectedNode = newNode; //Update UI m_Nodes.Remove(currentNode); currentNode = newNode; m_Nodes.Add(new NewNodeConfig()); //Update configuration model m_AgentConfig.Nodes.Add(currentNode); isNew = true; } currentNode.Name = node.Name; currentNode.Uri = node.Uri; currentNode.UserName = node.UserName; currentNode.Password = node.Password; //Save m_AgentConfig.Save(); //Added if (isNew) { FireEventHandler(Added, currentNode); } else { FireEventHandler(Updated, currentNode); } }