本文整理汇总了C#中XmlSerializer.SerializeAsXElement方法的典型用法代码示例。如果您正苦于以下问题:C# XmlSerializer.SerializeAsXElement方法的具体用法?C# XmlSerializer.SerializeAsXElement怎么用?C# XmlSerializer.SerializeAsXElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlSerializer
的用法示例。
在下文中一共展示了XmlSerializer.SerializeAsXElement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSalesMonth
protected override string GetSalesMonth(ref XElement xmlResult, DateTime exportDate, string filename)
{
//access Magento store API
DynamicProxy proxy = GetSoapProxy(m_storeUrl + "/api/v2_soap/?wsdl", "Mage_Api_Model_Server_V2_HandlerPortType");
if (proxy == null)
throw new Exception("Unable to create SOAP proxy for Magento");
//login to get a session id
object resultObj = proxy.CallMethod("login", m_apiUserName, m_apiKey);
string sessionID = resultObj.ToString();
//Get API calls available
resultObj = proxy.CallMethod("resources", sessionID);
Type t = resultObj.GetType();
XmlSerializer xs = new XmlSerializer(t);
XElement resources = xs.SerializeAsXElement(resultObj);
//TODO: check each CallMethod to make sure it is in this list...
//Get the sales records for the requested month
DateTime start = new DateTime(exportDate.Year, exportDate.Month, 1);
DateTime end = start.AddMonths(1);
string result = filename + ": ";
StringBuilder data = new StringBuilder();
try
{
//sales_order.list salesOrderList
resultObj = proxy.CallMethod("salesOrderList", sessionID); //PROBLEM: this gets all orders, not just the ones for this month
t = resultObj.GetType();
xs = new XmlSerializer(t);
XElement orders = xs.SerializeAsXElement(resultObj);
foreach (XElement order in orders.Elements("salesOrderEntity"))
{
string orderID = Client.GetValue(order, "order_id");
string date = Client.GetValue(order, "created_at");
//Get order details sales_order.info salesOrderInfo
resultObj = proxy.CallMethod("salesOrderInfo", sessionID, orderID);
t = resultObj.GetType();
if (!t.Name.Equals("salesOrderInfo"))
throw new Exception("Illegal response from magento service");
xs = new XmlSerializer(t);
XElement orderInfo = xs.SerializeAsXElement(resultObj);
//salesOrderEntity orderInfo = (salesOrderEntity)resultObj;
string customerID = Client.GetValue(orderInfo, "customer_id"); //orderInfo.customer_id;
bool isGuest = Client.GetValue(orderInfo, "customer_is_guest").Equals("1");//orderInfo.customer_is_guest.Equals("1");
if (isGuest)
customerID = Client.GetValue(orderInfo, "customer_email"); //orderInfo.customer_email;
//foreach (salesOrderItemEntity item in orderInfo.items)
foreach (XElement items in orderInfo.Elements("items"))
foreach (XElement x in items.Elements("salesOrderItemEntity"))
{
string productID = Client.GetValue(x, "product_id"); //item.product_id;
string q = Client.GetValue(x, "qty_ordered");
int len = q.IndexOf(".");
if (len > 0)
q = q.Substring(0, len);
int quantity = Convert.ToInt32(q); //item.qty_ordered);
//TODO: add line to sales data here
}
}
//TODO: upload sales data (check that string has some data in it)
if (data.Length > 0)
result += m_boostService.UploadFileTo4Tell(filename, data, false);
}
catch (Exception ex)
{
string errMsg = "Error extracting catalog: " + ex.Message;
if (ex.InnerException != null)
errMsg += "\nInner Exception" + ex.InnerException.Message;
}
return result;
}
示例2: LogSalesOrder
public override void LogSalesOrder(string orderID)
{
StopWatch stopWatch = new StopWatch(true);
string result = "AutoSalesLog: ";
ProgressText = result + "Exporting single sale...";
XElement xmlResult = null;
try
{
//access Magento store API
DynamicProxy proxy = GetSoapProxy(m_storeUrl + "/api/v2_soap/?wsdl", "Mage_Api_Model_Server_V2_HandlerPortType");
if (proxy == null)
throw new Exception("Unable to create SOAP proxy for Magento");
//login to get a session id
object resultObj = proxy.CallMethod("login", m_apiUserName, m_apiKey);
string sessionID = resultObj.ToString();
//Get order details
resultObj = proxy.CallMethod("salesOrderInfo", sessionID, orderID);
Type t = resultObj.GetType();
if (!t.Name.Equals("salesOrderEntity"))
throw new Exception("Illegal response from magento service");
XmlSerializer xs = new XmlSerializer(t);
XElement orderInfo = xs.SerializeAsXElement(resultObj);
xmlResult = orderInfo;
//salesOrderEntity orderInfo = (salesOrderEntity)resultObj;
string customerID = Client.GetValue(orderInfo, "customer_id"); //orderInfo.customer_id;
bool isGuest = Client.GetValue(orderInfo, "customer_is_guest").Equals("1");//orderInfo.customer_is_guest.Equals("1");
if (isGuest)
customerID = Client.GetValue(orderInfo, "customer_email"); //orderInfo.customer_email;
//foreach (salesOrderItemEntity item in orderInfo.items)
foreach (XElement items in orderInfo.Elements("items"))
foreach (XElement x in items.Elements("salesOrderItemEntity"))
{
string productID = Client.GetValue(x, "product_id"); //item.product_id;
string q = Client.GetValue(x, "qty_ordered");
int len = q.IndexOf(".");
if (len > 0)
q = q.Substring(0, len);
int quantity = Convert.ToInt32(q); //item.qty_ordered);
string d = Client.GetValue(x, "created_at");
DateTime date = DateTime.Parse(d);
m_log.LogSingleSale(m_alias, customerID, productID, quantity, date);
}
result += "Complete";
}
catch (Exception ex)
{
string errMsg = ex.Message;
if (xmlResult != null)
{
errMsg += "\nMagento Result: ";
if (xmlResult.Name.LocalName.Equals("Error"))
{
if (xmlResult.Element("Id") != null)
{
errMsg += "Id = " + xmlResult.Element("Id");
if (xmlResult.Element("Description") != null)
errMsg += " Description = " + xmlResult.Element("Description");
}
else if (xmlResult.Value != null)
errMsg += xmlResult.Value;
}
else if (xmlResult.Value != null)
errMsg += xmlResult.Value;
}
if (ex.InnerException != null)
errMsg += "\nInner Exception: " + ex.InnerException.Message;
result = ProgressText + "\n" + errMsg;
}
finally
{
stopWatch.Stop();
result += "\nTotal Time: " + stopWatch.TotalTime;
ProgressText = result;
//m_log.WriteEntry(result, System.Diagnostics.EventLogEntryType.Information, m_alias);
}
}
示例3: ApiTest
protected string ApiTest(ref XElement xmlResult)
{
string h2 = "";
xmlResult = null;
StringBuilder data = null;
string filename = "ProductDetails.txt";
string result = "\n" + filename + ": ";
string tempDisplay = ProgressText;
ProgressText += result + "Rows to export...";
StopWatch exportWatch = new StopWatch(true);
#region Dynamic
{
//http://whitesalmontea.gostorego.com/api/v2_soap/?wsdl
DynamicProxy proxy = GetSoapProxy(m_storeUrl + "/api/v2_soap/?wsdl", "Mage_Api_Model_Server_V2_HandlerPortType");
if (proxy == null)
throw new Exception("Unable to create SOAP proxy for Magento");
//login to get a session id
object resultObj = proxy.CallMethod("login", m_apiUserName, m_apiKey);
string sessionID = resultObj.ToString();
Type t;
XmlSerializer xs;
//---------------------CATALOG EXPORT----------------------------
try
{
//Get catalog details
resultObj = proxy.CallMethod("resources", sessionID);
t = resultObj.GetType();
xs = new XmlSerializer(t);
XElement resources = xs.SerializeAsXElement(resultObj);
//TODO: check each CallMethod to make sure it is in this list...
//catalog_product.list catalogProductList
resultObj = proxy.CallMethod("catalog_product.list", sessionID);
t = resultObj.GetType();
xs = new XmlSerializer(t);
XElement products = xs.SerializeAsXElement(resultObj); //catalogProductEntity[]
foreach (XElement product in products.Elements("catalogProductEntity"))
{
string pid = "";
string pname = "";
string patt1 = "";
try
{
pid = Client.GetValue(product, "product_id");
pname = Client.GetValue(product, "name");
}
catch (Exception ex) { }
try
{
bool first = true;
foreach (XElement cat in product.Elements("category_ids"))
{
if (first) first = false;
else patt1 += ",";
patt1 += Client.GetValue(cat, "id");
}
}
catch (Exception ex) { }
XElement pinfo = null;
string pfilter = "";
string plink = "";
string psku = "";
string pimage = "";
try
{
plink = Client.GetValue(pinfo, "url_key");
psku = Client.GetValue(pinfo, "sku");
XElement pimageinfo = null;
//catalog_product_attribute_media.info catalogProductAttributeMediaInfo
resultObj = proxy.CallMethod("catalog_product_attribute_media.info", sessionID, pid, "", "", "id");
t = resultObj.GetType();
xs = new XmlSerializer(t);
pimageinfo = xs.SerializeAsXElement(resultObj); //catalogProductImageEntity
if (pimageinfo != null)
{
pimage = Client.GetValue(pimageinfo, "url");
}
}
catch { }
}
}
catch (Exception ex)
{
string errMsg = "Error extracting catalog: " + ex.Message;
if (ex.InnerException != null)
errMsg += "\nInner Exception" + ex.InnerException.Message;
}
try
{
//catalog_category.info catalogCategoryInfo
//.........这里部分代码省略.........