public void Sms(ulong acceptor, string message) { if (CheckOperator()) { Console.WriteLine("Sent \"{0}\" from {1} to {2}", message, Number, acceptor); OnSms?.Invoke(this, new MobileAccountEventArgs(acceptor, message)); } }
public void Sms(object acceptor, string message) { if (!CheckOperator()) { return; } var phoneBookContact = acceptor as MobileAccount; foreach (var contact in phonebook) { if (contact == phoneBookContact) { Console.WriteLine("Sent {0} from {1} to {2}", message, Number, phoneBookContact.Name); OnSms?.Invoke(this, new MobileAccountEventArgs(phoneBookContact.Number, message)); return; } } Console.WriteLine("contact {0} is not in phone book", phoneBookContact.Number); }
public void Sms(MobileAccount phoneBookContact, string message) { if (CheckOperator()) { bool isFound = false; foreach (var contact in phonebook) { if (contact.Value == phoneBookContact) { Console.WriteLine("Sent {0} from {1} to {2}", message, number, phoneBookContact.name); OnSms?.Invoke(this, new MobileAccountEventArgs(phoneBookContact.number, message)); isFound = true; } } if (!isFound) { Console.WriteLine("contact {0} is not in phone book", phoneBookContact.number); } } }
private void CompareSMS() { fireCounter++; if (OldThreads == null) { OldThreads = Threads; } else { foreach (SMSThread newThread in Threads) { // check if all newThreads exist in OldThreads bool found = false; foreach (SMSThread oldThread in OldThreads) { if (oldThread.ID == newThread.ID) { found = true; // check that messages match if (oldThread.Messages.Count != newThread.Messages.Count) { // count mismatch for (int i = oldThread.Messages.Count; i < newThread.Messages.Count; i++) { oldThread.Messages.Add(newThread.Messages[i]); Trace.WriteLine("New SMS Message."); if (newThread.Messages[i].From == "Me") { Trace.WriteLine("Got new message - but it is from me."); } else { if (OnSms != null && fireCounter > 2) { OnSms.Invoke(newThread, newThread.Messages[i]); } } } } break; } } if (!found) { OldThreads.Add(newThread); // entire thread is new. Trace.WriteLine("New SMS Thread."); foreach (SMSMessage m in newThread.Messages) { Trace.WriteLine("New SMS Message."); if (m.From == "Me") { Trace.WriteLine("New SMS message is from me"); } else { if (OnSms != null && fireCounter > 2) { OnSms.Invoke(newThread, m); } } } } } //OldThreads = Threads; } }