mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-25 09:07:15 +00:00
Feature: Sync MWS Shipment with Database
Various restructuring and misc. features added. Removed reliance on ABrain Amazon MWS NuGet package, added Amazon's own C# lib
This commit is contained in:
47
src/bnhtrade.Core/Data/AmazonMWS/CurrentDateTime.cs
Normal file
47
src/bnhtrade.Core/Data/AmazonMWS/CurrentDateTime.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using System.Xml.XPath;
|
||||
|
||||
namespace bnhtrade.Core.Data.AmazonMWS
|
||||
{
|
||||
public class CurrentDateTime
|
||||
{
|
||||
public DateTime GetUtc()
|
||||
{
|
||||
var xmlDoc = new XmlDocument();
|
||||
xmlDoc.Load("https://mws.amazonservices.com/");
|
||||
DateTime returnTime = default(DateTime);
|
||||
|
||||
XmlNodeList elemList = xmlDoc.GetElementsByTagName("Timestamp");
|
||||
for (int i = 0; i < elemList.Count; i++)
|
||||
{
|
||||
string attrVal = elemList[i].Attributes["timestamp"].Value;
|
||||
if (!string.IsNullOrWhiteSpace(attrVal))
|
||||
{
|
||||
returnTime = DateTime.Parse(attrVal);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (returnTime == default(DateTime))
|
||||
{
|
||||
throw new Exception("Error requesting time from Amazon");
|
||||
}
|
||||
|
||||
returnTime = returnTime.ToUniversalTime();
|
||||
returnTime = returnTime.AddTicks(-(returnTime.Ticks % TimeSpan.TicksPerSecond));
|
||||
|
||||
return returnTime;
|
||||
}
|
||||
public DateTime GetLocal()
|
||||
{
|
||||
return GetUtc().ToLocalTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user