/// <summary> /// An async method to connect remote service. /// </summary> /// <since_tizen> 5 </since_tizen> /// <returns>A task representing the asynchronous connect operation.</returns> /// <exception cref="InvalidOperationException">Thrown when the connect is rejected.</exception> public Task Connect() { if (_connectionState == ConnectedState.Connected) { return(Task.CompletedTask); } else if (_connectionState == ConnectedState.Connecting) { return(_connectionTask); } _connectionState = ConnectedState.Connecting; TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>(); _msg = new Message(ServiceId); _msg.Disconnected += (s, e) => { _connectionState = ConnectedState.Disconnected; Disconnected?.Invoke(this, e); }; _msg.Connected += (sender, e) => { Log.Debug(LogTag, "start to register"); _msg.CoRegister(Application.Current.ApplicationInfo.ApplicationId, _noti); _connectionState = ConnectedState.Connected; tcs.SetResult(true); }; _msg.Rejected += (sender, e) => { _connectionState = ConnectedState.Disconnected; tcs.SetException(new InvalidOperationException("invalid id cause exception")); }; _msg.Connect(); return(_connectionTask = tcs.Task); }
public MainForm() { InitializeComponent(); m_previousChatMessages = new List <string>(); m_connectedState = ConnectedState.NotConnected; AutoLogin(); }
/// <summary> /// Поток передачи данных из выходной очереди в WebSocket-соединение /// </summary> private void OutputQueueProcessingThread() { while (IsStarting) { if (WebSocketClient.ReadyState == WebSocketState.Closed) { ServerErr?.Invoke(this, "Отсутствует подключение к серверу"); ConnectedState?.Invoke(this, "Отсутствует подключение"); } if (WebSocketClient.ReadyState == WebSocketState.Open) { ConnectedState?.Invoke(this, "Соеденено"); } if (OutputQueue.TryDequeue(out string Message)) { try { WebSocketClient.Send(Message); } catch { ServerErr?.Invoke(this, "Отсутствует подключение к серверу"); ConnectedState?.Invoke(this, "Отсутствует подключение"); } } Thread.Sleep(1); } }
public void CheckNetwork() { if (ClientSocket.Connected && State == ConnectedState.Connecting) { State = ConnectedState.PreConnected; } if (State == ConnectedState.NotConnected || State == ConnectedState.Connecting) { return; } if (State == ConnectedState.PreConnected) { stream = ClientSocket.GetStream(); State = ConnectedState.Connected; if (OnConnectedCallback != null) { OnConnectedCallback(); } } if (State != ConnectedState.Connected || stream == null || !stream.DataAvailable) { return; } ProcessIncoming(); ProcessOutgoing(); }
public static string ConnectedString(ConnectedState state) { switch (state) { case ConnectedState.Disconnected: return "Connect"; case ConnectedState.Connecting: return "Cancel"; case ConnectedState.Connected: return "Disconnect"; default: return null; } }
public VectorControllerPlus() { this.connection = ConnectedState.Disconnected; this.Behaviours = new List <IVectorBehaviourPlus>(); this.Actions = new Queue <IVectorActionPlus>(); this.Reports = new List <VectorBehaviourPlusReport>(); this.objectSeenStates = new Dictionary <int, ObjectSeenState>(); this.FrameProcessors = new List <ICameraFrameProcessor>(); OnConnectionChanged += async(previously, state) => await RespondToConnectionAsync(previously, state); }
private void OnGlfwMonitor(Monitor *monitor, ConnectedState state) { if (state == ConnectedState.Connected) { WinThreadSetupMonitor(monitor); } else { WinThreadDestroyMonitor(monitor); } }
public void Connect() { if (State == null) { State = new ConnectedState(); } State.Connected(this); Historic.Historic.GetInstance().DisplayAllMessages(); }
/// <summary> /// A method to close message connection /// </summary> /// <since_tizen> 5 </since_tizen> public void Close() { if (_connectionState == ConnectedState.Disconnected) { return; } _msg.UnRegister(); _msg.Dispose(); _msg = null; _connectionState = ConnectedState.Disconnected; _connectionTask.Dispose(); _connectionTask = null; }
void LoginOrConnectedStateChanged(LoginState loginState, ConnectedState connectedState) { if (connectedState == ConnectedState.ConnectingFailed || connectedState == ConnectedState.Disconnected || loginState == LoginState.LoggedOut || loginState == LoginState.InvalidLogin || connectedState == ConnectedState.Connecting) { IsEnabled = false; } if (connectedState == ConnectedState.Connected && loginState == LoginState.LoggedIn) { IsEnabled = _wasEnabled; } }
private void OnTwitchClientConnected() { if (m_connectButton.InvokeRequired) { m_connectButton.Invoke(new Action(OnTwitchClientConnected)); return; } m_connectedState = ConnectedState.Connected; m_connectButton.Visible = false; m_disconnectButton.Visible = true; m_whisperGroup.Visible = true; m_channelGroup.Visible = true; InitializeModManagers(); RegisterIrcEvents(); }
private void ConnectClient() { m_twitchClient = TwitchClient.GetInstance(new IrcCredentials(m_loginData.Username, m_loginData.OAuth)); if (m_twitchClient != null) { if (m_connectedState == ConnectedState.NotConnected) { m_connectedState = ConnectedState.AttemptingConnection; m_twitchClient.OnTwitchLoginFailed += OnLoginFailed; m_twitchClient.OnTwitchConnected += OnTwitchClientConnected; } } m_twitchClient?.Connect(); }
private Connection() { var socket = new CustomSocket(); IConnection connected = new ConnectedState <IConnection>(this, this, socket); IConnection disconnected = new DisconnectedState <IConnection>(this, this, socket); IConnection error = new ErrorState <IConnection>(this, this, socket); AddTransition(connected, ConnectedState <IConnection> .DISCONNECT, disconnected); AddTransition(connected, ConnectedState <IConnection> .ERROR, error); AddTransition(disconnected, DisconnectedState <IConnection> .CONNECT, connected); AddTransition(disconnected, DisconnectedState <IConnection> .ERROR, error); AddTransition(error, ErrorState <IConnection> .CONNECT, connected); AddTransition(error, ErrorState <IConnection> .DISCONNECT, disconnected); CurrentState = disconnected; }
private void DisconnectClient() { m_leaveChannelButton.Visible = false; m_channelLeaveCB.Items.Clear(); m_channelLeaveCB.ResetText(); m_channelLeaveCB.Visible = false; m_channelMessageSelectCB.Items.Clear(); m_channelMessageSelectCB.ResetText(); m_channelGroup.Visible = false; m_whisperGroup.Visible = false; m_eventGroup.Visible = false; m_connectButton.Enabled = true; m_connectedState = ConnectedState.NotConnected; UnregisterIrcEvents(); m_twitchClient?.Disconnect(); }
private async Task RespondToConnectionAsync(ConnectedState previously, ConnectedState state) { bool madeConnection = (state == ConnectedState.Connected && previously != ConnectedState.Connected); switch (state) { case ConnectedState.Connected: await UnregisterBehavioursAsync(Behaviours); await RegisterBehavioursAsync(Behaviours); await ActOnAnyBehaviourPermanentRequirements(); if (madeConnection && controllerConfig.ActionOnConnect != null) { EnqueueAction(controllerConfig.ActionOnConnect); } ResumeActionExecutor(); break; case ConnectedState.Disconnected: HaltActionExecutor(); break; // already lost control of the robot? } }
private static void JoystickCallback(int joystick, ConnectedState state) { // run on a separate thread to prevent deadlocks on single-threaded windows Task.Run(() => Contexts.ForEach(x => x.RaiseConnectionChange(joystick, state))); }
private static void JoystickCallback(int joystick, ConnectedState state) { Contexts.ForEach(x => x.RaiseConnectionChange(joystick, state)); }
public void Connect(string server, int port) { State = ConnectedState.Connecting; ClientSocket = new TcpClient(); ClientSocket.Connect(server, port); State = ConnectedState.Connecting; }
public void RaiseConnectionChange(int joystick, ConnectedState state) { ConnectionChanged?.Invoke(Util.Glfw.JoystickIsGamepad(joystick) ? (IInputDevice)Gamepads[joystick] : Joysticks[joystick], state == ConnectedState.Connected); }
public void RaiseConnectionChange(int joystick, ConnectedState state) { ConnectionChanged?.Invoke(Joysticks[joystick], state == ConnectedState.Connected); }
private async Task Controller_OnConnectionChanged(ConnectedState previously, ConnectedState state) { await HandleConnectionStateAsync(); }
private static unsafe void DpiMonitorCallback(Monitor *monitor, ConnectedState state) { // Normally, adding or removing from the cache would be nice, but this breaks // getting the info from an index, thus the cache must be built from scratch. BuildMonitorCache(); }
private void OnLoginFailed() { m_connectedState = ConnectedState.NotConnected; m_twitchClient.OnTwitchLoginFailed -= OnLoginFailed; m_twitchClient.OnTwitchConnected -= OnTwitchClientConnected; }