public void Test() { XMLValidator sut = new XMLValidator(); var Validate = sut.XmlValidate(@"C:\Users\z0045tam\source\repos\XMLParserConsoleTester\XMLParsing_UTest\test.u\Data\AiScheduler1.xml"); Assert.AreEqual(true, Validate); }
public void XMLValidator_Valid_isTrue() { XMLValidator sut = new XMLValidator(); var validate = sut.XmlValidate(@"C:\Users\z0045tam\source\repos\XMLParserConsoleTester\XMLParsing_UTest\test.u\Data\InvalidXML.xml"); Assert.AreEqual(false, validate); }
private void ReadXml() { data = new XMLDataHandler(); string filename = GetFileName("xml"); if (filename == null) { return; } try { _baseDocument = data.LoadXML(filename); _generatedXDocument = new XDocument(_baseDocument); } catch (Exception ex) { SweetAlert.Show("Error while reading file:", ex.Message, msgImage: SweetAlertImage.ERROR); } _schemaPath = GetFileName("xsd"); try { XMLValidator.ValidateSchema("http://www.gamelib.org/types", _schemaPath, _baseDocument); } catch (Exception ex) { SweetAlert.Show("XSD Schema validation error:", ex.Message, msgImage: SweetAlertImage.ERROR); } GameLibrary = data.GameLibrary; BaseGameLibrary = new GameLibrary(GameLibrary); UpdateIds(); RaisePropertyChanged("GamesIds"); }
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(); } }
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 static void ValidateXmlTest() { bool isValid = false; XMLValidator xmlValidator = new XMLValidator(); isValid = xmlValidator.Validate(@"c:\temp\TestDataTable.xml", @"c:\temp\TestDataTable.xsd"); if (isValid) { Program._messageLog.WriteLine("OK: Xml file has valid format."); } else { Program._messageLog.WriteLine("ERROR: Xml file does not have valid format."); Program._messageLog.WriteLine(xmlValidator.ValidationErrors); } }
static void Main(string[] args) { var schemaPath = ConfigurationManager.AppSettings["xsdSchemaPath"]; var schemaNamespace = ConfigurationManager.AppSettings["xsdSchemaNamespace"]; var validator = new XMLValidator(schemaPath, schemaNamespace); var validFilePath = ConfigurationManager.AppSettings["validFile"]; var invalidFilePath = ConfigurationManager.AppSettings["invalidFile"]; Console.WriteLine("Valid file output\n"); Console.WriteLine(validator.Validate(validFilePath)); Console.WriteLine("\n \n-------------------------------------------------------------------------------------\n \n"); Console.WriteLine("Invalid file output\n"); Console.WriteLine(validator.Validate(invalidFilePath)); Console.ReadKey(); }
public string parserReturn(string filePath) { XmlDocument doc = new XmlDocument(); doc.Load(filePath); String xmlJobString = doc.OuterXml; XMLValidator validator = new XMLValidator(); validator.XmlValidate(filePath); XMLDeserializer serializer = new XMLDeserializer(); serializer.Deserialize(xmlJobString.ToString()); return(null); }
public IActionResult Save() { var formData = this.Request.Form; try { OnlineCosmeticShop onlineCosmeticShop = ObjectConstuctor.constructXMLObject(formData); XmlSerializer xmlSerializer = new XmlSerializer(typeof(OnlineCosmeticShop)); FileStream fileStream = new FileStream( $"C:\\Users\\ksimeonova\\Documents\\ASP\\CozmeticZone\\CozmeticZone\\XML\\G_Products.xml", FileMode.CreateNew); using (StreamWriter streamWriter = new StreamWriter(fileStream)) { xmlSerializer.Serialize(streamWriter, onlineCosmeticShop); } string name = "G_Products.xml"; bool isValidXML = XMLValidator.isValidXML(name); if (isValidXML) { DBManipulator.fillDatabase(onlineCosmeticShop); } ViewBag.ValidXML = isValidXML; } catch (IOException e) { Console.WriteLine(e); ViewBag.FileExists = true; } catch (FormatException e) { Console.WriteLine(e); ViewBag.IncorrectFormat = true; } return(View("Save")); }
public IActionResult Save() { var formData = this.Request.Form; try { SmartphoneCatalog onlineCosmeticShop = ObjectConstuctor.constructXMLObject(formData); XmlSerializer xmlSerializer = new XmlSerializer(typeof(SmartphoneCatalog)); FileStream fileStream = new FileStream( $"C:\\Users\\Dan4inatora\\Desktop\\Kris_proj\\SmartPhone_Catalog\\SmartPhone_Catalog\\XML\\G_Books.xml", FileMode.CreateNew); using (StreamWriter streamWriter = new StreamWriter(fileStream)) { xmlSerializer.Serialize(streamWriter, onlineCosmeticShop); } string name = "G_Books.xml"; bool isValidXML = XMLValidator.isValidXML(name); if (isValidXML) { DBManipulator.fillDatabase(onlineCosmeticShop); } ViewBag.ValidXML = isValidXML; } catch (IOException e) { Console.WriteLine(e); ViewBag.FileExists = true; } catch (FormatException e) { Console.WriteLine(e); ViewBag.IncorrectFormat = true; } return(View("Save")); }
public IActionResult Serialize() { XmlSerializer xmlSerializer = new XmlSerializer(typeof(OnlineCosmeticShop)); var filesInfo = new Dictionary <string, bool>(); for (int index = 1; index <= 20; index++) { try { string fileName = $"Products_{index}.xml"; bool validXML = XMLValidator.isValidXML(fileName); bool isValid = XMLValidator.isValidXML(); FileStream fileStream = new FileStream( $"C:\\Users\\ksimeonova\\Documents\\ASP\\CozmeticZone\\CozmeticZone\\XML\\Products_{index}.xml", FileMode.Open); if (validXML) { OnlineCosmeticShop onlineCosmeticShop = (OnlineCosmeticShop)xmlSerializer.Deserialize(fileStream); var success = DBManipulator.fillDatabase(onlineCosmeticShop); ViewBag.Sucess = success; } fileStream.Close(); filesInfo.Add(fileName, validXML); } catch (Exception e) { Console.WriteLine(e); ViewBag.IncorrectFormat = true; } } ViewBag.FilesInfo = filesInfo; return(View()); }
public IActionResult Serialize() { XmlSerializer xmlSerializer = new XmlSerializer(typeof(SmartphoneCatalog)); var filesInfo = new Dictionary <string, bool>(); for (int index = 1; index <= 20; index++) { try { string fileName = $"Book_{index}.xml"; bool validXML = XMLValidator.isValidXML(fileName); string path = Environment.CurrentDirectory; FileStream fileStream = new FileStream( $"C:\\Users\\Dan4inatora\\Desktop\\Kris_proj\\SmartPhone_Catalog\\SmartPhone_Catalog\\XML\\Book_{index}.xml", FileMode.Open); if (validXML) { SmartphoneCatalog smartphoneCatalog = (SmartphoneCatalog)xmlSerializer.Deserialize(fileStream); var success = DBManipulator.fillDatabase(smartphoneCatalog); ViewBag.Sucess = success; } fileStream.Close(); filesInfo.Add(fileName, validXML); } catch (Exception e) { Console.WriteLine(e); ViewBag.IncorrectFormat = true; } } ViewBag.FilesInfo = filesInfo; return(View()); }
private void ValidateXml() { if (null == data.GameLibrary) { return; } try { _generatedXDocument = data.CreateXDocument(); _schemaPath = GetFileName("xsd"); XMLValidator.ValidateSchema("http://www.gamelib.org/types", _schemaPath, _generatedXDocument); } catch (XmlSchemaValidationException ex) { SweetAlert.Show("XSD Schema validation error:", ex.Message, msgImage: SweetAlertImage.ERROR); } catch (Exception ex) { SweetAlert.Show("Model error:", ex.Message, msgImage: SweetAlertImage.ERROR); } }
public void XMLValidationReturnsExpectedCodes(string command, string siteId, int code) { Assert.That(XMLValidator.Validate(XMLStrings.xmlString(command, siteId)), Is.EqualTo(code)); }
/// <summary> /// Scan the Plugins Directory for any plugins, validate them, and add them to the program. /// </summary> public void Scan() { if (!Directory.Exists("./Plugins/")) Directory.CreateDirectory("./Plugins/"); String[] files = Directory.GetFiles("./Plugins/", "*.xml"); foreach (String sFile in files) { XMLValidator validator = new XMLValidator(sFile, isplugin: true); if (validator.ValidateXMLFile()) { MessageBox.Show(String.Format("Plugin {0} is in an invalid format! Possibly out of date?", sFile)); continue; } XmlTextReader reader = new XmlTextReader(sFile); String element = ""; String name = "", client = "", realmlist = ""; SArray3 realmOptions = new SArray3(); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: { element = reader.Name; if (String.Compare(element, "Realm") == 0) { if (realmOptions.ContainsX(name)) continue; if (name != "" && Config.ValidateClient(client)) realmOptions.Add(name, realmlist, client); client = "0.0.0"; name = ""; realmlist = ""; } break; } case XmlNodeType.Text: { switch (element) { case "RealmName": name = reader.Value; break; case "RealmList": realmlist = reader.Value; break; case "RealmClient": client = reader.Value; break; } break; } } } if (realmOptions.ContainsX(name)) throw new Exception(String.Format("Realm id {0} used more than once!", name)); if (Config.ValidateClient(client)) realmOptions.Add(name, realmlist, client); foreach (Vector3<String> vector in realmOptions) Config.realmOptions.Add(vector); ListView box = (ListView)m_masterForm.Controls["chosenRealm"]; foreach (Vector3<String> kvp in realmOptions) { ListViewItem itemToAdd = new ListViewItem(kvp.X); itemToAdd.Name = kvp.X; box.Items.Add(itemToAdd); } } }
/// <summary> /// Scan the Plugins Directory for any plugins, validate them, and add them to the program. /// </summary> public void Scan() { if (!Directory.Exists("./Plugins/")) { Directory.CreateDirectory("./Plugins/"); } String[] files = Directory.GetFiles("./Plugins/", "*.xml"); foreach (String sFile in files) { XMLValidator validator = new XMLValidator(sFile, isplugin: true); if (validator.ValidateXMLFile()) { MessageBox.Show(String.Format("Plugin {0} is in an invalid format! Possibly out of date?", sFile)); continue; } XmlTextReader reader = new XmlTextReader(sFile); String element = ""; String name = "", client = "", realmlist = ""; SArray3 realmOptions = new SArray3(); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: { element = reader.Name; if (String.Compare(element, "Realm") == 0) { if (realmOptions.ContainsX(name)) { continue; } if (name != "" && Config.ValidateClient(client)) { realmOptions.Add(name, realmlist, client); } client = "0.0.0"; name = ""; realmlist = ""; } break; } case XmlNodeType.Text: { switch (element) { case "RealmName": name = reader.Value; break; case "RealmList": realmlist = reader.Value; break; case "RealmClient": client = reader.Value; break; } break; } } } if (realmOptions.ContainsX(name)) { throw new Exception(String.Format("Realm id {0} used more than once!", name)); } if (Config.ValidateClient(client)) { realmOptions.Add(name, realmlist, client); } foreach (Vector3 <String> vector in realmOptions) { Config.realmOptions.Add(vector); } ListView box = (ListView)m_masterForm.Controls["chosenRealm"]; foreach (Vector3 <String> kvp in realmOptions) { ListViewItem itemToAdd = new ListViewItem(kvp.X); itemToAdd.Name = kvp.X; box.Items.Add(itemToAdd); } } }
public void XMLValidationReturnsMinusThreeIfDocumentDoesntMatchSchema() { Assert.That(XMLValidator.Validate(XMLStrings.xmlStringDoesntMatchSchema), Is.EqualTo(-3)); }
public string TransferFund([FromBody] string xmlData) { // creating object of CultureInfo CultureInfo cultures = new CultureInfo("en-US"); try { var isSameBank = false; XmlDocument doc = new XmlDocument(); doc.LoadXml(xmlData); #region xml validation for PACS.008 XMLValidator.ValidatePain008(doc); #endregion xml validation for PACS.008 #region data fetched from xml string txnId, amount, senderBIC, receiverBIC, senderAccNo, receiverAccNo, sendingBankRoutingNo, receivingBankRoutingNo, purpose = string.Empty; txnId = doc.GetElementsByTagName("TxId").Item(0).InnerText; amount = doc.GetElementsByTagName("IntrBkSttlmAmt").Item(0).InnerText; senderBIC = doc.GetElementsByTagName("BICFI").Item(0).InnerText; receiverBIC = doc.GetElementsByTagName("BICFI").Item(3).InnerText; senderAccNo = doc.GetElementsByTagName("Id").Item(0).InnerText; receiverAccNo = doc.GetElementsByTagName("Id").Item(8).InnerText; sendingBankRoutingNo = doc.GetElementsByTagName("Id").Item(2).InnerText; receivingBankRoutingNo = doc.GetElementsByTagName("Id").Item(5).InnerText; purpose = doc.GetElementsByTagName("Ustrd").Item(0).InnerText; DateTime txnDt = DateTime.Now; DateTime stlmntDt = DateTime.Now; #endregion #region data fetched from db for further operation var sender = _businessLayer.GetAllBankUsers().SingleOrDefault(m => m.AccountNumber == senderAccNo); var receiver = _businessLayer.GetAllBankUsers().SingleOrDefault(m => m.AccountNumber == receiverAccNo); var senderBank = _businessLayer.GetAllBanks().SingleOrDefault(m => m.SwiftBic == senderBIC); var receiverBank = _businessLayer.GetAllBanks().SingleOrDefault(m => m.SwiftBic == receiverBIC); #endregion if (senderBank.Id == receiverBank.Id) { isSameBank = true; } //DBManager db = new DBManager(transactionRepository, sendingBankUserRepository, receivingBankUserRepository, bankNetDebitCapRepository, suspenseTransactionRepository, bankRepository); //update Sending Bank Net Debit Cap var senderInstitutionDebitCap = _businessLayer.GetParticipantDebitCapById(senderBank.Id); senderInstitutionDebitCap.CurrentNetDebitCap -= System.Convert.ToDecimal(amount, cultures); senderInstitutionDebitCap.EntityState = EntityState.Modified; _businessLayer.UpdateParticipantDebitCap(senderInstitutionDebitCap); //create suspense transaction var suspenseTransaction = new SuspenseTransaction { SuspenseTransactionId = Guid.NewGuid(), SenderAccountNo = senderAccNo, SendingBankId = senderBank.Id, SendingBankSuspanseAccount = senderBank.SuspenseAccount, Amount = Convert.ToDecimal(amount, cultures), TransactionInitiatedOn = txnDt, SuspenseClearingTime = DateTime.Now, TransactionId = txnId, SuspenseStatus = false, EntityState = EntityState.Added }; _businessLayer.AddSuspenseTransaction(suspenseTransaction); TransactionRequestLog transactionRequestLog = new TransactionRequestLog(); TransactionRequestLog transactionRequestLogReceive = new TransactionRequestLog(); List <TransactionRequestLog> logs = new List <TransactionRequestLog>(); var responseResult = string.Empty; var responseResultFromBB = string.Empty; using (var client = new HttpClient()) { transactionRequestLog.TransactionId = txnId; transactionRequestLog.RequestFrom = "IDTP"; transactionRequestLog.RequestTo = receiverBank.FinancialInstitution.InstitutionName; transactionRequestLog.RequestMessage = xmlData; transactionRequestLog.RequestTime = DateTime.Now; transactionRequestLog.EntityState = EntityState.Added; transactionRequestLog.CreatedBy = receiverBank.FinancialInstitution.InstitutionName; transactionRequestLog.CreatedOn = DateTime.Now; transactionRequestLog.ModifiedBy = receiverBank.FinancialInstitution.InstitutionName; transactionRequestLog.ModifiedOn = DateTime.Now; logs.Add(transactionRequestLog); //receiver bank call responseResult = HttpClientHelper.Post(new Uri("https://localhost:44372/api/Receiver"), xmlData); //responseResult = HttpClientHelper.Post(new Uri("https://idtp-external-receiver.azurewebsites.net/api/Receiver"), xmlData); #region xml validation for PACS.002 responseResult = responseResult.Replace("\\", "", StringComparison.CurrentCulture); responseResult = responseResult[1..^ 1];
public async Task Init() { string XSDFilePath = Path.Combine(_alfrescoConfig.ConfigurationFiles.FolderName, _alfrescoConfig.ConfigurationFiles.ContentModels.FolderName, _alfrescoConfig.ConfigurationFiles.ContentModels.XSDValidationFile); List <ConfigurationContent> files = (from string file in _alfrescoConfig.ConfigurationFiles.ContentModels.Files select new ConfigurationContent { FileName = file, FilePath = Path.Combine(_alfrescoConfig.ConfigurationFiles.FolderName, _alfrescoConfig.ConfigurationFiles.ContentModels.FolderName, file) }).ToList(); foreach (var file in files) { try { var validationResult = XMLValidator.ValidateXML("http://www.alfresco.org/model/dictionary/1.0", file.FilePath, XSDFilePath); if (validationResult.IsOK) { // Company Home var repositoryRootFolder = await _alfrescoHttpClient.GetNodeInfo(AlfrescoNames.Aliases.Root); var modelsNode = await _alfrescoHttpClient.GetNodeInfo(AlfrescoNames.Aliases.Root, ImmutableList <Parameter> .Empty .Add(new Parameter(AlfrescoNames.Headers.RelativePath, $"{DataDictionaryConfiguration.DataDictionary}/{DataDictionaryConfiguration.Models}", ParameterType.QueryString))); FormDataParam fileParams; using (var memstream = new MemoryStream()) { File.OpenRead(file.FilePath).CopyTo(memstream); fileParams = new FormDataParam(memstream.ToArray(), file.FileName); }; var createdChild = await _alfrescoHttpClient.CreateNode(modelsNode.Entry.Id, fileParams, ImmutableList <Parameter> .Empty .Add(new Parameter(HeaderNames.ContentType, "multipart/form-data", ParameterType.HttpHeader)) .Add(new Parameter(AlfrescoNames.Headers.OverWrite, true, ParameterType.GetOrPost))); var properties = new NodeBodyUpdate { Properties = new Dictionary <string, object> { { AlfrescoNames.ContentModel.ModelActive, true } } }; await _alfrescoHttpClient.UpdateNode(createdChild.Entry.Id, properties, ImmutableList <Parameter> .Empty .Add(new Parameter(HeaderNames.ContentType, MediaTypeNames.Application.Json, ParameterType.HttpHeader))); } else { Log.Error(validationResult.ErrorMessage); } } catch (Exception e) { Log.Error(e, "XML or XML file not found"); } } }
public int ValidateXML(string xml) { return(XMLValidator.Validate(xml)); }