public static PaymentReceived FromEmail(MailMessage email) { if (email is null) { throw new ArgumentNullException(nameof(email)); } if (email.Subject != "Payment Received") { throw new ArgumentNullException($"Wrong email typ: {email.Subject}"); } Match myCollection = myRegEx.Match(email.Body); Match myCollection2 = myRegEx2.Match(email.Body); Match myCollection3 = myRegEx3.Match(email.Body); Match myCollection4 = myRegEx4.Match(email.Body); PaymentReceived notice = new PaymentReceived { Amount = decimal.Parse(myCollection.Groups[1].Value), OrderNumber = int.Parse(myCollection2.Groups[1].Value), CheckNumber = decimal.Parse(myCollection4.Groups[1].Value) }; string[] myString = myCollection3.Groups[1].Value.Split(delimiters); DateTime myDateTime = new DateTime(int.Parse(myString[2]), int.Parse(myString[0]), int.Parse(myString[1])); notice.OrderDate = myDateTime; return(notice); }
public static PaymentReceived FromEmail(MailMessage email) { Match matchAmount = rxAmount.Match(email.Body); Match matchOrderNum = rxOrderNum.Match(email.Body); Match matchDate = rxDate.Match(email.Body); Match matchCheckNum = rxCheckNum.Match(email.Body); if (email is null) { throw new ArgumentNullException(nameof(email)); } if (email.Subject != "Payment Received") { throw new ArgumentException($"Wrong email type:{email.Subject}"); } if (!matchCheckNum.Success) { throw new ArgumentException("Invalid email body"); } PaymentReceived notice = new PaymentReceived { Amount = decimal.Parse(matchAmount.Groups[1].Value), OrderNum = int.Parse(matchOrderNum.Groups[1].Value), Date = DateTime.Parse(matchDate.Groups[1].Value), CheckNum = int.Parse(matchCheckNum.Groups[1].Value), }; return(notice); }