public override bool Export(ReportLogger reportLogger) { _reportLogger = reportLogger; SetupExport(); int stepId = reportLogger.AddStep(); try { FileInfo fileInfo = new FileInfo(PathAndFileName); FileInfo serverPathAndFile = new FileInfo(_serverPath + fileInfo.Name); FileInfo serverPath = new FileInfo(_serverPath); FileInfo tempDirectory = new FileInfo(_serverPath + @"Temp\"); string filename = fileInfo.Name.Split('.')[0]; XmlExport(fileInfo); if (File.Exists(serverPathAndFile.FullName)) { File.Delete(serverPathAndFile.FullName); } File.Move(tempDirectory + filename + _extension, serverPathAndFile.FullName); if (CoreDataLib.IsLive()) { if (ExportItem.ExportItemFtpId > 0) { FileFtp.FtpFile(serverPathAndFile, reportLogger, ExportItem); } } reportLogger.EndStep(stepId); } catch (Exception exception) { _reportLogger.EndStep(stepId, exception); return(false); } return(true); }
private void CreateCsvFile(FileInfo tempDirectory, string filename, FileInfo fileInfo, StringBuilder headers, FileInfo serverPathAndFile, FileInfo serverPath, string languageEncoding) { int stepId = _csvExporteLogger.AddStep(); try { string line; if (File.Exists(tempDirectory + filename + TEMPFILE_APPENDING)) { File.Delete(tempDirectory + filename + TEMPFILE_APPENDING); } StreamWriter writer = null; StreamReader reader = null; FileStream fs = new FileStream(tempDirectory + fileInfo.Name, FileMode.Open); FileStream outStream = new FileStream(tempDirectory + filename + TEMPFILE_APPENDING, FileMode.Append); reader = new StreamReader(fs, Encoding.Default); string encoding = Get.GetLanguageEncoding(languageEncoding); if (String.IsNullOrEmpty(encoding)) { writer = new StreamWriter(outStream, Encoding.GetEncoding("windows-1252")); } else { writer = new StreamWriter(outStream, Encoding.GetEncoding(encoding)); } if (headers.Length > 0) { writer.WriteLine(headers); } string[] stringSeperators = { "(!!!!!!!!!!)" }; string[] fieldSeperators = { "!|!" }; string lastEntry = ""; while ((line = reader.ReadLine()) != null) { string[] lines = line.Split(stringSeperators, StringSplitOptions.RemoveEmptyEntries); if (lines.Length > 0) { for (int i = 0; i <= lines.Length - 1; i++) { if (lines[i].Split(fieldSeperators, StringSplitOptions.None).Length - 1 == headers.ToString().Split('|').Length - 1) { string row = lines[i].Replace("!|!", "|"); writer.WriteLine(row); } else { lastEntry = lastEntry + lines[i]; if (lastEntry.Split(fieldSeperators, StringSplitOptions.None).Length - 1 == headers.ToString().Split('|').Length - 1) { lastEntry = lastEntry.Replace("!|!", "|"); writer.WriteLine(lastEntry); lastEntry = ""; } } } } } writer.Flush(); reader.Close(); writer.Close(); File.Delete(tempDirectory + fileInfo.Name); if (File.Exists(serverPathAndFile.FullName)) { File.Delete(serverPathAndFile.FullName); } File.Move(tempDirectory + filename + TEMPFILE_APPENDING, serverPathAndFile.FullName); File.Delete(tempDirectory + filename + TEMPFILE_APPENDING); if (CoreDataLib.IsLive()) { if (ExportItem.ExportItemFtpId > 0) { FileFtp.FtpFile(serverPathAndFile, _csvExporteLogger, ExportItem); } //FtpExportedFile(pathAndFileToFtp); } _csvExporteLogger.EndStep(stepId); } catch (Exception exception) { _csvExporteLogger.EndStep(stepId, exception); } }