Exemple #1
0
        private void OnAddRemoteServer(object o, EventArgs args)
        {
            ResponseType response;
            string       s_address;
            ushort       port;

            using (OpenRemoteServer dialog = new OpenRemoteServer()) {
                response  = (ResponseType)dialog.Run();
                s_address = dialog.Address;
                port      = (ushort)dialog.Port;
                dialog.Destroy();
            }

            if (response != ResponseType.Ok)
            {
                return;
            }

            Log.DebugFormat("Trying to add DAAP server on {0}:{1}", s_address, port);
            IPHostEntry hostEntry = null;

            try {
                hostEntry = Dns.GetHostEntry(s_address);
            } catch (SocketException) {
                Log.Warning("Unable to resolve host " + s_address);
                return;
            }

            IPAddress address = hostEntry.AddressList[0];

            foreach (IPAddress curAdd in hostEntry.AddressList)
            {
                if (curAdd.AddressFamily == AddressFamily.InterNetwork)
                {
                    address = curAdd;
                }
            }
            Log.DebugFormat(String.Format("Resolved {0} to {1}", s_address, address));
            Log.Debug("Spawning daap resolving thread");

            DaapResolverJob job = new DaapResolverJob(s_address, address, port);

            job.Finished += delegate {
                Service service = job.DaapService;

                if (service != null)
                {
                    AddDaapServer(service);
                    Log.DebugFormat("Created server {0}", service.Name);
                }
                else
                {
                    Log.DebugFormat("Unable to create service for {0}", s_address);
                }
            };

            ServiceManager.JobScheduler.Add(job);
        }
        private void OnAddRemoteServer (object o, EventArgs args)
        {
            ResponseType response;
            string s_address;
            ushort port;

            using (OpenRemoteServer dialog = new OpenRemoteServer ()) {
                response = (ResponseType) dialog.Run ();
                s_address = dialog.Address;
                port = (ushort) dialog.Port;
                dialog.Destroy ();
            }

            if (response != ResponseType.Ok)
                return;

            Log.DebugFormat ("Trying to add DAAP server on {0}:{1}", s_address, port);
            IPHostEntry hostEntry = null;
            try {
                hostEntry = Dns.GetHostEntry (s_address);
            } catch (SocketException) {
                Log.Warning ("Unable to resolve host " + s_address);
                return;
            }

            IPAddress address = hostEntry.AddressList[0];
            foreach (IPAddress curAdd in hostEntry.AddressList) {
                if (curAdd.AddressFamily == AddressFamily.InterNetwork) {
                    address = curAdd;
                }
            }
            Log.DebugFormat (String.Format("Resolved {0} to {1}", s_address, address));
            Log.Debug ("Spawning daap resolving thread");

            DaapResolverJob job = new DaapResolverJob(s_address, address, port);

            job.Finished += delegate {
                Service service = job.DaapService;

                if (service != null) {
                    AddDaapServer (service);
                    Log.DebugFormat ("Created server {0}", service.Name);
                } else {
                    Log.DebugFormat ("Unable to create service for {0}", s_address);
                }
            };

            ServiceManager.JobScheduler.Add (job);
        }