public async Task <bool> ChangeServerStatus(int id, CustomServer message) { var servers = await _Context.Server.FindAsync(id); var server = await _Context.Server.FindAsync(message.id); // comment tratar de que el id de url y body mach if (servers == server) { if (message.PayLoad == "activated") { server.IsOnline = true; await _Context.SaveChangesAsync(); } if (message.PayLoad == "deactivated") { server.IsOnline = false; await _Context.SaveChangesAsync(); } } else { throw new Exception("are different"); } return(true); }
public async Task <IActionResult> GetServerStatus(int id, [FromBody] CustomServer message) { var serverStatus = await _ServerService.ChangeServerStatus(id, message); var response = new ApiResponse <bool>(serverStatus); return(Ok(response)); }
/// <summary> /// 根据SessionId获取连接对象 /// </summary> /// <param name="sessionId"></param> /// <returns></returns> public static CustomSession GetSessionById(this string sessionId) { CustomServer server = SocketServiceObject.SocketService; if (server != null && server.SessionCount > 0) { return(server.GetSessionByID(sessionId)); } return(null); }
/// <summary> /// 向所有会话对象推送消息 /// </summary> /// <param name="command">命令</param> /// <param name="msg">数据包</param> public static void SendToAll(SocketCommand command, string msg) { CustomServer server = SocketServiceObject.SocketService; if (server != null && server.SessionCount > 0) { IEnumerable <CustomSession> allSessions = server.GetAllSessions(); foreach (CustomSession session in allSessions) { if (session != null && session.Connected) { session.Send(command, msg); } } } }
private void btnDeleteServer_Click(object sender, RoutedEventArgs e) { CustomServer myCustomServer = new CustomServer(); myCustomServer.ServerId = currentServer.ServerId; //remove it from the list myUserPrefs.UpdateSettings(UserPreferences.SettingsType.RemoveCustomServer, myCustomServer); if (myUserPrefs.DefaultServer == currentServer.ServerId) { //clear that out too myUserPrefs.UpdateSettings(UserPreferences.SettingsType.DefaultServer, Guid.Empty); } currentServer = null; Storyboard sbHideButtons = (Storyboard)this.Resources["HideCustomServerButtons"]; sbHideButtons.Begin(); ServerList_Loaded(sender, new RoutedEventArgs()); }
private void btnAdd_Click(object sender, RoutedEventArgs e) { bool blnContinue = true; if (string.IsNullOrEmpty(txtServerPort.Text)) { txtServerPort.Focus(); blnContinue = false; } if (string.IsNullOrEmpty(txtServerAddress.Text)) { txtServerAddress.Focus(); blnContinue = false; } if (string.IsNullOrEmpty(txtServerName.Text)) { txtServerName.Focus(); blnContinue = false; } if (blnContinue) { btnRefreshList.IsEnabled = true; brdCustomServer.Visibility = Visibility.Collapsed; svspServers.Visibility = Visibility.Visible; svwpServers.Visibility = Visibility.Visible; //make a server info object CustomServer myCustomServer = new CustomServer(); myCustomServer.ServerAddress = txtServerAddress.Text; myCustomServer.ServerId = new Guid(btnAdd.Tag.ToString()); btnAdd.Tag = null; myCustomServer.ServerName = txtServerName.Text; int nServerPort = 0; int.TryParse(txtServerPort.Text, out nServerPort); myCustomServer.ServerPort = nServerPort; myUserPrefs.UpdateSettings(UserPreferences.SettingsType.AddCustomServer, myCustomServer); ServerList_Loaded(sender, e); } }
public ServerForm() { InitializeComponent(); this.serverCred = new ServerCurrentCredential(PackageNames.Negotiate); this.serverContext = new ServerContext( serverCred, ContextAttrib.AcceptIntegrity | ContextAttrib.ReplayDetect | ContextAttrib.SequenceDetect | ContextAttrib.MutualAuth | ContextAttrib.Delegate | ContextAttrib.Confidentiality, true ); this.server = new CustomServer(); this.server.Received += server_Received; this.server.Disconnected += server_Disconnected; this.FormClosing += Form1_FormClosing; this.startButton.Click += startButton_Click; this.stopButton.Click += stopButton_Click; this.encryptButton.Click += encryptButton_Click; this.signButton.Click += signButton_Click; this.impersonateButton.Click += impersonateButton_Click; this.running = false; this.initializing = false; this.connected = false; UpdateButtons(); this.serverUsernameTextbox.Text = this.serverCred.PrincipleName; }
public void AddServer(CustomServer server) { listServer.Add(server); }
//添加一台服务器 public void AddServer(CustomServer server) { serverList.Add(server); }