Exemplo n.º 1
0
        protected ALeadsResponse Process(ALeadsRequest request)
        {
            //if the ClientId is not set in the 'File' then use the clientId from the posting URL authToken
            if (request.LeadFile?.ClientId == 0)
            {
                request.LeadFile.ClientId = this.AuthToken.ClientId;
            }

            this.CommonProcesses(Request);

            CancellationTokenSource cancelToken = this.StartTimeoutTimer(CommonParams.TimeoutInMill);

            ProcessFileRequest process = new ProcessFileRequest(request.LeadFile, cancelToken);

            Debug.WriteLine("Done. -Status:" + process.Request.StatusType + " -ActionType:" + process.Request.ActionType + " -In Secs:" + (process.Request.EndTime.GetValueOrDefault() - process.Request.StartTime).TotalSeconds);

            SalesLeadResponse response = new SalesLeadResponse();

            response.ExecutionTimeInMillisec = Sw.ElapsedMilliseconds;
            response.ClientDefinedIdentifier = request.LeadFile?.ClientDefinedIdentifier;
            response.ApiEndPoint             = this.EndPoint;
            response.PassThroughItems        = request.PassThroughItems;
            if (process.Request == null)
            {
                response.Status  = StatusType.Error;
                response.Message = "ProcessFile.Request is missing.";
            }
            else
            {
                response.LoanTekDefinedIdentifier = process.Request?.RequestId;
                response.Message = process.Request.ActionType + "|" + process.Request.Misc?.Replace("||", "|");
                response.Status  = process.Request.StatusType;
            }
            return(response);
        }
Exemplo n.º 2
0
        public override void TestInitialise()
        {
            base.TestInitialise();

            _callsToSendFile = 0;

            _requestArgument = new ProcessFileRequest
            {
                ApiUrl    = "https://test/api/upload",
                CipherKey = "test_key",
                FilePath  = @"C:\Test\Directory",
                Password  = "******",
                Username  = "******"
            };
        }
Exemplo n.º 3
0
        public async Task ProcessFile_WhenRequestArgumentIsNull_ExpectArgumentNullException()
        {
            // Arrange:
            _requestArgument = null;
            Stub();

            try
            {
                // Act:
                await Act();
            }
            catch (ArgumentNullException exception)
            {
                // Assert:
                Assert.AreEqual("request", exception.ParamName);
                AssertCore();
                throw;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Processes the file.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>The HTTP content.</returns>
        async Task <string> IUploadService.ProcessFile(ProcessFileRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (string.IsNullOrWhiteSpace(request.FilePath))
            {
                throw new ArgumentException(nameof(request.FilePath));
            }

            var items = ZipArchiveHelpers.ListArchiveItems(request.FilePath);
            var json  = NodeHelpers.ToJson(items, request.CipherKey);

            return(await _transferService.SendFile(new SendFileRequest
            {
                ContentType = ApplicationConstants.JsonContentType,
                Password = request.Password,
                StringContent = json,
                Url = request.ApiUrl,
                UserName = request.Username
            }));
        }
        public HttpResponseMessage SalesLeadRequestAdd(string authToken, SalesLeadRequest request)
        {
            string apiEndPoint = ApiObject.ApiName + ".SalesLeadRequest/POST";

            this.EndPoint = apiEndPoint;
            try
            {
                var startTime = DateTime.Now;

                this.ContentType = this.Request.Content?.Headers?.ContentType?.MediaType;

                HttpResponseMessage errorResponse = this.CommonChecks(request, apiEndPoint);
                if (errorResponse != null)
                {
                    return(errorResponse);
                }

                AuthToken authTokenObject = (!string.IsNullOrEmpty(authToken)) ? new AuthToken(authToken) : null;
                errorResponse = this.Authorize(apiEndPoint, authTokenObject, request.LeadFile?.UserId ?? 0);
                if (errorResponse != null)
                {
                    return(errorResponse);
                }

                //if the ClientId is not set in the 'File' then use the clientId from the posting URL authToken
                if (request.LeadFile.ClientId == 0)
                {
                    request.LeadFile.ClientId = authTokenObject.ClientId;
                }

                //TODO - check client for license...
                //if(!License.Has(LoanPricerAPILicenseType, authTokenObject.ClientId))
                //    return this.CreateErrorResponse(HttpStatusCode.PaymentRequired, "Missing valid license:"+ LoanPricerAPILicenseType.ToString(), apiEndPoint);

                this.CommonProcesses(Request);

                CancellationTokenSource cancelToken = this.StartTimeoutTimer(CommonParams.TimeoutInMill);

                ProcessFileRequest process = new ProcessFileRequest(request.LeadFile, cancelToken);
                Debug.WriteLine("Done. -Status:" + process.Request.StatusType + " -ActionType:" + process.Request.ActionType + " -In Secs:" + (process.Request.EndTime.GetValueOrDefault() - process.Request.StartTime).TotalSeconds);

                SalesLeadResponse response = new SalesLeadResponse();
                response.ExecutionTimeInMillisec  = (DateTime.Now - startTime).TotalMilliseconds;
                response.LoanTekDefinedIdentifier = StringUtilities.UniqueId();
                response.ApiEndPoint = apiEndPoint;
                //response.CachedId = processor.Request.CachedId;
                response.ClientDefinedIdentifier = request.LeadFile.ClientDefinedIdentifier;
                response.PassThroughItems        = request.PassThroughItems;
                if (process.Request == null)
                {
                    response.Status  = StatusType.Error;
                    response.Message = "ProcessFile.Request is missing.";
                }
                else
                {
                    switch (process.Request.StatusType)
                    {
                    case StatusType.Complete: response.Status = StatusType.Complete; break;

                    case StatusType.Cancelled: response.Status = StatusType.Cancelled; break;

                    default:  response.Status = StatusType.Error; break;
                    }
                    response.Message = process.Request.ActionType + "|" + process.Request.Misc.Replace("||", "|");
                }

                Types.Api.AppType appType = (request.LeadFile?.Source?.Name?.ToLower().Contains("widget") ?? false) || (request.LeadFile?.Source?.SubName?.ToLower().Contains("widget") ?? false)
                    ? Types.Api.AppType.Widget
                    : Types.Api.AppType.Api_Clients;
                Task.Run(() => this.CreateAndSaveService(request, response, response.Message, appType, new ApiWebService {
                    WebServiceName = "SalesLeadRequest", EndPoint = this.EndPoint
                })).ConfigureAwait(false);

                return(AApiResponse.CreateResponse(HttpStatusCode.OK, response));
            }
            catch (Exception ex)
            {
                Global.OutPrint(ex.Message, new SimpleLogger.LocationObject(this, apiEndPoint), SimpleLogger.LogLevelType.CRITICAL);
                return(this.CreateErrorResponse(HttpStatusCode.InternalServerError, "Exception:" + ex.Message, apiEndPoint));
            }
        }
Exemplo n.º 6
0
 /// <summary> Setter constructor. </summary>
 public ProcessFile(ProcessFileRequest request)
 {
     Request  = request;
     Response = new ProcessFileResponse();
 }
Exemplo n.º 7
0
 /// <summary> Empty constructor. </summary>
 public ProcessFile()
 {
     Request  = new ProcessFileRequest();
     Response = new ProcessFileResponse();
 }