Beispiel #1
0
        /// <summary>
        /// Given a patient, async-writes to the API and returns the results.
        /// </summary>
        /// <param name="patient">Patient to write to the API.</param>
        /// <returns>Result of the API call.</returns>
        private static async Task <PatientResult> WritePatientToApi(Patient patient)
        {
            //TODO: If you decide to have multiple patient result records per API call, this signature could change to return Task<IEnumerable<PatientResult>
            // and the next data flow block take in the enumerable or would be TransformManyBlock instead of TransformBlock

            var result = new PatientResult(patient);

            try
            {
                result.BeginTime = DateTime.UtcNow;

                //TODO: replace with actual API POST; make sure your API call does not block (use await)
                // simulating 10% failure rate of API call
                if (new Random().Next(10) == 0)
                {
                    throw new Exception();
                }
                // simulating how long an API call could take
                await Task.Delay(new Random().Next(1000, 5000));

                Console.Write("*");
            }
            catch (Exception ex)
            {
                result.Exception = ex;
                Console.Write("X");
            }
            finally
            {
                result.EndTime = DateTime.UtcNow;
            }
            return(result);
        }
Beispiel #2
0
 private static async Task WritePatientDetails(PatientResult patientResult)
 {
     //TODO: Change method signature to take in requirements shared over invocations, such as file stream
     //TODO: Here you would async write to file the PatientResult; use await
 }
Beispiel #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="patientResult"></param>
 /// <returns></returns>
 private static async Task WritePatientLog(PatientResult patientResult)
 {
     //TODO: Change method signature to take in requirements shared over invocations, such as file stream
     //TODO: Here you would async log to file the begin/end UTC timestamps for the api call (part of PatientResult); use await
 }