public NetworkInterfaceHandler(ServiceBrowser serviceBrowser, NetworkInterface networkInterface)
 {
     ServiceBrowser = serviceBrowser;
     NetworkInterface = networkInterface;
     _index = NetworkInterface.Information.GetIPProperties().GetIPv4Properties().Index;
     _queryTimer = new Timer(OnQueryTimerElapsed);
 }
 public NetworkInterfaceHandler(ServiceBrowser serviceBrowser, NetworkInterface networkInterface)
 {
     ServiceBrowser   = serviceBrowser;
     NetworkInterface = networkInterface;
     _index           = NetworkInterface.Information.GetIPProperties().GetIPv4Properties().Index;
     _queryTimer      = new Timer(OnQueryTimerElapsed);
 }
 public Network()
 {
     _serviceBrowser = new ServiceBrowser();
     _serviceBrowser.ServiceAdded += OnServiceAdded;
     _serviceBrowser.ServiceRemoved += OnServiceRemoved;
     _serviceBrowser.ServiceChanged += OnServiceChanged;
 }
Exemple #4
0
        public AmbiBeam()
        {
            _config = Properties.Settings.Default["Setting"] as Config;
            if (_config == null)
                _config = new Config();
            
            var trayMenu = new ContextMenu();
            trayMenu.MenuItems.Add("Start/Stop", OnStartStop);
            trayMenu.MenuItems.Add("Configure", OnConfigure);
            trayMenu.MenuItems.Add("Test", OnTest);
            trayMenu.MenuItems.Add("Exit", OnExit);

            _trayIcon = new NotifyIcon
            {
                Text = "AmbiBeam",
                Icon = Properties.Resources.Color,
                ContextMenu = trayMenu,
                Visible = true
            };

            _timer = new System.Timers.Timer
            {
                AutoReset = true,
                Interval = 50
            };

            _mDnsBrowser = new ServiceBrowser();
            _mDnsBrowser.StartBrowse("_ambibeam._udp");
            

        }
Exemple #5
0
        static void Main(string[] args)
        {
            string serviceType = "_workstation._tcp";
            if (args.Length >= 1)
            {
                serviceType = args[0];
            }

            ServiceBrowser serviceBrowser = new ServiceBrowser();
            serviceBrowser.ServiceAdded += onServiceAdded;
            serviceBrowser.StartBrowse(serviceType);
            Thread.Sleep(1000);
        }
Exemple #6
0
        public NetworkInterfaceHandler(ServiceBrowser serviceBrowser, NetworkInterface networkInterface)
        {
            ServiceBrowser   = serviceBrowser;
            NetworkInterface = networkInterface;
            _index           = NetworkInterface.GetIPProperties().GetIPv4Properties().Index;
#if NETSTANDARD1_3
            _queryTimer       = new Timer(OnQueryTimerElapsed, null, Timeout.Infinite, Timeout.Infinite);
            _receiveEventArgs = new SocketAsyncEventArgs();
            _receiveEventArgs.SetBuffer(_buffer, 0, _buffer.Length);
            _receiveEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(OnReceive);
#else
            _queryTimer = new Timer(OnQueryTimerElapsed);
#endif
        }
Exemple #7
0
        private void RemoveService(Name name)
        {
            ServiceInfo service;

            _serviceInfos.TryGetValue(name, out service);
            if (service != null)
            {
                _serviceInfos.Remove(name);
                _serviceHandlers[name.SubName(1)].ServiceInfos.Remove(service);
                if (service.IsComplete)
                {
                    ServiceBrowser.OnServiceRemoved(service);
                }
                if (service.HostName != null)
                {
                    ClearServiceHostInfo(service);
                }
            }
        }
        public Configure(ServiceBrowser serviceBrowser)
        {
            InitializeComponent();
            Icon = Properties.Resources.Color;

            cbNode.Items.AddRange(SerialPort.GetPortNames());

            ServiceBrowser = serviceBrowser;
           
            if (ServiceBrowser != null)
            {
                foreach (var item in ServiceBrowser.Services)
                {
                    cbNode.Items.Add(item.Hostname);
                }
                // in case we get more
                ServiceBrowser.ServiceAdded += BrowserOnServiceAdded;
            }
            



            cbNode.TextChanged += cbSerialPort_SelectedIndexChanged;
            
            foreach (Screen screen in Screen.AllScreens)
            {
                cbScreen.Items.Add(screen.DeviceName);
            }
            cbScreen.SelectedIndexChanged += CbScreenOnSelectedIndexChanged;

            numOffsetTop.ValueChanged += NumOffsetTopOnValueChanged;
            numOffsetBottom.ValueChanged += NumOffsetBottomOnValueChanged;
            numOffsetLeft.ValueChanged += NumOffsetLeftOnValueChanged;
            numOffsetRight.ValueChanged += NumOffsetRightOnValueChanged;
            numMarginTop.ValueChanged += NumMarginTopOnValueChanged;
            numMarginBottom.ValueChanged += NumMarginBottomOnValueChanged;
            numMarginLeft.ValueChanged += NumMarginLeftOnValueChanged;
            numMarginRight.ValueChanged += NumMarginRightOnValueChanged;
            numLEDWidth.ValueChanged += NumLedWidthOnValueChanged;
            numLEDHeight.ValueChanged += NumLedHeightOnValueChanged;
            tbBrightness.ValueChanged += TbBrightnessOnValueChanged;

        }
Exemple #9
0
        public void Disable()
        {
            if (!_isEnabled)
            {
                return;
            }

            lock (this)
            {
                _isEnabled = false;

                StopQuery();

                foreach (var serviceHandlerKV in _serviceHandlers)
                {
                    ServiceHandler serviceHandler = serviceHandlerKV.Value;
                    serviceHandler.ServiceInfos.Clear();
                }

                ((IDisposable)_socket).Dispose(); // .NET 3.5 Dispose is protected
                _socket = null;

                foreach (var serviceKV in _serviceInfos)
                {
                    ServiceInfo service = serviceKV.Value;

                    if (service.IsComplete)
                    {
                        ServiceBrowser.OnServiceRemoved(service);
                    }
                }

                _serviceInfos.Clear();
                _hostInfos.Clear();
            }
        }
Exemple #10
0
        private void HandlePacketServiceInfos()
        {
            foreach (var serviceKV in _packetServiceInfos)
            {
                Name        packetName    = serviceKV.Key;
                ServiceInfo packetService = serviceKV.Value;

                if (packetService == null)
                {
                    RemoveService(packetName);
                }
                else
                {
                    bool modified    = false;
                    bool wasComplete = false;

                    ServiceInfo service;
                    _serviceInfos.TryGetValue(packetName, out service);

                    if (service == null)
                    {
                        service = packetService;
                        _serviceInfos.Add(packetName, service);
                        _serviceHandlers[packetName.SubName(1)].ServiceInfos.Add(service);

                        if (service.HostName != null)
                        {
                            AddServiceHostInfo(service);
                        }

                        modified = true;
                    }
                    else
                    {
                        service.OpenQueryCount = 0;
                        wasComplete            = service.IsComplete;

                        if (packetService.Port != -1 && service.Port != packetService.Port)
                        {
                            service.Port = packetService.Port;
                            modified     = true;
                        }
                        if (packetService.Name.ToString() != service.Name.ToString())
                        {
                            service.Name = packetService.Name;
                            modified     = true;
                        }
                        if (packetService.Txt != null && (service.Txt == null || !packetService.Txt.SequenceEqual(service.Txt)))
                        {
                            service.Txt = packetService.Txt;
                            modified    = true;
                        }
                        if (packetService.HostName != null && (service.HostName == null || service.HostName.ToString() != packetService.HostName.ToString()))
                        {
                            if (service.HostName != null)
                            {
                                ClearServiceHostInfo(service);
                            }

                            service.HostName = packetService.HostName;
                            AddServiceHostInfo(service);
                            modified = true;
                        }
                        if (packetService.Addresses != null)
                        {
                            service.Addresses = packetService.Addresses;
                            modified          = true;
                        }
                    }

                    if (modified)
                    {
                        if (wasComplete != service.IsComplete)
                        {
                            if (wasComplete)
                            {
                                ServiceBrowser.OnServiceRemoved(service);
                            }
                            else
                            {
                                ServiceBrowser.OnServiceAdded(service);
                            }
                        }
                        else if (service.IsComplete)
                        {
                            ServiceBrowser.OnServiceChanged(service);
                        }
                    }
                }
            }
        }