Esempio n. 1
0
        private async Task <byte[]> CreateZip(IEnumerable <VouchersClient> vouchers)
        {
            var zippedMemoryStream = UnistreamReuse.Create();

            using (ZipOutputStream zipOutputStream = new ZipOutputStream(zippedMemoryStream))
            {
                // Highest compression rating
                zipOutputStream.SetLevel(9);
                busyIndicator.IsBusy = true;

                foreach (var voucher in vouchers)
                {
                    zippedMemoryStream.SecureSize();
                    if (voucher._Data == null)
                    {
                        await UtilDisplay.GetData(voucher, api);
                    }
                    byte[] attachment = voucher.Buffer;
                    zippedMemoryStream.SecureSize(attachment.Length);
                    // Write the data to the ZIP file
                    string name = string.Format("{0}_{1}.{2}", voucher.Text, voucher.RowId, Enum.GetName(typeof(FileextensionsTypes), voucher.Fileextension));
                    name = name.Replace("/", "-").Replace(@"\", "-");
                    ZipEntry entry = new ZipEntry(name);
                    zipOutputStream.PutNextEntry(entry);
                    zipOutputStream.Write(attachment, 0, attachment.Length);
                }
                busyIndicator.IsBusy = false;

                zipOutputStream.Finish();
            }
            return(zippedMemoryStream.ToArrayAndRelease());
        }
Esempio n. 2
0
        async private Task <ErrorCodes> ImportFromZipFile(BankImportFormatClient selectedbankFormat, SelectedFileInfo fileInfo, PostingAPI postingapi, bool append, DateTime fromDate, DateTime toDate)
        {
            var        zipContent      = new MemoryStream(fileInfo.FileBytes);
            var        zipFile         = new ZipFile(zipContent);
            ErrorCodes importZipResult = ErrorCodes.NoSucces;

            foreach (ZipEntry zipEntry in zipFile)
            {
                if (!zipEntry.IsFile)
                {
                    continue;
                }

                var bufferSize = (int)zipEntry.Size;
                var buffer     = UnistreamReuse.Create(bufferSize);
                var stream     = zipFile.GetInputStream(zipEntry);
                buffer.CopyFrom(stream);

                var zipFileInfo = new FileInfo(zipEntry.Name);
                importZipResult = await postingapi.ImportJournalLines(selectedbankFormat, buffer, append, fromDate, toDate);

                buffer.Release();

                if (importZipResult != ErrorCodes.Succes)
                {
                    break;
                }
            }

            return(importZipResult);
        }
        private byte[] ToBytes()
        {
            var memoryStream = UnistreamReuse.Create();
            var xmlWriter    = XmlWriter.Create(memoryStream);

            Document.WriteTo(xmlWriter);
            xmlWriter.Flush();
            xmlWriter.Close();

            return(memoryStream.ToArrayAndRelease());
        }
Esempio n. 4
0
        public byte[] CreatePkcs12(X509Certificate certificate, string password)
        {
            var store = new Pkcs12Store();
            var entry = new X509CertificateEntry(new X509CertificateParser().ReadCertificate(certificate.GetRawCertData()));

            store.SetKeyEntry("erp", new AsymmetricKeyEntry(asymmetricCipherKeyPair.Private), new[] { entry });
            var memoryStream = UnistreamReuse.Create();

            store.Save(memoryStream, password.ToCharArray(), SecureRandom);
            return(memoryStream.ToArrayAndRelease());
        }
        public Message ToMessage(XmlNode doc)
        {
            var memoryStream = UnistreamReuse.Create();
            var xmlWriter    = XmlWriter.Create(memoryStream);

            doc.WriteTo(xmlWriter);
            xmlWriter.Flush();
            xmlWriter.Close();

            memoryStream.Position = 0;
            var dictionaryReader = XmlDictionaryReader.CreateTextReader(memoryStream, new XmlDictionaryReaderQuotas());

            memoryStream.Release();
            return(Message.CreateMessage(dictionaryReader, int.MaxValue, originalMessage.Version));
        }
Esempio n. 6
0
        private byte[] CanonicalizeSignedInfo(XmlNode signatureElement)
        {
            var signedInfoNode = signatureElement.SelectSingleNode("ds:SignedInfo", Manager);
            var reader         = new XmlNodeReader(signedInfoNode);
            var stream         = UnistreamReuse.Create();
            var writer         = new XmlTextWriter(stream, Encoding.UTF8);

            writer.WriteNode(reader, false);
            writer.Flush();
            stream.Position = 0;
            var transform = new XmlDsigExcC14NTransform();

            transform.LoadInput(stream);
            stream.Release();

            var signedInfoStream = (Stream)transform.GetOutput();
            var signedBytes      = new byte[signedInfoStream.Length];

            signedInfoStream.Read(signedBytes, 0, signedBytes.Length);
            return(signedBytes);
        }
        public XmlDocument GetXmlDocument()
        {
            var xmlWriterSetting = new XmlWriterSettings {
                Encoding = Encoding.UTF8
            };
            var ms        = UnistreamReuse.Create();
            var xmlWriter = XmlWriter.Create(ms, xmlWriterSetting);

            var msgbuf = originalMessage.CreateBufferedCopy(int.MaxValue);

            msgbuf.CreateMessage().WriteMessage(xmlWriter);

            xmlWriter.Flush();
            ms.Flush();
            ms.Position = 0;

            var xml = new XmlDocument {
                PreserveWhitespace = true, XmlResolver = null
            };

            xml.Load(ms);
            ms.Release();
            return(xml);
        }
Esempio n. 8
0
        private string CDATAMvaOppgave(int year, int terminType, string termin)
        {
            XmlWriterSettings WriterSettings = new XmlWriterSettings {
                OmitXmlDeclaration = true, Indent = true, Encoding = new UTF8Encoding(false)
            };
            XmlSerializerNamespaces Namespaces = new XmlSerializerNamespaces(new[] { new XmlQualifiedName("", "") });

            string  returnData = string.Empty;
            melding mvaMelding = new melding();
            meldingMeldingsopplysning meldingsOppl      = new meldingMeldingsopplysning();
            meldingMvaAvgift          mvaAvgift         = new meldingMvaAvgift();
            meldingMvaGrunnlag        mvaGrunnlag       = new meldingMvaGrunnlag();
            meldingMvaSumAvgift       mvaSumAvgift      = new meldingMvaSumAvgift();
            meldingSkattepliktig      meldSkattepliktig = new meldingSkattepliktig();
            meldingTilleggsopplysning meldTilleggsOppl  = new meldingTilleggsopplysning();

            #region ID til meldingen
            mvaMelding.dataFormatId       = DATAFORMATID_VALUE;
            mvaMelding.dataFormatProvider = MELDING_DATAFORMATPROVIDER;
            mvaMelding.dataFormatVersion  = DATAFORMATVERSION_VALUE;
            mvaMelding.tjenesteType       = MVATJENESTETYPE_RF0002;
            #endregion

            #region Termin
            meldingsOppl.aar          = Convert.ToUInt16(year);
            meldingsOppl.meldingstype = MELDINGSTYPE_HOVED;
            meldingsOppl.termin       = termin;
            meldingsOppl.termintype   = terminType;
            #endregion

            #region Info om det som avgir oppgaven
            meldSkattepliktig.endretKontonummer = string.Empty;
            meldSkattepliktig.iban                = CompanyIBAN;
            meldSkattepliktig.ibanEndret          = string.Empty;
            meldSkattepliktig.KIDnummer           = string.Empty;
            meldSkattepliktig.kontonummer         = CompanyBBAN;
            meldSkattepliktig.organisasjonsnavn   = Comp._Name;
            meldSkattepliktig.organisasjonsnummer = getCompanyCVR();
            meldSkattepliktig.swiftBic            = CompanyBIC;
            meldSkattepliktig.swiftBicEndret      = string.Empty;
            meldTilleggsOppl.forklaring           = string.Empty;
            meldTilleggsOppl.forklaringSendt      = false;
            #endregion

            foreach (var rec in vatSumOperationLst)
            {
                switch (rec.Line)
                {
                case 1:
                    mvaGrunnlag.sumOmsetningUtenforMva = Math.Abs(Convert.ToInt32(rec.AmountBase));
                    break;

                case 2:
                    mvaGrunnlag.sumOmsetningInnenforMvaUttakOgInnfoersel = Math.Abs(Convert.ToInt32(rec.AmountBase));
                    break;

                case 3:
                    mvaGrunnlag.innlandOmsetningUttakHoeySats = Math.Abs(Convert.ToInt32(rec.AmountBase));
                    mvaAvgift.innlandOmsetningUttakHoeySats   = Math.Abs(Convert.ToInt32(rec.Amount));
                    break;

                case 4:
                    mvaGrunnlag.innlandOmsetningUttakMiddelsSats = Math.Abs(Convert.ToInt32(rec.AmountBase));
                    mvaAvgift.innlandOmsetningUttakMiddelsSats   = Math.Abs(Convert.ToInt32(rec.Amount));
                    break;

                case 5:
                    mvaGrunnlag.innlandOmsetningUttakLavSats = Math.Abs(Convert.ToInt32(rec.AmountBase));
                    mvaAvgift.innlandOmsetningUttakLavSats   = Math.Abs(Convert.ToInt32(rec.Amount));
                    break;

                case 6:
                    mvaGrunnlag.innlandOmsetningUttakFritattMva = Math.Abs(Convert.ToInt32(rec.AmountBase));
                    break;

                case 7:
                    mvaGrunnlag.innlandOmsetningOmvendtAvgiftsplikt = Math.Abs(Convert.ToInt32(rec.AmountBase));
                    break;

                case 8:
                    mvaGrunnlag.utfoerselVareTjenesteFritattMva = Math.Abs(Convert.ToInt32(rec.AmountBase));
                    break;

                case 9:
                    mvaGrunnlag.innfoerselVareHoeySats = Math.Abs(Convert.ToInt32(rec.AmountBase));
                    mvaAvgift.innfoerselVareHoeySats   = Math.Abs(Convert.ToInt32(rec.Amount));
                    break;

                case 10:
                    mvaGrunnlag.innfoerselVareMiddelsSats = Math.Abs(Convert.ToInt32(rec.AmountBase));
                    mvaAvgift.innfoerselVareMiddelsSats   = Math.Abs(Convert.ToInt32(rec.Amount));
                    break;

                case 11:
                    mvaGrunnlag.innfoerselVareFritattMva = Math.Abs(Convert.ToInt32(rec.AmountBase));
                    break;

                case 12:
                    mvaGrunnlag.kjoepUtlandTjenesteHoeySats = Math.Abs(Convert.ToInt32(rec.AmountBase));
                    mvaAvgift.kjoepUtlandTjenesteHoeySats   = Math.Abs(Convert.ToInt32(rec.Amount));

                    if (mvaGrunnlag.kjoepUtlandTjenesteHoeySats != 0 || mvaAvgift.kjoepUtlandTjenesteHoeySats != 0)
                    {
                        meldTilleggsOppl.forklaring      = "Avgift er beregnet med 10 % av grunnlaget";
                        meldTilleggsOppl.forklaringSendt = true;
                    }
                    else
                    {
                        meldTilleggsOppl.forklaring      = string.Empty;
                        meldTilleggsOppl.forklaringSendt = false;
                    }
                    break;

                case 13:
                    mvaGrunnlag.kjoepInnlandVareTjenesteHoeySats = Math.Abs(Convert.ToInt32(rec.AmountBase));
                    mvaAvgift.kjoepInnlandVareTjenesteHoeySats   = Math.Abs(Convert.ToInt32(rec.Amount));
                    break;

                case 14:
                    mvaAvgift.fradragInnlandInngaaendeHoeySats = Math.Abs(Convert.ToInt32(rec.Amount));
                    break;

                case 15:
                    mvaAvgift.fradragInnlandInngaaendeMiddelsSats = Math.Abs(Convert.ToInt32(rec.Amount));
                    break;

                case 16:
                    mvaAvgift.fradragInnlandInngaaendeLavSats = Math.Abs(Convert.ToInt32(rec.Amount));
                    break;

                case 17:
                    mvaAvgift.fradragInnfoerselMvaHoeySats = Math.Abs(Convert.ToInt32(rec.Amount));
                    break;

                case 18:
                    mvaAvgift.fradragInnfoerselMvaMiddelsSats = Math.Abs(Convert.ToInt32(rec.Amount));
                    break;

                case 19:
                    if (rec.AmountBase < 0)
                    {
                        mvaSumAvgift.aaBetale = Math.Abs(Convert.ToInt32(rec.Amount));
                    }
                    else
                    {
                        mvaSumAvgift.tilGode = Math.Abs(Convert.ToInt32(rec.Amount));
                    }
                    break;
                }
            }

            mvaMelding.mvaAvgift          = mvaAvgift;
            mvaMelding.mvaGrunnlag        = mvaGrunnlag;
            mvaMelding.mvaSumAvgift       = mvaSumAvgift;
            mvaMelding.meldingsopplysning = meldingsOppl;
            mvaMelding.tilleggsopplysning = meldTilleggsOppl;
            mvaMelding.skattepliktig      = meldSkattepliktig;
            var ms         = UnistreamReuse.Create();
            var writer     = XmlWriter.Create(ms, WriterSettings);
            var serializer = new XmlSerializer(mvaMelding.GetType());
            serializer.Serialize(writer, mvaMelding, Namespaces);
            return(Encoding.UTF8.GetString(ms.ToArrayAndRelease()));
        }