private static void InitializeSystemSecurityContext() { SettingsSecureFileStore securitySettings = new SettingsSecureFileStore(); ServiceConfiguration configs = securitySettings.GetConfigurations(); if (configs != null) { ServiceHelperFactory.get_Instance().set_BaseUri(configs.get_ServiceBaseUrl()); ClientConfiguration settings = securitySettings.GetClientSettingsFromConfigDll(); if (settings == null) { Program.logger.Error("Client configurations for security service not found"); } if (settings != null) { settings.set_ActAsClientUrl(ServiceHelperFactory.get_Instance().get_BaseUri()); NetworkCredential creds = CredentialCache.DefaultCredentials as NetworkCredential; ClaimsPrincipalSelector claimsPrincipalSelector = new ClaimsPrincipalSelector(creds, settings, null); claimsPrincipalSelector.GetClaimsPrincipal(); ClaimsPrincipal.ClaimsPrincipalSelector = new Func <ClaimsPrincipal>(claimsPrincipalSelector.GetClaimsPrincipal); if (claimsPrincipalSelector.get_ClaimsPrincipal() != null) { claimsPrincipalSelector.get_ClaimsPrincipal().set_ActAsToken(ActiveClient.GetActAsToken(creds, settings, claimsPrincipalSelector.get_ClaimsPrincipal())); } ServiceHelperFactory.get_Instance().set_StsClientConfiguration(settings); ServiceHelperFactory.get_Instance().set_StsUserCredentials(creds); } } else { Program.logger.Error("Client configurations not found"); } }
public void Close() { ActiveClient.Client.NoDelay = true; ActiveClient.Client.Disconnect(false); ActiveStream.Close(); ActiveClient.Close(); }
public virtual void Dispose() { lock (_syncRoot) { _client = null; } }
private bool StartMonitorForServer(BrainHatServerStatus status) { ActiveClient = ServersMonitor.GetHatClient(HostName); if (ActiveClient != null) { DataProcessor = new BrainflowDataProcessor(HostName, status.BoardId, status.SampleRate); SetBandPowerCalculator(); BlinkDetector.GetData = DataProcessor.GetRawChunk; BlinkDetector.GetStdDevMedians = DataProcessor.GetStdDevianMedians; ActiveClient.RawDataReceived += DataProcessor.AddDataToProcessor; SeekingAlpha.GetBandPower = DataProcessor.GetBandPower; DataProcessor.NewSample += BlinkDetector.OnNewSample; _ = Task.Run(async() => { await DataProcessor.StartDataProcessorAsync(); await DataProcessor.StartBandPowerMonitorAsync(); await ActiveClient.StartReadingFromLslAsync(); }); return(true); } return(false); }
/// <summary> /// Generate non airport client (fire,observer,alert) /// </summary> public void GeneratePositionableClient() { LastClient = new PositionableClient(); Rnd = new Random(DateTime.Now.Millisecond); int nbCall; //Observator LastClient = (PositionableClient)ClientFactory.CreateObserver(); AddClientToAirport(LastClient, 1); ActiveClient.Add(LastClient); //Fire LastClient = (PositionableClient)ClientFactory.CreateFire(); AddClientToAirport(LastClient, 2); ActiveClient.Add(LastClient); //ResuceTeam nbCall = Rnd.Next(1, 2); for (int i = 0; i < nbCall; i++) { LastClient = (PositionableClient)ClientFactory.CreateRescueTeam(); AddClientToAirport(LastClient, 3); ActiveClient.Add(LastClient); } }
/// <summary> /// Execute item. /// </summary> protected void WaitCallbackFunc(object parameter) { ActiveClient client = Client; if (client != null) { client.PerformExecution(parameter as Envelope); } }
/// <summary> /// Actually perform the exection. /// </summary> internal void PerformExecution(object envelope) { ActiveClient client = Client; if (client != null) { client.PerformExecution(envelope as Envelope); } }
public void Disconnect() { if (ActiveClient != null && ActiveClient.Connected) { ActiveClient.Close(); ActiveClient = null; } if (PassiveClient != null && PassiveClient.Connected) { PassiveClient.Close(); PassiveClient = null; } }
private void _useImplicitSSL() { if (ActiveClient != null) { if (ConnectionType == 0) { SslStream sslStream = new SslStream(ActiveClient.GetStream(), false, _validateServerCertificate); sslStream.AuthenticateAsClient(realServer); _activeClientStream = sslStream; ActiveClientReader = new BinaryReader(_activeClientStream); ActiveClientWriter = new StreamWriter(_activeClientStream); } } }
/// <summary> /// Enlist item for execution. /// </summary> public virtual void Execute(Envelope envelope) { ActiveClient client = _client; if (envelope.ExecutionModel == Envelope.ExecutionModelEnum.Direct) { if (client != null) { client.PerformExecution(envelope); } } else { OnExecute(envelope); } }
private async Task StopMonitorForServer() { if (ActiveClient != null) { ActiveClient.RawDataReceived -= DataProcessor.AddDataToProcessor; await ActiveClient.StopReadingFromLslAsync(); } ActiveClient = null; if (DataProcessor != null) { DataProcessor.NewSample -= BlinkDetector.OnNewSample; await DataProcessor.StopDataProcessorAsync(); } DataProcessor = null; }
/// <summary> /// Initialize the strategy. /// </summary> public bool Initialize(ActiveClient client) { lock (_syncRoot) { if (_client != null) { #if Matrix_Diagnostics SystemMonitor.Warning("Client already assigned to execution strategy."); #endif return(false); } //SystemMonitor.ThrowIf(client != null, "Client not assigned to execution strategy."); _client = client; return(true); } }
public void SetInputCapture(bool enable, bool showServerUI) { if (enable) { TryAutoEnableMulticastOnce(); if (!Mubox.Configuration.MuboxConfigSection.Default.IsCaptureEnabled) { Mubox.Configuration.MuboxConfigSection.Default.IsCaptureEnabled = true; this.Dispatcher.Invoke((Action) delegate() { try { ActiveClient = listBox1.SelectedItem as ClientBase; if (ActiveClient != null) { ActiveClient.Activate(); } else { this.Hide(); } } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } }); } } else { if (Mubox.Configuration.MuboxConfigSection.Default.IsCaptureEnabled) { Mubox.Configuration.MuboxConfigSection.Default.IsCaptureEnabled = false; if (showServerUI) { this.Dispatcher.Invoke((Action) delegate() { this.Show(); this.Topmost = true; }); } } } }
public async void StartListening() { try { IPHostEntry ipHostInfo = Dns.GetHostEntry("localhost"); IPAddress ipAddress = ipHostInfo.AddressList[0]; IPEndPoint localEndPoint = new IPEndPoint(ipAddress, vsPort); TcpListener tcpListener = new TcpListener(localEndPoint); tcpListener.Start(); Console.WriteLine("Listening for Visual Studio to connect"); while (true) { await Task.Run(async() => { // Wait for client to connect TcpClient tcpClient = await tcpListener.AcceptTcpClientAsync(); // tcpClient valid after connection Console.WriteLine("Visual Studio has connected"); if (activeClientCount > 0) { Debug.Assert(activeClientCount == 1); Debug.Assert(activeClient != null); activeClient.Close(); activeClient = null; activeClientCount = 0; } activeClient = new ActiveClient(this, tcpClient); activeClient.ReceiveVSDebug(); activeClientCount++; }); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
private static IEnumerable <ActiveClient> GetLanActiveClientsFromContent(string pageSource, string startString, int rowArrayLength) { IEnumerable <string[]> rowValues = GetRowValues(pageSource, startString, rowArrayLength); var clients = new List <ActiveClient>(); foreach (string[] rowValue in rowValues) { var i = 0; var client = new ActiveClient { HostName = rowValue[i++], IpAddress = rowValue[i++], MacAddress = rowValue[i++], ConnectionsCount = int.Parse(rowValue[i]) }; clients.Add(client); } return(clients); }
private void _useExplicitSSL() { if (!SupportedCommands.Contains("AUTH TLS")) { return; } if (ActiveClient != null) { string answer = SendCommandReadAnswer("AUTH TLS"); if (ConnectionType == 234) { SslStream sslStream = new SslStream(ActiveClient.GetStream(), false, _validateServerCertificate); sslStream.AuthenticateAsClient(realServer); _activeClientStream = sslStream; ActiveClientReader = new BinaryReader(_activeClientStream); ActiveClientWriter = new StreamWriter(_activeClientStream); } } }
internal void CloseActiveClient() { activeClient.Close(); activeClient = null; activeClientCount = 0; }
/// <summary> /// Initialize the strategy. /// </summary> public bool Initialize(ActiveClient client) { lock (_syncRoot) { if (_client != null) { #if Matrix_Diagnostics SystemMonitor.Warning("Client already assigned to execution strategy."); #endif return false; } //SystemMonitor.ThrowIf(client != null, "Client not assigned to execution strategy."); _client = client; return true; } }
public void Process() { try { Stream = client.GetStream(); // получаем имя пользователя MyMessage message = GetMessage(); if (message == null) { return; } userName = message.Name; var t = $"{userName} вошел в чат"; // посылаем сообщение о входе в чат всем подключенным пользователям server.BroadcastMessage($"\t\t\t{DateTime.Now.ToLocalTime()} {t}", Id, ""); var newActClient = new ActiveClient() { Id = this.Id, Name = message.Name }; activeClients.Add(newActClient); server.BroadcastMessage("", "", "", activeClients); Console.WriteLine($"{DateTime.Now.ToLocalTime()} {t}"); // в бесконечном цикле получаем сообщения от клиента while (true) { try { message = GetMessage(); if (message.ReceiverId != "") { message.Msg = String.Format("Private {0}: {1}", message.Name, message.Msg); Console.WriteLine($"{DateTime.Now.ToLocalTime()} {message.Msg}"); server.BroadcastMessage($"{DateTime.Now.ToLocalTime()} {message.Msg}", this.Id, message.ReceiverId); } else { message.Msg = String.Format("{0}: {1}", message.Name, message.Msg); Console.WriteLine($"{DateTime.Now.ToLocalTime()} {message.Msg}"); server.BroadcastMessage($"{DateTime.Now.ToLocalTime()} {message.Msg}", this.Id, ""); } } catch (Exception ex) { message.Msg = String.Format("\t\t\t{0}: покинул чат", message.Name); Console.WriteLine(message.Msg); server.BroadcastMessage(message.Msg, this.Id, ""); break; } } } catch (Exception e) { Console.WriteLine(e.Message); } finally { // в случае выхода из цикла закрываем ресурсы server.RemoveConnection(this.Id); Close(); } }
public void Update(ActiveClient activeClient) { ConnectionsCount = activeClient.ConnectionsCount; IsActive = true; }
public void Close() { ActiveClient.Close(); ActiveStream.Close(); }