private IActionResult SendPrescriptionSFTP(PrescriptionForSendingDTO prescription)
        {
            string fileName = prescriptionSearchService.GeneratePrescription(prescription);

            try
            {
                using HttpClient client = new HttpClient();

                string        response = "";
                StringContent content  = new StringContent(JsonConvert.SerializeObject(fileName), Encoding.UTF8, "application/json");
                var           task     = client.GetAsync("http://localhost:50202/api/Sftp/prescription/" + prescription.FileName())
                                         .ContinueWith((taskWithResponse) =>
                {
                    var message = taskWithResponse.Result;
                    var json    = message.Content.ReadAsStringAsync();
                    json.Wait();
                    response = json.Result;
                });
                task.Wait();

                return(Ok(response));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
        private void GenerateQRCode(PrescriptionForSendingDTO prescription)
        {
            QRCodeGenerator qrGenerator = new QRCodeGenerator();
            QRCodeData      qrCodeData  = qrGenerator.CreateQrCode(prescription.ToString(), QRCodeGenerator.ECCLevel.Q);

            PngByteQRCode qrCode = new PngByteQRCode(qrCodeData);

            byte[] qrCodeAsPngByteArr = qrCode.GetGraphic(5);
            Console.WriteLine("Generating QR code");
            using (var ms = new MemoryStream(qrCodeAsPngByteArr))
            {
                var qrCodeImage = new Bitmap(ms);
                qrCodeImage.Save("GeneratedPrescription" + Path.DirectorySeparatorChar + prescription.FileName() + "qrcode.png", ImageFormat.Png);
            }
            Console.WriteLine("Generated QR code");
        }
        public string GeneratePrescription(PrescriptionForSendingDTO prescription)
        {
            char   pathBase      = Path.DirectorySeparatorChar;
            string fileName      = prescription.FileName() + ".txt";
            string filePath      = "." + pathBase + "GeneratedPrescription" + pathBase + fileName;
            string stringToWrite = prescription.ToString();

            using (StreamWriter streamWriter = new StreamWriter(filePath))
            {
                string[] split = stringToWrite.Split("\n");
                foreach (string line in split)
                {
                    streamWriter.WriteLine(line);
                }
            }
            return(filePath);
        }
        public IActionResult SendPrescription(PrescriptionForSendingDTO prescription)
        {
            if (prescription.Pharmacy == null)
            {
                return(BadRequest());
            }

            string stage = Environment.GetEnvironmentVariable("STAGE") ?? "development";

            if (prescription.Pharmacy.ToLower().Contains("local") && stage.Contains("development"))
            {
                return(SendPrescriptionSFTP(prescription));
            }
            else
            {
                return(SendPrescriptionHTTP(prescription));
            }
        }
        private IActionResult SendPrescriptionHTTP(PrescriptionForSendingDTO prescription)
        {
            string fileName = prescriptionSearchService.GeneratePrescription(prescription);

            GenerateQRCode(prescription);
            WebClient    webClient = new WebClient();
            FileMetadata fileInfo  = new FileMetadata();

            fileInfo.Filename = fileName;
            fileInfo.URL      = "http://schnabel.herokuapp.com/pswupload";

            //SendMail();

            Console.WriteLine("Trying to send response...");
            byte[] responseArray = webClient.UploadFile(fileInfo.URL, fileInfo.Filename);
            string ur            = webClient.Encoding.GetString(responseArray).ToString();

            return(Ok(webClient.Encoding.GetString(responseArray)));
        }
示例#6
0
        public string GeneratePrescription(PrescriptionForSendingDTO prescription)
        {
            string generatedPrescription = "";

            using HttpClient client = new HttpClient();
            string serializedDto = JsonConvert.SerializeObject(prescription);

            var content = new StringContent(serializedDto, Encoding.UTF8, "application/json");

            var task = client.PostAsync(GetPrescriptionDomain() + "/api/prescription/generate", content)
                       .ContinueWith((taskWithResponse) =>
            {
                var message = taskWithResponse.Result;
                var json    = message.Content.ReadAsStringAsync();
                json.Wait();
                generatedPrescription = JsonConvert.DeserializeObject <string>(json.Result);
            });

            task.Wait();

            return(generatedPrescription);
        }