示例#1
0
        public GetReportListResult InvokeGetReportList(Operations.Reports.MarketplaceWebService client, GetReportListRequest request)
        {
            GetReportListResult getReportListResult = null;

            try
            {
                GetReportListResponse response = client.GetReportList(request);

                if (response != null)
                {
                    getReportListResult = response.GetReportListResult;
                }
            }
            catch (MarketplaceWebServiceException ex)
            {
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Response Status Code: " + ex.StatusCode);
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Error Type: " + ex.ErrorType);
                Console.WriteLine("Request ID: " + ex.RequestId);
                Console.WriteLine("XML: " + ex.XML);
                Console.WriteLine("ResponseHeaderMetadata: " + ex.ResponseHeaderMetadata);
            }

            return(getReportListResult);
        }
示例#2
0
        public MemoryStream GetMostRecentAutomaticallyScheduledReport(ReportType reportType)
        {
            GetReportListRequest request = new GetReportListRequest()
                                           .WithReportTypeList(new TypeList {
                Type = new List <string> {
                    reportType.ToString()
                }
            })
                                           .WithMerchant(m_sellerId);

            GetReportListResponse response = m_service.GetReportList(request);

            GetReportListResult result = response.GetReportListResult;

            List <ReportInfo> reportInfo = result.ReportInfo;

            ReportInfo mostRecentScheduledReport = reportInfo.OrderByDescending(o => o.AvailableDate).FirstOrDefault();

            MemoryStream memoryStream = new MemoryStream();

            if (mostRecentScheduledReport != null)
            {
                GetReportRequest reportRequest = new GetReportRequest
                {
                    Merchant = m_sellerId,
                    ReportId = mostRecentScheduledReport.ReportId,
                    Report   = memoryStream
                };

                m_service.GetReport(reportRequest);
            }

            return(memoryStream);
        }
        public void GetReportListTest()
        {
            GetReportListResult response = reportHandler.GetReportList();

            Assert.IsTrue(response.ReportInfo.Count > 0);

            foreach (var item in response.ReportInfo)
            {
                Console.WriteLine("ReportRequestId: " + item.ReportRequestId);
                Console.WriteLine("ReportType: " + item.ReportType);
                Console.WriteLine("ReportId: " + item.ReportId);
                Console.WriteLine("---------------------------------------------- ");
            }
        }
示例#4
0
        /// <summary>
        /// returns a list of reports; by default the most recent ten reports,
        /// regardless of their acknowledgement status
        ///
        /// </summary>
        /// <param name="service">Instance of MarketplaceWebService service</param>
        /// <param name="request">GetReportListRequest request</param>
        public static async Task InvokeGetReportList(MarketplaceWebService service, GetReportListRequest request)
        {
            try
            {
                GetReportListResponse response = await service.GetReportList(request);


                Console.WriteLine("Service Response");
                Console.WriteLine("=============================================================================");
                Console.WriteLine();

                Console.WriteLine("        GetReportListResponse");
                if (response.IsSetGetReportListResult())
                {
                    Console.WriteLine("            GetReportListResult");
                    GetReportListResult getReportListResult = response.GetReportListResult;
                    if (getReportListResult.IsSetNextToken())
                    {
                        Console.WriteLine("                NextToken");
                        Console.WriteLine("                    {0}", getReportListResult.NextToken);
                    }
                    if (getReportListResult.IsSetHasNext())
                    {
                        Console.WriteLine("                HasNext");
                        Console.WriteLine("                    {0}", getReportListResult.HasNext);
                    }
                    List <ReportInfo> reportInfoList = getReportListResult.ReportInfo;
                    foreach (ReportInfo reportInfo in reportInfoList)
                    {
                        Console.WriteLine("                ReportInfo");
                        if (reportInfo.IsSetReportId())
                        {
                            Console.WriteLine("                    ReportId");
                            Console.WriteLine("                        {0}", reportInfo.ReportId);
                        }
                        if (reportInfo.IsSetReportType())
                        {
                            Console.WriteLine("                    ReportType");
                            Console.WriteLine("                        {0}", reportInfo.ReportType);
                        }
                        if (reportInfo.IsSetReportRequestId())
                        {
                            Console.WriteLine("                    ReportRequestId");
                            Console.WriteLine("                        {0}", reportInfo.ReportRequestId);
                        }
                        if (reportInfo.IsSetAvailableDate())
                        {
                            Console.WriteLine("                    AvailableDate");
                            Console.WriteLine("                        {0}", reportInfo.AvailableDate);
                        }
                        if (reportInfo.IsSetAcknowledged())
                        {
                            Console.WriteLine("                    Acknowledged");
                            Console.WriteLine("                        {0}", reportInfo.Acknowledged);
                        }
                        if (reportInfo.IsSetAcknowledgedDate())
                        {
                            Console.WriteLine("                    AcknowledgedDate");
                            Console.WriteLine("                        {0}", reportInfo.AcknowledgedDate);
                        }
                    }
                }
                if (response.IsSetResponseMetadata())
                {
                    Console.WriteLine("            ResponseMetadata");
                    ResponseMetadata responseMetadata = response.ResponseMetadata;
                    if (responseMetadata.IsSetRequestId())
                    {
                        Console.WriteLine("                RequestId");
                        Console.WriteLine("                    {0}", responseMetadata.RequestId);
                    }
                }

                Console.WriteLine("            ResponseHeaderMetadata");
                Console.WriteLine("                RequestId");
                Console.WriteLine("                    " + response.ResponseHeaderMetadata.RequestId);
                Console.WriteLine("                ResponseContext");
                Console.WriteLine("                    " + response.ResponseHeaderMetadata.ResponseContext);
                Console.WriteLine("                Timestamp");
                Console.WriteLine("                    " + response.ResponseHeaderMetadata.Timestamp);
            }
            catch (MarketplaceWebServiceException ex)
            {
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Response Status Code: " + ex.StatusCode);
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Error Type: " + ex.ErrorType);
                Console.WriteLine("Request ID: " + ex.RequestId);
                Console.WriteLine("XML: " + ex.XML);
                Console.WriteLine("ResponseHeaderMetadata: " + ex.ResponseHeaderMetadata);
            }
        }
示例#5
0
        /// <summary>
        /// Gets the last 3 settlement reports from Amazon API
        /// </summary>
        /// <param name="service"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        private static List <Tuple <string, DateTime, DateTime> > getReportsIds(MarketplaceWebService.MarketplaceWebService service, GetReportListRequest request)
        {
            List <Tuple <string, DateTime, DateTime> > reports = new List <Tuple <string, DateTime, DateTime> >(); //Includes the reportId, dateFrom and dateTo for a settlement report.

            if ((service == null) || (request == null))
            {
                return(reports);
            }

            try
            {
                List <string>   reportIds      = new List <string>();
                List <DateTime> availableDates = new List <DateTime>();

                GetReportListResponse response = service.GetReportList(request);

                if (response.IsSetGetReportListResult())
                {
                    GetReportListResult getReportListResult = response.GetReportListResult;
                    List <ReportInfo>   reportInfoList      = getReportListResult.ReportInfo;
                    foreach (ReportInfo reportInfo in reportInfoList)
                    {
                        reportIds.Add(reportInfo.ReportId);
                        availableDates.Add(reportInfo.AvailableDate);
                    }
                }

                if (availableDates.Count < 4)
                {
                    //We were not able to get the last 3 reports. We will try then to return the most recent one.
                    string   reportId = reportIds[0];
                    DateTime dateFrom = availableDates[1].AddDays(-1); //Settlement reports are available only until the next day of their period.
                    DateTime dateTo   = availableDates[0].AddDays(-1);

                    Tuple <string, DateTime, DateTime> reportInfo = Tuple.Create(reportId, dateFrom, dateTo);
                    reports.Add(reportInfo);
                }
                else
                {
                    //We have more than 3 reports.
                    for (int i = 0; i < 4; i++)
                    {
                        if (DateTime.Now.Subtract(availableDates[i]).Days > 2)  //We exclude the last report if it is still open (open = haven't finished the actual period).
                        {
                            string   reportId = reportIds[i];
                            DateTime dateFrom = availableDates[i + 1].AddDays(-1); //Settlement reports are available only until the next day of their period.
                            DateTime dateTo   = availableDates[i].AddDays(-1);

                            Tuple <string, DateTime, DateTime> reportInfo = Tuple.Create(reportId, dateFrom, dateTo);
                            reports.Add(reportInfo);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Cannot download the list of settlement reports. Exception: " + e.Message);
            }

            return(reports);
        }
示例#6
0
        public List <SettlementReportDataItem> GetSettlementReports(string reportType, string sellerId)
        {
            try
            {
                MarketplaceWebServiceClient service = new MarketplaceWebServiceClient(accessKeyId, secretAccessKey, applicationName, applicationVersion, config);

                GetReportListRequest reportListRequest = new GetReportListRequest();
                reportListRequest.Merchant     = sellerId;
                reportListRequest.MWSAuthToken = mwsAuthToken;
                //reportListRequest.ReportRequestIdList = lstRequestID;
                reportListRequest.ReportTypeList      = new TypeList();
                reportListRequest.ReportTypeList.Type = new List <string>()
                {
                    reportType
                };
                var reportList = service.GetReportList(reportListRequest);

                GetReportListResult reportListResult = reportList.GetReportListResult;

                //TODO - Implement GetReportsListByNextToken
                if (reportListResult.ReportInfo.Count > 0)
                {
                    for (int i = 0; i < reportListResult.ReportInfo.Count; i++)
                    {
                        GetReportRequest reportRequest = new GetReportRequest();
                        reportRequest.Merchant     = sellerId;
                        reportRequest.MWSAuthToken = mwsAuthToken;
                        reportRequest.ReportId     = reportListResult.ReportInfo[i].ReportId;
                        string path = Path.Combine(_reportsPath, reportListResult.ReportInfo[i].ReportId + ".xml");
                        reportRequest.Report = File.Open(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                        var report = service.GetReport(reportRequest);
                    }
                }



                //if (myListzz.Count > 0)
                //{
                //    while (myListzz[0].ReportProcessingStatus.ToString() != "_DONE_")
                //    {
                //        Console.WriteLine("Waiting for Report");
                //        //Thread.Sleep(61000);
                //        reportRequestListResponse =
                //        service.GetReportRequestList(reportRequestListRequest);
                //        reportRequestListResult =
                //        reportRequestListResponse.GetReportRequestListResult;
                //        myListzz = reportRequestListResult.ReportRequestInfo;
                //    }


                //    if (myListzz[0].GeneratedReportId != null)
                //    {
                //        GetReportRequest reportRequest = new GetReportRequest();
                //        reportRequest.Merchant = sellerId;

                //        String source = "C:\\myreport.txt";
                //        reportRequest.ReportId = myListzz[0].GeneratedReportId;
                //        // reportRequest.Report = File.Open(source, FileMode.Create,  FileAccess.ReadWrite);
                //        service.GetReport(reportRequest);
                //    }
                //}
            }
            catch (Exception ex)
            {
                var msg = ex.Message;
            }
            return(null);
        }
示例#7
0
        public string GetReportLatestReport(DateTime From, DateTime To, string ReportType)
        {
            List <string> ReportList = new List <string>();

            GetReportListRequest requestReport = new GetReportListRequest();

            requestReport.Acknowledged      = false;
            requestReport.AvailableFromDate = From;
            requestReport.AvailableToDate   = To;
#pragma warning disable CS0618 // Type or member is obsolete
            requestReport.Marketplace = api.MarketplaceId;
#pragma warning restore CS0618 // Type or member is obsolete
            requestReport.MaxCount = 99;
            requestReport.Merchant = api.Merchant;

            List <string> reportCode = new List <string>();
            reportCode.Add(ReportType);
            TypeList typeList = new TypeList();
            typeList.Type = reportCode;
            requestReport.ReportTypeList = typeList;

            MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();
            config.ServiceURL = webService.SERVICE_URL;
            config.WithUserAgent(webService.USER_AGENT);

            MarketplaceWebServiceClient client = new MarketplaceWebServiceClient(api.AccessKey, api.SecretKey, config);

            GetReportListResult getReportListResult = null;

            getReportListResult = InvokeGetReportList(client, requestReport);
            if (getReportListResult != null)
            {
                if (getReportListResult.HasNext)
                {
                    while (getReportListResult.HasNext)
                    {
                        int i = 0;
                        if (i % 2 == 0)
                        {
                            Thread.Sleep(2000);
                        }
                        GetReportListByNextTokenRequest getReportListByNextTokenRequest = new GetReportListByNextTokenRequest();
#pragma warning disable CS0618 // Type or member is obsolete
                        getReportListByNextTokenRequest.Marketplace = api.MarketplaceId;
#pragma warning restore CS0618 // Type or member is obsolete
                        getReportListByNextTokenRequest.Merchant  = api.Merchant;
                        getReportListByNextTokenRequest.NextToken = getReportListResult.NextToken;
                        string ReportId = InvokeGetReportListByNextToken(client, getReportListByNextTokenRequest);
                        ReportList.Add(ReportId);
                        i++;
                    }
                }
                List <ReportInfo> reportInfoList = getReportListResult.ReportInfo;
                if (reportInfoList.Count > 0)
                {
                    foreach (ReportInfo reportInfo in reportInfoList)
                    {
                        ReportList.Add(reportInfo.ReportId);
                    }
                }
                else
                {
                    Console.WriteLine("No reports returned from Amazon.");
                    throw new Exception("No reports returned from Amazon.");
                }
            }

            return(ReportList[0]);
        }