Exemplo n.º 1
0
        /// <summary>
        /// Publish ZeroConf, so that WaveBox may advertise itself using mDNS to capable devices
        /// </summary>
        public bool Start()
        {
            string serverUrl = ServerUtility.GetServerUrl();

            if ((object)serverUrl == null)
            {
                logger.Error("Could not start ZeroConf service, due to null ServerUrl");
                return(false);
            }

            // If we're already registered, dispose of it and create a new one
            if ((object)ZeroConf != null)
            {
                this.Stop();
            }

            // Create and register the service
            try
            {
                ZeroConf             = new RegisterService();
                ZeroConf.Name        = Hostname;
                ZeroConf.RegType     = RegType;
                ZeroConf.ReplyDomain = ReplyDomain;
                ZeroConf.Port        = (short)Injection.Kernel.Get <IServerSettings>().Port;

                TxtRecord record = new TxtRecord();
                record.Add(ServerUrlKey, serverUrl);
                ZeroConf.TxtRecord = record;

                ZeroConf.Register();
            }
            catch (Exception e)
            {
                logger.Error(e);
                this.Stop();
                return(false);
            }

            return(true);
        }