Ejemplo n.º 1
0
        private void TrySendSms(object sender, AccountEventArgs e)
        {
            LogSmsEvent("Try to send sms.", e, MessageType.Message);

            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.OnSmsHandler -= ReceiveSms;
                }

                LogSmsEvent("Sms wasn't send.", e);

                return;
            }
            catch (ArgumentException)
            {
                if (mobileAccountSender != null)
                {
                    mobileAccountSender.OnSmsHandler -= ReceiveSms;
                }

                LogSmsEvent("Sms wasn't send.", e);

                return;
            }
            catch (Exception)
            {
                if (mobileAccountSender != null)
                {
                    mobileAccountSender.OnSmsHandler -= ReceiveSms;
                }

                LogSmsEvent("Sms wasn't send.", e);

                return;
            }

            LogSmsEvent("Sending.", e, MessageType.Message);

            mobileAccountReceiver.ReceiveSms(mobileAccountSender.Account.Number);
        }
Ejemplo n.º 2
0
        public MobileAccount CreateMobileAccount()
        {
            var mobileAccount = new MobileAccount();

            MobileAccounts.Add(mobileAccount);

            mobileAccount.OnCallHandler += EndCall;
            mobileAccount.OnCallHandler += TryMakeCall;
            mobileAccount.OnSmsHandler  += ReceiveSms;
            mobileAccount.OnSmsHandler  += TrySendSms;

            return(mobileAccount);
        }
Ejemplo n.º 3
0
        public MobileAccount SetAccountParametres(MobileAccount mobileAccount, string name, string surname, string email, DateTime dateTime)
        {
            var account = new Account(CreateNumber())
            {
                Name      = name,
                Surname   = surname,
                Email     = email,
                DateBirth = dateTime
            };

            mobileAccount.AddressBook.SetAccounts(StandardMobileAccounts);
            mobileAccount.Account = account;

            return(mobileAccount);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        private void TrySendSms(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.OnSmsHandler -= ReceiveSms;
                }

                LogSmsEvent("Sms wasn't send.", true);

                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Sms wasn't send.");
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.White;

                return;
            }
            catch (ArgumentException)
            {
                if (mobileAccountSender != null)
                {
                    mobileAccountSender.OnSmsHandler -= ReceiveSms;
                }

                LogSmsEvent("Sms wasn't send.", true);

                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Sms wasn't send.");
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.White;

                return;
            }
            catch (Exception standartException)
            {
                if (mobileAccountSender != null)
                {
                    mobileAccountSender.OnSmsHandler -= ReceiveSms;
                }

                LogSmsEvent("Sms wasn't send.", true);

                Console.WriteLine(standartException.Message + Environment.NewLine);
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Sms wasn't send.");
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.White;

                return;
            }

            LogSmsEvent("Try to send sms");

            mobileAccountReceiver.ReceiveSms(mobileAccountSender.Account.Number);
        }
Ejemplo n.º 6
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);
        }