示例#1
0
 public virtual void Charge(MobileBase mobile)
 {
     Mobile = mobile;
     if (mobile.Charger == null || mobile.Charger != this)
     {
         mobile.Charge(this);
     }
 }
示例#2
0
        public void RemovePhone()
        {
            MobileBase temp = Mobile;

            Mobile = null;
            if (temp.Charger != null)
            {
                temp.RemoveCharger();
            }
        }
示例#3
0
        public FormCharging()
        {
            InitializeComponent();

            comboBoxFormatter.SelectedIndex = 0;
            comboBoxFormatter.Items.AddRange(formatterFactory.AvailableNames.ToArray());

            currentFormatter = formatterFactory.DefaultFormatter;

            mobile = new ModernMobile(output);
            mobile.SMSMessenger.MessageAdded += (message, isAdded) => {
                if (!phonesSet.Contains(message.Number))
                {
                    phonesSet.Add(message.Number);
                    Invoke(new Action(() => comboBoxPhone.Items.Add(message.Number)));
                }

                if (mobile.SMSMessenger.MessageHistory.Count > MAXIMUM_OUTPUT)
                {
                    List <Message> temp = mobile.SMSMessenger.MessageHistory;
                    temp.RemoveRange(0, messageHistoryCopy.Count - MAXIMUM_OUTPUT);
                    messageHistoryCopy = temp;
                }
                else
                {
                    messageHistoryCopy = mobile.SMSMessenger.MessageHistory;
                }

                try {
                    Invoke(new Action(RefreshListView));
                }
                catch (ObjectDisposedException) {}
                catch (InvalidOperationException) {}
            };

            int notMainThreadSmsCount = 1;
            BackgroundWorkerFactoryMethod workerFactory = new BackgroundWorkerFactoryMethod();

            manageableAction = new ManageableAction(new Action(() => {
                if (notMainThreadSmsCount == 1)
                {
                    Thread.Sleep(300);
                }

                mobile.ReceiveSMS($"SMS #{notMainThreadSmsCount++} NOT from Main thread.", "700");

                Thread.Sleep(1000);
            }));
            SMSBackgroundSender = workerFactory.CreateWorker(() => manageableAction.ThreadStart());
            SMSBackgroundSender.Start();

            UpdateChargeBar();
        }
        public FormMessageFiltering()
        {
            InitializeComponent();

            comboBoxFormatter.SelectedIndex = 0;
            comboBoxFormatter.Items.AddRange(formatterFactory.AvailableNames.ToArray());

            currentFormatter = formatterFactory.DefaultFormatter;

            mobile = new ModernMobile(output);
            mobile.SMSMessenger.MessageAdded += (message, isAdded) => {
                if (!phonesSet.Contains(message.Number))
                {
                    phonesSet.Add(message.Number);
                    Invoke(new Action(() => comboBoxPhone.Items.Add(message.Number)));
                }

                if (mobile.SMSMessenger.MessageHistory.Count > MAXIMUM_OUTPUT)
                {
                    List <Message> temp = mobile.SMSMessenger.MessageHistory;
                    temp.RemoveRange(0, messageHistoryCopy.Count - MAXIMUM_OUTPUT);
                    messageHistoryCopy = temp;
                }
                else
                {
                    messageHistoryCopy = mobile.SMSMessenger.MessageHistory;
                }

                try {
                    Invoke(new Action(RefreshListView));
                }
                catch (ObjectDisposedException) {
                }
            };

            new Thread(() => {
                int notMainThreadSmsCount = 1;
                System.Threading.Timer notMainThreadTimer = new System.Threading.Timer((sender) => {
                    mobile.ReceiveSMS($"SMS #{notMainThreadSmsCount++} NOT from Main thread.", "700");
                }, null, 500, 2000);
            }).Start();
        }
        public MessageFormatting()
        {
            InitializeComponent();

            comboBoxFormatters.SelectedIndex = 0;
            foreach (string formatterName in formatterFactory.AvailableNames)
            {
                comboBoxFormatters.Items.Add(formatterName);
            }

            output                          = new TextBoxOutput(richTextBoxOutput);
            mobile                          = new ModernMobile(output);
            mobile.SMSProvider              = new SMSProvider();
            mobile.SMSProvider.SMSReciever += (message) => output.WriteLine(currentFormatter?.Invoke(message));

            new Thread(() =>
            {
                int notMainThreadSmsCount = 1;
                System.Threading.Timer notMainThreadTimer = new System.Threading.Timer((sender) =>
                {
                    mobile.ReceiveSMS($"SMS #{notMainThreadSmsCount++} NOT from Main thread.");
                }, null, 1000, 3000);
            }).Start();
        }
 public override void Charge(MobileBase mobile)
 {
     base.Charge(mobile);
     output.WriteLine($"{typeof(MobileBase).Name} is charging with {nameof(FastCharger)}.");
 }
 public override void Charge(MobileBase mobile)
 {
     Mobile = mobile;
     output.WriteLine($"{typeof(MobileBase).Name} is charging with {nameof(OrdinaryCharger)}.");
 }
示例#8
0
 public abstract void Charge(MobileBase mobile);