Пример #1
0
        }         // constructor

        public Response <Reply> Infer(InferenceInput inputData, HarvesterConfiguration cfg)
        {
            ValidateInput(inputData, cfg);

            using (var restClient = new HttpClient {
                BaseAddress = new Uri("https://" + cfg.HostName),
            }) {
                HttpRequestMessage request = CreateRequest(inputData, cfg, restClient);

                HttpResponseMessage response = restClient.SendAsync(request).Result;

                string responseContent = response.Content.ReadAsStringAsync().Result;

                this.log.Say(
                    response.StatusCode == HttpStatusCode.OK ? Severity.Debug : Severity.Warn,
                    "Response status code is {0}, content:\n" +
                    "=== Start of encrypted text ===\n" +
                    "{1}\n" +
                    "=== End of encrypted text ===",
                    response.StatusCode,
                    new Encrypted(responseContent)
                    );

                return(new Response <Reply>(response.StatusCode, responseContent));
            }     // using
        }         // Infer
Пример #2
0
        public void Serialize()
        {
            InferenceInput ii = new InferenceInput {
                CompanyRegistrationNumber = "12121234",
                Director = new DirectorData {
                    FirstName   = "Basil",
                    LastName    = "Poop-kind",
                    DateOfBirth = new DateTime(1980, 3, 8, 0, 0, 0, DateTimeKind.Utc),
                    Postcode    = "AB101BA",
                    HouseNumber = "61",
                },
                EquifaxData    = "<xml>equi</xml>",
                MonthlyPayment = 1265,
            };

            Console.WriteLine("Serialize this: {0}", ii);

            string serialized = JsonConvert.SerializeObject(ii, Formatting.Indented);

            Console.WriteLine("Serialized: {0}", serialized);

            InferenceInput deserialized = JsonConvert.DeserializeObject <InferenceInput>(serialized);

            Console.WriteLine("Deserialized: {0}", deserialized);

            Assert.AreEqual(ii, deserialized);
        } // Serialize
Пример #3
0
        }         // CreateRequest

        private void ValidateInput(InferenceInput inputData, HarvesterConfiguration cfg)
        {
            if (cfg == null)
            {
                throw new NoConfigurationAlert(this.log);
            }

            List <string> errors = cfg.Validate();

            if (errors != null)
            {
                throw new BadConfigurationAlert(errors, this.log);
            }

            if (inputData == null)
            {
                throw new NoInputDataAlert(this.log);
            }

            errors = inputData.Validate();

            if (errors != null)
            {
                throw new BadInputDataAlert(errors, this.log);
            }
        }         // ValidateInput
Пример #4
0
        }         // constructor

        public Response <Reply> Infer(InferenceInput inputData, HarvesterConfiguration cfg)
        {
            string reply = GetReply();

            this.log.Debug("Chosen reply in test harvester:\n{0}", reply);

            return(new Response <Reply>(Status, reply));
        }         // Infer
 public InferenceRequestSaverAlert(int customerID, InferenceInput request, Exception inner, ASafeLog log) : base(
         log,
         inner,
         "Failed to save the following inference request for customer {0}: '{1}'.",
         customerID,
         request.ToShortString()
         )
 {
 } // constructor
Пример #6
0
        }         // Infer

        private HttpRequestMessage CreateRequest(
            InferenceInput inputData,
            HarvesterConfiguration cfg,
            HttpClient restClient
            )
        {
            string path = string.IsNullOrWhiteSpace(inputData.EquifaxData)
                                ? cfg.NewCustomerRequestPath
                                : cfg.OldCustomerRequestPath;

            string requestUri = string.Format(path, inputData.RequestID);

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUri);

            request.Headers.Authorization = new AuthenticationHeaderValue(cfg.AuthorizationScheme, cfg.AccessToken);
            request.Headers.UserAgent.Add(new ProductInfoHeaderValue("EverlineLogicalGlueConnector", "1.0"));

            string serialized = JsonConvert.SerializeObject(inputData);

            request.Content = new StringContent(serialized, new UTF8Encoding(), JsonContentType);

            string contentToLog = serialized.TrimStart();

            const int maxLen = 256;

            if (contentToLog.Length > maxLen)
            {
                contentToLog = contentToLog.Substring(0, maxLen).TrimEnd() + "...";
            }

            var uri = new Uri(restClient.BaseAddress, request.RequestUri);

            string requestHeaders = string.Join("\n\t", request.Headers.Select(pair => string.Format(
                                                                                   "{0}: {1}",
                                                                                   pair.Key,
                                                                                   string.Join(", ", pair.Value)
                                                                                   )));

            string contentHeaders = string.Join("\n\t", request.Content.Headers.Select(pair => string.Format(
                                                                                           "{0}: {1}",
                                                                                           pair.Key,
                                                                                           string.Join(", ", pair.Value)
                                                                                           )));

            this.log.Debug(
                "Executing {0} request:\nURL: {1}\nRequest headers:\n\t{2}\nContent headers:\n\t{3}\nContent:\n\t{4}",
                request.Method,
                uri,
                requestHeaders,
                contentHeaders,
                contentToLog
                );

            return(request);
        }         // CreateRequest
Пример #7
0
 public InputDataLoader(
     AConnection db,
     ASafeLog log,
     int customerID,
     DateTime now,
     bool loadMonthlyRepaymentOnly
     ) : base(db, log, customerID, now)
 {
     Result = new InferenceInput();
     this.loadMonthlyRepaymentOnly = loadMonthlyRepaymentOnly;
 }         // constructor
Пример #8
0
            public void Inference(MarkersContext result, InferenceInput <PointerBitmap> input, Rectangle?inputWindow = null)
            {
                using var inputMat = input
                                     .GetClippedPointerBitmap(ref inputWindow)
                                     .WrapAsMat();

                if (inputMat == null)
                {
                    return;
                }

                Inference(result, inputMat);
            }
Пример #9
0
 public InferenceRequestSaver(
     AConnection db,
     ASafeLog log,
     int customerID,
     int companyID,
     bool isTryOut,
     InferenceInput request
     ) : base(db, log, customerID)
 {
     Result         = 0;
     this.companyID = companyID;
     this.isTryOut  = isTryOut;
     this.request   = request;
 }         // constructor
Пример #10
0
            public void Inference(ZXingCode result, InferenceInput <PointerBitmap> input, Rectangle?inputWindow = null)
            {
                var bmp = input.GetClippedPointerBitmap(ref inputWindow);

                var luminance = _Implementation.CreateLuminanceSource(bmp.AsSpanBitmap(), ref _RecyclableBuffer);

                var r = _Reader.Decode(luminance);

                result._Results.Clear();
                result._Results.Add(r);
                result._ResultRect = inputWindow; // we need to store the crop to reinterpret the results as full image.

                result.CaptureTime   = input.CaptureTime;
                result.CaptureDevice = input.CaptureDeviceName;
            }
Пример #11
0
 public SaveInferenceRequest(
     int customerID,
     int companyID,
     bool isTryOut,
     InferenceInput request,
     AConnection db,
     ASafeLog log
     ) : base(db, log)
 {
     this.request = request;
     CustomerID   = customerID;
     CompanyID    = companyID;
     IsTryOut     = isTryOut;
     Now          = DateTime.UtcNow;
 }         // constructor
Пример #12
0
        }         // LoadInputData

        public long SaveInferenceRequest(int customerID, int companyID, bool isTryOut, InferenceInput request)
        {
            try {
                return(new InferenceRequestSaver(
                           this.db,
                           this.log,
                           customerID,
                           companyID,
                           isTryOut,
                           request
                           ).Execute().Result);
            } catch (Exception e) {
                throw new InferenceRequestSaverAlert(customerID, request, e, this.log);
            }     // try
        }         // SaveRequest
Пример #13
0
 public InferenceInputPackage(InferenceInput input, int companyID)
 {
     InferenceInput = input;
     CompanyID      = companyID;
 }         // constructor