Ejemplo n.º 1
0
        /// <summary>
        /// Starts the DACP Server including any mDNS Services.
        /// </summary>
        protected virtual void Start()
        {
            Console.WriteLine("Starting DACPServer...");
            try {
                bool portAvailable = false;
                do
                {
                    portAvailable = FindNextAvailablePort(PORT);
                    if (portAvailable == false)
                    {
                        PORT = PORT + 1;
                    }
                } while (portAvailable == false);

                PairingDatabase = DACPPairingDatabase.Initialize(this);
                PairingServer   = new DACPPairingServer(this);
                PublishMdnsServices();
                StartNonblockingHttpListener();
            } catch (DACPBonjourException bex) {
                Console.WriteLine(this.GetApplicationName() + " Bonjour Error: " + bex.Message);
                throw bex;
            } catch (Exception ex) {
                Console.WriteLine(this.GetApplicationName() + "Unexpected Exception caught: " + ex.Message);
                throw ex;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Static method to create a DACPPairingDatabase and try and load XML
        /// file from disk located at EXENAME.xml in the same directory.
        /// </summary>
        /// <returns>a DACPPairingDatabase object</returns>
        public static DACPPairingDatabase Initialize(DACPServer dacpServer)
        {
            Console.WriteLine("Initializing DACPPairingDatabase");
            DACPPairingDatabase database = new DACPPairingDatabase();

            database.Server = dacpServer;

            string fileName = database.GetFileName();

            if (File.Exists(fileName))
            {
                Console.WriteLine("Deserializing XML file: {0}", fileName);

                try {
                    DACPPairingDatabaseSerializer serializer = new DACPPairingDatabaseSerializer();
                    //XmlSerializer serializer = new XmlSerializer(CLAZZ_TYPE);
                    using (FileStream stream = new FileStream(fileName, FileMode.Open)) {
                        database        = (DACPPairingDatabase)serializer.Deserialize(stream);
                        database.Server = dacpServer;
                    }
                } catch (Exception ex) {
                    Console.WriteLine("XML Exception", ex);
                    database        = new DACPPairingDatabase();
                    database.Server = dacpServer;
                }
            }

            return(database);
        }