Exemplo n.º 1
0
    private static void OnServiceResolved(object o, ServiceResolvedEventArgs args)
    {
        IResolvableService service = o as IResolvableService;

        Console.Write("*** Resolved name = '{0}', port = '{1}', interface = '{2}'",
                      service.FullName, service.Port, service.NetworkInterface);
        foreach (System.Net.IPAddress j in service.HostEntry.AddressList)
        {
            Console.Write("host = '{0}'", j);
        }

        ITxtRecord record       = service.TxtRecord;
        int        record_count = record != null ? record.Count : 0;

        if (record_count > 0)
        {
            Console.Write(", TXT Record = [");
            for (int i = 0, n = record.Count; i < n; i++)
            {
                TxtRecordItem item = record.GetItemAt(i);
                Console.Write("{0} = '{1}'", item.Key, item.ValueString);
                if (i < n - 1)
                {
                    Console.Write(", ");
                }
            }
            Console.WriteLine("]");
        }
        else
        {
            Console.WriteLine("");
        }
    }
Exemplo n.º 2
0
        void service_Resolved(object o, ServiceResolvedEventArgs args)

        {
            IResolvableService service = args.Service;

            service.Resolved -= new ServiceResolvedEventHandler(service_Resolved);



            DestinationPlatformType fcPlatform = KnownDestinationPlatformType.Other;

            if (service.TxtRecord != null)

            {
                foreach (TxtRecordItem record in service.TxtRecord)

                {
                    if (record.Key == "platform")

                    {
                        string platform = record.ValueString;

                        fcPlatform = KnownDestinationPlatformType.FromString(platform);

                        break;
                    }
                }
            }

            BonjourEventArgs e = new BonjourEventArgs(fcPlatform);



            this.OnServiceFound(service, e);
        }
Exemplo n.º 3
0
        public DetectedService(IResolvableService service, DestinationPlatformType platform)

        {
            this.service = service;

            this.platform = platform;
        }
        protected override void Initialize()
        {
            browser = new ServiceBrowser();
            browser.ServiceAdded += delegate(object o, ServiceBrowseEventArgs args)
            {
                Console.WriteLine("Found Service: {0}", args.Service.Name);
                args.Service.Resolved += delegate(object o2, ServiceResolvedEventArgs args2)
                {
                    lock (resolveLock)
                    {
                        IResolvableService s = (IResolvableService)args2.Service;

                        ServiceLocation loc = new ServiceLocation(s.HostEntry.AddressList[0], s.Port, s.FullName);
                        Logger.Info("A new ethernet interface was found");
                        SmartScopeInterfaceEthernet ethif = new SmartScopeInterfaceEthernet(loc.ip, loc.port, OnInterfaceDisconnect);
                        if (ethif.Connected)
                        {
                            createdInterfaces.Add(loc, ethif);
                            if (onConnect != null)
                            {
                                onConnect(ethif, true);
                            }
                        }
                        else
                        {
                            Logger.Info("... but could not connect to ethernet interface");
                        }
                    }
                };
                args.Service.Resolve();
            };

            browser.Browse(Net.Net.SERVICE_TYPE, Net.Net.REPLY_DOMAIN);
        }
        public void Update(IResolvableService service, BonjourEventArgs args)

        {
            if (service != null && service.HostEntry != null)

            {
                string host = DetectedService.GetHostname(service);

                int port = (int)service.Port;



                this.Description = service.Name;

                this.IPAddress = host;

                this.Port = port;

                this.Platform = args.Platform;

                this.Available = true;

                this.resolved = true;
            }
        }
Exemplo n.º 6
0
        public static string GetHostname(IResolvableService service)
        {
            string hostname = null;

            if (service != null)
            {
                hostname = service.HostTarget;

                if (String.IsNullOrEmpty(hostname))
                {
                    if (service.HostEntry != null)
                    {
                        hostname = service.HostEntry.HostName;

                        if (String.IsNullOrEmpty(hostname))
                        {
                            if (service.HostEntry.AddressList != null && service.HostEntry.AddressList.Length > 0)
                            {
                                hostname = service.HostEntry.AddressList[0].ToString();
                            }
                        }
                    }
                }
            }

            return(hostname);
        }
Exemplo n.º 7
0
        private static void OnServiceResolved(object o, ServiceResolvedEventArgs args)
        {
            IResolvableService service = o as IResolvableService;

            string ip     = service.HostEntry.AddressList[0].ToString();
            string serial = "";

            ITxtRecord record       = service.TxtRecord;
            int        record_count = record != null ? record.Count : 0;

            if (record_count > 0)
            {
                for (int i = 0, n = record.Count; i < n; i++)
                {
                    TxtRecordItem item = record.GetItemAt(i);
                    if (item.Key == "device")
                    {
                        serial = item.ValueString;
                        Regex regexASNSerial = new Regex(@"AS\w{8}");
                        Match match;

                        match = regexASNSerial.Match(serial);

                        if (match.Success)
                        {
                            name2Serial.Add(args.Service.Name, serial);
                            serial2IP.Add(serial, ip);
                            Console.WriteLine("Found Aroma Shooter: serial = {0}, IP = {1}.", serial, ip);
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
    private static void OnServiceResolved(object o, ServiceResolvedEventArgs args)
    {
        IResolvableService service = o as IResolvableService;

        Console.Write("*** Resolved name = '{0}', host ip = '{1}', hostname = {2}, port = '{3}', " +
                      "interface = '{4}', address type = '{5}'",
                      service.FullName, service.HostEntry.AddressList[0], service.HostEntry.HostName, service.Port,
                      service.NetworkInterface, service.AddressProtocol);

        ITxtRecord record       = service.TxtRecord;
        int        record_count = record != null ? record.Count : 0;

        if (record_count > 0)
        {
            Console.Write(", TXT Record = [");
            for (int i = 0, n = record.Count; i < n; i++)
            {
                TxtRecordItem item = record.GetItemAt(i);
                Console.Write("{0} = '{1}'", item.Key, item.ValueString);
                if (i < n - 1)
                {
                    Console.Write(", ");
                }
            }
            Console.WriteLine("]");
        }
        else
        {
            Console.WriteLine("");
        }
    }
Exemplo n.º 9
0
        void serviceBrowser_ServiceAdded(object o, ServiceBrowseEventArgs args)

        {
            IResolvableService service = args.Service;

            Utility.WriteDebugInfo(String.Format("Bonjour service detected: {0}", service.Name));



            // check if we simply found ourself or another service

            bool isSelf = IsOwnInstance(service);

            if (!isSelf)

            {
                Utility.WriteDebugInfo(String.Format("Bonjour Growl service detected: {0}", service.Name));



                service.Resolved += new ServiceResolvedEventHandler(service_Resolved);

                service.Resolve();
            }
        }
Exemplo n.º 10
0
        public static string GetHostname(IResolvableService service)
        {
            string hostname = null;

            if (service != null)
            {
                hostname = service.HostTarget;

                if (String.IsNullOrEmpty(hostname))
                {
                    if (service.HostEntry != null)
                    {
                        hostname = service.HostEntry.HostName;

                        if (String.IsNullOrEmpty(hostname))
                        {
                            if (service.HostEntry.AddressList != null && service.HostEntry.AddressList.Length > 0)
                            {
                                hostname = service.HostEntry.AddressList[0].ToString();
                            }
                        }
                    }
                }
            }

            return hostname;
        }
Exemplo n.º 11
0
 protected void OnServiceRemoved(IResolvableService service)
 {
     servicesFound.Remove(service.Name);
     if (this.ServiceRemoved != null)
     {
         this.ServiceRemoved(this, service);
     }
 }
Exemplo n.º 12
0
        void AddFoundServiceFromScResolvedData(IResolvableService metaData)
        {
            var sst = new ServiceInfo(metaData.TxtRecord["name"].ValueString, metaData.TxtRecord["loc"].ValueString,
                                      metaData.TxtRecord["addr"].ValueString, metaData.TxtRecord["code"].ValueString);

            ActivityServices.Add(sst);
            OnDiscoveryAddressAdded(new DiscoveryAddressAddedEventArgs(sst));
        }
Exemplo n.º 13
0
        void serviceBrowser_ServiceRemoved(object o, ServiceBrowseEventArgs args)
        {
            IResolvableService service = args.Service;

            Utility.WriteDebugInfo("Bonjour service removed: {0}", service.Name);

            service.Resolved -= service_Resolved;

            this.OnServiceRemoved(args.Service);
        }
Exemplo n.º 14
0
 private static bool IsOwnInstance(IResolvableService service)
 {
     if (service.Name == Growl.Daemon.GrowlServer.BonjourServiceName)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 15
0
 protected void OnServiceFound(IResolvableService service, BonjourEventArgs args)
 {
     if (!servicesFound.ContainsKey(service.Name))
     {
         DetectedService ds = new DetectedService(service, args.Platform);
         servicesFound.Add(service.Name, ds);
     }
     if (this.ServiceFound != null)
     {
         this.ServiceFound(this, service, args);
     }
 }
Exemplo n.º 16
0
        private void OnServiceResolved(object o, ServiceResolvedEventArgs args)
        {
            IResolvableService service = o as IResolvableService;

            if (service == null)
            {
                return;
            }

            Log.DebugFormat("Resolved RAOP service at {0}", service.HostEntry.AddressList[0]);

            ITxtRecord record = service.TxtRecord;

            string version = String.Empty;
            int    sample_size = 16, sample_rate = 44100, channels = 2;

            for (int i = 0, n = record.Count; i < n; i++)
            {
                TxtRecordItem item = record.GetItemAt(i);
                switch (item.Key)
                {
                case "vs":
                    version = item.ValueString;
                    break;

                case "ss":
                    sample_size = Convert.ToInt32(item.ValueString);
                    break;

                case "sr":
                    sample_rate = Convert.ToInt32(item.ValueString);
                    break;

                case "ch":
                    channels = Convert.ToInt32(item.ValueString);
                    break;
                }
            }

            lock (speakers) {
                // TODO: better Name
                speakers.Add(new RemoteSpeaker(service.HostEntry.HostName,
                                               service.HostEntry.AddressList[0], service.Port,
                                               version, sample_rate, sample_size, channels));
            }

            EventHandler handler = SpeakersChanged;

            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }
        }
Exemplo n.º 17
0
        private void OnServiceResolved(object o, ServiceResolvedEventArgs args)
        {
            IResolvableService service = o as IResolvableService;

            lock (locker) {
                if (services.ContainsKey(service.Name))
                {
                    // TODO: When making changes (like name or photo) at runtime becomes possible
                    // this should allow updates to this info
                    return;                     // we already have it somehow
                }
            }

            ServiceInfo serviceInfo = new ServiceInfo(service.Name, service.HostEntry.AddressList[0], (ushort)service.Port);

            ITxtRecord record = service.TxtRecord;

            serviceInfo.UserName      = record["User Name"].ValueString;
            serviceInfo.MachineName   = record["Machine Name"].ValueString;
            serviceInfo.Version       = record["Version"].ValueString;
            serviceInfo.PhotoType     = record["PhotoType"].ValueString;
            serviceInfo.PhotoLocation = record["Photo"].ValueString;

            Logger.Debug("Setting default photo");
            serviceInfo.Photo = Utilities.GetIcon("blankphoto", 48);

            lock (locker) {
                services[serviceInfo.Name] = serviceInfo;

                if (serviceInfo.PhotoType.CompareTo(Preferences.Local) == 0 ||
                    serviceInfo.PhotoType.CompareTo(Preferences.Gravatar) == 0 ||
                    serviceInfo.PhotoType.CompareTo(Preferences.Uri) == 0)
                {
                    // Queue the resolution of the photo
                    PhotoService.QueueResolve(serviceInfo);
                }
            }

            if (ServiceAdded != null)
            {
                Logger.Debug("About to call ServiceAdded");
                ServiceAdded(this, new ServiceArgs(serviceInfo));
                Logger.Debug("ServiceAdded was just called");
            }
            else
            {
                Logger.Debug("ServiceAdded was null and not called");
            }
        }
Exemplo n.º 18
0
 void dnsSD_ServiceAdded(object o, ServiceBrowseEventArgs args)
 {
     args.Service.Resolved += delegate(object sender, ServiceResolvedEventArgs e)
     {
         IResolvableService s = (IResolvableService)e.Service;
         foreach (IPAddress address in s.HostEntry.AddressList)
         {
             RdmEndPoint controlEndpoint = new RdmEndPoint(new IPEndPoint(address, RdmNetSocket.RdmNetPort), 0)
             {
                 Id = UId.ParseUrl(s.TxtRecord["id"].ValueString)
             };
             ControlEndpoints.Add(controlEndpoint);
             DiscoverEndpoints(controlEndpoint);
         }
     };
     args.Service.Resolve();
 }
Exemplo n.º 19
0
        private void OnServiceResolved(object o, ServiceResolvedEventArgs args)
        {
            IResolvableService s = (IResolvableService)args.Service;

            string name       = s.Name;
            string machine_id = null;
            bool   pwRequired = false;

            Console.WriteLine("Resolved Service: {0} - {1}:{2} ({3} TXT record entries)",
                              s.FullName, s.HostEntry.AddressList [0], s.Port, s.TxtRecord.Count);

            if (name.EndsWith("_PW"))
            {
                name       = name.Substring(0, name.Length - 3);
                pwRequired = true;
            }

            foreach (TxtRecordItem item in s.TxtRecord)
            {
                if (item.Key.ToLower() == "password")
                {
                    pwRequired = item.ValueString.ToLower() == "true";
                }
                else if (item.Key.ToLower() == "machine name")
                {
                    name = item.ValueString;
                }
                else if (item.Key.ToLower() == "machine id")
                {
                    machine_id = item.ValueString;
                }
            }

            DPAP.Service svc = new DPAP.Service(s.HostEntry.AddressList [0], (ushort)s.Port,
                                                name, pwRequired, machine_id);

            services [svc.Name] = svc;

            if (Found != null)
            {
                Found(this, new ServiceArgs(svc));
            }
        }
Exemplo n.º 20
0
        private void OnServiceResolved(object o, ServiceResolvedEventArgs args)
        {
            string             path    = "";
            IResolvableService service = o as IResolvableService;
            ITxtRecord         record  = service.TxtRecord;
            int record_count           = record != null ? record.Count : 0;

            if (record_count > 0)
            {
                for (int i = 0, n = record.Count; i < n; i++)
                {
                    TxtRecordItem item = record.GetItemAt(i);
                    if (item.Key.CompareTo("path") == 0)
                    {
                        path = item.ValueString;
                    }
                }
            }
            url = "http://" + service.HostEntry.AddressList[0] + ":" + service.Port + "/" + path;
            register();
        }
 public ServiceBrowseEventArgs(IResolvableService service)
 {
     this.service = service;
 }
Exemplo n.º 22
0
 protected void OnServiceRemoved(IResolvableService service)
 {
     servicesFound.Remove(service.Name);
     if (this.ServiceRemoved != null)
     {
         this.ServiceRemoved(this, service);
     }
 }
 public ServiceBrowseEventArgs(IResolvableService service)
 {
     this.service = service;
 }
Exemplo n.º 24
0
 private BonjourForwardDestination MatchBonjourServiceToForwardDestination(IResolvableService service)
 {
     if (this.forwards.ContainsKey(service.Name))
     {
         ForwardDestination fc = this.forwards[service.Name];
         BonjourForwardDestination bfc = fc as BonjourForwardDestination;
         if (bfc != null)
             return bfc;
     }
     return null;
 }
Exemplo n.º 25
0
 protected void OnServiceFound(IResolvableService service, BonjourEventArgs args)
 {
     if (!servicesFound.ContainsKey(service.Name))
     {
         DetectedService ds = new DetectedService(service, args.Platform);
         servicesFound.Add(service.Name, ds);
     }
     if (this.ServiceFound != null)
     {
         this.ServiceFound(this, service, args);
     }
 }
Exemplo n.º 26
0
 public DetectedService(IResolvableService service, DestinationPlatformType platform)
 {
     this.service = service;
     this.platform = platform;
 }
        public void Update(IResolvableService service, BonjourEventArgs args)
        {
            if (service != null && service.HostEntry != null)
            {

                string host = DetectedService.GetHostname(service);
                int port = (int) service.Port;

                this.Description = service.Name;
                this.IPAddress = host;
                this.Port = port;
                this.Platform = args.Platform;
                this.Available = true;
                this.resolved = true;
            }
        }
Exemplo n.º 28
0
 public ServiceResolvedEventArgs(IResolvableService service)
 {
     this.service = service;
 }
Exemplo n.º 29
0
        private void button1_Click(object sender, EventArgs e)
        {
            ServiceBrowser browser = new ServiceBrowser();

            //
            // Configure the code that will be called back when the information
            // becomes available
            //
            browser.ServiceAdded += delegate(object o, ServiceBrowseEventArgs argss) {
                argss.Service.Resolved += delegate(object oo, ServiceResolvedEventArgs argsss) {
                    IResolvableService s = (IResolvableService)argsss.Service;

                    DataRow new_device = device_info.NewRow();
                    new_device["Name"] = s.Name;
                    new_device["IP"]   = s.HostEntry.AddressList[0];
                    new_device["Port"] = s.Port;
                    new_device["Attached Sensors/Actuators"] = s.TxtRecord.Count;


                    bool contains = device_info.AsEnumerable().Any(row => s.Name == row.Field <String>("Name"));
                    if (!contains)
                    {
                        device_info.Rows.Add(new_device);
                        DataTable device_components = new DataTable(s.Name);
                        device_components.Columns.Add("Type", typeof(string));
                        device_components.Columns.Add("OSC Address", typeof(string));
                        device_components.Columns.Add("Range", typeof(string));

                        for (int i = 0; i < s.TxtRecord.Count; i++)
                        {
                            DataRow       new_device_component = device_components.NewRow();
                            TxtRecordItem Component            = s.TxtRecord.BaseRecord.GetItemAt(i);

                            new_device_component["Type"] = Component.Key;

                            String[] ComponentList = Component.ValueString.Split(':');
                            new_device_component["OSC Address"] = ComponentList[0];
                            new_device_component["Range"]       = ComponentList[1];
                            device_components.Rows.Add(new_device_component);
                        }

                        devices.Tables.Add(device_components);
                    }
                };
                argss.Service.Resolve();
            };


            browser.Browse("_http._udp.", "local"); // Triggering the discovery request
            dataGridView1.DataSource = device_info; // Binding DataGridView with main table

            dataGridView1.Columns[0].Width = 220;
            dataGridView1.Columns[1].Width = 140;
            dataGridView1.Columns[2].Width = 100;
            dataGridView1.Columns[3].Width = 250;

            //
            // Adding Checkbox column in table
            //

            DataGridViewCheckBoxColumn chk = new DataGridViewCheckBoxColumn();

            chk.HeaderText = "Select";
            chk.Name       = "Checkbox";
            chk.Width      = dataGridView1.Width - dataGridView1.Columns[0].Width - dataGridView1.Columns[1].Width - dataGridView1.Columns[2].Width - dataGridView1.Columns[3].Width - 45;
            dataGridView1.Columns.Add(chk);
        }
Exemplo n.º 30
0
 private static bool IsOwnInstance(IResolvableService service)
 {
     if (service.Name == Growl.Daemon.GrowlServer.BonjourServiceName)
         return true;
     else
         return false;
 }
Exemplo n.º 31
0
        private void OnServiceResolved(object o, ServiceResolvedEventArgs args)
        {
            string name = args.Service.Name;

            Log.DebugFormat("Managed to resolve DAAP share {0}.", args.Service.Name);

            bool password_required = false;

            // iTunes tacks this on to indicate a passsword protected share.  Ugh.
            if (name.EndsWith("_PW"))
            {
                name = name.Substring(0, name.Length - 3);
                password_required = true;
            }

            IResolvableService service = (IResolvableService)args.Service;

            foreach (TxtRecordItem item in service.TxtRecord)
            {
                if (item.Key.ToLower() == "password")
                {
                    password_required = item.ValueString.ToLower() == "true";
                }
                else if (item.Key.ToLower() == "machine name")
                {
                    name = item.ValueString;
                }
            }

            IPAddress address = args.Service.HostEntry.AddressList[0];

            Log.DebugFormat("OnServiceResolved provided {0}", address);

            // XXX: Workaround a Mono bug where we can't resolve IPv6 addresses properly
            if (services.ContainsKey(name) && address.AddressFamily == AddressFamily.InterNetworkV6)
            {
                // Only skip this service if it resolves to a IPv6 address, and we already have info
                // for this service already.
                Log.Debug("Skipping service", "already have IPv4 address.");
                return;
            }
            else if (!services.ContainsKey(name) && address.AddressFamily == AddressFamily.InterNetworkV6)
            {
                // This is the first address we've resolved, however, it's an IPv6 address.
                // Try and resolve the hostname in hope that it'll end up as an IPv4 address - it doesn't
                // really matter if it still ends up with an IPv6 address, we're not risking anything.

                foreach (IPAddress addr in Dns.GetHostEntry(args.Service.HostEntry.HostName).AddressList)
                {
                    if (addr.AddressFamily == AddressFamily.InterNetwork)
                    {
                        address = addr;
                    }
                }
            }

            Log.DebugFormat("Using address {0}", address);

            Daap.Service svc = new Daap.Service(address, (ushort)service.Port,
                                                name, password_required);

            if (services.ContainsKey(name))
            {
                services[name] = svc;
            }
            else
            {
                services.Add(name, svc);
            }

            if (Found != null)
            {
                Found(this, new ServiceArgs(svc));
            }
        }
Exemplo n.º 32
0
 void bonjour_ServiceFound(Bonjour sender, IResolvableService service, BonjourEventArgs args)
 {
     BonjourForwardDestination bfc = MatchBonjourServiceToForwardDestination(service);
     if (bfc != null)
     {
         bfc.Update(service, args);
         OnBonjourServiceUpdate(bfc);
     }
 }
Exemplo n.º 33
0
 private void AddFoundServiceFromSCResolvedData(IResolvableService metaData)
 {
     var sst = new ServiceInfo(metaData.TxtRecord["name"].ValueString, metaData.TxtRecord["loc"].ValueString,
                               metaData.TxtRecord["addr"].ValueString, metaData.TxtRecord["code"].ValueString);
     ActivityServices.Add(sst);
     OnDiscoveryAddressAdded(new DiscoveryAddressAddedEventArgs(sst));
 }
Exemplo n.º 34
0
 void bonjour_ServiceRemoved(Bonjour sender, IResolvableService service)
 {
     BonjourForwardDestination bfc = MatchBonjourServiceToForwardDestination(service);
     if (bfc != null)
     {
         bfc.NotAvailable();
         OnBonjourServiceUpdate(bfc);
     }
 }
Exemplo n.º 35
0
        private void OnServiceRemoved(object o, ServiceBrowseEventArgs args)
        {
            IResolvableService s = args.Service;

            Removed(this, new ServiceArgs(new DPAP.Service(null, 0, s.Name, false, null)));
        }
 public ServiceResolvedEventArgs(IResolvableService service)
 {
     this.service = service;
 }