Example #1
0
    public static string CreateSoapRegistrationQuery(string message, string taxRefNo, string messageId)
    {
        var sb = new StringBuilder();

        sb.Append(
            "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:esb=\"http://www.egovernment.gov.za/GMD/MessageIdentification/xml/schemas/version/7.1\">");
        sb.Append("<soap12:Header>");

        var header = new MessageIdentificationStructure
        {
            channelID            = "FDR",
            applicationID        = "EnquirePartyDetails",
            messageSeqNo         = DBReadManager.GetNextMessageId(messageId),
            messageTimeStamp     = DateTime.Now,
            externalReferenceID  = taxRefNo,
            originatingChannelID = "FDR",
            universalUniqueID    = messageId,
            versionNo            = Convert.ToSingle("3.3"),
            domain       = "PartyMgt",
            activityName = "Enquire Party Details",
            priority     = 9
        };

        var headerXml = Sars.Systems.Serialization.XmlObjectSerializer.GetXmlWithNoDeclaration(header);

        sb.Append(headerXml);

        sb.Append("</soap12:Header>");
        sb.Append("<soap12:Body>");
        sb.AppendFormat("{0}", message);
        sb.Append("</soap12:Body>");
        sb.Append("</soap12:Envelope>");
        return(sb.ToString());
    }
Example #2
0
        private void OutgoingFilePoll()
        {
            CancellationToken cancellation = cts.Token;
            TimeSpan          interval     = TimeSpan.Zero;

            while (!cancellation.WaitHandle.WaitOne(interval))
            {
                try
                {
                    //Get List of Approved outgoing CBCR's
                    var cbcr = DBReadManager.GetOutGoingCBCR(null, 0, 5);

                    //Loop through each approved CBCR and generate XML report
                    foreach (DataRow row in cbcr.Tables[0].Rows)
                    {
                        var outCBC = DatabaseReader.OutGoingCBCDeclarationsDetails(row["CountryCode"].ToString(), int.Parse(row["Period"].ToString()));

                        XmlDocument xmlDoc = new XmlDocument();
                        xmlDoc.LoadXml(outCBC.CBCData);

                        XmlNodeList    CBCxml = xmlDoc.GetElementsByTagName("CBC_OECD");
                        List <XmlNode> nodees = new List <XmlNode>(CBCxml.Cast <XmlNode>());

                        string cbcXML = nodees[0].OuterXml;

                        var    user  = Sars.Systems.Security.ADUser.SearchAdUsersBySid(outCBC.UpdatedBy);
                        string email = "";

                        if (user != null)
                        {
                            email = user[0].Mail;
                        }

                        //Begin CTS-SenderFileMetadata-1.0
                        CTSSenderFileMetadataType sender = new CTSSenderFileMetadataType();

                        sender.BinaryEncodingSchemeCdSpecified = true;
                        sender.FileCreateTsSpecified           = true;
                        sender.FileFormatCdSpecified           = true;
                        sender.FileRevisionIndSpecified        = true;

                        sender.BinaryEncodingSchemeCd = BinaryEncodingSchemeCdType.NONE;
                        sender.CTSCommunicationTypeCd = CTSCommunicationTypeCdType.CBCStatus;
                        sender.CTSReceiverCountryCd   = (CountryCode_Type)System.Enum.Parse(typeof(CountryCode_Type), row["CountryCode"].ToString());
                        sender.CTSSenderCountryCd     = (CountryCode_Type)System.Enum.Parse(typeof(CountryCode_Type), "ZA");
                        sender.SenderFileId           = "";
                        sender.FileFormatCd           = FileFormatCdType.XML;
                        sender.FileCreateTs           = DateTime.Now;
                        sender.TaxYear                      = row["Period"].ToString();
                        sender.FileRevisionInd              = false;
                        sender.OriginalCTSTransmissionId    = "";
                        sender.SenderContactEmailAddressTxt = email;

                        XmlSerializer xsSer = new XmlSerializer(typeof(CTSSenderFileMetadataType));

                        var settings = new XmlWriterSettings();
                        settings.Indent             = true;
                        settings.OmitXmlDeclaration = true;

                        string senderMetaDataXML;

                        using (var sww = new StringWriter())
                        {
                            using (XmlWriter writer = XmlWriter.Create(sww, settings))
                            {
                                xsSer.Serialize(writer, sender);

                                senderMetaDataXML = sww.ToString();
                            }
                        }
                        //End CTS-SenderFileMetadata-1.0

                        //Begin SARSStatusManagementV1.15
                        //StatusManagementRequest

                        //StatusManagementRequestStructure req = new StatusManagementRequestStructure();

                        //req.StatusDetails = new StatusStructure() { Description = "", Status = "" };
                        //req.DataType = "";
                        //req.TaxType = TypeOfTaxType.INCOME_TAX;
                        //req.TaxDateRange = new TaxDateRangeStructure() { FromTaxDate = DateTime.Now, ToTaxDate = DateTime.Now };
                        //req.TaxPeriodRange = new TaxPeriodRangeStructure() { FromTaxPeriod = "", ToTaxPeriod = "" };
                        //req.TaxYearRange = new TaxYearRangeStructure() { FromTaxYear = "", ToTaxYear = "" };
                        //req.SubReference = new SubReferenceStructure() { Type = SubReferenceStructureType.FORM_ID, Value = "" };
                        //req.Reference = new ReferenceStructure() { Identifier = ReferenceStructureIdentifier.TAX_REF_NO, Value = new[] { "", "", "" } };
                        //req.SourceChannel = "";
                        //req.RequestOperation = RequestOperationType.UPDATE_STATUS;

                        //XmlSerializer xsSerReq = new XmlSerializer(typeof(StatusManagementRequestStructure));
                        //string requestXML;

                        //using (var sww = new StringWriter())
                        //{
                        //    using (XmlWriter writer = XmlWriter.Create(sww, settings))
                        //    {
                        //        xsSerReq.Serialize(writer, req);

                        //        requestXML = sww.ToString();
                        //    }
                        //}

                        ////End SARSStatusManagementV1.15

                        //var str = string.Format("{0}{1}", cbcXML, senderMetaDataXML);
                        string zipFilename = row["CountryCode"].ToString() + "_FDR_" + DateTime.Now.ToString("yyyyMMddTHHmmssZ") + ".zip";
                        using (ZipFile zip = new ZipFile())
                        {
                            zip.AddEntry("ZA_CBC_Metadata.xml", senderMetaDataXML);
                            zip.AddEntry("ZA_CBC_Payload.xml", cbcXML);
                            zip.Save(path + "\\Outgoing\\" + zipFilename);//location and name for creating zip file
                        }

                        //XmlTypeMapping myTypeMapping = new SoapReflectionImporter().ImportTypeMapping(typeof(CountryByCountryReportManagementRequest));

                        var subReq = new CountryByCountryReportManagementRequestStructure();

                        subReq.RequestOperation          = CountryByCountryReportManagementRequestStructureRequestOperation.SUBMIT_REPORT;
                        subReq.RequestOperationSpecified = true;
                        subReq.Destination = row["CountryCode"].ToString();
                        subReq.Filename    = zipFilename;
                        subReq.FileContent = EncodeToBase64(path + "\\Outgoing\\" + zipFilename);

                        //*******************************************
                        var xml = Sars.Systems.Serialization.XmlObjectSerializer.GetXmlWithNoDeclaration(subReq, "cbcMgt", "http://www.sars.gov.za/enterpriseMessagingModel/CountryByCountryReportManagement/xml/schemas/version/1.2");

                        var xmlBuilder = new StringBuilder();
                        xmlBuilder.Append(
                            "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> " +
                            "<soap12:Envelope xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\" " +
                            "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
                            "xmlns:esb=\"http://www.egovernment.gov.za/GMD/MessageIdentification/xml/schemas/version/7.1\">"

                            );

                        var uid    = Guid.NewGuid().ToString();
                        var header = new MessageIdentificationStructure();
                        header.domain = "CBC Financial Data Reporting";
                        header.originatingChannelID = "FDR";
                        header.externalReferenceID  = zipFilename;
                        header.priority             = 6;
                        header.channelID            = "FDR";
                        header.applicationID        = "SubmitCBCReport";
                        header.versionNo            = (float)1.2;
                        header.activityName         = "Submit CBC Report";
                        header.messageSeqNo         = DBReadManager.GetNextMessageId(uid);
                        header.messageTimeStamp     = DateTime.Now;
                        header.universalUniqueID    = uid;

                        var headerXml = Sars.Systems.Serialization.XmlObjectSerializer.GetXmlWithNoDeclaration(header, "esb", "http://www.egovernment.gov.za/GMD/MessageIdentification/xml/schemas/version/7.1");

                        xmlBuilder.AppendFormat(
                            "<soap12:Header xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">" +
                            "{0}" +
                            "</soap12:Header>" +
                            " <soap12:Body>" +
                            "{1}" +
                            "</soap12:Body>" +
                            "</soap12:Envelope>",
                            headerXml,
                            xml
                            );


                        string myXML = FormatXml(xmlBuilder.ToString());

                        XmlDocument doc = new XmlDocument();

                        doc.LoadXml(myXML);

                        doc.Save(string.Format("{0}\\Outgoing\\OutgoingCBCR_{1}.xml", path, row["CountryCode"].ToString()));

                        try
                        {
                            PutFile(queueNameReq, File.ReadAllBytes(string.Format("{0}\\Outgoing\\OutgoingCBCR_{1}.xml", path, row["CountryCode"].ToString())));
                            DatabaseWriter.ApproveOutgoingCBC(row["CountryCode"].ToString(), int.Parse(row["Period"].ToString()), 6, "0");
                            eventLog1.WriteEntry("File " + uid + " sent to que.");
                        }
                        catch (MQException mqe)
                        {
                            interval = TimeSpan.FromSeconds(5);
                            eventLog1.WriteEntry(string.Format("MQException caught: {0} - {1}", mqe.ReasonCode, mqe.Message), EventLogEntryType.Error);
                            eventLog1.WriteEntry(mqe.StackTrace, EventLogEntryType.Error);
                        }
                    }

                    // Occasionally check the cancellation state.
                    if (cancellation.IsCancellationRequested)
                    {
                        break;
                    }

                    interval = TimeSpan.FromSeconds(15);
                }
                catch (Exception caught)
                {
                    eventLog1.WriteEntry(string.Format("Exception caught (OutgoingFilePoll): {0}", caught.Message), EventLogEntryType.Error);
                    eventLog1.WriteEntry(caught.StackTrace, EventLogEntryType.Error);
                    interval = TimeSpan.FromSeconds(30);
                }
            }
        }