/// <summary> /// Webs the socket connect. /// </summary> /// <returns>The socket connect.</returns> public async Task WebSocketConnect(OnRecivedMessage onRecivedMessage = null, OnOpened onOpened = null, OnClosed onClosed = null) { this.onRecivedMessage = onRecivedMessage; this.onOpened = onOpened; this.onClosed = onClosed; if (null != clientWebSocket) { await clientWebSocket.CloseAsync(WebSocketCloseStatus.Empty, "close", CancellationToken.None); } clientWebSocket = new ClientWebSocket(); clientWebSocket.Options.AddSubProtocol("Mixin-Blaze-1"); string token = GenGetJwtToken("/", ""); clientWebSocket.Options.SetRequestHeader("Authorization", "Bearer " + token); using (var cts = new CancellationTokenSource(ReadTimeout)) { Task taskConnect = clientWebSocket.ConnectAsync(new Uri(MIXIN_WEBSOCKET_URL), cts.Token); await taskConnect; } if (clientWebSocket.State == WebSocketState.Open) { onOpened?.Invoke(this, null); } else { Console.WriteLine("Connetced fails: " + clientWebSocket.State); } }
public void Open(IReadOnlyCollection <Item_Product> products, Chat_ReturnTo dialogueAfterShopClosed) { if (GameManager.IsScreenResolutionGreaterOrEqualThanFHD == false) { var canvasScaler = GetComponent <CanvasScaler>(); canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; canvasScaler.referenceResolution = new Vector2(GameManager.FULLHD_WIDTH, GameManager.FULLHD_HEIGHT); } else { var screenSize = new Vector2(Screen.width, Screen.height); Left.RectTransform.sizeDelta = new Vector2(screenSize.x * 0.5f, screenSize.y); Left.RectTransform.localPosition = new Vector3(screenSize.x * -0.25f, 0.0f); Right.RectTransform.sizeDelta = Left.RectTransform.sizeDelta; Right.RectTransform.localPosition = new Vector3(screenSize.x * 0.25f, 0.0f); } TradeType = TradeType.Buy; Products = products; Left.Activate(); Right.Activate(); UI_NavigatorManager.Instance.Add(ref uinav_escapeToCloseShop, "Back", InputEvent.ACTION_CLOSE_SHOP_MENU); UI_NavigatorManager.Instance.Add(ref uinav_tabSellOrBuy, "Sell", InputEvent.ACTION_SWITCH_SHOP_MENU); this.dialogueAfterShopClosed = dialogueAfterShopClosed; InputEvent.Instance.Event_CloseShop.AddListener(Close); InputEvent.Instance.Event_SwitchShop.AddListener(SwitchMenuToSell); OnOpened.Invoke(); }
public void Open(string url, string protocol = null) { _clientWebSocketConnection = ClientWebSocketWrapper.Create(url); _clientWebSocketConnection.OnConnect(_ => OnOpened?.Invoke()); _clientWebSocketConnection.OnDisconnect(_ => OnClosed?.Invoke()); _clientWebSocketConnection.OnMessage((s, _) => OnMessage?.Invoke(s)); _clientWebSocketConnection.Connect().Wait(); }
private void StartMonitor() { _monitorTask = Task.Run(() => { _monitorRunning = true; var needsReconnect = false; try { var lastState = State; while (_ws != null && !_disposedValue) { if (lastState == State) { Thread.Sleep(200); continue; } OnStateChanged?.Invoke(State, lastState); if (State == WebSocketState.Open) { OnOpened?.Invoke(); } if ((State == WebSocketState.Closed || State == WebSocketState.Aborted) && !_reconnecting) { if (lastState == WebSocketState.Open && !_disconnectCalled && _reconnectStrategy != null && !_reconnectStrategy.AreAttemptsComplete()) { // go through the reconnect strategy // Exit the loop and start async reconnect needsReconnect = true; break; } OnClosed?.Invoke(_ws.CloseStatus ?? WebSocketCloseStatus.Empty); if (_ws.CloseStatus != null && _ws.CloseStatus != WebSocketCloseStatus.NormalClosure) { OnError?.Invoke(new Exception(_ws.CloseStatus + " " + _ws.CloseStatusDescription)); } } lastState = State; } } catch (Exception ex) { OnError?.Invoke(ex); } if (needsReconnect && !_reconnecting && !_disconnectCalled) #pragma warning disable 4014 { DoReconnect(); } #pragma warning restore 4014 _monitorRunning = false; }); }
public void Open(string url, string protocol = null) { socket = protocol == null ? new WebSocket(url) : new WebSocket(url, protocol); socket.OnOpen += delegate { OnOpened?.Invoke(); }; socket.OnClose += delegate { OnClosed?.Invoke(); }; socket.OnError += (sender, args) => OnError?.Invoke(args.Message); socket.OnMessage += (sender, args) => OnMessage?.Invoke(args.Data); socket.Connect(); }
public void Open() { if (!IsOpened) { SetColorAlpha(1); IsOpened = true; OnOpened.Invoke(); } }
private void buttonOpen_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); if (dialog.ShowDialog() == DialogResult.OK) { txtPath.Text = dialog.FileName; OnOpened?.Invoke(this, e); } }
private void Monitor() { Log($"Starting monitor."); _tokenSource = new CancellationTokenSource(); while (RunMonitor) { do { InitializeClient(); Uri url = new Uri(Url); try { _reconnecting = true; if (_disconnectCalled == true) { _disconnectCalled = false; Log("Re-connecting closed connection."); } _ws.ConnectAsync(url, _tokenSource.Token).Wait(15000); } catch (Exception e) { Log(e.Message); _ws.Abort(); _ws.Dispose(); Thread.Sleep(_options.MyReconnectStrategy.GetReconnectInterval() - 1000); } } while (RunMonitor && _ws.State != WebSocketState.Open); _reconnecting = false; Console.WriteLine("Starting Listener & Sender tasks."); StartListener(); StartSender(); OnOpened?.Invoke(); while (_ws.State == WebSocketState.Open) { Thread.Sleep(200); } _reconnecting = true; for (int i = 0; i < 10; i++) { if ((_listenerRunning || _senderRunning) == false) { break; } else { Thread.Sleep(1000); } } } MonitorFinished = true; }
/// <summary> /// パネルを開く動作 /// </summary> protected virtual void OpenProcess(UnityAction onPrepared = null, UnityAction onCompleted = null) { onPrepared?.Invoke(); _canvasGroup.interactable = true; gameObject.SetActive(true); onCompleted?.Invoke(); OnOpened?.Invoke(); }
public void SetupQuests(IEnumerable <IQuest> quests) { RemoveChildren(); foreach (var quest in quests) { AddChild(new QuestLine(quest, Anchor.AutoCenter, .95f, .1f) { OnPressed = _ => OnOpened?.Invoke(quest), }); } }
/// <summary> /// 开始发送器。。 /// </summary> /// <param name="args"></param> public void Open(string[] args) { if (_isRunning) { return; } _isRunning = true; //启动接收线程 ThreadPool.QueueUserWorkItem((o) => { StartReceive(); }, null); OnOpened?.Invoke(this); LogHelper.Write("LXTcpConnection", "客户端[{0}-{1}]启动接收数据...", _id, this.RemoteEndpoint); }
public void Start() { if (IsOpen) { throw new InvalidOperationException("Cannot start a transaction twice."); } _raisedEvents.Clear(); _transactionFlavor = _transactionDomain.BeginTransaction(); IsOpen = true; Succeeded = false; OnOpened?.Invoke(this, new TransactionEventArgs(_transactionDomain)); }
private void Open(Popup popup) { popup.Setup(() => { typeof(PopupManager) .GetMethod("Close") ?.MakeGenericMethod(popup.GetType()) .Invoke(this, null); }); popup.AnimateIn(() => { OnOpened?.Invoke(popup.GetType()); }); }
private void PinValueChangedHandler(object sender, GpioPinValueChangedEventArgs e) { OnStateChanged?.Invoke(this, new SwitchStateChangedEventArgs { GpioPinValueChangedEventArgs = e }); var currentState = GetState(); if (currentState == SwitchState.Opened) { OnOpened?.Invoke(this, new SwitchOpenedEventArgs()); } else { OnClosed?.Invoke(this, new SwitchClosedEventArgs()); } }
/// <summary> /// Opens the <see cref="CanvasMenu"/> without playing the open transition. Does not record history. /// </summary> public void OpenImmediate() { if (_canvasGroup == null) { _canvasGroup = GetComponent <CanvasGroup>(); } _canvasGroup.alpha = 1; _canvasGroup.blocksRaycasts = true; _canvasGroup.interactable = true; _isOpen = true; if (!MenuManager.OpenCanvasMenus.Contains(this)) { MenuManager.OpenCanvasMenus.Add(this); } OnOpened.Invoke(); }
/// <summary> /// Creates a new instance of an <see cref="AudioPlayer"/> /// </summary> /// <param name="autoPlay">Whether to autoplay media.</param> /// <param name="defaultVolume">Default volume to set. Min-0, Max=1</param> /// <param name="tickIntervalMs">After how many milliseconds to update/call OnPlaying event.</param> public AudioPlayer(bool autoPlay = false, double defaultVolume = 1, double tickIntervalMs = 100) { _autoPlay = autoPlay; _volume = defaultVolume; Timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(tickIntervalMs) }; Timer.Tick += Timer_Tick; MediaPlayer = new MediaPlayer(); MediaPlayer.PlaybackSession.PlaybackStateChanged += (s, e) => OnStateChanged?.Invoke(s); MediaPlayer.MediaEnded += (s, e) => OnMediaEnded?.Invoke(); MediaPlayer.Volume = defaultVolume; MediaPlayer.AutoPlay = autoPlay; MediaPlayer.AudioCategory = MediaPlayerAudioCategory.Media; MediaPlayer.MediaFailed += (s, e) => OnError?.Invoke(e); MediaPlayer.MediaOpened += (s, e) => OnOpened?.Invoke(s.PlaybackSession); MediaPlayer.PlaybackSession.BufferingProgressChanged += (s, e) => OnBuffer?.Invoke(s.BufferingProgress); MediaPlayer.PlaybackSession.DownloadProgressChanged += (s, e) => OnDownload?.Invoke(s.DownloadProgress); }
private void Socket_OnOpened(object sender) { Log("OnOpened invoked."); _counter = 0; var authObject = new Dictionary <string, object> { { "event", "#handshake" }, { "data", new Dictionary <string, object> { { "authToken", _authToken } } }, { "cid", Interlocked.Increment(ref _counter) } }; var json = _options.Serializer.Serialize(authObject); _socket.Send(json); if (_options.Creds != null) { Emit("auth", _options.Creds); Task.Delay(500).Wait(); } OnOpened?.Invoke(this); }
/// <summary> /// Attempts to open this dialogue. /// </summary> /// <returns>Was this dialogue successfully opened?</returns> public virtual bool TryOpen() { bool wasOpened = opened; if (!capi.Gui.LoadedGuis.Contains(this)) { capi.Gui.RegisterDialog(this); } opened = true; if (DialogType == EnumDialogType.Dialog) { capi.Gui.RequestFocus(this); } if (!wasOpened) { OnGuiOpened(); OnOpened?.Invoke(); capi.Gui.TriggerDialogOpened(this); } return(true); }
public void Execute(object parameter) { OnOpened?.Invoke(parameter); }
private void Connection_OnOpened() { OnOpened?.Invoke(); }
/// <summary> /// Disparado ao estabelecer uma conexão com o servidor /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void objWebSocket_OnOpen(object sender, EventArgs e) { OnOpened?.Invoke(this); }
private void OnItemOpened(DirectoryItemViewModel item) => OnOpened?.Invoke(item);
protected void RaiseOpenEvent() { OnOpened?.Invoke(this, EventArgs.Empty); }
private void OnOpen(object sender, EventArgs e) { OnOpened?.Invoke(); }
private void WebSocketDidOpen(object sender, EventArgs e) { OnOpened?.Invoke(this, EventArgs.Empty); }