private string getPriorReportId(string ReportType, IEnumerable <XElement> ReportRequestInfos) { foreach (var ReportRequestInfo in ReportRequestInfos) { string rType = (string)ReportRequestInfo.Element("ReportType"); if (!String.IsNullOrEmpty(rType) && rType == ReportType) { var ReportProcessingStatus = (string)ReportRequestInfo.Element("ReportProcessingStatus"); //Log.Error(_acct.AmazonAccountId,$"Report request {ReportRequestId} status = {ReportProcessingStatus}"); if (ReportProcessingStatus.StartsWith("_DONE_")) { return((string)ReportRequestInfo.Element("GeneratedReportId")); } } } return(""); }
private string getCompletedReportId(string ReportRequestId, string ReportType, bool getPriorRun) { var responseKey = $"GetReportRequestList:{_acct.AmazonAccountId}"; string s = ""; //check cache first using (var r = RedisHelper.GetRedisConnection()) { s = r.Get <string>(responseKey); } if (String.IsNullOrEmpty(s)) { IDictionary <string, string> r1 = new Dictionary <string, String>(); r1["Action"] = "GetReportRequestList"; r1["Version"] = "2009-01-01"; String serviceURL = "https://mws.amazonservices.com"; r1["MarketplaceId"] = _acct.MarketplaceId; r1["SellerId"] = _acct.SellerId; r1["ReportTypeList.Type.1"] = ReportType; r1["RequestedFromDate"] = AMZNHelper.GetFormattedTimestamp(DateTime.Now.AddDays(-1)); AMZNWebResponse wr = new AMZNWebResponse(_acct); s = wr.getResponse(serviceURL, r1); // set cache, expires in 15 seconds using (var r = RedisHelper.GetRedisConnection()) { r.Set <string>(responseKey, s, DateTime.Now.AddSeconds(15)); s = r.Get <string>(responseKey); } } try { var xDoc = XDocument.Parse(s); //dynamic root = new ExpandoObject(); XElement xe = Util.stripNS(xDoc.Elements().First()); IEnumerable <XElement> ReportRequestInfos = xe.Descendants("ReportRequestInfo"); if (getPriorRun) { return(getPriorReportId(ReportType, ReportRequestInfos)); } foreach (var ReportRequestInfo in ReportRequestInfos) { string rId = (string)ReportRequestInfo.Element("ReportRequestId"); if (!String.IsNullOrEmpty(rId) && rId == ReportRequestId) { // this will return the last one. string ReportProcessingStatus = (string)ReportRequestInfo.Element("ReportProcessingStatus"); Log.Info(_acct.AmazonAccountId, $"Report request {ReportRequestId} status = {ReportProcessingStatus}"); if (ReportProcessingStatus.StartsWith("_DONE_")) { return((string)ReportRequestInfo.Element("GeneratedReportId")); } return(ReportProcessingStatus); // break; } } } catch (Exception e) { Log.Error(_acct.AmazonAccountId, "Error getting report id", e); return(""); } return(""); }