示例#1
0
        public bool ValidateFilesFromDirectory(string directory)
        {
            bool success = true;
            string[] xmlFiles = Directory.GetFiles(directory);
            XMLValidator validator = new XMLValidator();
            int numberOfCurrentlyValidatedFile = 0;
            try
            {
                foreach (string xmlFile in xmlFiles)
                {
                    if (!validator.ValidateXml(xmlSchemaPath, xmlFile))
                    {
                        break;
                    }
                    numberOfCurrentlyValidatedFile++;
                }

                if (numberOfCurrentlyValidatedFile == xmlFiles.Length)
                {
                    Console.WriteLine("All xml files were validated!");
                }
                else
                {
                    success = false;
                    Console.WriteLine("Error found in XML file with path {0}.", xmlFiles[numberOfCurrentlyValidatedFile++]);
                }
                return success;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return false;
            }
        }
        public Tuple<List<string>, List<string>> InsertFiles(string xmlFolderPath)
        {
            try
            {
                XMLSingleFileLoader manipulator = new XMLSingleFileLoader();
                string[] xmlPaths = Directory.GetFiles(xmlFolderPath);
                XMLValidator validator = new XMLValidator();
                //valid and invalid xmls list.
                List<string> validXmls = new List<string>();
                List<string> invalidXmls = new List<string>();

                foreach (string path in xmlPaths)
                {
                    if (validator.ValidateXml(validator.XmlShcemaPath, path))
                    {
                        manipulator.LoadXmlFile(path);
                        XMLMonitorParse mon = new XMLMonitorParse(manipulator.Doc);
                        InsertMonitor insMonitor = new InsertMonitor(mon);
                        XMLBoxSetParse box = new XMLBoxSetParse(manipulator.Doc);
                        InsertBoxSet insBox = new InsertBoxSet(box);

                        int monitorId = insMonitor.PopulateDatabase();
                        int boxId = insBox.PopulateDataBase();

                        InsertConfiguration config = new InsertConfiguration();

                        int configId = config.PopulateDataBase(boxId, monitorId);

                        XMLAdditionalSoftwareParse sof = new XMLAdditionalSoftwareParse(manipulator.Doc);
                        InsertSoftware insSoftware = new InsertSoftware(sof, configId);
                        XMLPeripheralsParse per = new XMLPeripheralsParse(manipulator.Doc);
                        InsertPeripheral insPeripheral = new InsertPeripheral(per, configId);

                        insSoftware.PopulateDataBase();
                        insPeripheral.PopulateDatabse();

                        validXmls.Add(path);
                    }
                    else
                    {
                        invalidXmls.Add(path);
                    }
                }
                Tuple<List<string>, List<string>> result = new Tuple<List<string>, List<string>>(validXmls, invalidXmls);
                return result;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Could not load successfully xml files into Database.Reason: {0}", ex.Message);
                return null;
            }
        }
        public bool ValidateFilesFromDirectory(string directory)
        {
            bool success = true;

            string[]     xmlFiles  = Directory.GetFiles(directory);
            XMLValidator validator = new XMLValidator();
            int          numberOfCurrentlyValidatedFile = 0;

            try
            {
                foreach (string xmlFile in xmlFiles)
                {
                    if (!validator.ValidateXml(xmlSchemaPath, xmlFile))
                    {
                        break;
                    }
                    numberOfCurrentlyValidatedFile++;
                }

                if (numberOfCurrentlyValidatedFile == xmlFiles.Length)
                {
                    Console.WriteLine("All xml files were validated!");
                }
                else
                {
                    success = false;
                    Console.WriteLine("Error found in XML file with path {0}.", xmlFiles[numberOfCurrentlyValidatedFile++]);
                }
                return(success);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
        }
        public void Insert()
        {
            XMLValidator validator = new XMLValidator();
            XmlDocument doc = new XmlDocument();
            doc.Load(this.xmlPath);
            if (validator.ValidateXml(validator.XmlShcemaPath, this.xmlPath))
            {
                XMLMonitorParse monitor = new XMLMonitorParse(doc);
                XMLBoxSetParse box = new XMLBoxSetParse(doc);
                XMLPeripheralsParse per = new XMLPeripheralsParse(doc);
                XMLAdditionalSoftwareParse soft = new XMLAdditionalSoftwareParse(doc);

                InsertMonitor insMonitor = new InsertMonitor(monitor);
                int monId = insMonitor.PopulateDatabase();
                InsertBoxSet insBox = new InsertBoxSet(box);
                int boxId = insBox.PopulateDataBase();
                InsertConfiguration insConfig = new InsertConfiguration();
                int configId = insConfig.PopulateDataBase(boxId,monId);
                InsertPeripheral insPer = new InsertPeripheral(per, configId);
                insPer.PopulateDatabse();
                InsertSoftware insSoft = new InsertSoftware(soft, configId);
                insSoft.PopulateDataBase();
            }
        }