public static ExecuteResult Until(Func <bool> method) { var timer = new System.Diagnostics.Stopwatch(); timer.Start(); var sleepTime = 100; var result = new ExecuteResult(); do { try { if (method.Invoke()) { return(result); } } catch (Exception exception) { Thread.Sleep(sleepTime); sleepTime = sleepTime + sleepTime; // increase waits between retry attempts result.LastException = exception; ConsoleD.WriteError(exception.ToString()); } }while (timer.ElapsedMilliseconds <= DefaultTimeout); return(result); }
/// <summary> /// Deserializes the specified XML. /// </summary> /// <param name="xml">The XML.</param> /// <returns>An instance of <see cref="PatientFile"/> represented by the passed in <paramref name="xml"/>.</returns> public PatientFile Deserialize(string xml) { PatientFile patientFile = null; try { patientFile = xml.Deserialize <PatientFile>(); } catch (Exception ex) { ConsoleD.WriteError("Error occured deserializing patient file data.", ex); } return(patientFile); }
public static T Deserialize <T>(this string xml) where T : new() { T result = default(T); try { var serializer = new XmlSerializer(typeof(T)); var stringReader = new StringReader(xml); result = (T)serializer.Deserialize(stringReader); } catch (Exception ex) { ConsoleD.WriteError("Deserializing type {0}.", ex, typeof(T).FullName); } return(result); }
private bool SaveToDatabase(PatientFile patientFile) { bool result = false; try { ConsoleD.WriteLine("Saving the patient file data to sqlite"); if (patientFile.Patients.Count > 0) { this.DataManager.DeletePatients(); this.DataManager.SavePatients(patientFile.Patients); } result = true; } catch (Exception ex) { ConsoleD.WriteError("Saving patient file data failed for the following reasons ", ex); } return(result); }