Пример #1
0
 void IObservable <ListenerStartedArgs> .Notify(ListenerStartedArgs eventArgs)
 {
     if (ListenerStarted != null)
     {
         ListenerStarted.Invoke(this, eventArgs);
     }
 }
Пример #2
0
        public void StartListening()
        {
            // Retrieve the device list
            try
            {
                var devices = CaptureDeviceList.Instance;
                if (devices.Count < 1)
                {
                    throw new PcapMissingException("No interfaces found! Make sure WinPcap is installed.");
                }
                foreach (var device in devices)
                {
                    if (device == null)
                    {
                        continue;
                    }
                    device.OnPacketArrival += delegate(object sender, CaptureEventArgs e)
                    {
                        var packet  = Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data);
                        var eth     = (EthernetPacket)packet;
                        var dashMac = eth.SourceHwAddress.ToString();
                        if (dashMac.Equals(device.MacAddress.ToString()))
                        {
                            //ignore packets from our own device
                            return;
                        }
                        var dashId = dashMac.GetHashCode();

                        DashButtonProbed?.Invoke(this,
                                                 new DashResponse
                        {
                            DashMac = dashMac,
                            DashId  = dashId,
                            Device  = device.MacAddress.ToString()
                        });
                    };
                    device.Open(DeviceMode.Promiscuous, ReadTimeoutMilliseconds);
                    // tcpdump filter to capture only ARP Packets
                    device.Filter = "arp";
                    Action action = device.Capture;
                    action.BeginInvoke(ar => action.EndInvoke(ar), null);
                    ListenerStarted?.Invoke(this,
                                            new DashListenerResponse
                    {
                        Started = true,
                        Message = $"Started listenr on {device.MacAddress}"
                    });
                }
            }
            catch (Exception)
            {
                throw new PcapMissingException("No interfaces found! Make sure WinPcap is installed.");
            }
        }
Пример #3
0
 public DefaultFtpListenerService(
     IOptions <FtpServerOptions> serverOptions,
     ILogger <DefaultFtpListenerService>?logger = null)
 {
     _listenerService = new FtpServerListenerService(
         _channels.Writer,
         serverOptions,
         _serverShutdown,
         logger);
     _listenerService.ListenerStarted += (sender, args) => ListenerStarted?.Invoke(sender, args);
 }
Пример #4
0
        /// <summary>
        /// Starts the Server <see cref="Listener"/> and <see cref="Router"/>
        /// </summary>
        /// <param name="cancellationToken">The Cancellation Task</param>
        /// <returns>An awaitable task with the Start</returns>
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            // Validate Variables before starting the service

            // Initializes the Listener and hook events
            this.Listener = new Listener(this.ServerName, this.Ports, this.RequiresAuthentication, this.UseSSL);
            this.Listener.MessageReceived += Listener_MessageReceived;
            ListenerStarted?.Invoke(this, new EventArgs());

            // Initializes the Router and hook events
            this.Router = new Router(this.QueueName, this.QueuePath)
            {
                RoutingRules         = this.RoutingRules,
                DestinationSmtps     = this.DestinationSmtps,
                MessageLifespan      = this.MessageLifespan,
                MessagePurgeLifespan = this.MessagePurgeLifespan
            };
            RouterStarted?.Invoke(this, new EventArgs());

            // Start the Service
            await Task.WhenAll(this.Listener.StartAsync(cancellationToken),
                               this.Router.StartAsync(cancellationToken)).ConfigureAwait(false);
        }
Пример #5
0
        public void StartListening(string ipAddress, int port)
        {
            if (port <= 0)
            {
                throw new ArgumentException("Please provide a valid port value");
            }

            OscServerPort = port;

            if (string.IsNullOrEmpty(ipAddress))
            {
                throw new ArgumentNullException(nameof(ipAddress));
            }
            //Try to parse the ip
            var ipToListen = IPAddress.Parse(ipAddress);

            OscServerIp = ipAddress;

            //If we are already listening we restart the listener
            if (_oscReveiver?.State == OscSocketState.Connected)
            {
                StopListening();
                StartListening(ipAddress, port);
                return;
            }
            _cancelationTokenSource = new CancellationTokenSource();
            _packetAlreadyNotified.Clear();
            //Starting a thread  to listen message
            Task.Factory.StartNew(() => {
                ListenToMessage(ipToListen, port, _cancelationTokenSource.Token);
            },
                                  _cancelationTokenSource.Token,
                                  TaskCreationOptions.LongRunning, TaskScheduler.Default);

            ListenerStarted?.Invoke(this, EventArgs.Empty);
        }
Пример #6
0
 private void OnListenerStarted(ListenerStartedEventArgs e)
 {
     ListenerStarted?.Invoke(this, e);
 }
Пример #7
0
 private void OnListenerStarted(ListenerStarted data)
 {
     Notifications.Enqueue(new ListenerStartedNotification(Localhost, data.Port));
     Settings.ListenerPort = data.Port;
 }