internal bool isValid(ICallMessage callMessage) { if (callMessage.DateTimeInterval().Equals(TimeSpan.Zero)) return false; DataTable table = parent.ExecReader( @" SELECT TOP 1 id_phone_call FROM phone_call WHERE id_operator = @id_operator AND NOT ( ((date_start + date_interval) <= @date_start AND (date_start + date_interval) < @date_finish) OR ( @date_start < date_start AND @date_finish <= date_start ) )", new SqlParameter[] { new SqlParameter("@id_operator", id_operator), new SqlParameter("@date_start", callMessage.DateTimeStart()), new SqlParameter("@date_finish", callMessage.DateTimeStart().Add(callMessage.DateTimeInterval()))}); //if we found one row here, //that means, we have duplicates or overlaying dates for the same operator return (0 == table.Rows.Count); }
public void HandleMessage(ICallMessage callMessage) { if (null == callMessage || !callMessage.isValid()) return; if ("".Equals(callMessage.Operator()) || // <---- these fields could be empty DateTime.MinValue.Equals(callMessage.DateTimeStart()) || // <---- because of incorrect mail template (regex), DateTime.MaxValue.Equals(callMessage.DateTimeInterval()) ||// <---- they must be checked in the CallDataConsumer "".Equals(callMessage.Abonent())) // <---- and mail should be saved in special table { String description = "Possibly the regex is incorrect. Check the MessageRegex element in the MessageStructure section of the config class. "; saveFailedMessage(callMessage, description); return; } OperatorTimeChecker ot; if (!operatorOperatorTime.TryGetValue(callMessage.Operator(), out ot)) { ot = new OperatorTimeChecker(callMessage, this); operatorOperatorTime.Add(callMessage.Operator(), ot); } checkDateAndSave(callMessage, ot); }
private void saveNormalMessage(ICallMessage callMessage, OperatorTimeChecker ot) { string fileName = saveFileGetNewName(callMessage); try { string query = @"INSERT INTO phone_call( id_operator, phone, date_start, date_interval, sender_mail, file_name) VALUES (@id_operator, @phone, @date_start, @date_interval, @sender_mail, @file_name)"; ExecNonQuery(query, new SqlParameter[] { new SqlParameter("@id_operator", ot.getIdOperator()), new SqlParameter("@phone", callMessage.Abonent()), new SqlParameter("@date_start", callMessage.DateTimeStart()), new SqlParameter("@date_interval", callMessage.DateTimeInterval()), new SqlParameter("@sender_mail", callMessage.Sender()), new SqlParameter("@file_name", fileName) }); } catch(Exception e) { saveFailedMessage(callMessage, "Cannot save message to phone_call table: " + e.Message, fileName); } }