コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the ClearingParser class.
 /// </summary>
 /// <param name="log">
 /// The CommerceLog object through which log entries can be made.
 /// </param>
 public ClearingParser(CommerceLog log)
 {
     Log = log;
     ClearingHeaderParser  = new ClearingHeaderParser(log);
     ClearingDataParser    = new ClearingDataParser(log);
     ClearingTrailerParser = new ClearingTrailerParser(log);
 }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the RebateConfirmationParser class.
 /// </summary>
 /// <param name="log">
 /// The CommerceLog object through which log entries can be made.
 /// </param>
 public RebateConfirmationParser(CommerceLog log)
 {
     Log = log;
     RebateConfirmationHeaderParser  = new RebateConfirmationHeaderParser(log);
     RebateConfirmationDataParser    = new RebateConfirmationDataParser(log);
     RebateConfirmationTrailerParser = new RebateConfirmationTrailerParser(log);
 }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the ApplyReferralRewardTask class.
 /// </summary>
 /// <param name="rewardPayoutRecord">
 /// The RewardPayoutRecord to process.
 /// </param>
 /// <param name="userId">
 /// The ID of the user who was referred into the system.
 /// </param>
 /// <param name="log">
 /// The CommerceLog object through which log entries can be made.
 /// </param>
 public ApplyRewardTask(RewardPayoutRecord rewardPayoutRecord,
                        string userId,
                        CommerceLog log)
 {
     RewardPayoutRecord = rewardPayoutRecord;
     UserId             = userId;
     Log = log;
 }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the JobOrchestrator class.
 /// </summary>
 /// <param name="job">
 /// The job being executed.
 /// </param>
 /// <param name="jobDetails">
 /// Details about the job being executed.
 /// </param>
 /// <param name="log">
 /// The CommerceLog object through which log entries can be made.
 /// </param>
 public JobOrchestrator(IOrchestratedJob job,
                        ScheduledJobDetails jobDetails,
                        CommerceLog log)
 {
     Job        = job;
     JobDetails = jobDetails;
     Log        = log;
 }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the MasterCardBlobClient class.
 /// </summary>
 /// <param name="folderName">
 /// The name of the folder in which files will be uploaded.
 /// </param>
 /// <param name="fileTypeDescription">
 /// The description for the type of file this object is addressing.
 /// </param>
 /// <param name="log">
 /// The CommerceLog object within which to place log entries.
 /// </param>
 protected MasterCardBlobClient(string folderName,
                                string fileTypeDescription,
                                CommerceLog log)
     : base(ConnectionString, folderName)
 {
     FileTypeDescription = fileTypeDescription;
     Log = log;
 }
コード例 #6
0
        /// <summary>
        /// Execute the file sync job
        /// </summary>
        /// <param name="details">
        /// Details of the job we are executing here.
        /// </param>
        /// <param name="logger">
        /// Handle to the logger
        /// </param>
        /// <remarks>
        /// This job:
        /// 1. If response is pending, it waits for response to be available
        /// 2. When response becomes available, the job processes it and puts flag that response is processed
        /// 3. If response is not pending, it checks to see if there are records to upload and uploads them
        /// 4. After file is sent to Amex, job puts flag that response is being waited on
        /// </remarks>
        public async Task Execute(ScheduledJobDetails details, CommerceLog logger)
        {
            Logger     = logger;
            JobDetails = details;
            Init();

            Logger.Exhaustive("Starting execution of job \r\n Details {0}", details);

            ////if (IsWaitingForResponse())
            ////{
            ////    // check the response
            ////    string[] responseFileNames = await RetrieveResponseFileNamesAsync().ConfigureAwait(false);
            ////    if (responseFileNames == null)
            ////    {
            ////        // we have to wait for response.
            ////        return;
            ////    }

            ////    await UploadResponseFilesToBlobStoreAsync(responseFileNames).ConfigureAwait(false);

            ////    // update job to mark, no response is expected now
            ////    UpdateResponsePendingIndicatorInJob("false");
            ////}
            ////else
            ////{
            ////    // process response files if present in blob store
            ////    await ProcessResponseFilesAsync().ConfigureAwait(false);

            ////    // if we reach here, we have either processed the response or no response is being waited on
            ////    // so create new request file if needed
            ////    string requestFile = await CreateNewRequestFileIfNeededAsync().ConfigureAwait(false);

            ////    if (requestFile != null)
            ////    {
            ////        await SendRequestFileAsync(requestFile).ConfigureAwait(false);

            ////        // successfully sent file -> update job to wait for response
            ////        UpdateResponsePendingIndicatorInJob("true");

            ////    }
            ////}

            // Process if any response files are pending
            string[] responseFileNames = await RetrieveResponseFileNamesAsync().ConfigureAwait(false);

            if (responseFileNames != null && responseFileNames.Length > 0)
            {
                await UploadResponseFilesToBlobStoreAsync(responseFileNames).ConfigureAwait(false);
            }

            // Process if any requests files are pending
            string requestFile = await CreateNewRequestFileIfNeededAsync().ConfigureAwait(false);

            if (requestFile != null)
            {
                await SendRequestFileAsync(requestFile).ConfigureAwait(false);
            }
        }
コード例 #7
0
 /// <summary>
 /// Initializes a new instance of the ExtractParser class.
 /// </summary>
 /// <param name="log">
 /// The CommerceLog object through which log entries can be made.
 /// </param>
 public ExtractParser(CommerceLog log)
 {
     Log = log;
     ExtractHeaderParser           = new ExtractHeaderParser(log);
     RedemptionDetailParser        = new RedemptionDetailParser(log);
     SettlementDetailParser        = new SettlementDetailParser(log);
     TransactionNotificationParser = new TransactionNotificationParser(log);
     ExtractFooterParser           = new ExtractFooterParser(log);
 }
コード例 #8
0
        /// <summary>
        /// Creates and initializes an instance of IOrchestratedJob of the specified type.
        /// </summary>
        /// <param name="jobDetails">
        /// Details describing the IOrchestratedJob type to create.
        /// </param>
        /// <param name="scheduler">
        /// The scheduler managing the job.
        /// </param>
        /// <param name="log">
        /// The object through which log entries can be made.
        /// </param>
        /// <returns>
        /// An instance of IOrchestratedJob of the specified type.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// * Parameter jobDetails cannot be null.
        /// -OR-
        /// * Parameter log cannot be null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Parameter JobDetails does not specify a valid IOrchestratedJob type.
        /// </exception>
        public static IOrchestratedJob Create(ScheduledJobDetails jobDetails,
                                              IScheduler scheduler,
                                              CommerceLog log)
        {
            if (jobDetails == null)
            {
                throw new ArgumentNullException("jobDetails", "Parameter jobDetails cannot be null.");
            }

            if (log == null)
            {
                throw new ArgumentNullException("log", "Parameter log cannot be null.");
            }

            IOrchestratedJob result = null;

            if (jobDetails.Payload != null)
            {
                switch (jobDetails.JobType)
                {
                case ScheduledJobType.ApplyReferralReward:
                    result = new ApplyReferralRewardJob(log);
                    break;

                case ScheduledJobType.ApplyRedemptionReward:
                    result = new ApplyRedemptionRewardJob(log);
                    break;

                case ScheduledJobType.ClaimDiscountsForNewCard:
                    result = new ClaimDiscountsForNewCardJob(log);
                    break;

                case ScheduledJobType.ClaimDiscountForExistingCards:
                    result = new ClaimDiscountForExistingCardsJob(log);
                    break;

                case ScheduledJobType.AmexOfferRegistration:
                    result = new AmexOfferRegistrationJob(log);
                    break;

                default:
                    throw new ArgumentException("Parameter JobDetails does not specify a valid IOrchestratedJob type.",
                                                "jobDetails");
                }

                result.Initialize(jobDetails, scheduler);
            }
            else
            {
                log.Error("{0} orchestrated job contains no Payload.", null, jobDetails.JobType,
                          ResultCode.JobContainsNoPayload);
            }

            return(result);
        }
コード例 #9
0
        /// <summary>
        /// Process MasterCard rebate confirmation file job execution.
        /// </summary>
        /// <param name="details">
        /// Details of the job to be executed.
        /// </param>
        /// <param name="log">
        /// Log within which to log status of job processing.
        /// </param>
        /// <returns>
        /// A task to execute the  job.
        /// </returns>
        /// <remarks>
        /// Once complete, this job will schedule a corresponding MasterCardProcessRebateConfirmationJob.
        /// </remarks>
        public async Task Execute(ScheduledJobDetails details,
                                  CommerceLog log)
        {
            Log = log;
            Log.Verbose("Starting execution of job.\r\nDetails {0}", details);

            MasterCardRebateConfirmationBlobClient blobClient = MasterCardBlobClientFactory.MasterCardRebateConfirmationBlobClient(log);

            // Download files from MasterCard and upload them to the blob store.
            IFtpClient ftpClient = MasterCardFtpClientFactory.RebateConfirmationFtpClient(Log);

            string[] files = await ftpClient.DirectoryListAsync();

            if (files != null)
            {
                foreach (string fileName in files)
                {
                    using (MemoryStream memStream = new MemoryStream())
                    {
                        // Download the file from MasterCard.
                        await ftpClient.DownloadFileAsync(fileName, memStream).ConfigureAwait(false);

                        // Upload the file to the blob store.
                        memStream.Position = 0;
                        await blobClient.UploadAsync(memStream, fileName).ConfigureAwait(false);
                    }
                }
            }

            // Process all pending rebate confirmation files in the blob store.
            ICollection <string> fileNames = blobClient.RetrieveNamesOfPendingFiles();

            if (fileNames != null)
            {
                foreach (string fileName in fileNames)
                {
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        // Download the file from the blob store.
                        memoryStream.Position = 0;
                        await blobClient.DownloadAsync(memoryStream, fileName).ConfigureAwait(false);

                        // Process the file.
                        memoryStream.Position = 0;
                        ISettlementFileProcessor rebateConfirmationProcessor = MasterCardFileProcessorFactory.MasterCardRebateConfirmationProcessor(memoryStream, fileName);
                        await rebateConfirmationProcessor.Process().ConfigureAwait(false);
                    }

                    // Mark the file as having been processed.
                    await blobClient.MarkAsCompleteAsync(fileName).ConfigureAwait(false);
                }
            }

            Log.Verbose("Execution of job {0} complete ", details.JobId);
        }
コード例 #10
0
        private async Task <AmexCardResponse> AddOrRemoveCardAsync <T>(T requestPayload, string requestUri, AmexOAuthResponse amexOAuthResponse)
        {
            if (amexOAuthResponse != null)
            {
                string     timestamp = ((int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString();
                string     nonce     = string.Concat(timestamp, ":AMEX");
                UriBuilder uri       = new UriBuilder(requestUri);

                //Format = timestamp \n timestamp:AMEX \n method \n path \n port \n\n
                string message = string.Format("{0}\n{1}\nPOST\n{2}\n{3}\n{4}\n\n", timestamp, nonce, Regex.Replace(HttpUtility.UrlEncode(uri.Path.ToLowerInvariant()), @"%[a-f0-9]{2}", c => c.Value.ToUpper()), uri.Host.ToLowerInvariant(), uri.Port);

                using (HMACSHA256 hmac = new HMACSHA256(Encoding.UTF8.GetBytes(amexOAuthResponse.MacKey)))
                {
                    string mac = Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(message)));
                    // Format -> MAC id="access_token",ts="timestamp",nonce="timestamp:AMEX",mac="HMACSHA256 hash"
                    string    authorizationHeader = string.Format("MAC id=\"{0}\",ts=\"{1}\",nonce=\"{2}\",mac=\"{3}\"", amexOAuthResponse.AccessToken, timestamp, nonce, mac);
                    Stopwatch timer = Stopwatch.StartNew();

                    try
                    {
                        using (HttpClient httpClient = new HttpClient())
                        {
                            httpClient.DefaultRequestHeaders.Accept.Clear();
                            //httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("MAC", authorizationHeader.ToString());
                            httpClient.DefaultRequestHeaders.Add("Authorization", authorizationHeader.ToString());
                            httpClient.DefaultRequestHeaders.Add("X-AMEX-API-KEY", ConfigurationManager.AppSettings[AmexConstants.AmexOAuthClientId]);
                            httpClient.DefaultRequestHeaders.Add("X-AMEX-MSG-ID", CommerceLog.ActivityId.ToString("N"));

                            HttpResponseMessage response = await httpClient
                                                           .PostAsJsonAsync(requestUri, requestPayload)
                                                           .ConfigureAwait(false);

                            string content = await response.Content.ReadAsStringAsync();

                            if (response.IsSuccessStatusCode)
                            {
                                CommerceLog.Verbose("Received Amex AddOrRemoveCardAsync response. \r\nUri: {0} \r\nContent: {1}", requestUri, content);
                                return(JsonConvert.DeserializeObject <AmexCardResponse>(content));
                            }
                            else
                            {
                                CommerceLog.Critical("Unable to get Amex AddOrRemoveCardAsync response. \r\nUri: {0} \r\nStatus: {1} \r\nContent: {2}", null, requestUri, response.StatusCode, content);
                            }
                        }
                    }
                    finally
                    {
                        timer.Stop();
                        PerformanceInformation.Add(requestUri, string.Format("{0} ms", timer.ElapsedMilliseconds));
                    }
                }
            }

            return(null);
        }
コード例 #11
0
        /// <summary>
        /// Creates an instance of the rebate confirmation file FTP client.
        /// </summary>
        /// <param name="log">
        /// The CommerceLog object through which log entries can be made.
        /// </param>
        /// <returns>
        /// An instance of the rebate confirmation file FTP client.
        /// </returns>
        public static IFtpClient RebateConfirmationFtpClient(CommerceLog log)
        {
            IFtpClient result = new RebateConfirmationFtpClient(log);

            if (CommerceWorkerConfig.Instance.UseMockPartnerDependencies == true)
            {
                result = LateBinding.BuildObjectFromLateBoundAssembly <IFtpClient>("MockMasterCardFtpClient", LateBoundMocksAssemblyTypes);
            }

            return(result);
        }
コード例 #12
0
 /// <summary>
 /// Ctor for runner
 /// </summary>
 /// <param name="jobFactory">
 /// Job Factory to get implementation of the job
 /// </param>
 /// <param name="scheduler">
 /// Scheduler
 /// </param>
 /// <param name="commerceConfig">
 /// Config
 /// </param>
 /// <param name="log">
 /// Logger
 /// </param>
 public OrchestratedJobRunner(
     Func <ScheduledJobDetails, IScheduler, CommerceLog, IOrchestratedJob> jobFactory,
     IScheduler scheduler,
     CommerceConfig commerceConfig,
     CommerceLog log)
 {
     JobFactory     = jobFactory;
     CommerceConfig = commerceConfig;
     Log            = log;
     Scheduler      = scheduler;
 }
コード例 #13
0
        /// <summary>
        /// Creates instance of FDC Pts FTP Client
        /// </summary>
        /// <param name="log">
        /// Commerce Logger
        /// </param>
        /// <returns>
        /// Instance of ftp client
        /// </returns>
        public static IFtpClient FirstDataPtsFtpClient(CommerceLog log)
        {
            IFtpClient result = new FirstDataPtsFtpClient(log);

            if (CommerceWorkerConfig.Instance.UseMockPartnerDependencies == true)
            {
                result = LateBinding.BuildObjectFromLateBoundAssembly <IFtpClient>("MockFirstDataFtpClient",
                                                                                   LateBoundMocksAssemblyTypes);
            }

            return(result);
        }
コード例 #14
0
        public async Task Execute(ScheduledJobDetails details, CommerceLog log)
        {
            Log = log;

            Log.Verbose("Starting execution of job.\r\nDetails {0}", details);

            // Process rebate job for Visa.
            var visaProcessor = VisaSettlementProcessorFactory.VisaRebateProcessor();
            await visaProcessor.Process().ConfigureAwait(false);

            Log.Verbose("Exeuction of job {0} complete ", details.JobId);
        }
コード例 #15
0
        private async Task <AmexOAuthResponse> GetOAuthTokenAsync()
        {
            // unix epoch format
            string timestamp = ((int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString();
            string nonce     = string.Concat(timestamp, ":AMEX");
            string clientId  = ConfigurationManager.AppSettings[AmexConstants.AmexOAuthClientId];

            // Format -> client_id \n timestamp \n timestamp:AMEX \n grant
            string message = string.Format("{0}\n{1}\n{2}\nclient_credentials\n", clientId, timestamp, nonce);

            using (HMACSHA256 hmac = new HMACSHA256(Encoding.UTF8.GetBytes(ConfigurationManager.AppSettings[AmexConstants.AmexOAuthClientSecret])))
            {
                string mac = Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(message)));
                // Format -> MAC id="client_id",ts="timestamp",nonce="timestamp:AMEX",mac="HMACSHA256 hash"
                string authenticationHeader = string.Format("MAC id=\"{0}\",ts=\"{1}\",nonce=\"{2}\",mac=\"{3}\"", clientId, timestamp, nonce, mac);

                Stopwatch timer = Stopwatch.StartNew();
                try
                {
                    using (HttpClient httpClient = new HttpClient())
                    {
                        httpClient.DefaultRequestHeaders.Accept.Clear();
                        httpClient.DefaultRequestHeaders.Add("Authentication", authenticationHeader);
                        httpClient.DefaultRequestHeaders.Add("X-AMEX-API-KEY", clientId);
                        HttpContent httpContent = new StringContent("grant_type=client_credentials&app_spec_info=Apigee&guid_type=privateguid");
                        httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
                        HttpResponseMessage response = await httpClient
                                                       .PostAsync(ConfigurationManager.AppSettings[AmexConstants.AmexOAuthUri], httpContent)
                                                       .ConfigureAwait(false);

                        string content = await response.Content.ReadAsStringAsync();

                        if (response.IsSuccessStatusCode)
                        {
                            CommerceLog.Verbose("Received Amex OAuth token. \r\nContent: {0}", content);
                            return(JsonConvert.DeserializeObject <AmexOAuthResponse>(content));
                        }
                        else
                        {
                            CommerceLog.Critical("Unable to get Amex OAuth token. \r\nStatus: {0} \r\nContent: {1}", null, response.StatusCode, content);
                        }
                    }
                }
                finally
                {
                    timer.Stop();
                    PerformanceInformation.Add("Amex OAuth API", string.Format("{0} ms", timer.ElapsedMilliseconds));
                }
            }

            return(null);
        }
コード例 #16
0
        /// <summary>
        /// Process MasterCard rebate file job execution.
        /// </summary>
        /// <param name="details">
        /// Details of the job to be executed.
        /// </param>
        /// <param name="log">
        /// Log within which to log status of job processing.
        /// </param>
        /// <returns>
        /// A task to execute the  job.
        /// </returns>
        public async Task Execute(ScheduledJobDetails details,
                                  CommerceLog log)
        {
            Log = log;

            Log.Verbose("Starting execution of job.\r\nDetails {0}", details);

            // Process rebate job for MasterCard.
            ISettlementFileProcessor masterCardProcessor = MasterCardFileProcessorFactory.MasterCardRebateProcessor(UploadRebateFile);
            await masterCardProcessor.Process().ConfigureAwait(false);

            Log.Verbose("Exeuction of job {0} complete ", details.JobId);
        }
コード例 #17
0
        /// <summary>
        /// Process Pts File Job Execution
        /// </summary>
        /// <param name="details">
        /// Details of the job we are executing here.
        /// </param>
        /// <param name="logger">
        /// Handle to the logger
        /// </param>
        public async Task Execute(ScheduledJobDetails details, CommerceLog logger)
        {
            Logger = logger;

            Logger.Verbose("Starting execution of job \r\n " +
                           "Details {0}", details);

            // Process PTS Job for FDC
            ISettlementFileProcessor ptsProcessor = FirstDataFileProcessorFactory.FirstDataPtsProcessor(OnPtsBuild);
            await ptsProcessor.Process().ConfigureAwait(false);

            Logger.Verbose("Exeuction of job {0} complete ", details.JobId);
        }
コード例 #18
0
 /// <summary>
 /// Creates a new instance for the Commerce Context class.
 /// You can specify the config to use.
 /// </summary>
 /// <param name="apiCallDescription">
 /// The call description for the API in which this context object is used.
 /// </param>
 /// <param name="config">
 /// The config to use to get configuration info from.
 /// </param>
 public CommerceContext(string apiCallDescription,
                        CommerceConfig config)
 {
     ApiCallDescription = apiCallDescription;
     Config             = config;
     if (config != null)
     {
         Log = new CommerceLog(Guid.NewGuid(), config.LogVerbosity, General.CommerceLogSource);
         CommerceLog.Config = config;
     }
     PerformanceInformation = new PerformanceInformation();
     Values = new Hashtable();
 }
コード例 #19
0
 /// <summary>
 /// Creates a new instance of the FtpsClientBase class.
 /// </summary>
 /// <param name="credentials">
 /// The creditals to use in the FTP request.
 /// </param>
 /// <param name="certificates">
 /// The certificates to add to the FTP request, if any.
 /// </param>
 /// <param name="ssl">
 /// Specifies whether to connect using SSL.
 /// </param>
 /// <param name="keepAlive">
 /// Specifies whether to keep the connection to the FTP server alive after operation has completed.
 /// </param>
 /// <param name="usePassive">
 /// Specifies whether to send the use passive command to the server.
 /// </param>
 /// <param name="log">
 /// The CommerceLog object through which log entries can be made.
 /// </param>
 protected FtpClientBase(ICredentials credentials,
                         X509CertificateCollection certificates,
                         bool ssl,
                         bool keepAlive,
                         bool usePassive,
                         CommerceLog log)
 {
     Credentials  = credentials;
     Certificates = certificates;
     Ssl          = ssl;
     KeepAlive    = keepAlive;
     UsePassive   = usePassive;
     Log          = log;
 }
コード例 #20
0
        /// <summary>
        /// Creates an instance of a MasterCard Rebate blob client.
        /// </summary>
        /// <param name="log">
        /// The CommerceLog object within which to place log entries.
        /// </param>
        /// <returns>
        /// And instace of the MasterCard Rebate blob client.
        /// </returns>
        public static MasterCardRebateBlobClient MasterCardRebateBlobClient(CommerceLog log)
        {
            MasterCardRebateBlobClient result = null;

            if (CommerceWorkerConfig.Instance.UseMockPartnerDependencies == true)
            {
                result = LateBinding.BuildObjectFromLateBoundAssembly <MasterCardRebateBlobClient>("MockMasterCardRebateBlobClient", LateBoundMocksAssemblyTypes);
            }
            else
            {
                result = new MasterCardRebateBlobClient(log);
            }

            return(result);
        }
コード例 #21
0
        /// <summary>
        /// Process Amex Statement Credi File Job Execution
        /// </summary>
        /// <param name="details">
        /// Details of the job we are executing here.
        /// </param>
        /// <param name="logger">
        /// Handle to the logger
        /// </param>
        public async Task Execute(ScheduledJobDetails details, CommerceLog logger)
        {
            Logger = logger;

            Logger.Verbose("Starting execution of job \r\n Details {0}", details);

            // Process Statement Credit Acknowledgment files
            await ProcessStatementCreditResponse();

            // Process Statement Credit files
            StatementCreditFileBuilder builder = new StatementCreditFileBuilder();
            await builder.Build(OnStmtCreditFileBuild).ConfigureAwait(false);

            Logger.Verbose("Execution of job {0} complete ", details.JobId);
        }
コード例 #22
0
        /// <summary>
        ///  Gets the Visa Pts Blob Client
        /// </summary>
        /// <param name="connectionString">
        /// Storage connection string
        /// </param>
        /// <param name="log">
        /// Commerce Logger
        /// </param>
        /// <returns>
        /// Instace of Visa Pts Blob Client
        /// </returns>
        public static VisaPtsBlobClient VisaPtsBlobClient(string connectionString, CommerceLog log)
        {
            VisaPtsBlobClient result = null;

            if (CommerceWorkerConfig.Instance.UseMockPartnerDependencies == true)
            {
                result = LateBinding.BuildObjectFromLateBoundAssembly <VisaPtsBlobClient>("MockVisaPtsBlobClient",
                                                                                          LateBoundMocksAssemblyTypes);
            }
            else
            {
                result = new VisaPtsBlobClient(connectionString, log);
            }

            return(result);
        }
コード例 #23
0
        /// <summary>
        /// Process Amex Transaction Log File Job Execution
        /// </summary>
        /// <param name="details">
        /// Details of the job we are executing here.
        /// </param>
        /// <param name="logger">
        /// Handle to the logger
        /// </param>
        public async Task Execute(ScheduledJobDetails details, CommerceLog logger)
        {
            logger.Verbose("Starting execution of job \r\n Details {0}", details);
            string connectionString = CloudConfigurationManager.GetSetting("Lomo.Commerce.Fdc.Blob.ConnectionString");
            AmexTransactionLogSftpClient     ftpClient  = new AmexTransactionLogSftpClient(logger);
            AmexTransactionLogFileBlobClient blobClient = AmexBlobFactory.TransactionLogBlobClient(connectionString, logger);

            string[] files = await ftpClient.DirectoryListAsync("AXP_MSF_TLOG", "outbox");

            if (files != null)
            {
                foreach (string fileName in files)
                {
                    MemoryStream memStream = new MemoryStream();
                    await ftpClient.DownloadFileAsync(fileName, memStream, "outbox").ConfigureAwait(false);

                    // lets upload it to blob
                    memStream.Position = 0;
                    await blobClient.UploadAsync(memStream, fileName).ConfigureAwait(false);
                }
            }

            ICollection <string> listOfFiles = blobClient.RetrieveFilesToProcess();

            if (listOfFiles != null)
            {
                foreach (string fileName in listOfFiles)
                {
                    MemoryStream memStream = new MemoryStream();
                    memStream.Position = 0;
                    await blobClient.DownloadAsync(memStream, fileName).ConfigureAwait(false);

                    memStream.Position = 0;
                    TransactionLogFileProcessor transactionLogFileProcessor = new TransactionLogFileProcessor()
                    {
                        TransactionLogFileName   = fileName,
                        TransactionLogFileStream = memStream
                    };
                    await transactionLogFileProcessor.Process().ConfigureAwait(false);

                    await blobClient.MarkAsProcessedAsync(fileName).ConfigureAwait(false);
                }
            }

            logger.Verbose("Execution of job {0} complete ", details.JobId);
        }
コード例 #24
0
        /// <summary>
        /// 1. Process the FDC Extract file.
        /// 2. Schedule the Process Pts Job
        /// </summary>
        /// <param name="details">
        /// Details of the job we are executing here.
        /// </param>
        /// <param name="logger">
        /// Handle to the logger
        /// </param>
        public async Task Execute(ScheduledJobDetails details, CommerceLog logger)
        {
            logger.Verbose("Starting execution of job \r\n " +
                           "Details {0}", details);

            string     connectionString = CloudConfigurationManager.GetSetting("Lomo.Commerce.Fdc.Blob.ConnectionString");
            IFtpClient ftpClient        = FirstDataFtpClientFactory.FirstDataExtractFtpClient(logger);

            FirstDataExtractBlobClient blobClient = FirstDataBlobClientFactory.FirstDataExtractBlobClient(connectionString, logger);

            string[] files = await ftpClient.DirectoryListAsync();

            if (files != null)
            {
                foreach (string fileName in files)
                {
                    MemoryStream memStream = new MemoryStream();
                    await ftpClient.DownloadFileAsync(fileName, memStream).ConfigureAwait(false);

                    // lets upload it to blob
                    memStream.Position = 0;
                    await blobClient.UploadAsync(memStream, fileName).ConfigureAwait(false);
                }
            }

            // Now try to run all the pending files in the blob
            ICollection <string> listOfFiles = blobClient.RetrieveFilesToProcess();

            if (listOfFiles != null)
            {
                foreach (string fileName in listOfFiles)
                {
                    MemoryStream memStream = new MemoryStream();
                    memStream.Position = 0;
                    await blobClient.DownloadAsync(memStream, fileName).ConfigureAwait(false);

                    memStream.Position = 0;
                    ISettlementFileProcessor extractProcessor = FirstDataFileProcessorFactory.FirstDataExtractProcessor(fileName, memStream);
                    await extractProcessor.Process().ConfigureAwait(false);

                    await blobClient.MarkAsProcessedAsync(fileName).ConfigureAwait(false);
                }
            }

            logger.Verbose("Execution of job {0} complete ", details.JobId);
        }
コード例 #25
0
        /// <summary>
        /// Initializes a new instance of the ParsingUtilities class.
        /// </summary>
        /// <param name="recordType">
        /// The type of record being parsed to place in the log.
        /// </param>
        /// <param name="recordNumber">
        /// The number of the record being parsed to place in the log.
        /// </param>
        /// <param name="fileName">
        /// The name of the file for which the record being parsed originated to place in the log.
        /// </param>
        /// <param name="timeFieldLength">
        /// The length of the time field.
        /// </param>
        /// <param name="log">
        /// The CommerceLog object through which log entries can be made.
        /// </param>
        /// <exception cref="ArgumentExeception">
        /// The value of parameter timeFieldLength must be at least 4.
        /// </exception>
        public ParsingUtilities(string recordType,
                                int recordNumber,
                                string fileName,
                                int timeFieldLength,
                                CommerceLog log)
        {
            if (timeFieldLength < 4)
            {
                throw new ArgumentException("The value of parameter timeFieldLength must be at least 4.", "timeFieldLength");
            }

            RecordType      = recordType;
            RecordNumber    = recordNumber;
            FileName        = fileName;
            TimeFieldLength = timeFieldLength;
            Log             = log;
        }
コード例 #26
0
        public Task Execute(ScheduledJobDetails details, CommerceLog logger)
        {
            this.log = logger;
            DateTime startDate;
            DateTime endDate = DateTime.UtcNow.Date;

            //Check if we have the last successful report run date in the payload
            if (details.Payload != null && details.Payload.ContainsKey(RewardNetworkReportLastRunDate))
            {
                string strLastRunDate = details.Payload[RewardNetworkReportLastRunDate];
                if (!DateTime.TryParse(strLastRunDate, out startDate))
                {
                    log.Error(
                        "LastRunDate specified for the RewardNetworksReportJob in the payload is invalid. Invalid value is {0}",
                        null, (int)ResultCode.JobExecutionError, strLastRunDate);
                }
                //If we have the last successful run date, add a day to it to set as the start date for the next run
                startDate = startDate.AddDays(1).Date;
            }
            else
            {
                startDate = DateTime.UtcNow.AddDays(-1).Date;
            }

            RewardNetworkReportProcessor rewardNetworkReportProcessor = new RewardNetworkReportProcessor(Context);

            rewardNetworkReportProcessor.GenerateReportForDays(startDate, endDate);
            DateTime lastSuccessfulRun = (DateTime)Context[Key.RewardNetworkReportLastRunDate];

            if (details.Payload == null)
            {
                details.Payload = new Dictionary <string, string>();
            }

            if (details.Payload.ContainsKey(RewardNetworkReportLastRunDate))
            {
                details.Payload[RewardNetworkReportLastRunDate] = lastSuccessfulRun.ToString("yyyy-MM-dd");
            }

            this.log.Verbose("Execution of job {0} complete ", details.JobId);

            return(Task.FromResult(0));
        }
コード例 #27
0
        /// <summary>
        /// Gets the object to use to perform operations on users.
        /// </summary>
        /// <param name="performanceInformation">
        /// The object through which performance information can be added and obtained.
        /// </param>
        /// <param name="amexInvokerOverride">
        /// The specific AmexInvoker object to return, if not null.
        /// </param>
        public static IAmexInvoker BuildAmexInvoker(PerformanceInformation performanceInformation,
                                                    CommerceLog commerceLog,
                                                    IAmexInvoker amexInvokerOverride)
        {
            IAmexInvoker result = new AmexInvoker();

            result.PerformanceInformation = performanceInformation;
            result.CommerceLog            = commerceLog;

            if (CommerceServiceConfig.Instance.UseMockPartnerDependencies == true)
            {
                result = LateBinding.BuildObjectFromLateBoundAssembly <IAmexInvoker>("MockAmexInvoker",
                                                                                     LateBoundMocksAssemblyTypes);
            }

            // If the override object is not null, return it instead.
            if (amexInvokerOverride != null)
            {
                result = amexInvokerOverride;
            }

            return(result);
        }
コード例 #28
0
        /// <summary>
        /// When the worker role starts, we do the following:
        /// 1. Initialize Logger to be used
        /// 2. Schedule Extract Processing job on startup if configured for.
        /// 3. Schedule Ping Job
        /// </summary>
        /// <remarks>
        /// If we schedule Extract Processing job at the same time everyday, we might get
        /// duplicate jobs to execute at the same time (which might be a problem when we have
        /// more than one instance of the role). We can revisit this later, but for now we will
        /// schedule it at the start.
        /// </remarks>
        /// <returns>
        /// boolean status about startup
        /// </returns>
        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 100 * Environment.ProcessorCount;

            // Use only for debugging
            // TelemetryConfiguration.Active.TelemetryChannel.DeveloperMode = true;
            //TelemetryConfiguration.Active.InstrumentationKey = CloudConfigurationManager.GetSetting("APPINSIGHTS_INSTRUMENTATIONKEY");

            // Create a CommerceLog instance to funnel log entries to the log.
            LogInitializer.CreateLogInstance(CommerceWorkerConfig.Instance.LogVerbosity,
                                             CommerceWorkerConfig.Instance.ForceEventLog, CommerceLogSource,
                                             CommerceWorkerConfig.Instance);
            Log = new CommerceLog(Guid.NewGuid(), CommerceWorkerConfig.Instance.LogVerbosity, CommerceLogSource);
            ConfigChangeHandler = new ConfigChangeHandler(Log, ExemptConfigurationItems);

            // turn off processing jobs at start
            ProcessJobs = Convert.ToBoolean(CloudConfigurationManager.GetSetting(ProcessJobsPropertyKey));
            // role should not exit even after processing jobs stop
            ExitRole = false;

            // event handlers
            RoleEnvironment.Changing += RoleEnvironmentChanging;
            RoleEnvironment.Changed  += RoleEnvironmentChanged;

            if (!string.IsNullOrEmpty(ConcurrencyMonitorConnectionString))
            {
                Log.Verbose("Initializing Jobs.");
                using (ConcurrencyMonitor monitor = new ConcurrencyMonitor(ConcurrencyMonitorConnectionString))
                {
                    monitor.InvokeWithLease(() => PartnerJobInitializer.InitializeJobs(Scheduler));
                }
                Log.Verbose("Initialized Jobs.");
            }

            return(base.OnStart());
        }
コード例 #29
0
 /// <summary>
 /// Constructor to create Rewards Pts Client Instance
 /// </summary>
 /// <param name="connectionString">
 /// Azure Storage Connection String
 /// </param>
 public RewardsPtsBlobClient(string connectionString, CommerceLog log)
     : base(connectionString, "rewards-ptsfiles")
 {
     Log = log;
 }
コード例 #30
0
 /// <summary>
 /// Initializes a new instance of the ApplyReferralRewardJob class.
 /// </summary>
 /// <param name="log">
 /// The CommerceLog object through which log entries can be made.
 /// </param>
 public ApplyReferralRewardJob(CommerceLog log)
 {
     Log = log;
 }