Example #1
0
        /// <summary>
        /// Serializes Auditfile
        /// </summary>
        /// <param name="auditfile">The auditfile object to serialize</param>
        /// <param name="filePath">The path where the file will be written</param>
        /// <param name="compression">Optional: When true file will be compressed into Zip file. Default: false</param>
        public static void Serialize(Auditfile.auditfile auditfile, string filePath, bool compression = false)
        {
            var xmlFile = new FileInfo(filePath);
            var xml     = new XmlSerializer(typeof(Auditfile.auditfile));

            if (compression)
            {
                var zipFile = new FileInfo("SAF-T Export_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".zip");
                using (FileStream zipStream = zipFile.Open(FileMode.Create))
                {
                    using (ZipArchive zip = new ZipArchive(zipStream, ZipArchiveMode.Create))
                    {
                        ZipArchiveEntry entry = zip.CreateEntry(xmlFile.Name);
                        using (var writer = new StreamWriter(entry.Open()))
                        {
                            xml.Serialize(writer, auditfile);
                        }
                    }
                }
            }
            else
            {
                using (TextWriter writer = new StreamWriter(xmlFile.Open(FileMode.Create)))
                {
                    xml.Serialize(writer, auditfile);
                }
            }
        }
Example #2
0
 /// <summary>
 /// Generates a filename string according to spec.
 /// </summary>
 /// <param name="auditfile">Auditfile object to get Organization Number from</param>
 /// <param name="currentFile">Optional: Current file of Multi-File export</param>
 /// <param name="totalFiles">Optional: Total files in Multi-File export</param>
 /// <returns>Generated filename string</returns>
 public static string MakeFilename(Auditfile.auditfile auditfile, int currentFile = 1, int totalFiles = 1)
 {
     return(MakeFilename(auditfile.company.companyIdent, currentFile, totalFiles));
 }