public Gtk.Widget ProvideInfo(ServiceAnnouncement service)
        {
            var locations = service.Locations.GetEnumerator();

            locations.MoveNext();
            return(new RawXmlInfo(new Uri(locations.Current)));
        }
예제 #2
0
 static void printService(char startChar, ServiceAnnouncement service)
 {
     Console.WriteLine("{0} '{1}' on {2}", startChar, service.Instance, service.NetworkInterface.Name);
     Console.WriteLine("\tHost: {0} ({1})", service.Hostname, string.Join(", ", service.Addresses));
     Console.WriteLine("\tPort: {0}", service.Port);
     Console.WriteLine("\tTxt : [{0}]", string.Join(", ", service.Txt));
 }
예제 #3
0
 private static void printService(char startChar, ServiceAnnouncement service)
 {
     Debug.WriteLine($"{startChar} '{service.Instance}' on {service.NetworkInterface.Name}");
     Debug.WriteLine($"\tHost: {service.Hostname} ({string.Join(", ", service.Addresses)})");
     Debug.WriteLine($"\tPort: {service.Port}");
     Debug.WriteLine($"\tTxt : [{string.Join(", ", service.Txt)}]");
 }
예제 #4
0
        private void onServiceAdded(object sender, ServiceAnnouncementEventArgs e)
        {
            ServiceAnnouncement service = e.Announcement;
            mDNSObject          mDNS    = new mDNSObject();

            mDNS.Type = (service.Type == "_https._tcp") ? "https" : "http";
            mDNS.Name = service.Instance;
            foreach (string txt in service.Txt)
            {
                if (txt.Contains("uuid"))
                {
                    mDNS.Txt = txt;
                }
            }
            foreach (IPAddress ipaddr in service.Addresses)
            {
                if (ipaddr.AddressFamily.ToString() == ProtocolFamily.InterNetwork.ToString()) // IPv4
                {
                    mDNS.Address = ipaddr.ToString();
                }
            }
            if (mDNS.Address == "")
            {
                return;
            }
            mDNS.Port = service.Port;
            services.Add(mDNS);
            cboxDevice.Items.Add(mDNS.Name);
        }
예제 #5
0
        private void HandleInternal(ServiceAnnouncement msg)
        {
            //EventLog.WriteEntry("Fingerpass", "Tray received a service announcement");

            //the service just started. get it's status (and trigger it to start listening)...
            _trayIcon.Publish(new GetStatus());
        }
        public Gtk.Widget ProvideInfo(ServiceAnnouncement service)
        {
            var controller        = service.GetService().GetController();
            var content_directory = new RemoteContentDirectory(new ContentDirectoryController(controller));

            return(new ContentDirectoryInfo(content_directory));
        }
예제 #7
0
 void OnAnnouncement(ServiceAnnouncement sa)
 {
     Log.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
     {
         WriteLogLine("---- Announced on {0} ({1}) ----", sa.AdapterInformation.Name, sa.AdapterInformation.Address);
         WriteLogLine(sa.Host.ToString());
     }));
 }
예제 #8
0
 private void OnAnnouncement(ServiceAnnouncement sa)
 {
     Log.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
     {
         WriteLogLine("---- Announced on {0} ({1}) ----", sa.AdapterInformation.Name, sa.AdapterInformation.Address);
         WriteLogLine(sa.Host.ToString());
     }));
 }
예제 #9
0
 public LazyServiceInfo (IServiceInfoProvider provider, ServiceAnnouncement service)
 {
     this.provider = provider;
     this.service = service;
     
     this.Build ();
     
     loading.Text = Catalog.GetString (string.Format ("Loading {0}", provider.Name));
 }
 public ConnectionManagerController(ServiceAnnouncement announcement)
 {
     if (announcement == null)
     {
         throw new ArgumentNullException("announcement");
     }
     controller = announcement.GetService().GetController();
     Verify();
 }
예제 #11
0
        public LazyServiceInfo(IServiceInfoProvider provider, ServiceAnnouncement service)
        {
            this.provider = provider;
            this.service  = service;

            this.Build();

            loading.Text = Catalog.GetString(string.Format("Loading {0}", provider.Name));
        }
예제 #12
0
 static void printService(char startChar, ServiceAnnouncement service)
 {
     lock (s_gate)
     {
         Console.WriteLine($"{DateTime.Now} : {startChar} service '{service.Instance}' of type '{service.Type}' on {service.NetworkInterface.Name}");
         Console.WriteLine("\tHost: {0} ({1})", service.Hostname, string.Join(", ", service.Addresses));
         Console.WriteLine("\tPort: {0}", service.Port);
         Console.WriteLine("\tTxt : [{0}]", string.Join(", ", service.Txt));
     }
 }
예제 #13
0
 public ServiceAnnouncementInfo (ServiceAnnouncement service)
 {
     this.Build ();
     
     serviceType.Text = service.Type.ToString ();
     deviceUdn.Text = service.DeviceUdn;
     foreach (var location in service.Locations) {
         locationBox.PackStart (new Gtk.Label (location) { Selectable = true, Xalign = 0F }, true, true, 0);
     }
 }
예제 #14
0
 private void debugAnnouncement(string header, ServiceAnnouncement a)
 {
     Trace.WriteLine(header);
     Trace.Indent();
     Trace.WriteLine("Instance: " + a.Instance);
     Trace.WriteLine("Type: " + a.Type);
     Trace.WriteLine("IP: " + string.Join(", ", a.Addresses));
     Trace.WriteLine("Port: " + a.Port);
     Trace.WriteLine("Txt: " + string.Join(", ", a.Txt));
     Trace.Unindent();
 }
예제 #15
0
        Widget CreateNotebook(ServiceAnnouncement service)
        {
            var notebook = new Notebook();

            foreach (var provider in ServiceInfoProviders)
            {
                if (provider.CanProvideInfo(service.Type))
                {
                    notebook.AppendPage(new LazyServiceInfo(provider, service), new Label(provider.Name));
                }
            }
            return(notebook);
        }
예제 #16
0
        private void onServiceRemoved(object sender, ServiceAnnouncementEventArgs e)
        {
            ServiceAnnouncement service = e.Announcement;
            mDNSObject          mDNS    = new mDNSObject();

            mDNS = services.Find(x => x.Name == service.Instance);
            services.Remove(mDNS);
            cboxDevice.Items.Clear();
            foreach (mDNSObject mdns in services)
            {
                cboxDevice.Items.Add(mdns.Name);
            }
        }
        public ServiceAnnouncementInfo(ServiceAnnouncement service)
        {
            this.Build();

            serviceType.Text = service.Type.ToString();
            deviceUdn.Text   = service.DeviceUdn;
            foreach (var location in service.Locations)
            {
                locationBox.PackStart(new Gtk.Label(location)
                {
                    Selectable = true, Xalign = 0F
                }, true, true, 0);
            }
        }
예제 #18
0
        public static void Main(string[] args)
        {
            AdapterInformation info = new AdapterInformation("Aaron's DAAP Share", "");
            //service.RegType = "_hap._tcp";
            //service.ReplyDomain = "local.";
            //service.Port = 3689;

            ServiceAnnouncement service = new ServiceAnnouncement(info, null);

            // TxtRecords are optional
            //TxtRecord txt_record = new TxtRecord();
            //txt_record.Add("Password", "false");
            //service.TxtRecord = txt_record;

            //service.Register();

            BuildWebHost(args).Run();
        }
예제 #19
0
        static void addService(ServiceAnnouncement service)
        {
            if (service.Port != 80)
            {
                return;
            }

            foreach (var addr in service.Addresses)
            {
                if (addr.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    Match  m          = service.Txt.Select(txt => System.Text.RegularExpressions.Regex.Match(txt, @"device=(?<deviceType>.+)")).FirstOrDefault(_ => _.Success);
                    string deviceType = m != default(Match) && m.Success ? m.Groups["deviceType"].Value : "<Unknown>";

                    string msg = $"{service.Instance} ({deviceType}) - http://{addr} on '{service.NetworkInterface.Name}'";
                    if (endpoints.TryAdd(msg, service))
                    {
                        Console.WriteLine(msg);
                    }
                }
            }
        }
 public Gtk.Widget ProvideInfo (ServiceAnnouncement service)
 {
     var locations = service.Locations.GetEnumerator ();
     locations.MoveNext ();
     return new RawXmlInfo (new Uri (locations.Current));
 }
예제 #21
0
 private void OnAnnouncement(ServiceAnnouncement sa)
 {
     WriteLogLine("---- Announced on {0} ({1}) ----", sa.AdapterInformation.Name, sa.AdapterInformation.Address);
     WriteLogLine(sa.Host.ToString());
 }
 public Gtk.Widget ProvideInfo (ServiceAnnouncement service)
 {
     return new ServiceAnnouncementInfo (service);
 }
예제 #23
0
 public Gtk.Widget ProvideInfo(ServiceAnnouncement service)
 {
     return(new RawXmlInfo(service.GetService().ScpdUrl));
 }
예제 #24
0
        private void ServiceBrowser_ServiceAdded(object sender, ServiceAnnouncementEventArgs e)
        {
            var id = Thread.CurrentThread.ManagedThreadId;

            _serviceAnnouncement = e.Announcement;
        }
예제 #25
0
 public ServiceEventArgs(ServiceAnnouncement service, UpnpOperation operation)
 {
     this.service = service;
     this.operation = operation;
 }
 public Gtk.Widget ProvideInfo (ServiceAnnouncement service)
 {
     return new ServiceDescriptionInfo (service.GetService ());
 }
 public Gtk.Widget ProvideInfo(ServiceAnnouncement service)
 {
     return(new ServiceScpdInfo(service.GetService().GetController()));
 }
예제 #28
0
 public Gtk.Widget ProvideInfo (ServiceAnnouncement service)
 {
     return new ServiceScpdInfo (service.GetService ().GetController ());
 }
 public Gtk.Widget ProvideInfo (ServiceAnnouncement service)
 {
     var controller = service.GetService ().GetController ();
     var content_directory = new RemoteContentDirectory (new ContentDirectoryController (controller));
     return new ContentDirectoryInfo (content_directory);
 }
예제 #30
0
        void printService(char startChar, ServiceAnnouncement service)
        {
            lock (s_gate)
            {
                if (!shellyList.Contains(service.Instance))
                {
                    if (service.Hostname.StartsWith("shelly"))
                    {
                        Console.WriteLine("{0} '{1}' on {2}", startChar, service.Instance, service.NetworkInterface.Name);

                        Console.WriteLine("\tHost: {0} ({1})", service.Hostname, string.Join(", ", service.Addresses));
                        Console.WriteLine("\tPort: {0}", service.Port);
                        Console.WriteLine("\tTxt : [{0}]", string.Join(", ", service.Txt));

                        dynamic result         = Newtonsoft.Json.JsonConvert.DeserializeObject <object>(ShellySharp.Discover.GetDeviceInformationJson(string.Format("http://{0}/{1}", service.Addresses[0].ToString(), "status")));
                        dynamic resultSettings = Newtonsoft.Json.JsonConvert.DeserializeObject <object>(ShellySharp.Discover.GetDeviceInformationJson(string.Format("http://{0}/{1}", service.Addresses[0].ToString(), "settings")));

                        File.WriteAllText(
                            FindFilename(string.Format("{0}_{1}", resultSettings.device.type, "shelly")),
                            ShellySharp.Discover.GetDeviceInformationJson(string.Format("http://{0}/{1}", service.Addresses[0].ToString(), "shelly")));

                        File.WriteAllText(
                            FindFilename(string.Format("{0}_{1}", resultSettings.device.type, "status")),
                            ShellySharp.Discover.GetDeviceInformationJson(string.Format("http://{0}/{1}", service.Addresses[0].ToString(), "status")));

                        File.WriteAllText(
                            FindFilename(string.Format("{0}_{1}", resultSettings.device.type, "settings")),
                            ShellySharp.Discover.GetDeviceInformationJson(string.Format("http://{0}/{1}", service.Addresses[0].ToString(), "settings")));

                        int    metersCount = result.meters.Count != null ? result.meters.Count : 0;
                        string mode        = resultSettings.mode != null ? resultSettings.mode : string.Empty;
                        string type        = resultSettings.device.type != null ? resultSettings.device.type : string.Empty;

                        switch (mode)
                        {
                        case "relay":
                            int relaysCount = result.relays.Count != null ? result.relays.Count : 0;

                            for (int x = 0; x < relaysCount; x++)
                            {
                                File.WriteAllText(
                                    FindFilename(string.Format("{0}_{1}_{2}", resultSettings.device.type, "relay", x)),
                                    ShellySharp.Discover.GetDeviceInformationJson(string.Format("http://{0}/relay/{1}", service.Addresses[0].ToString(), x)));
                            }
                            break;

                        case "roller":
                            int rollersCount = resultSettings.device.num_rollers != null ? resultSettings.device.num_rollers : 0;

                            for (int x = 0; x < rollersCount; x++)
                            {
                                File.WriteAllText(
                                    FindFilename(string.Format("{0}_{1}_{2}", resultSettings.device.type, "roller", x)),
                                    ShellySharp.Discover.GetDeviceInformationJson(string.Format("http://{0}/roller/{1}", service.Addresses[0].ToString(), x)));
                            }
                            break;

                        default:
                            break;
                        }

                        for (int x = 0; x < metersCount; x++)
                        {
                            switch (type)
                            {
                            case "SHDM-2":
                                Console.WriteLine("Shelly Dimmer");
                                break;

                            case "SHSW-L":
                                Console.WriteLine("Shelly Switch 1L");
                                break;

                            default:
                                File.WriteAllText(
                                    FindFilename(string.Format("{0}_{1}_{2}", resultSettings.device.type, "meter", x)),
                                    ShellySharp.Discover.GetDeviceInformationJson(string.Format("http://{0}/meter/{1}", service.Addresses[0].ToString(), x)));
                                break;
                            }
                        }
                    }
                }

                shellyList.Add(service.Instance);
            }
        }
 public Gtk.Widget ProvideInfo(ServiceAnnouncement service)
 {
     return(new ServiceDescriptionInfo(service.GetService()));
 }
 public Gtk.Widget ProvideInfo (ServiceAnnouncement service)
 {
     return new RawXmlInfo (service.GetService ().ScpdUrl);
 }
예제 #33
0
        private DeviceDiscoveryReportItem ParseServiceAnnouncement(ServiceAnnouncement announcement)
        {
            IPAddress localInterface = IPAddress.Any;

            // Retrieve local interface address
            // TODO: This will need some IPv6 love at some point
            if (announcement.NetworkInterface.Information.OperationalStatus == System.Net.NetworkInformation.OperationalStatus.Up)
            {
                var ipv4Addresses = announcement.NetworkInterface.Information.GetIPProperties().UnicastAddresses.Where((ad) => ad.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork);
                localInterface = ipv4Addresses.FirstOrDefault().Address;
            }

            // Retrieve version string
            var versionTempString = announcement.Txt.Where((kvp) => kvp.Contains("ve=")).FirstOrDefault();
            int versionNumber     = 2;

            if (string.IsNullOrEmpty(versionTempString) == false)
            {
                versionNumber = int.Parse(versionTempString.Split('=')[1]);
            }

            // Retrieve device ID
            var    idTempString = announcement.Txt.Where((kvp) => kvp.Contains("id=")).FirstOrDefault();
            string Id           = "";

            if (string.IsNullOrEmpty(idTempString) == false)
            {
                Id = idTempString.Split('=')[1];
            }
            else
            {
                // Log.Error(string.Format("Unable to get ID of device {0}", e.Announcement.Hostname));
                return(null);
            }

            // Optional: Verify that it's a Chromecast device
            var tempDeviceType = announcement.Txt.Where((kvp) => kvp.Contains("md=")).FirstOrDefault();
            var deviceType     = DeviceType.Generic;

            if (string.IsNullOrEmpty(tempDeviceType) == false && tempDeviceType.Split('=')[1] == "Chromecast")
            {
                deviceType = DeviceType.Chromecast;
            }
            else
            {
                deviceType = DeviceType.Generic;
            }


            // Build baseUrl
            // This might not be right as there URI scheme could be something else.
            var scheme  = "http";
            var address = announcement.Addresses.First();
            var port    = announcement.Port;
            var uri     = new Uri(string.Format("{0}://{1}:{2}", scheme, address, port));

            var report = new ChromecastV2DeviceDiscoveryReportItem()
            {
                DeviceType = deviceType,
                Version    = versionNumber,
                Id         = Id,
                Name       = announcement.Hostname,
                EndPoint   = new IPEndPoint(announcement.Addresses.First(), announcement.Port),
                Interface  = localInterface,
                BaseUri    = uri,
            };

            return(report);
        }
예제 #34
0
 public Gtk.Widget ProvideInfo(ServiceAnnouncement service)
 {
     return(new ServiceAnnouncementInfo(service));
 }