Exemplo n.º 1
0
        public bool Validate(ns2BilanzdatenTyp elbaInformation)
        {
            ResultMessages.Clear();

            XmlNode instanceNode = elbaInformation.Abschluss.First()?.Daten.XbrlAbschlussdaten.XBRL.Any.FirstOrDefault();

            if (instanceNode == null)
            {
                ResultMessages.Add(new RequestResultMessage("Es konnte keine XBRL-Instanz gefunden werden.", MessageId));
                return(IsValid);
            }

            XmlNamespaceManager    namespaceManager = BalanceInformation.SetupNamespaceManager(instanceNode.OwnerDocument);
            ns2BilanzdatenTypKunde kunde            = elbaInformation.Kunde;

            CompareValues(instanceNode, namespaceManager, CompanyNameConcept, kunde.Name, "Name (Kunde)");
            CompareValues(instanceNode, namespaceManager, CompanyCountryConcept, kunde.Adresse.Land, "Land (Kunde)");
            if (kunde.Adresse.Hausanschrift != null)
            {
                CompareValues(instanceNode, namespaceManager, CompanyCityConcept, kunde.Adresse.Hausanschrift.Ort,
                              "Ort (Kunde Hausanschrift)");
                CompareValues(instanceNode, namespaceManager, CompanyZipCodeConcept, kunde.Adresse.Hausanschrift.PLZ,
                              "PLZ (Kunde Hausanschrift)");
                ValidateAddress(instanceNode, namespaceManager, kunde.Adresse.Hausanschrift.Strasse_Hausnummer.Trim());
            }

            return(IsValid);
        }
Exemplo n.º 2
0
 public RequestValidator(ns2BilanzdatenTyp elbaData)
     : this()
 {
     Absender   = elbaData.Absender;
     Empfaenger = elbaData.Empfaenger;
     Kunde      = elbaData.Kunde;
     Abschluss  = elbaData.Abschluss.FirstOrDefault();
 }
Exemplo n.º 3
0
        public ns2BilanzdatenTyp ToElbaData()
        {
            ns2BilanzdatenTyp balanceData = new ns2BilanzdatenTyp
            {
                Absender   = SenderInformation.ToElbaData(),
                Empfaenger = RecieverInformation.ToElbaData(),
                Kunde      = CustomerInformation.ToElbaData(),
                Abschluss  = new ns2AbschlussTyp[BalanceInformation.Count]
            };

            for (int i = 0; i < BalanceInformation.Count; i++)
            {
                balanceData.Abschluss[i] = BalanceInformation[i].ToElbaData();
            }

            return(balanceData);
        }
Exemplo n.º 4
0
        public RequestResult SendData(Software channelSoftware, bool isTest = false)
        {
            if (!IfpClientSettings.IsAutoDownloadRoutingTableFileDisabled)
            {
                var baseSettingsDirPath = new FileInfo(_ifpSettingsFilePath).DirectoryName;
                var downloadedRemoteFileLastWriteDate = IfpClientSettings.RemoteDownloadInstituteMappingTestFileLastWriteDate;
                if (!isTest)
                {
                    downloadedRemoteFileLastWriteDate = IfpClientSettings.RemoteDownloadInstituteMappingProdFileLastWriteDate;
                }

                var mappingFilePath = RoutingTableReader.DownloadInstituteMappingFileFromSftpServerIfNewer(
                    IfpClientSettings.SftpSchufaFilesUserName,
                    IfpClientSettings.SftpSchufaFilesPassword,
                    isTest,
                    baseSettingsDirPath,
                    downloadedRemoteFileLastWriteDate,
                    out var remoteFileLastWriteDate,
                    HttpProxySettings.HttpProxyAddresUri,
                    HttpProxySettings.UserName,
                    HttpProxySettings.Password
                    );

                if (remoteFileLastWriteDate.HasValue)
                {
                    IfpClientSettings.RoutingTableFilePath = mappingFilePath;
                    if (isTest)
                    {
                        IfpClientSettings.RemoteDownloadInstituteMappingTestFileLastWriteDate = remoteFileLastWriteDate;
                    }
                    else
                    {
                        IfpClientSettings.RemoteDownloadInstituteMappingProdFileLastWriteDate = remoteFileLastWriteDate;
                    }

                    IfpClientSettings.Save();
                }
            }

            RoutingTableReader.Read(IfpClientSettings.RoutingTableFilePath);

            if (RoutingTableReader.Mappings == null)
            {
                throw new NullReferenceException("Die Routing-Tabelle konnte nicht ausgelesen werden. " +
                                                 "Bitte überprüfen Sie in den allgemeinen Einstellungen, " +
                                                 "ob der Pfad zur Mappingdatei korrekt gesetzt wurde.");
            }

            if (!ElbaInformation.BalanceInformation.Any() ||
                ElbaInformation.BalanceInformation.First().GetFirstXmlDocument() == null)
            {
                throw new NullReferenceException("Keine XBRL-Datei zum Übermitteln gefunden. " +
                                                 "Bitte geben Sie unter den Abschlussinformationen eine XBRL-Instanz an.");
            }

            ns2BilanzdatenTyp elbaData = ElbaInformation.ToElbaData();

            if (!elbaData.Abschluss.Any())
            {
                throw new ArgumentException("Es wurden keine Abschlüsse zum Übermiteln gefudnen. " +
                                            "Bitte geben Sie mindestens einen Abschluss an.");
            }

            if (IfpClientSettings.ValidateIfpData)
            {
                RequestValidator validator = new RequestValidator(elbaData);
                validator.Validate();
                if (!validator.AnfrageBearbeitet)
                {
                    return(new RequestResult(validator.CreateQuittung(), true));
                }
            }

            if (IfpClientSettings.ValidateGcdData)
            {
                GcdDataValidator validator = new GcdDataValidator();
                if (!validator.Validate(elbaData))
                {
                    return(new RequestResult(validator.ResultMessages, true));
                }
            }

            IfpMapping recieverMapping = null;
            Version    recieverVersion = null;
            DateTime   date            = DateTime.Now.Date;
            string     taxonomyName    = elbaData.Abschluss.First().Taxonomie;

            foreach (IfpMapping mapping in RoutingTableReader.Mappings)
            {
                if (mapping.BLZ == ElbaInformation.RecieverInformation.BankId.Value &&
                    mapping.ValidFrom <= date &&
                    mapping.ValidTo >= date &&
                    mapping.Umgebung == UmgebungType.test == isTest)
                {
                    foreach (Version version in mapping.Version)
                    {
                        foreach (Taxonomie taxonomy in version.Taxonomie)
                        {
                            if (taxonomy.name == taxonomyName &&
                                (string.IsNullOrEmpty(taxonomy.Gueltig_ab) || DateTime.Parse(taxonomy.Gueltig_ab) <= date) &&
                                (string.IsNullOrEmpty(taxonomy.Gueltig_bis) || DateTime.Parse(taxonomy.Gueltig_bis) >= date))
                            {
                                recieverMapping = mapping;
                                recieverVersion = version;
                                break;
                            }
                        }
                    }
                }
            }

            if (recieverMapping == null)
            {
                throw new ArgumentException(
                          "In der Routing-Tabelle konnte kein Mapping " +
                          $"mit der Bank ID {ElbaInformation.RecieverInformation.BankId.Value} " +
                          $"und der Taxonomie {taxonomyName} gefunden werden." +
                          "Bitte überprüfen Sie, ob die angegebene Bank ID (BLZ) korrekt ist" +
                          "und ob die XBRL-Instanz mit einer unterstützten Taxonomieversion generiert wurde.");
            }

            if (recieverVersion == null)
            {
                throw new NullReferenceException("In der Routing-Tabelle konnte kein Eintrag " +
                                                 $"mit der Taxonomieversion '{Version}' gefunden werden. " +
                                                 "Bitte überprüfen Sie, ob die XBRL-Instanz " +
                                                 "mit einer unterstützen Taxonomieversion generiert wurde.");
            }

            elbaData.Abschluss.First().Software.Erstellung = new ns2SoftwareTyp
            {
                Name       = channelSoftware.Name,
                Hersteller = channelSoftware.Manufacturer,
                Version    = channelSoftware.Version,
                ID         = channelSoftware.Id
            };

            elbaData.Abschluss.First().Software.Versand = new ns2SoftwareTyp
            {
                Name       = channelSoftware.Name,
                Hersteller = channelSoftware.Manufacturer,
                Version    = channelSoftware.Version,
                ID         = channelSoftware.Id
            };

            ns3QuittungTyp quittung = Client.SendElbaData(channelSoftware.ToChannelData(), elbaData,
                                                          HeaderIdentity.ToElbaData(), recieverMapping, recieverVersion, HttpProxySettings, IfpClientSettings.CertificateSettings);

            return(new RequestResult(quittung));
        }
Exemplo n.º 5
0
        public RequestResult SendData(Software channelSoftware, bool isTest = false)
        {
            //if (RoutingTableReader.Mappings == null)
            RoutingTableReader.Read(IfpClientSettings.RoutingTableFilePath);

            if (RoutingTableReader.Mappings == null)
            {
                throw new NullReferenceException("Die Routing-Tabelle konnte nicht ausgelesen werden. " +
                                                 "Bitte überprüfen Sie in den allgemeinen Einstellungen, " +
                                                 "ob der Pfad zur Mappingdatei korrekt gesetzt wurde.");
            }

            if (!ElbaInformation.BalanceInformation.Any() ||
                ElbaInformation.BalanceInformation.First().GetFirstXmlDocument() == null)
            {
                throw new NullReferenceException("Keine XBRL-Datei zum Übermitteln gefunden. " +
                                                 "Bitte geben Sie unter den Abschlussinformationen eine XBRL-Instanz an.");
            }

            ns2BilanzdatenTyp elbaData = ElbaInformation.ToElbaData();

            if (!elbaData.Abschluss.Any())
            {
                throw new ArgumentException("Es wurden keine Abschlüsse zum Übermiteln gefudnen. " +
                                            "Bitte geben Sie mindestens einen Abschluss an.");
            }

            if (IfpClientSettings.ValidateIfpData)
            {
                RequestValidator validator = new RequestValidator(elbaData);
                validator.Validate();
                if (!validator.AnfrageBearbeitet)
                {
                    return(new RequestResult(validator.CreateQuittung(), true));
                }
            }

            if (IfpClientSettings.ValidateGcdData)
            {
                GcdDataValidator validator = new GcdDataValidator();
                if (!validator.Validate(elbaData))
                {
                    return(new RequestResult(validator.ResultMessages, true));
                }
            }

            IfpMapping recieverMapping = null;
            Version    recieverVersion = null;
            DateTime   date            = DateTime.Now.Date;
            string     taxonomyName    = elbaData.Abschluss.First().Taxonomie;

            foreach (IfpMapping mapping in RoutingTableReader.Mappings)
            {
                if (mapping.BLZ == ElbaInformation.RecieverInformation.BankId.Value &&
                    mapping.ValidFrom <= date &&
                    mapping.ValidTo >= date &&
                    mapping.Umgebung == UmgebungType.test == isTest)
                {
                    foreach (Version version in mapping.Version)
                    {
                        foreach (Taxonomie taxonomy in version.Taxonomie)
                        {
                            if (taxonomy.name == taxonomyName &&
                                (string.IsNullOrEmpty(taxonomy.Gueltig_ab) || DateTime.Parse(taxonomy.Gueltig_ab) <= date) &&
                                (string.IsNullOrEmpty(taxonomy.Gueltig_bis) || DateTime.Parse(taxonomy.Gueltig_bis) >= date))
                            {
                                recieverMapping = mapping;
                                recieverVersion = version;
                                break;
                            }
                        }
                    }
                }
            }

            if (recieverMapping == null)
            {
                throw new ArgumentException(
                          "In der Routing-Tabelle konnte kein Mapping " +
                          $"mit der Bank ID {ElbaInformation.RecieverInformation.BankId.Value} " +
                          $"und der Taxonomie {taxonomyName} gefunden werden." +
                          "Bitte überprüfen Sie, ob die angegebene Bank ID (BLZ) korrekt ist" +
                          "und ob die XBRL-Instanz mit einer unterstützten Taxonomieversion generiert wurde.");
            }

            if (recieverVersion == null)
            {
                throw new NullReferenceException("In der Routing-Tabelle konnte kein Eintrag " +
                                                 $"mit der Taxonomieversion '{Version}' gefunden werden. " +
                                                 "Bitte überprüfen Sie, ob die XBRL-Instanz " +
                                                 "mit einer unterstützen Taxonomieversion generiert wurde.");
            }

            ns3QuittungTyp quittung = Client.SendElbaData(channelSoftware.ToChannelData(), elbaData,
                                                          HeaderIdentity.ToElbaData(), recieverMapping, recieverVersion, HttpProxySettings, IfpClientSettings.CertificateSettings);

            return(new RequestResult(quittung));
        }
Exemplo n.º 6
0
        public ns3QuittungTyp SendElbaData(ns1ChannelHeaderTyp channel, ns2BilanzdatenTyp bilanzdaten,
                                           ns1IdentityHeaderTyp identity, Mapping mapping, Version version, HttpProxySettings httpProxySettings,
                                           CertificateSettings certificateSettings)
        {
            try
            {
                ns1ProtocolHeaderTyp protocol = new ns1ProtocolHeaderTyp();
                protocol.version = "IFP_1.6";
                protocol.engine  = "Apache CXF 3.1.4";

                ns1ServiceHeaderTyp service = new ns1ServiceHeaderTyp();
                service.name    = "BilanzdatenELBA";
                service.version = version.name;
                service.method  = "uebernehmeElbaDaten";

                ns1SessionHeaderTyp session = new ns1SessionHeaderTyp();

                ns1TargetHeaderTyp target = new ns1TargetHeaderTyp();
                target.institute    = new ns1TargetHeaderTypInstitute();
                target.institute.id = mapping.BLZ;
                target.provider     = mapping.IFPID;

                ns1TicketHeaderTyp ticket = new ns1TicketHeaderTyp();
                DateTime           time   = DateTime.Now;

                ticket.value =
                    $"{identity.provider}{time.Year.ToString("d4")}{time.Month.ToString("d2")}{time.Day.ToString("d2")}{time.Hour.ToString("d2")}{time.Minute.ToString("d2")}{time.Second.ToString("d2")}";

                IWebProxy webProxy  = WebRequest.DefaultWebProxy;
                WebProxy  httpProxy = null;

                if (httpProxySettings.ProxyMode == HttpProxySettings.HttpProxyMode.OwnProxy)
                {
                    httpProxy = new WebProxy(httpProxySettings.HttpProxyAddresUri);
                    httpProxy.UseDefaultCredentials = false;
                    httpProxy.Credentials           = new NetworkCredential(httpProxySettings.UserName, httpProxySettings.Password);
                    webProxy = httpProxy;
                }
                else if (httpProxySettings.ProxyMode == HttpProxySettings.HttpProxyMode.SystemProxy)
                {
                    httpProxy             = new WebProxy();
                    httpProxy.Credentials = CredentialCache.DefaultNetworkCredentials;
                    webProxy = httpProxy;
                }

                WebRequest.DefaultWebProxy = webProxy;

                _elbaClient = new BilanzdatenELBAPortTypeClient("BilanzdatenELBAPortTestCertSecurityProfileStandardEndpoint");

                var behavior = _elbaClient.Endpoint.Behaviors.Find <ClientCredentials>();
                behavior.ClientCertificate.SetCertificate(certificateSettings.StoreLocation, certificateSettings.StoreName, certificateSettings.FindType, certificateSettings.FindValue);

                if (behavior.ServiceCertificate.DefaultCertificate == null)
                {
                    behavior.ServiceCertificate.SetDefaultCertificate(certificateSettings.StoreLocation, certificateSettings.StoreName, certificateSettings.FindType, certificateSettings.FindValue);
                }

                _elbaClient.Endpoint.Address = new EndpointAddress(new Uri(version.URL), EndpointIdentity.CreateDnsIdentity(behavior.ServiceCertificate.DefaultCertificate.GetNameInfo(X509NameType.SimpleName, false)));

                ns3QuittungTyp quittung = _elbaClient.uebernehmeElbaDaten(
                    channel,
                    identity,
                    ref protocol,
                    service,
                    ref session,
                    ref target,
                    ref ticket,
                    bilanzdaten);

                _elbaClient.Close();

                return(quittung);
            }
            catch (Exception)
            {
                if (_elbaClient != null)
                {
                    if (_elbaClient.State == CommunicationState.Faulted)
                    {
                        _elbaClient.Abort();
                        _elbaClient.ChannelFactory.Abort();
                    }
                    else if (_elbaClient.State != CommunicationState.Opened)
                    {
                        _elbaClient.Close();
                        _elbaClient.ChannelFactory.Close();
                    }
                }

                throw;
            }
        }
Exemplo n.º 7
0
        public ns3QuittungTyp SendElbaData(ns1ChannelHeaderTyp channel, ns2BilanzdatenTyp bilanzdaten,
                                           ns1IdentityHeaderTyp identity, Mapping mapping, Version version, HttpProxySettings httpProxySettings,
                                           CertificateSettings certificateSettings)
        {
            try
            {
                ns1ProtocolHeaderTyp protocol = new ns1ProtocolHeaderTyp();
                protocol.version = "IFP_1.6";
                protocol.engine  = "Apache CXF 3.1.4";

                ns1ServiceHeaderTyp service = new ns1ServiceHeaderTyp();
                service.name    = "BilanzdatenELBA";
                service.version = version.name;
                service.method  = "uebernehmeELBADaten";

                ns1SessionHeaderTyp session = new ns1SessionHeaderTyp();

                ns1TargetHeaderTyp target = new ns1TargetHeaderTyp();
                target.institute    = new ns1TargetHeaderTypInstitute();
                target.institute.id = mapping.BLZ;
                target.provider     = mapping.IFPID;

                ns1TicketHeaderTyp ticket = new ns1TicketHeaderTyp();
                DateTime           time   = DateTime.Now;
                string             ifpId  = "IFP999nnnn";
                ticket.value =
                    $"{ifpId}_{time.Year.ToString("d4")}{time.Month.ToString("d2")}{time.Day.ToString("d2")}{time.Hour.ToString("d2")}{time.Minute.ToString("d2")}{time.Second.ToString("d2")}";

                WSHttpBinding binding = new WSHttpBinding {
                    ReceiveTimeout = new TimeSpan(0, 0, 1, 0)
                };
                binding.Security.Mode = SecurityMode.TransportWithMessageCredential;
                binding.Security.Message.ClientCredentialType   = MessageCredentialType.Certificate;
                binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;

                WebProxy httpProxy = null;
                if (httpProxySettings.ProxyMode == HttpProxySettings.HttpProxyMode.OwnProxy)
                {
                    httpProxy = new WebProxy(httpProxySettings.ProxyAddresUri);
                    httpProxy.UseDefaultCredentials = false;
                    httpProxy.Credentials           = new NetworkCredential(httpProxySettings.UserName, httpProxySettings.Password);
                    binding.UseDefaultWebProxy      = false;
                }
                else if (httpProxySettings.ProxyMode == HttpProxySettings.HttpProxyMode.SystemProxy)
                {
                    httpProxy                  = new WebProxy();
                    httpProxy.Credentials      = CredentialCache.DefaultNetworkCredentials;
                    binding.UseDefaultWebProxy = true;
                }

                WebRequest.DefaultWebProxy = httpProxy;

                EndpointAddress address = new EndpointAddress(version.URL);
                _client = new BilanzdatenELBAPortTypeClient(binding, address);
                _client.ClientCredentials.ClientCertificate.SetCertificate(certificateSettings.StoreLocation,
                                                                           certificateSettings.StoreName, certificateSettings.FindType, certificateSettings.FindValue);
                _client.ClientCredentials.ServiceCertificate.SetDefaultCertificate(certificateSettings.StoreLocation,
                                                                                   certificateSettings.StoreName, certificateSettings.FindType, certificateSettings.FindValue);

                ElbaEndpointBehavior endpointBehavior = new ElbaEndpointBehavior();

#if DEBUG
                endpointBehavior.IsDebugMode = true;
#endif

                _client.Endpoint.EndpointBehaviors.Add(endpointBehavior);

                X509Certificate2 certificate = null;
                X509Store        store       = new X509Store(certificateSettings.StoreName, certificateSettings.StoreLocation);
                store.Open(OpenFlags.ReadOnly);
                X509Certificate2Collection certificates = store.Certificates.Find(certificateSettings.FindType, certificateSettings.FindValue, false);
                store.Close();
                if (certificates.Count > 0)
                {
                    certificate = certificates[0];
                }
                else
                {
                    throw new ArgumentException($"No certificate found using the following settings: {certificateSettings}");
                }

                X509SecurityToken token = new X509SecurityToken(certificate);

                ns3QuittungTyp quittung = _client.uebernehmeElbaDaten(
                    channel,
                    identity,
                    ref protocol,
                    service,
                    ref session,
                    ref target,
                    ref ticket,
                    bilanzdaten);

                _client.Close();
                return(quittung);
            }
            catch (Exception)
            {
                _client?.Close();
                throw;
            }
        }