private void getProtectedID(XmlDocument checkedDocument) { XmlNode id = XmlHelperFunctions.GetSubNode(checkedDocument.DocumentElement, "fu:ProtectedID"); this.ProtectedID = (id == null) ? string.Empty : id.InnerText; this.BarCodes = (id == null) ? null : BarCodes.Create(checkedDocument); }
private void checkAndCalculateProtectedID(XmlDocument message, XmlNode invoice) { // field ProtectedID is mandatory, but if it is not suplied it is going to be calculated! XmlNodeList protectedIDs = (invoice as XmlElement).GetElementsByTagName("fu:ProtectedID"); if (protectedIDs.Count == 0) { ProtectiveMark pm = new ProtectiveMark(); string protectedIDValue = pm.Calculate(invoice as XmlElement, Settings.CryptoProvider); // ProtectedID is not the last element in XML Schema, so we must put it in the right spot // we are going from bottom up, searching for the right spot XmlNode protectedIDNode = XmlHelperFunctions.CreateElement(message, this.Settings.FursXmlNamespace, "ProtectedID", protectedIDValue); XmlNode currentNode = invoice.LastChild; while ((currentNode != null) && (this.isNodeAfterProtectedID(currentNode))) { currentNode = currentNode.PreviousSibling; } if (currentNode != null) { invoice.InsertAfter(protectedIDNode, currentNode); } } }
private void processSend() { this.getProtectedID(this.originalMessage); if (this.MessageReceivedFromFurs == null) { this.Success = false; this.ErrorMessage = "Unknown error"; this.ErrorMessageSource = ErrorMessageSource.System; } XmlNode errMsgNode = XmlHelperFunctions.GetSubNode(this.MessageReceivedFromFurs.DocumentElement, "fu:ErrorMessage"); XmlNode errMsgCodeNode = XmlHelperFunctions.GetSubNode(this.MessageReceivedFromFurs.DocumentElement, "fu:ErrorCode"); if (errMsgNode != null) { this.Success = false; string id = (errMsgCodeNode == null) ? string.Empty : string.Format("[{0}]: ", errMsgCodeNode.InnerText); this.ErrorMessage = id + errMsgNode.InnerText; this.ErrorMessageSource = ErrorMessageSource.Furs; } XmlNode uniqueInvoiceIDNode = XmlHelperFunctions.GetSubNode(this.MessageReceivedFromFurs.DocumentElement, "fu:UniqueInvoiceID"); if (uniqueInvoiceIDNode != null) { this.UniqueInvoiceID = uniqueInvoiceIDNode.InnerText; } }
public XmlDocument Send(XmlDocument message, MessageType messageType) { HttpWebRequest request = this.createWebRequest(message, messageType); ServicePointManager.Expect100Continue = true; ////ServicePointManager.SecurityProtocol = System.Security.Authentication.SslProtocols.Tls; ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback((sender, certificate, chain, sslPolicyErrors) => { return(true); }); request.ClientCertificates.Add(this.settings.Certificate); using (Stream stream = request.GetRequestStream()) { StreamWriter sw = new StreamWriter(stream, new System.Text.UTF8Encoding(false, true)); message.Save(sw); } XmlDocument result = XmlHelperFunctions.CreateNewXmlDocument(); using (WebResponse response = request.GetResponse()) { using (StreamReader rd = new StreamReader(response.GetResponseStream())) { string soapResult = rd.ReadToEnd(); result.LoadXml(soapResult); } } return(result); }
private void checkData() { XmlNode businessPremise = XmlHelperFunctions.GetSubNode(this.Message.DocumentElement, "fu:BusinessPremise"); if (businessPremise == null) { throw new ArgumentNullException("BusinessPremise"); } }
private string getNodeValue(XmlElement parentElement, string nodeName) { XmlNode node = XmlHelperFunctions.GetFirstSubNode(parentElement, nodeName); if (node == null) { return(string.Empty); } return(node.InnerText); }
protected void checkHeader() { XmlNode header = XmlHelperFunctions.GetSubNode(this.Message.DocumentElement, "fu:Header"); if (header != null) return; XmlNode headerNode = XmlHelperFunctions.CreateElement(this.Message, this.Settings.FursXmlNamespace, "Header"); headerNode.AppendChild(XmlHelperFunctions.CreateElement(this.Message, this.Settings.FursXmlNamespace, "MessageID", Guid.NewGuid().ToString())); headerNode.AppendChild(XmlHelperFunctions.CreateElement(this.Message, this.Settings.FursXmlNamespace, "DateTime", DateTime.Now.ToString("s"))); this.Message.DocumentElement.InsertBefore(headerNode, this.Message.DocumentElement.FirstChild); }
public void testInvoice2() { XmlDocument xmlDoc = this.getXml("OKInvoice4.xml"); BarCodes bc = BarCodes.Create(xmlDoc); Assert.AreEqual(bc.BarCodeValue, "069869408702625034879475616534770898107101290141508071305245"); string xmlTaxNumber = XmlHelperFunctions.GetSubNode(xmlDoc.DocumentElement, "fu:TaxNumber").InnerText; string codeTaxNumber = bc.BarCodeValue.Substring(39, 8); Assert.AreEqual(xmlTaxNumber, codeTaxNumber); }
public static Echo Create(string message, Settings settings) { string xmlEcho = @"<?xml version='1.0' encoding='UTF-8'?><fu:EchoRequest xmlns:fu='http://www.fu.gov.si/' />"; XmlDocument echoDoc = XmlHelperFunctions.CreateNewXmlDocument(); echoDoc.LoadXml(xmlEcho); XmlNode xmlMessage = echoDoc.CreateTextNode(message); echoDoc.DocumentElement.AppendChild(xmlMessage); return(new Echo(echoDoc, settings)); }
private XmlNode getMainNode(XmlDocument message, MessageType messageType) { switch (messageType) { case MessageType.Invoice: return(XmlHelperFunctions.GetSubNode(message.DocumentElement, "fu:InvoiceRequest")); case MessageType.BusinessPremise: return(XmlHelperFunctions.GetSubNode(message.DocumentElement, "fu:BusinessPremiseRequest")); } return(null); }
private void checkAndCalculateProtectedID(XmlDocument message, XmlNode invoice) { // field ProtectedID is mandatory, but if it is not suplied it is going to be calculated! XmlNodeList protectedIDs = (invoice as XmlElement).GetElementsByTagName("fu:ProtectedID"); if (protectedIDs.Count == 0) { ProtectiveMark pm = new ProtectiveMark(); string protectedIDValue = pm.Calculate(invoice as XmlElement, Settings.CryptoProvider); invoice.AppendChild(XmlHelperFunctions.CreateElement(message, this.Settings.FursXmlNamespace, "ProtectedID", protectedIDValue)); } }
public ReturnValue Send(string message) { try { XmlDocument xmlDoc = XmlHelperFunctions.CreateNewXmlDocument(); xmlDoc.LoadXml(message); return(this.Send(xmlDoc)); } catch (System.Exception ex) { return(ReturnValue.Error(SendingStep.MessageReceived, null, ex.Message)); } }
private void checkData() { XmlNode invoice = XmlHelperFunctions.GetSubNode(this.Message.DocumentElement, "fu:Invoice"); if (invoice != null) { this.checkAndCalculateProtectedID(this.Message, invoice); return; } XmlNode salesBookInvoice = XmlHelperFunctions.GetSubNode(this.Message.DocumentElement, "fu:SalesBookInvoice"); if (salesBookInvoice == null) { throw new ArgumentNullException("Invoice"); } }
protected XmlDocument getXml(string fileName) { string fullName = this.getFullFileName(fileName); XmlDocument xml = XmlHelperFunctions.CreateNewXmlDocument(); xml.Load(fullName); // It is important to set the tax number to match the one that is in certificate or else FURS will not proceed messages XmlNode nodeTaxNumber = xml.GetElementsByTagName("fu:TaxNumber")[0]; if (nodeTaxNumber != null) { nodeTaxNumber.InnerText = MyTaxNumber; } return(xml); }
public void SurroundWithSoap() { string emptySoap = string.Format( @"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' " + " xmlns:fu='{0}' " + " xmlns:xd='http://www.w3.org/2000/09/xmldsig#' " + " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> " + " <soapenv:Header /> " + " <soapenv:Body /> " + "</soapenv:Envelope>", this.Settings.FursXmlNamespace); this.MessageSendToFurs = XmlHelperFunctions.CreateNewXmlDocument(); this.MessageSendToFurs.Schemas = this.Settings.Schemas; this.MessageSendToFurs.LoadXml(emptySoap); XmlNode body = this.MessageSendToFurs.ImportNode(this.Message.DocumentElement, true); XmlNode soapBody = XmlHelperFunctions.GetSubNode(this.MessageSendToFurs.DocumentElement, "soapenv:Body"); soapBody.AppendChild(body); }
private BarCodes(XmlDocument invoice) { // People at FURS say that modulo is just easy modulo 10 and not luhn! IModulo modulo = new Modulo10_Easy(); this.invoice = invoice; XmlNode protectedIDNode = XmlHelperFunctions.GetSubNode(invoice.DocumentElement, "fu:ProtectedID"); XmlNode taxNumberNode = XmlHelperFunctions.GetSubNode(invoice.DocumentElement, "fu:TaxNumber"); XmlNode timeStampNode = XmlHelperFunctions.GetSubNode(invoice.DocumentElement, "fu:IssueDateTime"); if ((protectedIDNode == null) || (taxNumberNode == null) || (timeStampNode == null)) { this.BarCodeValue = string.Empty; } else { this.BarCodeValue = BarCodesHelpers.GenerateCode(protectedIDNode.InnerText, taxNumberNode.InnerText, Convert.ToDateTime(timeStampNode.InnerText), modulo); } }
public ReturnValue Send(XmlDocument message) { string root = message.DocumentElement.LocalName; XmlNode node = XmlHelperFunctions.GetSubNode(message.DocumentElement, "fu:InvoiceRequest"); if (string.Compare(root, "InvoiceRequest", true) == 0) { return(this.SendInvoice(message)); } if (string.Compare(root, "BusinessPremiseRequest", true) == 0) { return(this.SendBusinessPremise(message)); } if (string.Compare(root, "EchoRequest", true) == 0) { return(this.SendEcho(message)); } return(ReturnValue.Error(SendingStep.MessageReceived, null, "Neznani dokument / Unknown document")); }
public void Validate() { XmlHelperFunctions.Validate(this.MessageSendToFurs); }