コード例 #1
0
ファイル: AdbManager.cs プロジェクト: sp0x/ApkLoader
        private void OnDeviceDisconnected(object sender, DeviceDataEventArgs args)
        {
            var dev = args.Device;

            Debug.WriteLine($"Device disconnected {dev.Name}[{dev.Model}/{dev.Serial}]");
            DeviceDisconnected?.Invoke(this, args);
        }
コード例 #2
0
 /// <summary>
 /// Invokes the <see cref="DeviceDisconnected"/> event.
 /// </summary>
 /// <param name="device"></param>
 protected void OnDeviceDisconnected(Device device)
 {
     if (DeviceDisconnected != null)
     {
         DeviceDisconnected.Invoke(device);
     }
 }
コード例 #3
0
 private void DeviceOnDisconnected(DeviceEventArgs args)
 {
     lock (_connectedDevices)
     {
         _connectedDevices.Remove(args.Device);
     }
     DeviceDisconnected?.Invoke(args.Device);
 }
コード例 #4
0
        public void DisconnectDevice(IDevice device)
        {
            connectedDevices.Remove(device);
            var args = new DeviceConnectionEventArgs();

            args.Device = device;
            DeviceDisconnected?.Invoke(this, args);
        }
コード例 #5
0
        private void AxLEDeviceConnectionLost(object sender, IDevice device)
        {
            var serial = _devices.SingleOrDefault(d => d.Value.Id == device.Id).Key;

            if (!string.IsNullOrEmpty(serial))
            {
                DeviceDisconnected?.Invoke(this, serial);
            }
        }
コード例 #6
0
        private void InitSystem()
        {
            Context.System.Scheduler.ScheduleTellRepeatedlyCancelable(1000, 1000, Self, new Evalutate(), ActorRefs.NoSender);

            var gatewaystrepo = repositoryManager.Ask <List <GatewayModel> >(new GetAll()).Result;

            foreach (var gateway in gatewaystrepo)
            {
                var gatewayCreated     = new GatewayCreated(gateway.Id);
                var gatewaySended      = new GatewaySended(gateway.Id, gateway.Value);
                var gatewayStarted     = new GatewayStarted(gateway.Id, gateway.Ip);
                var gatewayUpdate      = new GatewayUpdate(gateway.Id, gateway.Name);
                var gatewayDisconnectd = new GatewayDisconnected(gateway.Id);
                var gatewayStatus      = new GatewayStatus(gateway.Id);

                deviceManager.Tell(gatewayCreated.GatewayPhysicalCreated);
                dashboardManager.Tell(gatewayCreated.GatewayDashBoardCreated);

                deviceManager.Tell(gatewaySended.GatewayPhysicalSended);
                dashboardManager.Tell(gatewaySended.GatewayDashBoardSended);

                dashboardManager.Tell(gatewayStarted.GatewayDashBoardStarted);

                dashboardManager.Tell(gatewayUpdate.GatewayDashBoardUpdate);

                deviceManager.Tell(gatewayDisconnectd.GatewayPhysicalDisconnected);
                dashboardManager.Tell(gatewayDisconnectd.GatewayDashBoardDisconnected);

                deviceManager.Tell(gatewayStatus.GatewayPhysicalStatus);

                foreach (var device in gateway.Devices)
                {
                    var deviceInfo        = new DeviceInfo(device.Id, gateway.Id);
                    var deviceCreated     = new DeviceCreated(deviceInfo);
                    var deviceSended      = new DeviceSended(deviceInfo, device.Value);
                    var deviceStarted     = new DeviceStarted(deviceInfo, device.Ip);
                    var deviceUpdate      = new DeviceUpdate(deviceInfo, device.Name);
                    var deviceDisconnectd = new DeviceDisconnected(deviceInfo);
                    var deviceStatus      = new DeviceStatus(deviceInfo);

                    deviceManager.Tell(deviceCreated.DevicePhysicalCreated);
                    dashboardManager.Tell(deviceCreated.DeviceDashBoardCreated);

                    deviceManager.Tell(deviceSended.DevicePhysicalSended);
                    dashboardManager.Tell(deviceSended.DeviceDashBoardSended);

                    dashboardManager.Tell(deviceStarted.DeviceDashBoardStarted);

                    dashboardManager.Tell(deviceUpdate.DeviceDashBoardUpdate);

                    deviceManager.Tell(deviceDisconnectd.DevicePhysicalDisconnected);
                    dashboardManager.Tell(deviceDisconnectd.DeviceDashBoardDisconnected);

                    deviceManager.Tell(deviceStatus.DevicePhysicalStatus);
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// Callback method that MdsLib calls when a device disconnects from MdsLib
        /// </summary>
        /// <param name="MACaddress"></param>
        public void OnDisconnect(string MACaddress)
        {
            Debug.WriteLine($"SUCCESS MdsConnectionListener OnDisconnect callback called: MACaddress {MACaddress}");
            var uuid   = GetUuidFromMACAddress(MACaddress);
            var serial = string.Empty;

            this.UuidToSerialMapper.TryGetValue(uuid, out serial);
            DeviceDisconnected?.Invoke(this, new MdsConnectionListenerEventArgs(serial, uuid));
        }
コード例 #8
0
 protected void InvokeDeviceDisconnected()
 {
     try
     {
         DeviceDisconnected?.Invoke(this);
     }
     catch (Exception e)
     {
         UPnPConfiguration.LOGGER.Warn("DeviceConnection: Error invoking DeviceDisconnected delegate", e);
     }
 }
コード例 #9
0
ファイル: USBDetector.cs プロジェクト: Shooshp/TailTestPCWPF
 private void DisconnectArrived(object sender, EventArrivedEventArgs e)
 {
     if (IsConnected)
     {
         if (!InitialChek())
         {
             IsConnected = false;
             DeviceDisconnected?.Invoke();
         }
     }
 }
コード例 #10
0
 private void BluetoothDevice_ConnectionStatusChanged(BluetoothDevice sender, object args)
 {
     if (sender.ConnectionStatus == BluetoothConnectionStatus.Disconnected)
     {
         if (connectedDevices.ContainsKey(sender.DeviceId))
         {
             var device = connectedDevices[sender.DeviceId];
             connectedDevices.Remove(device.deviceInfo.Id);
             DeviceDisconnected?.Invoke(device);
         }
     }
 }
コード例 #11
0
ファイル: TCPServer.cs プロジェクト: javirs85/javirsRepo
        public async void OpenServer()
        {
            TokenSource = new CancellationTokenSource();
            IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Parse(Utils.GetLocalIp()), port);

            try
            {
                listener.Bind(localEndPoint);
                listener.Listen(10);
                await Task.Run(() =>
                {
                    try
                    {
                        newDebugMessage(this, $"Server started accepting connections at {Utils.GetLocalIp().ToString()}:{port}");
                        IsRunning = true;
                        while (!TokenSource.Token.IsCancellationRequested)
                        {
                            var handler                 = listener.Accept();
                            var connectedItem           = new TCPConnector(handler);
                            connectedItem.disconnected += (sender, arg) => {
                                var connector = sender as TCPConnector;
                                lock (ConnectedClients)
                                    ConnectedClients.Remove(connector);
                                DeviceDisconnected?.Invoke(this, connector);
                                connector.Dispose();
                            };
                            connectedItem.newError += (sender2, err2) => {
                                this.newError(this, err2);
                            };

                            connectedItem.StartListening();

                            lock (ConnectedClients)
                                ConnectedClients.Add(connectedItem);
                            newDeviceConnected?.Invoke(this, connectedItem);
                        }
                        IsRunning = false;
                    }
                    catch (Exception e)
                    {
                        IsRunning = false;
                        if (!((e as SocketException).NativeErrorCode == 10004)) //error code for "async task canceled"
                        {
                            newError?.Invoke(this, e);
                        }
                    }
                });
            }
            catch (Exception e)
            {
                newError?.Invoke(this, e);
            }
        }
コード例 #12
0
ファイル: Device.cs プロジェクト: RSG-XGame/ScanSystem
 private void Disconnection(bool stopListen = true)
 {
     CheckDisposed();
     DeviceDisconnecting?.Invoke(this);
     Disconnect();
     client?.Close();
     client?.Dispose();
     if (stopListen)
     {
         StopListen();
     }
     DeviceDisconnected?.Invoke(this);
 }
コード例 #13
0
        public BleAdapter(IAdapter adapter)
        {
            _adapter = adapter;

            _adapter.DeviceDiscovered += (sender, args) =>
                                         DeviceDiscovered?.Invoke(sender, BleDevice.Wrap(args.Device));
            _adapter.DeviceConnected += (sender, args) =>
                                        DeviceConnected?.Invoke(sender, args.Adapt <DeviceConnectionEventArgs>());
            _adapter.DeviceDisconnected += (sender, args) =>
                                           DeviceDisconnected?.Invoke(sender, args.Adapt <DeviceConnectionEventArgs>());

            _adapter.ScanTimeoutElapsed += (sender, args) => ScanTimeoutElapsed?.Invoke(sender, args);
        }
コード例 #14
0
ファイル: DeviceController.cs プロジェクト: wearrocena/BleLab
        public void Disconnect()
        {
            if (ConnectedDevice == null)
            {
                return;
            }

            DeviceDisconnecting?.Invoke(this, EventArgs.Empty);

            ConnectedDevice.Dispose();
            ConnectedDevice = null;

            DeviceDisconnected?.Invoke(this, EventArgs.Empty);
        }
コード例 #15
0
ファイル: BthPS3Device.cs プロジェクト: sulidev/Shibari
        private void OnDisconnected()
        {
            if (!Monitor.TryEnter(this))
            {
                return;
            }

            try
            {
                DeviceDisconnected?.Invoke(this, EventArgs.Empty);
            }
            finally
            {
                Monitor.Exit(this);
            }
        }
コード例 #16
0
        private void Watcher_EventArrived(object sender, EventArrivedEventArgs e)
        {
            bool connected = IsDeviceConnected();

            if (!Connected && connected)
            {
                Trace.WriteLine("Device Connected: " + DeviceName);
                Connected = true;
                DeviceConnected?.Invoke(this, null);
            }
            else if (Connected && !connected)
            {
                Trace.WriteLine("Device Disconnected: " + DeviceName);
                Connected = false;
                DeviceDisconnected?.Invoke(this, null);
            }
        }
コード例 #17
0
        private void Heartbeat(object state)
        {

            if (!_socket.Connected && IsConnected)
            {
                DeviceDisconnected?.Invoke();
                IsConnected = false;
            }

            if (!IsConnected)
            {
                // Try reconnect
                try
                {
                    ConnectSocket();
                    DeviceConnected?.Invoke();

                }
                catch (Exception e)
                {
                    IsConnected = false;
                }
            }

            try
            {
                var response = Ping();

                Span<byte> statusSpan = Serialize<DacStatusDto>(response.DacStatus);

                var dacStatus = DacStatus.ParseDacStatus(statusSpan);

                var ack = DacResponse.ParseAckCode(response.Response);     

                StatusUpdated?.Invoke(ack, dacStatus.BufferFullness);
            }
            catch (Exception e)
            {

            }
        }
コード例 #18
0
        /// <summary>
        /// Callback function that MdsLib calls when an exception is thrown during device connection
        /// </summary>
        /// <param name="e"></param>
        public void OnError(Com.Movesense.Mds.MdsException e)
        {
            // Unexpected device disconnections come in here
            if (e.Message.StartsWith("com.polidea.rxandroidble.exceptions.BleDisconnectedException"))
            {
                var    msgParts   = e.Message.Split(" ");
                string MACaddress = msgParts[msgParts.Length - 1];
                var    uuid       = GetUuidFromMACAddress(MACaddress);

                Debug.WriteLine($"DISCONNECT MdsConnectionListener OnError callback called for unintended disconnection: MACaddress {MACaddress}");
                var serial = string.Empty;
                this.UuidToSerialMapper.TryGetValue(uuid, out serial);
                DeviceDisconnected?.Invoke(this, new MdsConnectionListenerEventArgs(serial, uuid));
            }
            else
            {
                // Other unexpected error
                Debug.WriteLine($"ERROR MdsConnectionListener OnError callback called for unexpected error: {e.ToString()}");
                DeviceConnectionError?.Invoke(this, new MdsException("MdsConnectionListener unexpected error", e));
            }
        }
コード例 #19
0
        /// <summary>
        /// Callback method that MdsLib calls when a device connects or disconnects
        /// </summary>
        /// <param name="mdsevent">details of device connection/disconnection</param>
        public void OnDeviceConnectionEvent(MDSEvent mdsevent)
        {
            var method = ((NSString)mdsevent.BodyDictionary.ValueForKey(new NSString("Method")));

            if (method == new NSString("POST"))
            {
                // Device connected
                var bodyDict = (NSDictionary)mdsevent.BodyDictionary.ValueForKey(new NSString("Body"));
                var serial   = ((NSString)bodyDict.ValueForKey(new NSString("Serial"))).ToString();
                var connDict = (NSDictionary)bodyDict.ValueForKey(new NSString("Connection"));
                var uuid     = ((NSString)connDict.ValueForKey(new NSString("UUID"))).ToString();

                var uniqueIDGuid = new Guid(uuid);
                this.UuidToSerialMapper.TryAdd(uniqueIDGuid, serial);

                Debug.WriteLine($"MdsConnectionListener OnDeviceConnectionEvent CONNECTED: Serial {serial}");
                DeviceConnected?.Invoke(this, new MdsConnectionListenerBLEConnectedEventArgs(uuid));
                DeviceConnectionComplete?.Invoke(this, new MdsConnectionListenerEventArgs(serial, uniqueIDGuid));
            }
            else if (method == new NSString("DEL"))
            {
                // Device disconnected
                var bodyDict = (NSDictionary)mdsevent.BodyDictionary.ValueForKey(new NSString("Body"));
                var serial   = ((NSString)bodyDict.ValueForKey(new NSString("Serial"))).ToString();

                // Get the matching Uuid
                var uniqueIDGuid = this.UuidToSerialMapper.First(kv => kv.Value == serial).Key;

                Debug.WriteLine($"MdsConnectionListener OnDeviceConnectionEvent DISCONNECTED: Serial {serial}");
                DeviceDisconnected?.Invoke(this, new MdsConnectionListenerEventArgs(serial, uniqueIDGuid));
            }
            else
            {
                throw new MdsException($"OnDeviceConnectionEvent unexpected method: {method}");
            }
        }
コード例 #20
0
 /// <summary>Raises the <see cref="E:RAPISink.DeviceDisconnected"/> event.</summary>
 public void OnDeviceDisconnected(IRAPIDevice pIDevice)
 {
     DeviceDisconnected?.Invoke(this, new DeviceConnectEventArgs(pIDevice));
 }
コード例 #21
0
ファイル: DeviceManager.cs プロジェクト: fguiet/kQuatreWPF
 private void OnDeviceDisconnectedEvent()
 {
     DeviceDisconnected?.Invoke(this, new EventArgs());
 }
コード例 #22
0
        public async Task CheckForDevicesAsync(CancellationToken cancellationToken = default)
        {
            try
            {
                if (_IsDisposed)
                {
                    return;
                }
                await _ListenSemaphoreSlim.WaitAsync(cancellationToken).ConfigureAwait(false);

                var connectedDeviceDefinitions = (await DeviceFactory.GetConnectedDeviceDefinitionsAsync(cancellationToken).ConfigureAwait(false)).ToList();

                //Iterate through connected devices
                foreach (var connectedDeviceDefinition in connectedDeviceDefinitions)
                {
                    //TODO: What to do if there are multiple?

                    IDevice device = null;
                    if (_CreatedDevicesByDefinition.ContainsKey(connectedDeviceDefinition.DeviceId))
                    {
                        device = _CreatedDevicesByDefinition[connectedDeviceDefinition.DeviceId];
                    }

                    if (device == null)
                    {
                        //Need to use the connected device def here instead of the filter version because the filter version won't have the id or any details
                        device = await DeviceFactory.GetDeviceAsync(connectedDeviceDefinition, cancellationToken).ConfigureAwait(false);

                        if (device == null)
                        {
                            _logger.LogWarning("A connected device with id {deviceId} was detected but the factory didn't create an instance of it. Bad stuff is going to happen now.", connectedDeviceDefinition.DeviceId);
                        }
                        else
                        {
                            _CreatedDevicesByDefinition.Add(connectedDeviceDefinition.DeviceId, device);
                        }
                    }
                    else
                    {
                        if (device.IsInitialized)
                        {
                            continue;
                        }
                    }

                    _logger.LogDebug("Attempting to initialize with DeviceId of {deviceId}", device.DeviceId);

                    //The device is not initialized so initialize it
                    await device.InitializeAsync(cancellationToken).ConfigureAwait(false);

                    //Let listeners know a registered device was initialized
                    DeviceInitialized?.Invoke(this, new DeviceEventArgs(device));

                    _logger.LogDebug(Messages.InformationMessageDeviceConnected, device.DeviceId);
                }

                var removeDeviceIds = new List <string>();

                //Iterate through registered devices
                foreach (var deviceId in _CreatedDevicesByDefinition.Keys)
                {
                    var device = _CreatedDevicesByDefinition[deviceId];

                    if (connectedDeviceDefinitions.Any(cdd => cdd.DeviceId == deviceId))
                    {
                        continue;
                    }

                    if (!device.IsInitialized)
                    {
                        continue;
                    }

                    //Let listeners know a registered device was disconnected
                    //NOTE: let the rest of the app know before disposal so that the app can stop doing whatever it's doing.
                    DeviceDisconnected?.Invoke(this, new DeviceEventArgs(device));

                    //The device is no longer connected so close it
                    device.Close();

                    removeDeviceIds.Add(deviceId);

                    _logger.LogDebug(Messages.InformationMessageDeviceListenerDisconnected);
                }

                foreach (var deviceId in removeDeviceIds)
                {
                    _ = _CreatedDevicesByDefinition.Remove(deviceId);
                }

                _logger.LogDebug(Messages.InformationMessageDeviceListenerPollingComplete);
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                //Log and move on
                _logger.LogError(ex, Messages.ErrorMessagePollingError);

                //TODO: What else to do here?
            }
            finally
            {
                if (!_IsDisposed)
                {
                    _ = _ListenSemaphoreSlim.Release();
                }
            }
        }
コード例 #23
0
 void hidDevice_Removed()
 {
     Device.CloseDevice();
     DeviceDisconnected?.Invoke();
 }
コード例 #24
0
 public override void OnDeviceDisconnected() => DeviceDisconnected?.Invoke();
コード例 #25
0
 protected virtual void OnDeviceDisconnected(BleDeviceEventArgs args)
 {
     DeviceDisconnected?.Invoke(this, args);
 }
コード例 #26
0
ファイル: BLEDevice.cs プロジェクト: poz1/Poz1.BLE
 public void OnDeviceDisconnected()
 {
     DeviceDisconnected?.Invoke(null, null);
 }
コード例 #27
0
        public async Task CheckForDevicesAsync()
        {
            try
            {
                if (_IsDisposed)
                {
                    return;
                }
                await _ListenSemaphoreSlim.WaitAsync();

                var connectedDeviceDefinitions = new List <ConnectedDeviceDefinition>();
                foreach (var deviceDefinition in FilterDeviceDefinitions)
                {
                    connectedDeviceDefinitions.AddRange(await DeviceManager.Current.GetConnectedDeviceDefinitionsAsync(deviceDefinition));
                }

                //Iterate through connected devices
                foreach (var connectedDeviceDefinition in connectedDeviceDefinitions)
                {
                    var deviceDefinition = FilterDeviceDefinitions.FirstOrDefault(d => DeviceManager.IsDefinitionMatch(d, connectedDeviceDefinition));

                    if (deviceDefinition == null)
                    {
                        continue;
                    }

                    //TODO: What to do if there are multiple?

                    IDevice device = null;
                    if (_CreatedDevicesByDefinition.ContainsKey(deviceDefinition))
                    {
                        device = _CreatedDevicesByDefinition[deviceDefinition];
                    }

                    if (device == null)
                    {
                        //Need to use the connected device def here instead of the filter version because the filter version won't have the id or any details
                        device = DeviceManager.Current.GetDevice(connectedDeviceDefinition);
                        _CreatedDevicesByDefinition.Add(deviceDefinition, device);
                    }

                    if (device.IsInitialized)
                    {
                        continue;
                    }

                    Log($"Attempting to initialize with DeviceId of {device.DeviceId}", null);

                    //The device is not initialized so initialize it
                    await device.InitializeAsync();

                    //Let listeners know a registered device was initialized
                    DeviceInitialized?.Invoke(this, new DeviceEventArgs(device));

                    Log(Messages.InformationMessageDeviceConnected, null);
                }

                var removeDefs = new List <FilterDeviceDefinition>();

                //Iterate through registered devices
                foreach (var filteredDeviceDefinitionKey in _CreatedDevicesByDefinition.Keys)
                {
                    var device = _CreatedDevicesByDefinition[filteredDeviceDefinitionKey];

                    if (connectedDeviceDefinitions.Any(cdd =>
                                                       DeviceManager.IsDefinitionMatch(filteredDeviceDefinitionKey, cdd)))
                    {
                        continue;
                    }

                    if (!device.IsInitialized)
                    {
                        continue;
                    }

                    //Let listeners know a registered device was disconnected
                    //NOTE: let the rest of the app know before disposal so that the app can stop doing whatever it's doing.
                    DeviceDisconnected?.Invoke(this, new DeviceEventArgs(device));

                    //The device is no longer connected so close it
                    device.Close();

                    removeDefs.Add(filteredDeviceDefinitionKey);

                    Log(Messages.InformationMessageDeviceListenerDisconnected, null);
                }

                foreach (var removeDef in removeDefs)
                {
                    _CreatedDevicesByDefinition.Remove(removeDef);
                }

                Log(Messages.InformationMessageDeviceListenerPollingComplete, null);
            }
            catch (Exception ex)
            {
                Log(Messages.ErrorMessagePollingError, ex);

                //TODO: What else to do here?
            }
            finally
            {
                if (!_IsDisposed)
                {
                    _ListenSemaphoreSlim.Release();
                }
            }
        }
コード例 #28
0
 protected virtual void OnDeviceDisconnected(IDeviceService device)
 {
     DeviceDisconnected?.Invoke(device);
 }
コード例 #29
0
        void OnUpdate()
        {
            if (m_MessageProvider == null)
            {
                return;
            }

            if (m_MessageProvider.HasExited)
            {
                Stop();
                if (DeviceDisconnected != null)
                {
                    DeviceDisconnected.Invoke(Device.Id);
                }

                return;
            }

            List <LogEntry> entries = new List <LogEntry>();

            lock (m_CachedLogLines)
            {
                if (m_CachedLogLines.Count == 0)
                {
                    return;
                }

                var   needFilterByPid    = !m_Device.SupportsFilteringByPid && PackagePid > 0;
                var   needFilterByTags   = Tags != null && Tags.Length > 0;
                var   needFilterBySearch = !m_Device.SupportsFilteringByRegex && !string.IsNullOrEmpty(Filter);
                Regex regex = LogParseRegex;
                foreach (var logLine in m_CachedLogLines)
                {
                    var m = regex.Match(logLine);
                    if (!m.Success)
                    {
                        // The reason we need to check `needFilterByTags` is we don't really want to show the error logs that we can't parse if a tag is chosen.
                        // For logs we can't parse, please refer to https://gitlab.cds.internal.unity3d.com/upm-packages/mobile/mobile-android-logcat/issues/44
                        // And we should remove this check once #44 is fixed completely.
                        if (!needFilterByTags)
                        {
                            entries.Add(LogEntryParserErrorFor(logLine));
                        }
                        continue;
                    }

                    if (needFilterByPid && Int32.Parse(m.Groups["pid"].Value) != PackagePid)
                    {
                        continue;
                    }

                    if (needFilterByTags && !MatchTagsFilter(m.Groups["tag"].Value))
                    {
                        continue;
                    }

                    if (needFilterBySearch && !MatchSearchFilter(m.Groups["msg"].Value))
                    {
                        continue;
                    }

                    entries.Add(ParseLogEntry(m));
                }
                m_CachedLogLines.Clear();
            }

            if (entries.Count == 0)
            {
                return;
            }

            ResolveStackTrace(entries);
            LogEntriesAdded(entries);
        }
コード例 #30
0
 private void OnDeviceDisconnected(IDevice device)
 {
     CurConnectDeves.Remove(device);
     DeviceDisconnected?.Invoke(device);
 }