Example #1
0
        private void TryMakeCall(object sender, AccountEventArgs e)
        {
            LogCallEvent("Try to call.", e, MessageType.Call);

            try
            {
                mobileAccountSender   = sender as MobileAccount;
                mobileAccountReceiver = MobileAccounts.FirstOrDefault(mobileAccount => e.ReceiverNumber.Equals(mobileAccount.Account.Number));

                if (string.IsNullOrEmpty(mobileAccountSender?.ToString()) || string.IsNullOrEmpty(mobileAccountReceiver?.ToString()))
                {
                    throw new NullReferenceException();
                }

                if (mobileAccountSender.Account.Number == 2219324 || mobileAccountSender.Account.Number == 2219325 || mobileAccountReceiver.Account.Number == 2219324 || mobileAccountReceiver.Account.Number == 2219325)
                {
                    throw new ArgumentException();
                }
            }
            catch (NullReferenceException)
            {
                e.IsHandled = true;
                LogCallEvent("Call crashed.", e);

                return;
            }
            catch (ArgumentException)
            {
                e.IsHandled = true;
                LogCallEvent("Call crashed.", e);

                return;
            }
            catch (Exception)
            {
                e.IsHandled = true;
                LogCallEvent("Call crashed.", e);

                return;
            }

            LogCallEvent("Speaking.", e, MessageType.Call);

            mobileAccountReceiver.ReceiveCall(mobileAccountSender.Account.Number);
        }
Example #2
0
        private void TryMakeCall(object sender, AccountEventArgs e)
        {
            try
            {
                mobileAccountSender   = sender as MobileAccount;
                mobileAccountReceiver = MobileAccounts.FirstOrDefault(mobileAccount => e.ReceiverNumber.Equals(mobileAccount.Account.Number));

                if (string.IsNullOrEmpty(mobileAccountSender?.ToString()) || string.IsNullOrEmpty(mobileAccountReceiver?.ToString()))
                {
                    throw new NullReferenceException();
                }

                if (mobileAccountSender.Account.Number == 2219324 || mobileAccountSender.Account.Number == 2219325 || mobileAccountReceiver.Account.Number == 2219324 || mobileAccountReceiver.Account.Number == 2219325)
                {
                    throw new ArgumentException();
                }
            }
            catch (NullReferenceException)
            {
                if (mobileAccountSender != null)
                {
                    mobileAccountSender.OnCallHandler -= EndCall;
                }

                LogCallEvent("Call crashed.", true);

                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Call crashed");
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.White;

                return;
            }
            catch (ArgumentException)
            {
                if (mobileAccountSender != null)
                {
                    mobileAccountSender.OnCallHandler -= EndCall;
                }

                LogCallEvent("Call crashed.", true);

                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Call crashed");
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.White;

                return;
            }
            catch (Exception exceptionStandart)
            {
                if (mobileAccountSender != null)
                {
                    mobileAccountSender.OnCallHandler -= EndCall;
                }

                LogCallEvent("Call crashed.", true);

                Console.WriteLine(exceptionStandart.Message);
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Call crashed");
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.White;

                return;
            }

            LogCallEvent("Try to call");

            mobileAccountReceiver.ReceiveCall(mobileAccountSender.Account.Number);
        }