Exemplo n.º 1
0
        public static MobileAccount GetByName(string adress, string name)
        {
            XDocument xdoc    = XDocument.Load(adress);
            XElement  Account = xdoc.Element("MobileOperator").Element("Accounts");

            foreach (XElement MobileAccounts in Account.Elements("MobileAccount"))
            {
                XElement NameElement      = MobileAccounts.Element("Name");
                XElement LastNameElement  = MobileAccounts.Element("LastName");
                XElement BirthDateElement = MobileAccounts.Element("BirthDate");
                XElement EmailElement     = MobileAccounts.Element("Email");
                XElement NumberElement    = MobileAccounts.Element("Number");

                if (name == NameElement.Value)
                {
                    MobileAccount user = new MobileAccount();
                    user.Name      = NameElement.Value;
                    user.LastName  = LastNameElement.Value;
                    user.BirthDate = DateTime.Parse(BirthDateElement.Value);
                    user.Email     = EmailElement.Value;
                    user.Number    = Int32.Parse(NumberElement.Value);
                    return(user);
                }
            }
            return(default(MobileAccount));
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public static List <string> Sample(string adress, string fieldName)
        {
            List <string> fields = new List <string>();

            XDocument xdoc    = XDocument.Load(adress);
            XElement  Account = xdoc.Element("MobileOperator").Element("Accounts");

            foreach (XElement MobileAccounts in Account.Elements("MobileAccount"))
            {
                XElement SomeField = MobileAccounts.Element(fieldName);
                fields.Add(SomeField.Value.ToString());
            }
            return(fields);
        }
Exemplo n.º 5
0
        public MobileAccount FindMobileAccountByName(string name)
        {
            var mobileAccount = MobileAccounts.SingleOrDefault(mobileAcc => mobileAcc.Account.Name == name);

            if (mobileAccount == null)
            {
                return(null);
            }

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

            return(mobileAccount);
        }
Exemplo n.º 6
0
        public static void RemuveByName(string adress, string name)
        {
            XDocument xdoc    = XDocument.Load(adress);
            XElement  Account = xdoc.Element("MobileOperator").Element("Accounts");

            foreach (XElement MobileAccounts in Account.Elements("MobileAccount"))
            {
                XElement NameElement = MobileAccounts.Element("Name");

                if (name == NameElement.Value)
                {
                    MobileAccounts.RemoveAll();
                    Console.WriteLine(name + " was successfully removed");
                }
            }
            xdoc.Save("removed" + adress);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        public static void FindByName(string adress, string name)
        {
            XDocument xdoc    = XDocument.Load(adress);
            XElement  Account = xdoc.Element("MobileOperator").Element("Accounts");

            foreach (XElement MobileAccounts in Account.Elements("MobileAccount"))
            {
                XElement NameElement      = MobileAccounts.Element("Name");
                XElement LastNameElement  = MobileAccounts.Element("LastName");
                XElement BirthDateElement = MobileAccounts.Element("BirthDate");
                XElement EmailElement     = MobileAccounts.Element("Email");
                XElement NumberElement    = MobileAccounts.Element("Number");
                if (name == NameElement.Value)
                {
                    Console.WriteLine("Name: {0} Last name: {1} Birth date: {2} Email: {3} Number: {4}",
                                      NameElement.Value, LastNameElement.Value, BirthDateElement.Value,
                                      EmailElement.Value, NameElement.Value);
                }
            }
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }