-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeasure-performance-differences-between-file-based-and-stream-based-xml-export-for-large-barcode-configurations.cs
More file actions
84 lines (75 loc) · 4.12 KB
/
Copy pathmeasure-performance-differences-between-file-based-and-stream-based-xml-export-for-large-barcode-configurations.cs
File metadata and controls
84 lines (75 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Diagnostics;
using System.IO;
using Aspose.BarCode;
using Aspose.BarCode.Generation;
/// <summary>
/// Demonstrates exporting and importing barcode configuration to/from XML using Aspose.BarCode.
/// </summary>
class Program
{
/// <summary>
/// Entry point of the application. Generates a barcode, exports its configuration to XML,
/// measures export performance, and verifies import from both file and stream.
/// </summary>
static void Main()
{
// Define barcode type and content
BaseEncodeType type = EncodeTypes.Code128;
string codeText = "Sample1234567890";
// Create a barcode generator with the specified type and text
using (var generator = new BarcodeGenerator(type, codeText))
{
// Configure barcode appearance and generator settings to produce a sizable XML
generator.Parameters.Barcode.BarHeight.Point = 50f; // Height of the barcode
generator.Parameters.Barcode.XDimension.Point = 2f; // Width of the smallest bar
generator.Parameters.Barcode.IsChecksumEnabled = EnableChecksum.Yes; // Enable checksum
generator.Parameters.Barcode.Padding.Left.Point = 5f; // Left padding
generator.Parameters.Barcode.Padding.Top.Point = 5f; // Top padding
generator.Parameters.Barcode.Padding.Right.Point = 5f; // Right padding
generator.Parameters.Barcode.Padding.Bottom.Point = 5f; // Bottom padding
generator.Parameters.Resolution = 300f; // Image resolution (dpi)
generator.Parameters.AutoSizeMode = AutoSizeMode.None; // Disable auto‑sizing
string xmlFilePath = "barcodeConfig.xml";
// -------------------- Export to XML file --------------------
var swFile = Stopwatch.StartNew(); // Start timing file export
generator.ExportToXml(xmlFilePath); // Export configuration to file
swFile.Stop(); // Stop timing
// -------------------- Export to XML stream --------------------
long streamLength; // Will hold the size of the exported stream
var swStream = Stopwatch.StartNew(); // Start timing stream export
using (var ms = new MemoryStream())
{
generator.ExportToXml(ms); // Export configuration to memory stream
ms.Position = 0; // Reset position for reading
streamLength = ms.Length; // Capture stream length in bytes
}
swStream.Stop(); // Stop timing
// Output performance metrics
Console.WriteLine($"File export time: {swFile.ElapsedMilliseconds} ms");
Console.WriteLine($"Stream export time: {swStream.ElapsedMilliseconds} ms");
Console.WriteLine($"Exported stream size: {streamLength} bytes");
// -------------------- Import from XML file --------------------
using (var genFromFile = BarcodeGenerator.ImportFromXml(xmlFilePath))
{
// Import succeeded; no further action required for this demo
}
// -------------------- Import from XML stream --------------------
using (var msLoad = new MemoryStream())
{
// Re‑export to a new stream to simulate loading from stream
generator.ExportToXml(msLoad);
msLoad.Position = 0; // Reset for reading
using (var genFromStream = BarcodeGenerator.ImportFromXml(msLoad))
{
// Import succeeded; no further action required for this demo
}
}
}
// Remove the temporary XML file created during the demo
if (File.Exists("barcodeConfig.xml"))
{
File.Delete("barcodeConfig.xml");
}
}
}