Beispiel #1
0
        public override bool Stop()
        {
            if (!IsActive)
            {
                return(base.Stop());
            }

            _state = DsState.Reserved;

            // disconnect all connected devices gracefully
            foreach (var device in _connected.Values)
            {
                device.Disconnect();
                device.Stop();
            }

            // notify tasks to stop work
            _hciCancellationTokenSource.Cancel();
            _l2CapCancellationTokenSource.Cancel();
            // reset tokens
            _hciCancellationTokenSource   = new CancellationTokenSource();
            _l2CapCancellationTokenSource = new CancellationTokenSource();

            _connected.Clear();

            return(base.Stop());
        }
Beispiel #2
0
 /// <summary>
 /// 刷新数据库连接
 /// </summary>
 /// <param name="connS"></param>
 /// <param name="poolSize"></param>
 public void Refresh(List <ConnectionStringConfiguration> connS, int poolSize = 32)
 {
     using (easyLock.Write())
     {
         NpgsqlConnection.ClearAllPools();
         ConnectionList?.Clear();
         ConnectionList = connS;
     }
 }
        public override Boolean Stop()
        {
            if (IsActive)
            {
                m_State = DeviceState.Reserved;

                foreach (BthDs3 Device in m_Connected.Values)
                {
                    Device.Disconnect();
                    Device.Stop();
                }

                HCI_Reset(); Thread.Sleep(250);

                m_Connected.Clear();
            }

            return(base.Stop());
        }
 /**
  * リストの切断
  * @param index		切断したい要素のインデックス。-1の場合は全て切断する
  */
 public void Disconnection(int index = -1)
 {
     if (index >= 0)
     {
         ConnectionList.RemoveAt(index);
     }
     else
     {
         ConnectionList.Clear();
     }
 }
Beispiel #5
0
 public void UpdateConnectionList()
 {
     if (Server == null)
     {
         return;
     }
     ConnectionList.Clear();
     Server.ConnectionInfos.ForEach((c) =>
     {
         ListViewItem item = new ListViewItem(new [] { c.ID.ToString(), c.User, c.UserGroup, c.IP, c.CurrentPosition, c.CurrentFile, c.LastCommand });
         ConnectionList.Add(item);
     });
 }
Beispiel #6
0
 /// <summary>
 /// Kills all alive connections
 /// </summary>
 public void KillAllConnections()
 {
     try
     {
         foreach (var conn in ConnectionList)
         {
             if (conn.Value.ConnectionSocket.Connected)
             {
                 conn.Value.Close();
             }
         }
         ConnectionList.Clear();
         InvokeUI.UpdateConnectionsCount(ConnectionList.Count);
     }
     catch (Exception Ex)
     {
         if (WriteDebugLogs)
         {
             Logs.WriteLog("red", Ex.Message);
         }
     }
 }
        public void Load(WorkAreaSerialization ser)
        {
            #region Clear

            ConnectionList.Clear();
            GateList.Clear();

            InputPins.Clear();
            OutputPins.Clear();

            SelectedInputPin  = null;
            SelectedOutputPin = null;

            #endregion

            foreach (WorkAreaSerialization.GateModelWithCoordinates g in ser.GateList)
            {
                AddGate(new GateViewModelWithCoordinates(new GateViewModel(g.gate), g.X, g.Y));
            }

            GatesLoaded();

            RestoreConnections();
        }
Beispiel #8
0
 public void Clear()
 {
     Connections.Clear();
     ConnectionList.Clear();
     outLookup.Clear();
 }
Beispiel #9
0
        void Listen(int port = 9600, string ip = "127.0.0.1")
        {
            Ip      = ip;
            Port    = port;
            _server = new SocketServer(Ip, Port);

            //处理从客户端收到的消息
            _server.HandleRecMsg = new Action <byte[], SocketConnection, SocketServer>((bytes, client, theServer) =>
            {
                string msg = Encoding.UTF8.GetString(bytes);
                System.Diagnostics.Debug.WriteLine($"MyServer | {client.RemoteEndPoint.ToString()}=>:{msg}");
            });

            //处理服务器启动后事件
            _server.HandleServerStarted = new Action <SocketServer>(theServer =>
            {
                System.Diagnostics.Debug.WriteLine("MyServer | 服务已启动");
            });

            //处理新的客户端连接后的事件
            _server.HandleNewClientConnected = new Action <SocketServer, SocketConnection>((theServer, theCon) =>
            {
                System.Diagnostics.Debug.WriteLine($@"MyServer | 一个新的客户端接入,当前连接数:{theServer.GetConnectionCount()}");
                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle, new Action(() =>
                {
                    //ConnectionList.Add(theCon.RemoteEndPoint.ToString());
                    ConnectionList.Clear();
                    foreach (var node in _server.GetRemoteEndPointList())
                    {
                        ConnectionList.Add(node.ToString());
                    }
                }));
            });

            //处理客户端连接关闭后的事件
            _server.HandleClientClose = new Action <SocketConnection, SocketServer>((theCon, theServer) =>
            {
                System.Diagnostics.Debug.WriteLine($@"MyServer | 一个客户端关闭,当前连接数为:{theServer.GetConnectionCount()}");
                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle, new Action(() =>
                {
                    ConnectionList.Clear();
                    if (_server.GetConnectionCount() < 1)
                    {
                        return;
                    }
                    foreach (var node in _server.GetRemoteEndPointList())
                    {
                        ConnectionList.Add(node.ToString());
                    }
                }));
            });

            //处理异常
            _server.HandleException = new Action <Exception>(ex =>
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            });

            //服务器启动
            _server.StartServer();
        }