public static Level GetAttributeInfo(MethodBase method) { OperatorMessageAttribute attribute = (OperatorMessageAttribute)method .GetCustomAttribute(typeof(OperatorMessageAttribute), true); return(attribute.Level); }
public void SendMessage(MobileAccount forWhom, string message) { MethodBase method = MethodBase.GetCurrentMethod(); Level level = OperatorMessageAttribute.GetAttributeInfo(method); if (Balance >= _messagePrice) { if (SentSMS != null) { SentSMS(this, new MobileEventArgs(MobileOperation.Message, forWhom, message)); Balance -= _messagePrice; } } else { if (level == Level.Warn) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("It's not enought money to send message to {0}!", forWhom); Console.ForegroundColor = ConsoleColor.White; } } }
public void MakeCall(MobileAccount forWhom) { MethodBase method = MethodBase.GetCurrentMethod(); Level level = OperatorMessageAttribute.GetAttributeInfo(method); if (Balance >= _callPrice) { if (MadeCall != null) { MadeCall(this, new MobileEventArgs(MobileOperation.Call, forWhom)); Balance -= _callPrice; } } else { if (level == Level.Warn) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("It's not enought money to make call to {0}!", forWhom); Console.ForegroundColor = ConsoleColor.White; } } }