using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Xml.Linq;
using System.Xml.Serialization;
using Virinco.WATS.Schemas.WSBF;
namespace Virinco.WATS.Schemas.Examples
{
public class WSBFExample
{
public WSBFExample()
{
// Create the BOM
BOM bom = CreateBOM();
// Convert BOM to XML
string bomXml = SerializeToXml(bom);
// Todo: Upload XML using WATS Rest API
}
///
/// Creates and returns the BOM list
///
///
public BOM CreateBOM()
{
BOM bom = new BOM() { Components = new List(), Partnumber = "100100", Revision = "1.0", Desc = "Product Description" };
bom.Components.Add(new BOMComponent() { Number = "100200", Rev = "1.0", Desc = "Article Description", FunctionBlock = "A", Qty = 2, QtySpecified = true, Ref = "A30;A31" });
bom.Components.Add(new BOMComponent() { Number = "100201", Rev = "1.1", Desc = "Article Description", FunctionBlock = "B", Qty = 2, QtySpecified = true, Ref = "A32;A34" });
return bom;
}
///
/// Converts the BOM object to XML
///
///
///
///
public static string SerializeToXml(T obj)
{
StringWriter sw = new StringWriter();
System.Xml.XmlWriterSettings xws = new System.Xml.XmlWriterSettings();
xws.Indent = false;
XmlSerializerNamespaces xsn = new XmlSerializerNamespaces();
xsn.Add("", "http://wats.virinco.com/schemas/WATS/wsbf");
System.Xml.XmlWriter wr = System.Xml.XmlWriter.Create(sw, xws);
XmlSerializer serializer = new XmlSerializer(typeof(T));
serializer.Serialize(wr, obj, xsn);
return sw.ToString();
}
}
}