Doe.mXMLHandler.xHandle.verify C# (CSharp) Method

verify() public method

public verify ( ) : bool
return bool
        public bool verify()
        {
            if (!(File.Exists(xmlPath) && File.Exists(schemaPath)))
            {
                throw new customException("Schema or Config corrupted or doesn't exist");
            }
            //code to check if config matches schema
            XmlSchemaSet xs = new XmlSchemaSet();

            xs.Add("",schemaPath);

            XmlReaderSettings setting = new XmlReaderSettings();
            setting.ValidationType = ValidationType.Schema;
            setting.Schemas = xs;
            setting.ValidationEventHandler += new ValidationEventHandler(customEHandle);

            XmlReader xr = XmlReader.Create(xmlPath, setting);

            while (xr.Read()) ;
            return isValid;
        }

Usage Example

Ejemplo n.º 1
0
        //also starts the server
        static void Main(string[] args)
        {
            String docPath, scmPath;
            docPath = "Config.xml";
            scmPath = "Config.xsd";
            xHandle config = new xHandle(docPath, scmPath);
            try
            {
                if (!config.verify())
                {
                    Console.WriteLine("Bad config file");
                    Environment.Exit(1);
                }
                Console.WriteLine("Successfully loaded xml");
            }
            catch (customException e)
            {
                Console.WriteLine(e.ErrorMessage);
                Environment.Exit(1);
            }

            Server myServer = new Server(config);
            Thread myThread = new Thread(new ThreadStart(myServer.ListenForClients));
            myThread.Start();

            while (!myThread.IsAlive) ;         //spin a while for thread to be alive
            while (myThread.IsAlive)
                Thread.Sleep(100);          //do nothing while thread is alive
            myThread.Join();
        }