-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathQbXmlRequest.cs
More file actions
88 lines (79 loc) · 2.62 KB
/
QbXmlRequest.cs
File metadata and controls
88 lines (79 loc) · 2.62 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
85
86
87
88
using QbSync.QbXml.Objects;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Serialization;
namespace QbSync.QbXml
{
/// <summary>
/// Base XML object which holds the request.
/// </summary>
public class QbXmlRequest
{
/// <summary>
/// Version used by QBXML.
/// </summary>
public static readonly Version VERSION = new Version(16, 0);
private readonly List<QBXMLMsgsRq> qbxmlMsgsRqList;
private readonly Version version;
/// <summary>
/// Creates a QbXmlRequest.
/// </summary>
public QbXmlRequest()
: this(VERSION)
{
qbxmlMsgsRqList = new List<QBXMLMsgsRq>();
}
/// <summary>
/// Creates a QbXmlRequest with a specific version.
/// </summary>
/// <param name="version">The requested QBXML version.</param>
public QbXmlRequest(Version version)
{
qbxmlMsgsRqList = new List<QBXMLMsgsRq>();
this.version = version;
}
/// <summary>
/// Adds a message.
/// </summary>
/// <param name="messages">The message.</param>
public void Add(params QBXMLMsgsRq[] messages)
{
qbxmlMsgsRqList.AddRange(messages);
}
/// <summary>
/// Adds requests to a single message.
/// </summary>
/// <param name="requests">The requests.</param>
public void AddToSingle(params object[] requests)
{
Add(new QBXMLMsgsRq
{
Items = requests
});
}
/// <summary>
/// Gets the XML request.
/// </summary>
/// <returns>XML.</returns>
public string GetRequest()
{
var qbXml = new QBXML
{
Items = qbxmlMsgsRqList.ToArray(),
ItemsElementName = Enumerable.Repeat(ItemsChoiceType106.QBXMLMsgsRq, qbxmlMsgsRqList.Count()).ToArray()
};
using var writer = new StringWriter();
using XmlWriter xmlWriter = new QbXmlTextWriter(writer);
xmlWriter.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\"");
xmlWriter.WriteProcessingInstruction("qbxml", string.Format("version=\"{0}.{1}\"", version.Major, version.Minor));
var ns = new XmlSerializerNamespaces();
ns.Add("", "");
QbXmlSerializer.Instance.XmlSerializer.Serialize(xmlWriter, qbXml, ns);
xmlWriter.Flush();
return writer.ToString();
}
}
}