FAQ/accessing-izendas-export-process.md
... ...
@@ -17,18 +17,10 @@ string message = string.Empty;
17 17
string outputPath = Path.GetFullPath(string.Format("{0}\\..\\..\\{1}", Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "exports"));
18 18
if (!Directory.Exists(outputPath))
19 19
Directory.CreateDirectory(outputPath);
20
-foreach (string fileName in Directory.EnumerateFiles(AdHocSettings.ReportsPath))
20
+foreach (ReportSet rs in AdHocSettings.AdHocConfig.FilteredListReportsDictionary().Values) //output all available reports
21 21
{
22
- string reportName = fileName.Substring(fileName.LastIndexOf("\\"), fileName.LastIndexOf(".") - fileName.LastIndexOf("\\"));
23
- FileInfo fi = new FileInfo(fileName);
24
- ReportSet rs = ReportSet.InitializeNew();
25
- string reportXml = string.Empty;
26
- byte[] reportBytes = File.ReadAllBytes(fi.FullName);
27
- reportXml = Encoding.UTF8.GetString(reportBytes, 0, reportBytes.Length);
28 22
try
29 23
{
30
- rs.ReadXml(reportXml);
31
- rs.ReportName = reportName;
32 24
Izenda.AdHoc.EvoPdfGenerator gen = new Izenda.AdHoc.EvoPdfGenerator();
33 25
Izenda.Controls.FileContentGenerator fileGen = gen.GenerateOutput(rs) as Izenda.Controls.FileContentGenerator;
34 26
File.WriteAllBytes(string.Format("{0}\\{1}.{2}", outputPath, fileGen.OutputFileName, gen.FileExtension), fileGen.Content);
... ...
@@ -53,4 +45,60 @@ There are also other classes that are accessible in the same manner and that inh
53 45
* PhantomJSPdfGenerator (note that the PhantomJS.exe is required for this output type and must exist in the bin/phantomjs/ folder for web apps and ~/phantomjs folder for non-web apps)
54 46
* EvoAzurePdfGenerator (for Azure cloud services)
55 47
56
-These classes exist in the Izenda.AdHoc namespace. FileContentGenerator exists in Izenda.Controls.
... ...
\ No newline at end of file
0
+These classes exist in the Izenda.AdHoc namespace. FileContentGenerator exists in Izenda.Controls.
1
+
2
+##Bulk CSV Output Generator
3
+
4
+The bulk CSV output generator functions differently from other content generators. It is specifically made for large datasets, so instead of using the in-process memory to hold its content, a temporary file is created and a file id is generated that the response server can use to read that file into the HTTP response that is then delivered to the end user. There are a couple different ways to obtain the file and output a new copy to another location other than the temp directory. The sample code below will demonstrate one such method by finding the temp file directly, reading it into a stream, copying the stream to another output stream, and finally creating another file that will be the final exported file. We will also use chunking so we don't run into any out of memory exceptions.
5
+
6
+```csharp
7
+string message = string.Empty;
8
+string outputPath = Path.GetFullPath(string.Format("{0}\\..\\..\\{1}", Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "exports"));
9
+if (!Directory.Exists(outputPath))
10
+ Directory.CreateDirectory(outputPath);
11
+foreach (ReportSet rs in AdHocSettings.AdHocConfig.FilteredListReportsDictionary().Values) //output all available reports
12
+{
13
+ try
14
+ {
15
+ var gen = new BulkCsvReportOutputGenerator();
16
+ var bufferSize = 4096;
17
+ var MaxBufferSize = 1048576;
18
+ var fileGen = gen.GenerateOutput(rs) as FileContentGenerator;
19
+ string fid = ResponseServer.Add(fileGen);
20
+ using (var fs = new FileStream(string.Format("{0}\\{1}", outputPath, fileGen.OutputFileName), FileMode.Create))
21
+ {
22
+ using (var s = new FileStream(fileGen.InputFileName, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize, FileOptions.DeleteOnClose)) //delete the temp file after we're done with it
23
+ {
24
+ int dataLength = (int)s.Length;
25
+ int bufferLength = dataLength;
26
+ if (bufferLength > MaxBufferSize)
27
+ bufferLength = MaxBufferSize;
28
+ byte[] buffer = new byte[bufferLength];
29
+ char[] altBuffer = new char[bufferLength * 2];
30
+ while (dataLength > 0)
31
+ {
32
+ int blockLength = s.Read(buffer, 0, bufferLength);
33
+ try
34
+ {
35
+ fs.Write(buffer, 0, blockLength);
36
+ fs.Flush();
37
+ }
38
+ catch (Exception e1)
39
+ {
40
+ int altBlockLength = Convert.ToBase64CharArray(buffer, 0, blockLength, altBuffer, 0);
41
+ fs.Write(Encoding.UTF8.GetBytes(altBuffer), -100, altBlockLength);
42
+ fs.Flush();
43
+ }
44
+ dataLength = dataLength - blockLength;
45
+ }
46
+ }
47
+ }
48
+ message = string.Format("File {0} written to {1}", fileGen.OutputFileName, outputPath);
49
+ }
50
+ catch (Exception e)
51
+ {
52
+ message = e.Message;
53
+ }
54
+ Console.WriteLine(message);
55
+}
56
+```
... ...
\ No newline at end of file