public static bool TryParse(string line, out PriceUpdate priceUpdate) { var update = Parse(line); priceUpdate = update; return(update.Timestamp != default(DateTime) && !string.IsNullOrWhiteSpace(update.Exchange) && !string.IsNullOrWhiteSpace(update.SourceCurrency) && !string.IsNullOrWhiteSpace(update.DestinationCurrency) && update.Factor != default(double)); }
private static PriceUpdate Parse(string line) { if (line == null) { return(PriceUpdate.empty); } var splitted = line.Split(' '); if (splitted.Length != 5) { return(PriceUpdate.empty); } else { try { DateTime dateTime; DateTime.TryParse(splitted[0], CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out dateTime); var pu = new PriceUpdate { Timestamp = dateTime, Exchange = splitted[1], SourceCurrency = splitted[2], DestinationCurrency = splitted[3], Factor = Double.Parse(splitted[4]) }; return(pu); } catch (Exception ex) { // TODO: log exception return(PriceUpdate.empty); } } }