private Stream downloadReportStream(string repordId) { var errorCode = string.Empty; var reportStream = new MemoryStream(); do { try { // if there is an error, let's sleep for a while if (!string.IsNullOrEmpty(errorCode)) { Thread.Sleep(46000); } errorCode = string.Empty; var request = new GetReportRequest { Merchant = _merchantId, ReportId = repordId, Report = reportStream }; var response = _amazonClient.GetReport(request); } catch (MarketplaceWebServiceException ex) { errorCode = ex.ErrorCode; Console.WriteLine("Error encountered in downloading the Amazon report. \nError: {0} - Msg:{1}", ex.ErrorCode, ex.Message); } } while (!string.IsNullOrEmpty(errorCode)); return(reportStream); }
public GetReportResult GetReport(string reportId) { if (string.IsNullOrWhiteSpace(reportId)) { throw new ArgumentNullException("reportId is empty"); } nLogger.Info("GetReport for : " + reportId); GetReportRequest req = new GetReportRequest(); req.MWSAuthToken = serviceContext.MwsAuthToken; if (string.IsNullOrEmpty(req.MWSAuthToken)) { req.MWSAuthToken = "MWSAuthToken"; } req.Merchant = serviceContext.SellerId; req.ReportId = reportId; GetReportResponse response = null; try { response = service.GetReport(req); } catch (Exception e) { nLogger.Error("GetReport Failed"); throw; } return(response.GetReportResult); }
public OrderReportModel GetOrderReport(GetReportRequest Request) { var Response = new OrderReportModel(); Response.AllOrders = _unitOfWork.RepositoryFactory <Order>() .GetMany(q => q.DateTime.Value.Date >= Request.From && q.DateTime.Value.Date <= Request.To).Select(q => new OrderDTO { AllOrder = q.Order_Meals.Select(w => new OrderMealModel { AddOns = (w.IsCombo ? "Compo 3LE" : "") + (w.IsSpicy ? " Spicy 3LE" : ""), Item = w.Meal.Name, Item_Id = w.Meal_Id, Price = (int)w.Meal.Price, TotalPrice = (((int)w.Meal.Price + (w.IsCombo ? 3 : 0) + (w.IsSpicy ? 3 : 0)) * w.Q), Q = w.Q }).ToList(), Date = q.DateTime.Value.ToShortTimeString() + ' ' + q.DateTime.Value.ToShortDateString(), OrderTotalPrice = (int)q.Order_Meals.Sum(w => ((w.Meal.Price + (w.IsCombo ? 3:0) + (w.IsSpicy ? 3 : 0)) * w.Q)), }).ToList(); Response.OverAllTotalPrice = Response.AllOrders.Sum(q => q.OrderTotalPrice); Response.OverAllTotalNumberOfMeals = Response.AllOrders.Sum(q => q.AllOrder.Sum(w => w.Q)); Response.OverAllTotalNumberOfOrders = Response.AllOrders.Count(); return(Response); }
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 async Task <IActionResult> GetReport([FromQuery] GetReportRequest request) { var response = await mediator.Send(request); Log.Information($"User #{HttpContext.GetCurrentUserId()} fetched report #{request.ReportId}"); return(this.CreateResponse(response)); }
public async Task <IActionResult> GetReport([FromQuery] GetReportRequest request) { var response = await mediator.Send(request); logger.LogResponse($"User #{HttpContext.GetCurrentUserId()} fetched report #{response?.Report?.Id}", response.Error); return(this.CreateResponse(response)); }
public Report GetReport(string period, string employerId) { var request = new GetReportRequest { Period = period, EmployerId = employerId }; var report = _mediator.Send(request).Result; return(report); }
public void InvokeGetReport(Operations.Reports.MarketplaceWebService client, GetReportRequest requestReport) { try { GetReportResponse response = null; response = client.GetReport(requestReport); Console.WriteLine("Service Response"); Console.WriteLine("============================================================================="); Console.WriteLine(); Console.WriteLine(" GetReportResponse"); if (response.IsSetGetReportResult()) { Console.WriteLine(" GetReportResult"); GetReportResult getReportResult = response.GetReportResult; if (getReportResult.IsSetContentMD5()) { Console.WriteLine(" ContentMD5"); Console.WriteLine(" {0}", getReportResult.ContentMD5); } } 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); } }
/// <summary> /// The GetReport operation returns the contents of a report. Reports can potentially be /// very large (>100MB) which is why we only return one report at a time, and in a /// streaming fashion. /// /// </summary> /// <param name="service">Instance of MarketplaceWebService service.</param> /// <param name="request">GetReportRequest request.</param> public static async Task InvokeGetReport(IMarketplaceWebService service, GetReportRequest request) { try { var response = await service.GetReport(request); Console.WriteLine("Service Response"); Console.WriteLine("============================================================================="); Console.WriteLine(); Console.WriteLine(" GetReportResponse"); if (response.IsSetGetReportResult()) { Console.WriteLine(" GetReportResult"); var getReportResult = response.GetReportResult; if (getReportResult.IsSetContentMD5()) { Console.WriteLine(" ContentMD5"); Console.WriteLine(" {0}", getReportResult.ContentMD5); } } if (response.IsSetResponseMetadata()) { Console.WriteLine(" ResponseMetadata"); var 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); } }
public List <MealOrderReportModel> GetMealOrderReport(GetReportRequest Request) { var response = new DAL.DataModel.RestaurantEntities1().GetMealOrderReport(Request.From, Request.To).Select (q => new MealOrderReportModel { Product = q.Name, Count = (int)q.allsum } ).ToList(); return(response); }
private async Task <List <ReportModel> > GetReportModelsAsync(int stateId = 2) { var request = new GetReportRequest() { StateId = stateId }; var result = await _mediator.Send(request); var viewModel = _mapper.Map <List <ReportModel> >(result.ReportModels); return(viewModel); }
public async Task <ReportResult> UpdateReports(CancellationToken token) { if (!_service.IsAuthorized) { return(ReportResult.Error); } //If dates of report is not init, then we get report for week var from = From; if (from == default) { from = DateTime.UtcNow.AddDays(-7); } var to = To; if (to == default) { to = DateTime.UtcNow; } if (to < from) { return(ReportResult.ToLessFrom); } var getExpenseReportRequest = new GetReportRequest { From = from, To = to, Type = CategoryType.Expense }; var expenseReport = await _service.GetChartByCategories(getExpenseReportRequest, token); var getIncomeReportRequest = new GetReportRequest { From = from, To = to, Type = CategoryType.Income }; var incomeReport = await _service.GetChartByCategories(getIncomeReportRequest, token); ExpenseReport = new ReportModel(expenseReport); IncomeReport = new ReportModel(incomeReport); return(ReportResult.Ok); }
private void GetInventoryReport(ERPContext context, string accountName, string reportId) { GetReportRequest request = new GetReportRequest(); request.MWSAuthToken = mwsAuthTokenDictionary[accountName]; request.Merchant = sellerIdDictionary[accountName]; request.ReportId = reportId; MemoryStream stream = new MemoryStream(); request.Report = stream; GetReportResponse response = mwsClient.GetReport(request); ParseInventoryReport(context, accountName, stream); }
public async Task <NameValueContract[]> GetAllReportInWorkSpace(GetReportRequest getReportRequest) { UserCredential = getReportRequest.Credential; await AuthenticateAsync(); var reportList = new List <NameValueContract>(); using (var pClient = new PowerBIClient(new Uri(POWER_BI_API_URL), PTokenCredentials)) { var reportsInGroup = await pClient.Reports.GetReportsInGroupWithHttpMessagesAsync(getReportRequest.WorkSpaceId); reportList.AddRange(reportsInGroup.Body.Value.Select(@report => new NameValueContract { Id = @report.Id, Name = @report.Name })); } return(reportList.ToArray()); }
public string GetReport(string ReportId, string Path) { string amazonFileLocation = ""; GetReportRequest requestReport = new GetReportRequest(); #pragma warning disable CS0618 // Type or member is obsolete requestReport.Marketplace = api.MarketplaceId; #pragma warning restore CS0618 // Type or member is obsolete requestReport.Merchant = api.Merchant; requestReport.ReportId = ReportId; string Extension = string.Format("{1}{0}", ".txt", DateTime.Now.ToString("hh.mm.ss.ffffff")); string FullPath = Path + Extension; if (!File.Exists(FullPath)) { var stream = File.Create(FullPath); stream.Close(); } // string fileLocation = FileAmazon.createFile(reportId, "txt", ReportModule, ""); -> METHOD TO CREATE THE PATH if (FullPath != "") { var stream = File.Open(FullPath, FileMode.OpenOrCreate, FileAccess.ReadWrite); requestReport.Report = stream; MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig(); config.ServiceURL = webService.SERVICE_URL; config.WithUserAgent(webService.USER_AGENT); MarketplaceWebServiceClient client = new MarketplaceWebServiceClient(api.AccessKey, api.SecretKey, config); InvokeGetReport(client, requestReport); stream.Close(); amazonFileLocation = FullPath; } return(amazonFileLocation); }
private void GetReportData(RequestInfo requestInfo, Stream stream) { var requestReport = new GetReportRequest(); var requestsListInfo = requestInfo.Owner; var merchant = requestsListInfo.UserId; var access = requestsListInfo.Access; var requestName = requestInfo.Name; var requestReportList = new GetReportListRequest { Merchant = merchant }; ReportInfo reportInfo = null; var respGetReportList = AmazonWaitBeforeRetryHelper.DoServiceAction( requestsListInfo.ErrorRetryingInfo, ReportGetReportListTrapForThrottling, requestName, access, requestsListInfo.RequestsCounter, () => _Service.GetReportList(requestReportList), "GetReportList"); if (respGetReportList != null && respGetReportList.IsSetGetReportListResult()) { reportInfo = respGetReportList.GetReportListResult.ReportInfo.FirstOrDefault(r => r.ReportRequestId.Equals(requestInfo.Id)); } if (reportInfo != null) { requestReport.Merchant = merchant; requestReport.ReportId = reportInfo.ReportId; requestReport.Report = stream; AmazonWaitBeforeRetryHelper.DoServiceAction( requestsListInfo.ErrorRetryingInfo, ReportGetReportTrapForThrottling, requestName, access, requestsListInfo.RequestsCounter, () => _Service.GetReport(requestReport), "GetReport"); } }
/// <summary> /// The GetReport operation returns the contents of a report. Reports can potentially be /// very large (>100MB) which is why we only return one report at a time, and in a /// streaming fashion. /// /// </summary> /// <param name="service">Instance of MarketplaceWebService service</param> /// <param name="request">GetReportRequest request</param> public static void InvokeGetReport(MarketplaceWebService service, GetReportRequest request) { try { GetReportResponse response = service.GetReport(request); Console.WriteLine("Service Response"); Console.WriteLine("============================================================================="); Console.WriteLine(); Console.WriteLine(" GetReportResponse"); if (response.IsSetGetReportResult()) { Console.WriteLine(" GetReportResult"); GetReportResult getReportResult = response.GetReportResult; if (getReportResult.IsSetContentMD5()) { Console.WriteLine(" ContentMD5"); Console.WriteLine(" {0}", getReportResult.ContentMD5); } } if (response.IsSetResponseMetadata()) { Console.WriteLine(" ResponseMetadata"); ResponseMetadata responseMetadata = response.ResponseMetadata; if (responseMetadata.IsSetRequestId()) { Console.WriteLine(" RequestId"); Console.WriteLine(" {0}", responseMetadata.RequestId); } } } 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); } }
private void HandleOutput(GetReportRequest request) { var waiterConfig = new WaiterConfiguration { MaxAttempts = MaxWaitAttempts, GetNextDelayInSeconds = (_) => WaitIntervalSeconds }; switch (ParameterSetName) { case LifecycleStateParamSet: response = client.Waiters.ForReport(request, waiterConfig, WaitForLifecycleState).Execute(); break; case Default: response = client.GetReport(request).GetAwaiter().GetResult(); break; } WriteOutput(response, response.Report); }
public void GetReportTest() { MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig(); config.ServiceURL = serviceURL; MarketplaceWebService.MarketplaceWebService service = new MarketplaceWebServiceClient( creds.AccessKey, creds.SecretKey, appName, appVersion, config); GetReportRequest request = new GetReportRequest(); request.Merchant = sellerId; request.MWSAuthToken = mWSAuthToken; // Optional //@TODO: set additional request parameters here request.ReportId = "123"; GetReportResponse response = service.GetReport(request); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] GetReportRequest req, ILogger log) { try { log.LogInformation("C# HTTP trigger function processed a request."); GetReportResponse response = await _mediator.Send(req); return(new OkObjectResult(ResponseWrapper <GetReportResponse, RequestServiceErrorCode> .CreateSuccessfulResponse(response))); } catch (Exception exc) { log.LogError("Exception occured in Log Request", exc); return(new ObjectResult(ResponseWrapper <GetReportResponse, RequestServiceErrorCode> .CreateUnsuccessfulResponse(RequestServiceErrorCode.InternalServerError, "Internal Error")) { StatusCode = StatusCodes.Status500InternalServerError }); } }
private Stream downloadReportStream(string repordId) { try { var reportStream = new MemoryStream(); var request = new GetReportRequest { Merchant = "A12HYFEDED6DEW", ReportId = repordId, Report = reportStream }; var response = _amazonClient.GetReport(request); return(reportStream); } catch (MarketplaceWebServiceException) { return(null); } }
protected override void ProcessRecord() { base.ProcessRecord(); GetReportRequest request; try { request = new GetReportRequest { ReportId = ReportId, OpcRequestId = OpcRequestId }; HandleOutput(request); FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
public async Task <IEnumerable <PowerReport> > GetWorkSpaceReports(WorkSpaceRequestVM workSpaceRequestVm) { var list = new List <PowerReport>(); var request = new GetReportRequest { Credential = new UserData { TenantId = workSpaceRequestVm.Credential.TenantId, SecretId = workSpaceRequestVm.Credential.SecretId, ApplicationId = workSpaceRequestVm.Credential.ApplicationId }, WorkSpaceId = workSpaceRequestVm.GroupId }; var Result = await _powerService.GetAllReportInWorkSpace(request); Result.ForEach(s => { list.Add(new PowerReport { Id = s.Id, Name = s.Name }); }); return(list.ToArray()); }
public Stream GetReport(string ReportId) { this.Throttle(); AmazonCredential Credentials = this.GetCredential(); MarketplaceWebServiceClient Client = this.GetClient(Credentials); MemoryStream ReportStream = new MemoryStream(); GetReportRequest Request = new GetReportRequest() { Merchant = Credentials.MerchantID, ReportId = ReportId, Report = ReportStream }; GetReportResponse Response = Client.GetReport(Request); if (Response.IsSetGetReportResult()) { return(ReportStream); } else { return(null); } }
public void InvokeGetReport(PXGraph graph, ReportParameters reportParams, MemoryStream ms) { try { GetReportRequest request = new GetReportRequest(); request.Merchant = reportParams.objSOAmazonSetup.SellerId; request.MWSAuthToken = reportParams.objSOAmazonSetup.AuthToken; request.ReportId = reportParams.generatedReportId; request.Report = ms; clientReports.GetReport(request); } catch (Exception ex) { if (ex is MarketplaceWebServiceException) { MarketplaceWebServiceException exception = ex as MarketplaceWebServiceException; if (!string.IsNullOrEmpty(exception.ErrorCode) && exception.ErrorCode.ToLower().Trim() == SOMessages.requestThrottled) { Thread.Sleep(SOHelper.DelayProcess(graph, SOConstants.apiGetReport)); InvokeGetReport(graph, reportParams, ms); } else { throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message : ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message : SOConstants.exceptionIsEmpty); } } else { throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message : ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message : SOConstants.exceptionIsEmpty); } } }
public async Task <IEnumerable <ItemReport> > GetChartByCategories(CategoryType type, DateTime from, DateTime to, CancellationToken token) { if (_service.IsAuthorized) { var request = new GetReportRequest { Type = type, From = from, To = to }; var response = await _service.GetChartByCategories(request, token); return(response.Select(c => new ItemReport { Amount = c.Amount, CategoryId = c.CategoryId, CategoryTitle = c.CategoryTitle, CategoryHexColor = c.CategoryHexColor })); } return(null); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] GetReportRequest req, ILogger log) { try { NewRelic.Api.Agent.NewRelic.SetTransactionName("UserService", "GetReport"); log.LogInformation("C# HTTP trigger function processed a request."); GetReportResponse response = await _mediator.Send(req); return(new OkObjectResult(ResponseWrapper <GetReportResponse, UserServiceErrorCode> .CreateSuccessfulResponse(response))); } catch (Exception exc) { LogError.Log(log, exc, req); return(new ObjectResult(ResponseWrapper <GetReportResponse, UserServiceErrorCode> .CreateUnsuccessfulResponse(UserServiceErrorCode.UnhandledError, "Internal Error")) { StatusCode = StatusCodes.Status500InternalServerError }); } }
/** * Samples for Marketplace Web Service functionality */ public static void Main(string[] args) { Console.WriteLine("==========================================="); Console.WriteLine("Welcome to Marketplace Web Service Samples!"); Console.WriteLine("==========================================="); Console.WriteLine("To get started:"); Console.WriteLine("==========================================="); Console.WriteLine(" - Fill in your AWS credentials"); Console.WriteLine(" - Uncomment sample you're interested in trying"); Console.WriteLine(" - Set request with desired parameters"); Console.WriteLine(" - Hit F5 to run!"); Console.WriteLine(); Console.WriteLine("==========================================="); Console.WriteLine("Samples Output"); Console.WriteLine("==========================================="); Console.WriteLine(); /************************************************************************ * Access Key ID and Secret Acess Key ID, obtained from: * http://aws.amazon.com * * IMPORTANT: Your Secret Access Key is a secret, and should be known * only by you and AWS. You should never include your Secret Access Key * in your requests to AWS. You should never e-mail your Secret Access Key * to anyone. It is important to keep your Secret Access Key confidential * to protect your account. ***********************************************************************/ String accessKeyId = "AKIAIKYYTE7TYRWSAIEA"; String secretAccessKey = "jFA0WUoRP1yJty5pp8BXWfHN/UwMOecXQ6grn2D9"; /************************************************************************ * Instantiate Implementation of Marketplace Web Service ***********************************************************************/ //MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig(); /************************************************************************ * The application name and version are included in each MWS call's * HTTP User-Agent field. These are required fields. ***********************************************************************/ const string applicationName = "T-Tek Seller Tool"; const string applicationVersion = "0.1"; /*MarketplaceWebService service = * new MarketplaceWebServiceClient( * accessKeyId, * secretAccessKey, * applicationName, * applicationVersion, * config);*/ /************************************************************************ * All MWS requests must contain the seller's merchant ID and * marketplace ID. ***********************************************************************/ const string merchantId = "A380610PV1XE6A"; const string marketplaceId = "ATVPDKIKX0DER"; /************************************************************************ * Uncomment to configure the client instance. Configuration settings * include: * * - MWS Service endpoint URL * - Proxy Host and Proxy Port * - User Agent String to be sent to Marketplace Web Service service * ***********************************************************************/ MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig(); config.ProxyHost = "https://PROXY_URL"; config.ProxyPort = 9090; // // IMPORTANT: Uncomment out the appropiate line for the country you wish // to sell in: // // United States: config.ServiceURL = "https://mws.amazonservices.com"; // // United Kingdom: // config.ServiceURL = "https://mws.amazonservices.co.uk"; // // Germany: // config.ServiceURL = "https://mws.amazonservices.de"; // // France: // config.ServiceURL = "https://mws.amazonservices.fr"; // // Japan: // config.ServiceURL = "https://mws.amazonservices.jp"; // // China: // config.ServiceURL = "https://mws.amazonservices.com.cn"; // // Canada: // config.ServiceURL = "https://mws.amazonservices.ca"; // // Italy: // config.ServiceURL = "https://mws.amazonservices.it"; // config.SetUserAgentHeader( applicationName, applicationVersion, "C#", "<Parameter 1>", "<Parameter 2>"); MarketplaceWebService service = new MarketplaceWebServiceClient(accessKeyId, secretAccessKey, config); /************************************************************************ * Uncomment to try out Mock Service that simulates Marketplace Web Service * responses without calling Marketplace Web Service service. * * Responses are loaded from local XML files. You can tweak XML files to * experiment with various outputs during development * * XML files available under MarketplaceWebService\Mock tree * ***********************************************************************/ //MarketplaceWebService service = new MarketplaceWebServiceMock(); /************************************************************************ * Uncomment to invoke Get Report Action ***********************************************************************/ { GetReportRequest request = new GetReportRequest(); request.Merchant = merchantId; //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional // Note that depending on the type of report being downloaded, a report can reach // sizes greater than 1GB. For this reason we recommend that you _always_ program to // MWS in a streaming fashion. Otherwise, as your business grows you may silently reach // the in-memory size limit and have to re-work your solution. // NOTE: Due to Content-MD5 validation, the stream must be read/write. request.ReportId = "REPORT_ID"; request.Report = File.Open("report.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite); GetReportSample.InvokeGetReport(service, request); } /************************************************************************ * Uncomment to invoke Get Report Schedule Count Action ***********************************************************************/ { GetReportScheduleCountRequest request = new GetReportScheduleCountRequest(); request.Merchant = merchantId; //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional // @TODO: set additional request parameters here GetReportScheduleCountSample.InvokeGetReportScheduleCount(service, request); } /************************************************************************ * Uncomment to invoke Get Report Request List By Next Token Action ***********************************************************************/ { //GetReportRequestListByNextTokenRequest request = new GetReportRequestListByNextTokenRequest(); //request.Merchant = merchantId; //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional //request.NextToken = "NextToken from GetReportRequestList"; // @TODO: set additional request parameters here //GetReportRequestListByNextTokenSample.InvokeGetReportRequestListByNextToken(service, request); } /************************************************************************ * Uncomment to invoke Update Report Acknowledgements Action ***********************************************************************/ { //UpdateReportAcknowledgementsRequest request = new UpdateReportAcknowledgementsRequest(); //request.Merchant = merchantId; //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional //request.WithReportIdList(new IdList().WithId("REPORT_ID")); // @TODO: set additional request parameters here //UpdateReportAcknowledgementsSample.InvokeUpdateReportAcknowledgements(service, request); } /************************************************************************ * Uncomment to invoke Submit Feed Action ***********************************************************************/ { // SubmitFeedRequest request = new SubmitFeedRequest(); // request.Merchant = merchantId; // request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional // request.MarketplaceIdList = new IdList(); // request.MarketplaceIdList.Id = new List<string>( new string [] { marketplaceId } ); // MWS exclusively offers a streaming interface for uploading your feeds. This is because // feed sizes can grow to the 1GB+ range - and as your business grows you could otherwise // silently reach the feed size where your in-memory solution will no longer work, leaving you // puzzled as to why a solution that worked for a long time suddenly stopped working though // you made no changes. For the same reason, we strongly encourage you to generate your feeds to // local disk then upload them directly from disk to MWS. //request.FeedContent = File.Open("feed.xml", FileMode.Open, FileAccess.Read); // Calculating the MD5 hash value exhausts the stream, and therefore we must either reset the // position, or create another stream for the calculation. //request.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(request.FeedContent); //request.FeedContent.Position = 0; //request.FeedType = "FEED_TYPE"; //SubmitFeedSample.InvokeSubmitFeed(service, request); } /************************************************************************ * Uncomment to invoke Get Report Count Action ***********************************************************************/ { // GetReportCountRequest request = new GetReportCountRequest(); // request.Merchant = merchantId; // request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional // @TODO: set additional request parameters here // GetReportCountSample.InvokeGetReportCount(service, request); } /************************************************************************ * Uncomment to invoke Get Feed Submission List By Next Token Action ***********************************************************************/ { //GetFeedSubmissionListByNextTokenRequest request = new GetFeedSubmissionListByNextTokenRequest(); //request.Merchant = merchantId; //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional //request.NextToken = "NextToken from GetFeedSubmissionList"; // @TODO: set additional request parameters here //GetFeedSubmissionListByNextTokenSample.InvokeGetFeedSubmissionListByNextToken(service, request); } /************************************************************************ * Uncomment to invoke Cancel Feed Submissions Action ***********************************************************************/ { //CancelFeedSubmissionsRequest request = new CancelFeedSubmissionsRequest(); //request.Merchant = merchantId; //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional // @TODO: set additional request parameters here //CancelFeedSubmissionsSample.InvokeCancelFeedSubmissions(service, request); } /************************************************************************ * Uncomment to invoke Request Report Action ***********************************************************************/ { //RequestReportRequest request = new RequestReportRequest(); //request.Merchant = merchantId; //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional //request.MarketplaceIdList = new IdList(); //request.MarketplaceIdList.Id = new List<string>( new string [] { marketplaceId } ); //request.ReportType = "Desired Report Type"; // @TODO: set additional request parameters here //request.ReportOptions = "ShowSalesChannel=true"; //RequestReportSample.InvokeRequestReport(service, request); } /************************************************************************ * Uncomment to invoke Get Feed Submission Count Action ***********************************************************************/ { //GetFeedSubmissionCountRequest request = new GetFeedSubmissionCountRequest(); //request.Merchant = merchantId; //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional // @TODO: set additional request parameters here //GetFeedSubmissionCountSample.InvokeGetFeedSubmissionCount(service, request); } /************************************************************************ * Uncomment to invoke Cancel Report Requests Action ***********************************************************************/ { //CancelReportRequestsRequest request = new CancelReportRequestsRequest(); //request.Merchant = merchantId; //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional // @TODO: set additional request parameters here //CancelReportRequestsSample.InvokeCancelReportRequests(service, request); } /************************************************************************ * Uncomment to invoke Get Report List Action ***********************************************************************/ { //GetReportListRequest request = new GetReportListRequest(); //request.Merchant = merchantId; //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional // @TODO: set additional request parameters here //GetReportListSample.InvokeGetReportList(service, request); } /************************************************************************ * Uncomment to invoke Get Feed Submission Result Action ***********************************************************************/ { //GetFeedSubmissionResultRequest request = new GetFeedSubmissionResultRequest(); //request.Merchant = merchantId; //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional // Note that depending on the size of the feed sent in, and the number of errors and warnings, // the result can reach sizes greater than 1GB. For this reason we recommend that you _always_ // program to MWS in a streaming fashion. Otherwise, as your business grows you may silently reach // the in-memory size limit and have to re-work your solution. // NOTE: Due to Content-MD5 validation, the stream must be read/write. //request.FeedSubmissionId = "FEED_SUBMISSION_ID"; //request.FeedSubmissionResult = File.Open("feedSubmissionResult.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite); //GetFeedSubmissionResultSample.InvokeGetFeedSubmissionResult(service, request); } /************************************************************************ * Uncomment to invoke Get Feed Submission List Action ***********************************************************************/ { //GetFeedSubmissionListRequest request = new GetFeedSubmissionListRequest(); //request.Merchant = merchantId; //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional // @TODO: set additional request parameters here //GetFeedSubmissionListSample.InvokeGetFeedSubmissionList(service, request); } /************************************************************************ * Uncomment to invoke Get Report Request List Action ***********************************************************************/ { //GetReportRequestListRequest request = new GetReportRequestListRequest(); //request.Merchant = merchantId; //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional // @TODO: set additional request parameters here //GetReportRequestListSample.InvokeGetReportRequestList(service, request); } /************************************************************************ * Uncomment to invoke Get Report Schedule List By Next Token Action ***********************************************************************/ { //GetReportScheduleListByNextTokenRequest request = new GetReportScheduleListByNextTokenRequest(); //request.Merchant = merchantId; //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional //request.NextToken = "NextToken from GetReportScheduleList"; // @TODO: set additional request parameters here //GetReportScheduleListByNextTokenSample.InvokeGetReportScheduleListByNextToken(service, request); } /************************************************************************ * Uncomment to invoke Get Report List By Next Token Action ***********************************************************************/ { // GetReportListByNextTokenRequest request = new GetReportListByNextTokenRequest(); // request.Merchant = merchantId; // request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional //request.NextToken = "NextToken from GetReportList"; // @TODO: set additional request parameters here // GetReportListByNextTokenSample.InvokeGetReportListByNextToken(service, request); } /************************************************************************ * Uncomment to invoke Manage Report Schedule Action ***********************************************************************/ { //ManageReportScheduleRequest request = new ManageReportScheduleRequest(); //request.Merchant = merchantId; //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional //request.ReportType = "Report Type"; //request.Schedule = "Schedule"; // @TODO: set additional request parameters here //ManageReportScheduleSample.InvokeManageReportSchedule(service, request); } /************************************************************************ * Uncomment to invoke Get Report Request Count Action ***********************************************************************/ { //GetReportRequestCountRequest request = new GetReportRequestCountRequest(); //request.Merchant = merchantId; //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional // @TODO: set additional request parameters here //GetReportRequestCountSample.InvokeGetReportRequestCount(service, request); } /************************************************************************ * Uncomment to invoke Get Report Schedule List Action ***********************************************************************/ { //GetReportScheduleListRequest request = new GetReportScheduleListRequest(); //request.Merchant = merchantId; //request.MWSAuthToken = "<Your MWS Auth Token>"; // Optional // @TODO: set additional request parameters here //GetReportScheduleListSample.InvokeGetReportScheduleList(service, request); } Console.WriteLine(); Console.WriteLine("==========================================="); Console.WriteLine("End of output. You can close this window"); Console.WriteLine("==========================================="); System.Threading.Thread.Sleep(50000); }
private static string AdlsAccountName = ""; // Name of the Azure Data Lake Store static void Main(string[] args) { // Fetching Prerequisites Data from Azure SQL Server using (SqlConnection con = new SqlConnection(connectionString)) { // Fetching data from Report Config Table SqlCommand cmd = new SqlCommand("USE CommerceLabsDW;OPEN SYMMETRIC KEY SymmetricKey1 DECRYPTION BY CERTIFICATE Certificate1; SELECT CONVERT(varchar(max), DECRYPTBYKEY(SellerCentral_LoginID)), CONVERT(varchar(max), DECRYPTBYKEY(SellerCentral_LoginPWD)), CONVERT(varchar(max), DECRYPTBYKEY(ADS_RefreshToken)), CONVERT(varchar(max), DECRYPTBYKEY(ADS_ClientID)), CONVERT(varchar(max), DECRYPTBYKEY(ADS_ClientSecret)), CONVERT(varchar(max), DECRYPTBYKEY(ADS_Scope)), CONVERT(varchar(max), DECRYPTBYKEY(WP_Authorization)), CONVERT(varchar(max), DECRYPTBYKEY(MWS_AccessID)), CONVERT(varchar(max), DECRYPTBYKEY(MWS_SecretKey)), CONVERT(varchar(max), DECRYPTBYKEY(MWS_MerchantID)), CONVERT(varchar(max), DECRYPTBYKEY(MWS_AuthToken)), CONVERT(varchar(max), DECRYPTBYKEY(Azure_ClientID)), CONVERT(varchar(max), DECRYPTBYKEY(Azure_ClientSecret)), CONVERT(varchar(max), DECRYPTBYKEY(Azure_TenantID)), CONVERT(varchar(max), DECRYPTBYKEY(Azure_DataLakeName)) FROM stage.rpt_ConfigTable WHERE ID = 1; ", con); //Opening the Connection con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { SC_LoginID = reader.GetString(0); SC_LoginPwd = reader.GetString(1); ADS_RefreshToken = reader.GetString(2); ADS_ClientID = reader.GetString(3); ADS_ClientSecret = reader.GetString(4); ADS_Scope = reader.GetString(5); WP_Authorization = reader.GetString(6); MWS_AccessID = reader.GetString(7); MWS_SecretKey = reader.GetString(8); MWS_MerchantID = reader.GetString(9); MWS_AuthToken = reader.GetString(10); AzureClientId = reader.GetString(11); AzureClientSecret = reader.GetString(12); AzureTenantId = reader.GetString(13); AdlsAccountName = reader.GetString(14); } //Closing the Connection con.Close(); } // Azure Data Lake Initialisation SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); var clientCredential = new ClientCredential(AzureClientId, AzureClientSecret); var creds = ApplicationTokenProvider.LoginSilentAsync(AzureTenantId, clientCredential).Result; adlsFileSystemClient = new DataLakeStoreFileSystemManagementClient(creds); string Azuresource = "", Azuredestination = ""; // Azure Source and Destination Variable // Creating a Folder in the App Path var directoryFullPath = AppDomain.CurrentDomain.BaseDirectory + @"DownloadedReports\"; // Creating a Folder in Current Directory if not exists Directory.CreateDirectory(directoryFullPath); // Web Driver Object IWebDriver driver; // Setting the needed Chrome Options ChromeOptions options = new ChromeOptions(); options.AddUserProfilePreference("download.default_directory", directoryFullPath); // Setting the default directory for the report to be downloaded options.AddUserProfilePreference("intl.accept_languages", "en-us"); // Setting the language as English // options.AddArgument("--headless"); // Setting headless browser option driver = new ChromeDriver(options); // Assigning all the above options to Chrome Driver Console.WriteLine("Started"); // Amazon Seller Central Login Page driver.Navigate().GoToUrl("https://sellercentral.amazon.com/"); driver.FindElement(By.ClassName("secondary")).Click(); driver.FindElement(By.Id("ap_email")).SendKeys(SC_LoginID); driver.FindElement(By.Id("ap_password")).SendKeys(SC_LoginPwd); driver.FindElement(By.Id("signInSubmit")).Click(); /*// Generating OTP * var otpKeyStr = "WGHSYZEE2RJOO6OFMCBMB6HKNHDZRADH4TK2FDJ77YWQ5YFRWDBQ"; // 2FA secret key. * var otpKeyBytes = Base32Encoding.ToBytes(otpKeyStr); * var totp = new Totp(otpKeyBytes); * var twoFactorCode = totp.ComputeTotp(DateTime.UtcNow); // 2FA code at this time! * Console.WriteLine(twoFactorCode);*/ // OTP Console.WriteLine("Please enter the OTP : "); var input = Console.ReadLine(); driver.FindElement(By.Id("auth-mfa-otpcode")).SendKeys(input); driver.FindElement(By.Id("auth-mfa-remember-device")).Click(); driver.FindElement(By.Id("auth-signin-button")).Click(); // ------------------ REPORT 1 ------------------ // ---- Automating Scraping Method ----- // Downloading Business Report driver.Navigate().GoToUrl("https://sellercentral.amazon.com/gp/site-metrics/report.html#reportID=102%3ADetailSalesTrafficBySKU&runDate=&fromDate=&toDate="); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1000); Thread.Sleep(1000); // Downloading Past 3 Days' Reports by looping through dates for (int i = -1; i > -4; i--) { // Looping through Dates and setting the Date Value var DateValue = DateTime.Now.AddDays(i).ToString("MM/dd/yyyy").Replace("-", "/"); // Setting From Date IWebElement FromDateBox = driver.FindElement(By.Id("fromDate2")); FromDateBox.Clear(); FromDateBox.SendKeys(DateValue + Keys.Enter); // Setting To Date IWebElement ToDateBox = driver.FindElement(By.Id("toDate2")); ToDateBox.Clear(); ToDateBox.SendKeys(DateValue + Keys.Enter); // Downloading the Report Thread.Sleep(1000); driver.FindElement(By.Id("export")).Click(); Thread.Sleep(1000); driver.FindElement(By.Id("downloadCSV")).Click(); Thread.Sleep(1000); // Editing the Business Report CSV string BusRepfilePath = directoryFullPath + "BusinessReport-" + DateTime.Now.AddDays(-1).ToString("MM/dd/yy") + ".csv"; Thread.Sleep(1000); // Transaction Date var Buscol1 = File.ReadLines(BusRepfilePath).Select((line, index) => index == 0 ? line + ", Transaction Date" : line + "," + DateValue.Replace("/", "-")).ToList(); File.WriteAllLines(BusRepfilePath, Buscol1); // Account var Buscol2 = File.ReadLines(BusRepfilePath).Select((line, index) => index == 0 ? line + ",Account" : line + ",Meal Prep Haven").ToList(); File.WriteAllLines(BusRepfilePath, Buscol2); // Country var Buscol3 = File.ReadLines(BusRepfilePath).Select((line, index) => index == 0 ? line + ",Country" : line + ",US").ToList(); File.WriteAllLines(BusRepfilePath, Buscol3); // Reference URL var Buscol4 = File.ReadLines(BusRepfilePath).Select((line, index) => index == 0 ? line + ",Reference" : line + "," + driver.Url).ToList(); File.WriteAllLines(BusRepfilePath, Buscol4); // Renaming the Report File File.Move(BusRepfilePath, directoryFullPath + "BusinessReport" + i + ".csv"); } // Combining all the CSV Files into 1 string BussourceFolder = directoryFullPath; string BusdestinationFile = directoryFullPath + "BusinessReport-" + DateTime.Now.ToString("dd/MM/yyyy") + ".csv"; // Matches the CSV files by searching the specified wildcard and combines them to single file string[] filePaths = Directory.GetFiles(BussourceFolder, "BusinessReport-?.csv"); StreamWriter fileDest = new StreamWriter(BusdestinationFile, true); for (int j = 0; j < filePaths.Length; j++) { string file = filePaths[j]; string[] lines = File.ReadAllLines(file); if (j > 0) { lines = lines.Skip(1).ToArray(); // Skipping Header row for all except first file } foreach (string line in lines) { fileDest.WriteLine(line); } } fileDest.Close(); // Uploading Business Report to Azure Data Lake Azuresource = directoryFullPath + @"BusinessReport-" + DateTime.Now.ToString("dd/MM/yyyy") + ".csv"; Azuredestination = "Meal prep haven/CA_AO/Business Reports/" + "BusinessReport-" + DateTime.Now.ToString("dd/MM/yyyy") + ".csv"; adlsFileSystemClient.FileSystem.UploadFile(AdlsAccountName, Azuresource, Azuredestination, 1, false, true); Console.WriteLine("Uploaded Business Report"); // Deleting the Business Report Files Array.ForEach(Directory.GetFiles(directoryFullPath), File.Delete); // ------------------ REPORT 2 ------------------ // ---- Automating Scraping Method ---- // Downloading Reserved Inventory Report driver.Navigate().GoToUrl("https://sellercentral.amazon.com/gp/ssof/reports/search.html#orderAscending=&recordType=ReserveBreakdown&noResultType=&merchantSku=&fnSku=&FnSkuXORMSku=&reimbursementId=&orderId=&genericOrderId=&asin=&lpn=&shipmentId=&problemType=ALL_DEFECT_TYPES&hazmatStatus=&inventoryEventTransactionType=&fulfillmentCenterId=&transactionItemId=&inventoryAdjustmentReasonGroup=&eventDateOption=1&fromDate=mm%2Fdd%2Fyyyy&toDate=mm%2Fdd%2Fyyyy&startDate=&endDate=&fromMonth=1&fromYear=2019&toMonth=1&toYear=2019&startMonth=&startYear=&endMonth=&endYear=&specificMonth=1&specificYear=2019"); Thread.Sleep(1000); driver.FindElement(By.XPath("//*[@id=\"requestCsvTsvDownload\"]/tr[1]/td[2]/button")).Click(); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1000); Thread.Sleep(10000); driver.FindElement(By.XPath("//*[@id=\"downloadArchive\"]/table/tbody/tr[1]/td[5]/a")).Click(); // Editing the Reserved Inventory CSV // Appending Columns and Values in Existing CSV File string ResRepfilePath = ""; foreach (string filename in Directory.GetFiles(directoryFullPath)) { ResRepfilePath = directoryFullPath + Path.GetFileName(filename); // Getting the File Name } // Account var Rescol1 = File.ReadLines(ResRepfilePath).Select((line, index) => index == 0 ? line + ",Account" : line + ",Meal Prep Haven").ToList(); File.WriteAllLines(ResRepfilePath, Rescol1); // Country var Rescol2 = File.ReadLines(ResRepfilePath).Select((line, index) => index == 0 ? line + ",Country" : line + ",US").ToList(); File.WriteAllLines(ResRepfilePath, Rescol2); // Reference URL var Rescol3 = File.ReadLines(ResRepfilePath).Select((line, index) => index == 0 ? line + ",Reference" : line + "," + driver.Url).ToList(); File.WriteAllLines(ResRepfilePath, Rescol3); // Transaction Date var Rescol4 = File.ReadLines(ResRepfilePath).Select((line, index) => index == 0 ? line + ", Transaction Date" : line + "," + DateTime.Now.ToString("MM/dd/yyyy")).ToList(); File.WriteAllLines(ResRepfilePath, Rescol4); // Renaming the Report File File.Move(ResRepfilePath, directoryFullPath + "ReservedInventoryReport.csv"); // Uploading Reserved Inventory Report to Azure Data Lake Azuresource = directoryFullPath + "ReservedInventoryReport.csv"; Azuredestination = "Meal prep haven/CA_AO/Reserved Inventory Reports/" + "ReservedInventoryReport-" + DateTime.Now.ToString("dd/MM/yyyy") + ".csv"; adlsFileSystemClient.FileSystem.UploadFile(AdlsAccountName, Azuresource, Azuredestination, 1, false, true); Console.WriteLine("Uploaded Reserved Inventory Report"); // Deleting the Reserved Inventory Report File Array.ForEach(Directory.GetFiles(directoryFullPath), File.Delete); // ------------------ REPORT 3 ------------------ // ---- Automating Scraping Method ---- // Downloading Managed Inventory Report driver.Navigate().GoToUrl("https://sellercentral.amazon.com/gp/ssof/reports/search.html?#orderAscending=&recordType=FBA_MYI_UNSUPPRESSED_INVENTORY&noResultType=&merchantSku=&fnSku=&FnSkuXORMSku=&reimbursementId=&orderId=&genericOrderId=&asin=&lpn=&shipmentId=&problemType=ALL_DEFECT_TYPES&hazmatStatus=&inventoryEventTransactionType=&fulfillmentCenterId=&transactionItemId=&inventoryAdjustmentReasonGroup=&eventDateOption=1&fromDate=mm%2Fdd%2Fyyyy&toDate=mm%2Fdd%2Fyyyy&startDate=&endDate=&fromMonth=1&fromYear=2019&toMonth=1&toYear=2019&startMonth=&startYear=&endMonth=&endYear=&specificMonth=1&specificYear=2019"); Thread.Sleep(1000); driver.FindElement(By.XPath("//*[@id=\"requestCsvTsvDownload\"]/tr[1]/td[2]/button")).Click(); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1000); Thread.Sleep(10000); driver.FindElement(By.XPath("//*[@id=\"downloadArchive\"]/table/tbody/tr[1]/td[5]/a")).Click(); // Editing the Managed Inventory CSV // Appending Columns and Values in Existing CSV File string ManRepfilePath = ""; foreach (string filename in Directory.GetFiles(directoryFullPath)) { ManRepfilePath = directoryFullPath + Path.GetFileName(filename); // Getting the File Name } // Account var Mancol1 = File.ReadLines(ManRepfilePath).Select((line, index) => index == 0 ? line + ",Account" : line + ",Meal Prep Haven").ToList(); File.WriteAllLines(ManRepfilePath, Mancol1); // Country var Mancol2 = File.ReadLines(ManRepfilePath).Select((line, index) => index == 0 ? line + ",Country" : line + ",US").ToList(); File.WriteAllLines(ManRepfilePath, Mancol2); // Reference URL var Mancol3 = File.ReadLines(ManRepfilePath).Select((line, index) => index == 0 ? line + ",Reference" : line + "," + driver.Url).ToList(); File.WriteAllLines(ManRepfilePath, Mancol3); // Transaction Date var Mancol4 = File.ReadLines(ManRepfilePath).Select((line, index) => index == 0 ? line + ", Transaction Date" : line + "," + DateTime.Now.ToString("MM/dd/yyyy")).ToList(); File.WriteAllLines(ManRepfilePath, Mancol4); // Renaming the Report File File.Move(ManRepfilePath, directoryFullPath + "ManagedInventoryReport.csv"); // Uploading Reserved Inventory Report to Azure Data Lake Azuresource = directoryFullPath + "ManagedInventoryReport.csv"; Azuredestination = "Meal prep haven/CA_AO/Managed Inventory Reports/" + "ManagedInventoryReport-" + DateTime.Now.ToString("dd/MM/yyyy") + ".csv"; adlsFileSystemClient.FileSystem.UploadFile(AdlsAccountName, Azuresource, Azuredestination, 1, false, true); Console.WriteLine("Uploaded Managed Inventory Report"); // Deleting the Managed Inventory Report File Array.ForEach(Directory.GetFiles(directoryFullPath), File.Delete); // ------------------ REPORT 4 ------------------ // ---- Automating Scraping Method ---- // Downloading Payment Report driver.Navigate().GoToUrl("https://sellercentral.amazon.com/payments/reports/custom/request?tbla_daterangereportstable=sort:%7B%22sortOrder%22%3A%22DESCENDING%22%7D;search:undefined;pagination:1;"); Thread.Sleep(1000); driver.FindElement(By.XPath("//*[@id=\"drrGenerateReportButton\"]/span/input")).Click(); driver.FindElement(By.XPath("//*[@id=\"drrReportTypeRadioTransaction\"]")).Click(); driver.FindElement(By.XPath("//*[@id=\"drrReportRangeTypeRadioCustom\"]")).Click(); driver.FindElement(By.XPath("//*[@id=\"drrFromDate\"]")).SendKeys(DateTime.Now.AddDays(-2).ToString("MM/dd/yyyy").Replace("-", "/") + Keys.Enter); driver.FindElement(By.XPath("//*[@id=\"drrToDate\"]")).SendKeys(DateTime.Now.AddDays(-2).ToString("MM/dd/yyyy").Replace("-", "/") + Keys.Enter); driver.FindElement(By.XPath("//*[@id=\"drrGenerateReportsGenerateButton\"]/span/input")).Click(); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1000); driver.FindElement(By.ClassName("drrRefreshTable")).Click(); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1000); Thread.Sleep(10000); driver.FindElement(By.XPath("//*[@id=\"downloadButton\"]")).Click(); // Editing the Payment CSV // Appending Columns and Values in Existing CSV File string PayRepfilePath = ""; foreach (string filename in Directory.GetFiles(directoryFullPath)) { PayRepfilePath = directoryFullPath + Path.GetFileName(filename); // Getting the File Name } // Account var Paycol1 = File.ReadLines(PayRepfilePath).Select((line, index) => index == 0 ? line + ",Account" : line + ",Meal Prep Haven").ToList(); File.WriteAllLines(PayRepfilePath, Paycol1); // Country var Paycol2 = File.ReadLines(PayRepfilePath).Select((line, index) => index == 0 ? line + ",Country" : line + ",US").ToList(); File.WriteAllLines(PayRepfilePath, Paycol2); // Reference URL var Paycol3 = File.ReadLines(PayRepfilePath).Select((line, index) => index == 0 ? line + ",Reference" : line + ",https://sellercentral.amazon.com/payments/reports/custom/request?tbla_daterangereportstable=sort:%7B%22sortOrder%22%3A%22DESCENDING%22%7D;search:undefined;pagination:1;").ToList(); //+ driver.Url).ToList(); File.WriteAllLines(PayRepfilePath, Paycol3); // Renaming the Report File File.Move(PayRepfilePath, directoryFullPath + "PaymentReport.csv"); // Uploading Payment Report to Azure Data Lake Azuresource = directoryFullPath + "PaymentReport.csv"; Azuredestination = "Meal prep haven/CA_AO/Payment Reports/" + "PaymentReport-17-10-2019.csv"; //+ DateTime.Now.ToString("dd/MM/yyyy") + ".csv"; adlsFileSystemClient.FileSystem.UploadFile(AdlsAccountName, Azuresource, Azuredestination, 1, false, true); Console.WriteLine("Uploaded Payment Report"); // Deleting the Payment Report File Array.ForEach(Directory.GetFiles(directoryFullPath), File.Delete); // ------------------ REPORT 5 ------------------ // ---- Automating Scraping Method ---- // Downloading Storage Fees Report driver.Navigate().GoToUrl("https://sellercentral.amazon.com/gp/ssof/reports/search.html#orderAscending=&recordType=STORAGE_FEE_CHARGES&noResultType=&merchantSku=&fnSku=&FnSkuXORMSku=&reimbursementId=&orderId=&genericOrderId=&asin=&lpn=&shipmentId=&problemType=ALL_DEFECT_TYPES&hazmatStatus=&inventoryEventTransactionType=&fulfillmentCenterId=&transactionItemId=&inventoryAdjustmentReasonGroup=&eventDateOption=1&fromDate=mm%2Fdd%2Fyyyy&toDate=mm%2Fdd%2Fyyyy&startDate=&endDate=&fromMonth=1&fromYear=2019&toMonth=1&toYear=2019&startMonth=&startYear=&endMonth=&endYear=&specificMonth=1&specificYear=2019"); Thread.Sleep(1000); driver.FindElement(By.XPath("//*[@id=\"specificMonthDownload\"]/option[9]")).Click(); driver.FindElement(By.XPath("//*[@id=\"specificYearDownload\"]/option[1]")).Click(); driver.FindElement(By.XPath("//*[@id=\"requestCsvTsvDownload\"]/tr[1]/td[2]/button")).Click(); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(4000); Thread.Sleep(10000); driver.FindElement(By.XPath("//*[@id=\"downloadArchive\"]/table/tbody/tr[1]/td[5]/a")).Click(); // Editing the Storage Fees CSV // Appending Columns and Values in Existing CSV File string StoRepfilePath = ""; foreach (string filename in Directory.GetFiles(directoryFullPath)) { StoRepfilePath = directoryFullPath + Path.GetFileName(filename); // Getting the File Name } // Account var Stocol1 = File.ReadLines(StoRepfilePath).Select((line, index) => index == 0 ? line + ",Account" : line + ",Meal Prep Haven").ToList(); File.WriteAllLines(StoRepfilePath, Stocol1); // Country var Stocol2 = File.ReadLines(StoRepfilePath).Select((line, index) => index == 0 ? line + ",Country" : line + ",US").ToList(); File.WriteAllLines(StoRepfilePath, Stocol2); // Reference URL var Stocol3 = File.ReadLines(StoRepfilePath).Select((line, index) => index == 0 ? line + ",Reference" : line + "," + driver.Url).ToList(); File.WriteAllLines(StoRepfilePath, Stocol3); // Transaction Date var Stocol4 = File.ReadLines(StoRepfilePath).Select((line, index) => index == 0 ? line + ", Transaction Date" : line + "," + DateTime.Now.ToString("MM/dd/yyyy")).ToList(); File.WriteAllLines(StoRepfilePath, Stocol4); // Renaming the Report File File.Move(StoRepfilePath, directoryFullPath + "StorageFeesReport.csv"); // Uploading Storage Fees Report to Azure Data Lake Azuresource = directoryFullPath + "StorageFeesReport.csv"; Azuredestination = "Meal prep haven/CA_AO/Storage Fees Reports/" + "StorageFeesReport-" + DateTime.Now.ToString("dd/MM/yyyy") + ".csv"; adlsFileSystemClient.FileSystem.UploadFile(AdlsAccountName, Azuresource, Azuredestination, 1, false, true); Console.WriteLine("Uploaded Storage Fees Report"); // Deleting the Storage Fees Report File Array.ForEach(Directory.GetFiles(directoryFullPath), File.Delete); // ------------------ REPORT 6 ------------------ // ---- API Method ---- // Downloading Amazon ADS Product Report through API // Refreshing Access Token var client1 = new RestClient("https://api.amazon.com/auth/o2/token"); var request1 = new RestRequest(Method.POST); request1.AddHeader("Content-Type", "application/x-www-form-urlencoded"); request1.AddParameter("grant_type", "refresh_token"); request1.AddParameter("refresh_token", ADS_RefreshToken); request1.AddParameter("client_id", ADS_ClientID); request1.AddParameter("client_secret", ADS_ClientSecret); IRestResponse response1 = client1.Execute(request1); dynamic result1 = JsonConvert.DeserializeObject(response1.Content); string ADS_AccessToken = result1.access_token; // Getting the Report ID var client2 = new RestClient("https://advertising-api.amazon.com/v2/sp/productAds/report"); var request2 = new RestRequest(Method.POST); request2.AddHeader("Content-Type", "application/json"); request2.AddHeader("Authorization", "Bearer " + ADS_AccessToken); request2.AddHeader("Amazon-Advertising-API-ClientId", ADS_ClientID); request2.AddHeader("Amazon-Advertising-API-Scope", ADS_Scope); request2.AddParameter("undefined", "{\"reportDate\":\"20190930\", \"metrics\":\"campaignName,campaignId,adGroupName,adGroupId,currency,asin,sku,impressions,clicks,cost,attributedConversions1d,attributedConversions7d,attributedConversions14d,attributedConversions30d,attributedConversions1dSameSKU,attributedConversions7dSameSKU,attributedConversions14dSameSKU,attributedConversions30dSameSKU,attributedUnitsOrdered1d,attributedUnitsOrdered7d,attributedUnitsOrdered14d,attributedUnitsOrdered30d,attributedSales1d,attributedSales7d,attributedSales14d,attributedSales30d,attributedSales1dSameSKU,attributedSales7dSameSKU,attributedSales14dSameSKU,attributedSales30dSameSKU\"}", ParameterType.RequestBody); IRestResponse response2 = client2.Execute(request2); dynamic result2 = JsonConvert.DeserializeObject(response2.Content); string ReportID = result2.reportId; Thread.Sleep(3000); // Retrieving the Report Status var client3 = new RestClient("https://advertising-api.amazon.com/v2/reports/" + ReportID); var request3 = new RestRequest(Method.GET); request3.AddHeader("Content-Type", "application/json"); request3.AddHeader("Authorization", "Bearer " + ADS_AccessToken); request3.AddHeader("Amazon-Advertising-API-ClientId", ADS_ClientID); request3.AddHeader("Amazon-Advertising-API-Scope", ADS_Scope); IRestResponse response3 = client3.Execute(request3); dynamic result3 = JsonConvert.DeserializeObject(response3.Content); string DownloadLocation = result3.location; if (result3.status == "SUCCESS") { // Retrieving Report Download URL var client4 = new RestClient(DownloadLocation); var request4 = new RestRequest(Method.GET); request4.AddHeader("Authorization", "Bearer " + ADS_AccessToken); request4.AddHeader("Amazon-Advertising-API-Scope", ADS_Scope); IRestResponse response4 = client4.Execute(request4); string DownloadURL = response4.ResponseUri.ToString(); // Downloading the Report driver.Navigate().GoToUrl(DownloadURL); } // Extracting .gz Zip file DirectoryInfo directorySelected = new DirectoryInfo(directoryFullPath); foreach (FileInfo fileToDecompress in directorySelected.GetFiles("*.gz")) { Decompress(fileToDecompress); } // Uploading Amazon ADS Product Report to Azure Data Lake Azuresource = directoryFullPath + "ADSProductReport.json"; Azuredestination = "Meal prep haven/CA_AO/Advertised Product Reports/" + "AmazonADSProductReport-" + DateTime.Now.ToString("dd/MM/yyyy") + ".json"; adlsFileSystemClient.FileSystem.UploadFile(AdlsAccountName, Azuresource, Azuredestination, 1, false, true); Console.WriteLine("Uploaded Amazon ADS Product Report"); // Deleting the Amazon ADS Product Report File Array.ForEach(Directory.GetFiles(directoryFullPath), File.Delete); // ------------------ REPORT 7 ------------------ // ---- API Method ---- // Downloading WorldPack Report through API // Getting the Access Token var clientw1 = new RestClient("http://secure-wms.com/AuthServer/api/Token"); var requestw1 = new RestRequest(Method.POST); requestw1.AddHeader("Content-Type", "application/json; charset=utf-8"); requestw1.AddHeader("Accept", "application/json"); requestw1.AddHeader("Authorization", "Basic " + WP_Authorization); requestw1.AddParameter("undefined", "{\"grant_type\": \"client_credentials\",\"tpl\": \"{1ddbea91-a4ff-4b42-a25d-81a25b8cb727}\",\"user_login_id\": \"759\"}", ParameterType.RequestBody); IRestResponse responsew1 = clientw1.Execute(requestw1); dynamic resultw1 = JsonConvert.DeserializeObject(responsew1.Content); string WP_AccessToken = resultw1.access_token; // Getting the Inventory Details var clientw2 = new RestClient("https://secure-wms.com/inventory/stockdetails?customerid=194&facilityid=4"); var requestw2 = new RestRequest(Method.GET); requestw2.AddHeader("Content-Type", "application/hal+json; charset=utf-8"); requestw2.AddHeader("Accept", "application/hal+json"); requestw2.AddHeader("Authorization", "Bearer " + WP_AccessToken); IRestResponse responsew2 = clientw2.Execute(requestw2); dynamic resultw2 = JsonConvert.DeserializeObject(responsew2.Content); string jsonstr = resultw2._embedded.ToString(); // Uploading WorldPack Report to Azure Data Lake Azuresource = directoryFullPath + "WorldPackReport.json"; Azuredestination = "Third Party Reports/WorldPack Reports/" + "WorldPackReport-" + DateTime.Now.ToString("dd/MM/yyyy") + ".json"; adlsFileSystemClient.FileSystem.UploadFile(AdlsAccountName, Azuresource, Azuredestination, 1, false, true); Console.WriteLine("Uploaded World Pack Report"); // Deleting the Amazon ADS Product Report File Array.ForEach(Directory.GetFiles(directoryFullPath), File.Delete); // ------------------ REPORT 8 ------------------ // ---- API Method ---- // Downloading Amazon MWS Reports - FBA_StorageFees Report through API string accessKeyId = MWS_AccessID; string secretAccessKey = MWS_SecretKey; MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig(); config.ServiceURL = "https://mws.amazonservices.com"; const string applicationName = "ApplicationName"; const string applicationVersion = "0.1a"; MarketplaceWebServiceClient service = new MarketplaceWebServiceClient( accessKeyId, secretAccessKey, applicationName, applicationVersion, config); string merchantID = MWS_MerchantID; string mwsauthtoken = MWS_AuthToken; // Requesting the Report RequestReportRequest reportRequest = new RequestReportRequest(); reportRequest.Merchant = merchantID; reportRequest.MWSAuthToken = mwsauthtoken; reportRequest.ReportType = "_GET_FBA_STORAGE_FEE_CHARGES_DATA_"; reportRequest.StartDate = DateTime.Parse(DateTime.Now.AddMonths(-1).ToString("dd/MM/yyyy")); reportRequest.EndDate = DateTime.Now; reportRequest.ReportOptions = "true"; //shows sales channel to certain reports // Handling the Response of RequestReport RequestReportResponse reportResponse = service.RequestReport(reportRequest); Thread.Sleep(30000); //sleep for 30 seconds to allow report request to generate prior to requesting the reportRequestID string requestID = reportResponse.RequestReportResult.ReportRequestInfo.ReportRequestId; string reportStatus = ""; // holds the status of the report // Getting the Report Request List GetReportRequestListRequest reportRequestList = new GetReportRequestListRequest(); reportRequestList.Merchant = merchantID; reportRequestList.MWSAuthToken = mwsauthtoken; // Handling the Response of Report Request List GetReportRequestListResponse reportRequestListReponse = service.GetReportRequestList(reportRequestList); foreach (ReportRequestInfo info in reportRequestListReponse.GetReportRequestListResult.ReportRequestInfo) { if (info.ReportRequestId.Equals(requestID)) { reportStatus = info.ReportProcessingStatus; if (reportStatus == "_DONE_") { // Getting the Report using Report ID GetReportRequest getReport = new GetReportRequest(); getReport.ReportId = info.GeneratedReportId; getReport.Merchant = merchantID; getReport.MWSAuthToken = mwsauthtoken; // Writting the Report as a File string filename = Path.Combine(directoryFullPath, "FBA_StorageFeesReport-" + DateTime.Now.ToString("dd/MM/yyyy") + ".csv"); getReport.Report = File.Open(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite); GetReportResponse report_response = service.GetReport(getReport); Console.WriteLine("Sleeping for 1 minute to allow processes to settle. "); Thread.Sleep(60000); getReport.Report.Close(); // Uploading FBA Storage Fees to Azure Data Lake Azuresource = filename; Azuredestination = "Amazon MWS Reports/" + "FBA_StorageFeesReport-" + System.DateTime.Now.ToString("dd/MM/yyyy") + ".csv"; adlsFileSystemClient.FileSystem.UploadFile(AdlsAccountName, Azuresource, Azuredestination, 1, false, true); Console.WriteLine("Uploaded Amazon MWS FBA_StorageFees Report"); break; } } else { continue; // Only concerning about the requested report, not all the reports being generated } } // Closing the Browser driver.Quit(); }
/// <remarks/> public void GetReportAsync(GetReportRequest GetReportRequest) { this.GetReportAsync(GetReportRequest, null); }
// Public API ------------------------------------------------------------// /// <summary> /// Get Report /// </summary> /// <param name="request">Get Report request</param> /// <returns>Get Report Response from the service</returns> /// <remarks> /// The GetReport operation returns the contents of a report. Reports can potentially be /// very large (>100MB) which is why we only return one report at a time, and in a /// streaming fashion. /// /// </remarks> public GetReportResponse GetReport(GetReportRequest request) { return(Invoke <GetReportResponse>("GetReportResponse.xml")); }
/// <remarks/> public void GetReportAsync(GetReportRequest GetReportRequest, object userState) { if ((this.GetReportOperationCompleted == null)) { this.GetReportOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetReportOperationCompleted); } this.InvokeAsync("GetReport", new object[] { GetReportRequest}, this.GetReportOperationCompleted, userState); }