Пример #1
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);
            }
        }