private void RouterListView_KeyUp(object sender, KeyEventArgs e) { if ((e.Key == Key.Down) || (e.Key == Key.Up)) { RouterController.Select(); } }
/// <summary> /// Open websocket connection. /// </summary> /// <returns>The async.</returns> /// <param name="secure">If set to <c>true</c> secure.</param> /// <param name="subprotocol">Subprotocol.</param> /// <param name="enforce">If set to <c>true</c> enforce.</param> /// <param name="cancellationToken">Cancellation token.</param> public Task <bool> OpenAsync(bool secure, string subprotocol = null, bool enforce = false, CancellationToken cancellationToken = default(CancellationToken)) { _secure = secure; if (state == Status.Online && !enforce) { AVRealtime.PrintLog("state is Status.Online."); return(Task.FromResult(true)); } if (CurrentConfiguration.RealtimeServer != null) { _wss = CurrentConfiguration.RealtimeServer.ToString(); AVRealtime.PrintLog("use configuration realtime server with url: " + _wss); return(OpenAsync(_wss, subprotocol, enforce)); } var routerUrl = CurrentConfiguration.RTMRouter != null?CurrentConfiguration.RTMRouter.ToString() : (AVClient.CurrentConfiguration.PushServer != null ? AVClient.CurrentConfiguration.PushServer.ToString() : null); return(RouterController.GetAsync(routerUrl, secure, cancellationToken).OnSuccess(r => { var routerState = r.Result; if (routerState == null) { return Task.FromResult(false); } _wss = routerState.server; _secondaryWss = routerState.secondary; state = Status.Connecting; AVRealtime.PrintLog("push router give a url :" + _wss); return OpenAsync(routerState.server, subprotocol, enforce); }).Unwrap()); }
private void OnUserConnected(object sender, NetEventArgs e) { UserUpdateSet.Send(new UpdateSet() { Models = this.Models.ToList(), ModelCount = this.Models.Count, }, RouterController.GetUser(e.User)); }
private void DataGrid_Select(DataGridRow row) { // TODO: Add more tabs // if (RouterTab != null && RouterTab.IsSelected) { DemonSaw.Entity.Entity entity = (DemonSaw.Entity.Entity)row.Item; RouterController.Select(entity); ServerController.Select(entity); } }
/// <summary> /// Opens WebSocket connection with LeanCloud Push server. /// </summary> /// <returns>The async.</returns> /// <param name="cancellationToken">Cancellation token.</param> public Task OpenAsync(CancellationToken cancellationToken = default(CancellationToken)) { if (state == Status.Online) { return(Task.FromResult(true)); } return(RouterController.GetAsync(cancellationToken).OnSuccess(_ => { _wss = _.Result.server; state = Status.Connecting; return OpenAsync(_.Result.server, cancellationToken); }).Unwrap()); }
private void RouterListView_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { DataGridRow row = WpfUtil.GetGridRow(e.OriginalSource); if (row == null) { DataGrid grid = (DataGrid)sender; grid.UnselectAll(); e.Handled = true; } RouterController.Select(); }
public static void Create(MainWindow window) { Main = window; Config = new ConfigFile(); // Controllers LogController = new LogController(Main.LogTextBox, Main.LogTextBlock); RouterController = new RouterController(Main.RouterListView, Main.RouterListViewTextBlock); ServerController = new ServerController(Main.ServerListView, Main.ServerListViewTextBlock); #if !DEBUG Main.DebugTab.IsEnabled = false; Main.DebugTab.Visibility = Visibility.Collapsed; #endif }
/// <summary> /// 初始化实时消息客户端 /// </summary> /// <param name="config"></param> public AVRealtime(Configuration config) { lock (mutex) { if ((int)config.OfflineMessageStrategy == 0) { config.OfflineMessageStrategy = OfflineMessageStrategy.UnreadAck; } CurrentConfiguration = config; if (CurrentConfiguration.WebSocketClient != null) { webSocketController = CurrentConfiguration.WebSocketClient; } if (CurrentConfiguration.SignatureFactory != null) { this.SignatureFactory = CurrentConfiguration.SignatureFactory; } ReconnectOptions = new AVIMReconnectOptions() { Interval = 5, Retry = 120 }; RegisterMessageType <AVIMMessage>(); RegisterMessageType <AVIMTypedMessage>(); RegisterMessageType <AVIMTextMessage>(); RegisterMessageType <AVIMImageMessage>(); RegisterMessageType <AVIMAudioMessage>(); RegisterMessageType <AVIMVideoMessage>(); RegisterMessageType <AVIMFileMessage>(); RegisterMessageType <AVIMLocationMessage>(); RegisterMessageType <AVIMRecalledMessage>(); // 注册服务端 goaway 指令 var goAwayListener = new GoAwayListener(); goAwayListener.OnGoAway += () => { RouterController.ClearCache().ContinueWith(_ => { reborn = true; // 关闭 WebSocket AVWebSocketClient.Disconnect(); }); }; SubscribeNoticeReceived(goAwayListener); reconnectTimes = 0; } }
public QuickOpsForm(SSController controller) { this._controller = controller; router = controller.router; statistics = controller.statistics; FormClosing += QuickOpsForm_FormClosing; InitializeComponent(); statistics.StatusChanged += Statistics_StatusChanged; dataGridView1.DataSource = statistics.Statuses; dataGridView1.CellDoubleClick += DataGridView1_CellDoubleClick; foreach (SingleRoute s in router.GetRouteTable().Routes) { richTextBox1.Text += s.ToString() + "\n"; } }
private void RouterListView_Address_DropDownClosed(object sender, EventArgs e) { DemonSaw.Entity.Entity entity = RouterController.SelectedItem; if (entity == null) { return; } ComboBox control = (ComboBox)sender; ServerComponent server = entity.Get <ServerComponent>(); if (!server.Address.Equals(control.SelectedItem)) { server.Address = (string)control.SelectedItem; RouterController.Restart(entity); } }
private void RouterListView_Enabled_CheckedChanged(object sender, RoutedEventArgs e) { DataGridRow row = WpfUtil.GetGridRow(e.OriginalSource); if (row != null) { DemonSaw.Entity.Entity entity = (DemonSaw.Entity.Entity)row.Item; if (entity != null) { CheckBox control = (CheckBox)sender; bool enabled = (bool)control.IsChecked; ServerComponent server = entity.Get <ServerComponent>(); if (server.Enabled != enabled) { RouterController.Toggle(entity); } } } }
void PrepareReconnect() { AVRealtime.PrintLog("Prepare Reconnect"); Task.Delay(RECONNECT_DELAY).ContinueWith(_ => { // 开启重连 AutoReconnect().ContinueWith(t => { if (t.IsFaulted) { // 重连失败,延迟再次重连 reconnectTimes++; AVRealtime.PrintLog(String.Format("reconnect {0} times", reconnectTimes)); if (reconnectTimes >= RECONNECT_FROM_APP_ROUTER) { // 如果大于当前服务地址的最大重连次数,则清空 Router 后重新重连 RouterController.ClearCache().ContinueWith(__ => { reborn = true; PrepareReconnect(); }); } else if (reconnectTimes >= RECONNECT_USE_SECONDARY_TIMES) { // 如果大于单台 IM 服务器的重连次数,则启用备用服务器 useSecondary = true; PrepareReconnect(); } else { PrepareReconnect(); } } else { // 重连成功 reconnectTimes = 0; reborn = false; useSecondary = false; } }); }); }
/// <summary> /// fetch wss address from push router and open the websocket connection. /// </summary> /// <param name="secure">if use ssl encrept</param> /// <param name="subprotocol">subprotocol</param> /// <param name="cancellationToken"></param> /// <returns></returns> public Task OpenAsync(bool secure = true, string subprotocol = null, CancellationToken cancellationToken = default(CancellationToken)) { if (state == Status.Online) { AVRealtime.PrintLog("state is Status.Online."); return(Task.FromResult(true)); } if (CurrentConfiguration.RealtimeServer != null) { AVRealtime.PrintLog("use configuration websocket url:" + _wss); return(OpenAsync(CurrentConfiguration.RealtimeServer.ToString(), subprotocol, cancellationToken)); } return(RouterController.GetAsync(CurrentConfiguration.PushRouterServer.ToString(), secure, cancellationToken).OnSuccess(_ => { _wss = _.Result.server; state = Status.Connecting; AVRealtime.PrintLog("push router give a url :" + _wss); return OpenAsync(_.Result.server, subprotocol, cancellationToken); }).Unwrap()); }
public void Update() { RouterController.Update(); }
public static void Init() { LogController.Init(); RouterController.Init(); ServerController.Init(); }
public static void Shutdown() { ServerController.Shutdown(); RouterController.Shutdown(); LogController.Shutdown(); }
private void RouterAddCommand_Executed(object sender, ExecutedRoutedEventArgs e) { RouterController.Add(); }
private void Window_Loaded(object sender, RoutedEventArgs e) { DemonSaw.Entity.Entity entity = RouterController.Get(); RouterListView.SelectedItem = entity; RouterController.Select(entity); }
private void RouterRemoveCommand_Executed(object sender, ExecutedRoutedEventArgs e) { RouterController.Remove(RouterController.SelectedItem); ServerController.Clear(); }
private void ReadRouter(XmlReader reader) { if (reader.IsEmptyElement) { return; } bool loop = true; string name = null; // Router Entity entity = new Entity(); ServerComponent server = new ServerComponent(); ServerOptionsComponent options = new ServerOptionsComponent(); ServerListComponent servers = new ServerListComponent(); server.Enabled = bool.Parse(reader.GetAttribute(XmlTag.Enabled)); while (loop && reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: { name = reader.Name; switch (name) { case XmlTag.Servers: { ReadServers(reader, ref servers); break; } case XmlTag.Options: { ReadOptions(reader, ref options); break; } } break; } case XmlNodeType.Text: { switch (name) { case XmlTag.Id: { entity.Id = reader.Value; break; } case XmlTag.Name: { server.Name = reader.Value; break; } case XmlTag.Passphrase: { server.Passphrase = reader.Value; break; } case XmlTag.Address: { server.Address = reader.Value; break; } case XmlTag.Port: { server.Port = int.Parse(reader.Value); break; } } break; } case XmlNodeType.EndElement: { if (XmlTag.Router.Equals(reader.Name)) { loop = false; } break; } } } // Router entity.Add(server); entity.Add(options); entity.Add(servers); ServerStatusComponent status = new ServerStatusComponent(); entity.Add(status); MachineComponent machine = new RouterMachineComponent(); entity.Add(machine); EntityMapComponent entities = new EntityMapComponent(); entity.Add(entities); SessionMapComponent sessions = new SessionMapComponent(); entity.Add(sessions); GroupListMapComponent groups = new GroupListMapComponent(); entity.Add(groups); ClientMapComponent clients = new ClientMapComponent(); entity.Add(clients); TransferMapComponent transfers = new TransferMapComponent(); entity.Add(transfers); #if DEBUG LogComponent log = new LogComponent(LogController); entity.Add(log); #endif RouterController.Add(entity); }
private void RouterUpdateCommand_Executed(object sender, ExecutedRoutedEventArgs e) { RouterController.Update(); }