コード例 #1
0
        public void ConnectDevice()
        {
            _networkList = new ObservableCollection <Network>(App.am.Networks);
            _network     = new Network(null);
            foreach (Network n in _networkList)
            {
                if (Messenger.connected(n.Names, n.Comm))
                {
                    App.Current.Dispatcher.Invoke((Action) delegate()
                    {
                        _network.UpdateStatus(n.Names, "connected");
                        InputBlock.Text = InputBlock.Text + Environment.NewLine + "Connected:" + n.Names + "to:" + n.Comm;
                        Scroller.ScrollToBottom();
                        InputBlock.ScrollToEnd();
                    });
                    Console.WriteLine("modem  connected:" + n.Names + "to:" + n.Comm);

                    port2.Content = port2.Content + Environment.NewLine + "Connected:" + n.Names + "";
                }

                else
                {
                    _network.UpdateStatus(n.Names, "disconnected");
                    App.Current.Dispatcher.Invoke((Action) delegate()
                    {
                        InputBlock.Text = InputBlock.Text + Environment.NewLine + "Not connected:" + n.Names + "to:" + n.Comm;
                        Scroller.ScrollToBottom();
                        InputBlock.ScrollToEnd();
                    });
                    Console.WriteLine("not connected:" + n.Names + "to:" + n.Comm);
                    port2.Content = port2.Content + Environment.NewLine + " " + n.Names + " " + n.Status;
                }
            }
        }
コード例 #2
0
        private void bwMessage_DoWork(object sender, DoWorkEventArgs e)
        {
            App.Current.Dispatcher.Invoke((Action) delegate()
            {
                InputBlock.Text = InputBlock.Text + Environment.NewLine + "Downloading messages from the server......" + "  " + DateTime.Now.ToString();
                Scroller.ScrollToBottom();
                InputBlock.ScrollToEnd();
            });
            Console.WriteLine("starting the back ground task");
            BackgroundWorker worker = sender as BackgroundWorker;

            syncs(url);
            System.Threading.Thread.Sleep(1000);
        }
コード例 #3
0
        void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            App.Current.Dispatcher.Invoke((Action) delegate()
            {
                InputBlock.Text = " " + "  " + DateTime.Now.ToString();// InputBlock.Text + Environment.NewLine + "now sending messages";
                // Scroller.ScrollToBottom();
                InputBlock.ScrollToEnd();
            });

            if (!bwMessage.IsBusy)
            {
                tasks();
            }
            Console.WriteLine("new process after one minute:");
        }
コード例 #4
0
 private void refreshClick(object sender, RoutedEventArgs e)
 {
     if (Messenger.disconnected())
     {
         App.Current.Dispatcher.Invoke((Action) delegate()
         {
             InputBlock.Text = InputBlock.Text + Environment.NewLine + "Ports disconnected " + DateTime.Now.ToString();
             Scroller.ScrollToBottom();
             InputBlock.ScrollToEnd();
         });
     }
     else
     {
         App.Current.Dispatcher.Invoke((Action) delegate()
         {
             InputBlock.Text = InputBlock.Text + Environment.NewLine + "disconnection process failed " + DateTime.Now.ToString();
             Scroller.ScrollToBottom();
             InputBlock.ScrollToEnd();
         });
     }
 }
コード例 #5
0
        private void syncs(string url)
        {
            App.Current.Dispatcher.Invoke((Action) delegate()
            {
                InputBlock.Text = InputBlock.Text + Environment.NewLine + "Connecting to the download url" + "  " + DateTime.Now.ToString();
                Scroller.ScrollToBottom();
                InputBlock.ScrollToEnd();
            });

            double lastID = 0;

            _messageList = new ObservableCollection <Message>(App.am.Messages);

            try
            {
                lastID = _messageList.Max(h => Convert.ToDouble(h.Id));
            }
            catch
            {
                MessageBox.Show("you have no last ID please insert/reset the last ID !");
                App.Current.Dispatcher.Invoke((Action) delegate()
                {
                    InputBlock.Text = Environment.NewLine + "you have no last ID please insert/reset the last ID !";
                    Scroller.ScrollToBottom();
                    InputBlock.ScrollToEnd();
                });
            }

            if (lastID != 0)
            {
                url = url + lastID.ToString();
                using (var client = new WebClient())
                {
                    try
                    {
                        var json = client.DownloadString(url);
                        //Console.WriteLine(url);
                        WebRequest      request    = WebRequest.Create(url);
                        HttpWebResponse response   = (HttpWebResponse)request.GetResponse();
                        Stream          dataStream = response.GetResponseStream();

                        StreamReader reader = new StreamReader(dataStream);

                        string responseFromServer = reader.ReadToEnd();

                        Console.WriteLine(responseFromServer);
                        App.Current.Dispatcher.Invoke((Action) delegate()
                        {
                            InputBlock.Text = InputBlock.Text + Environment.NewLine + responseFromServer + "  " + DateTime.Now.ToString();
                        });

                        // Console.WriteLine(response.ToString());
                        List <Message> models = JsonConvert.DeserializeObject <List <Message> >(responseFromServer);

                        for (int d = 0; d < models.Count; d++)
                        {
                            //Console.WriteLine( models[d].Numbers);


                            _message          = App.am.Messages.Add();
                            _message.Numbers  = models[d].Numbers;
                            _message.Id       = models[d].Id;
                            _message.Messages = models[d].Messages;
                            _message.Dor      = DateTime.Now.ToString();
                            _message.Sent     = "F";

                            _message.Save();
                        }
                        App.Current.Dispatcher.Invoke((Action) delegate()
                        {
                            Refresh();
                        });
                    }
                    catch
                    {
                        Console.WriteLine("server is taking long to respond");
                        App.Current.Dispatcher.Invoke((Action) delegate()
                        {
                            InputBlock.Text = InputBlock.Text + Environment.NewLine + "server is taking long to respond!";
                            Scroller.ScrollToBottom();
                            InputBlock.ScrollToEnd();
                        });
                    }
                }
            }
        }
コード例 #6
0
        public void send()
        {
            Console.WriteLine("sending the messsages");

            App.Current.Dispatcher.Invoke((Action) delegate()
            {
                InputBlock.Text = InputBlock.Text + Environment.NewLine + "sending the messsages" + "  " + DateTime.Now.ToString();
            });
            _networkList = new ObservableCollection <Network>(App.am.Networks);
            foreach (Network n in _networkList)
            {
                if (n.Status == "connected")
                {
                    Console.WriteLine(" we are sending the messsages to " + n.Names + " Network:");

                    App.Current.Dispatcher.Invoke((Action) delegate()
                    {
                        InputBlock.Text = InputBlock.Text + Environment.NewLine + " we are sending the messsages to " + n.Names + " Network:" + "  " + DateTime.Now.ToString();
                        Scroller.ScrollToBottom();
                        InputBlock.ScrollToEnd();
                    });
                    _prefixList = new ObservableCollection <Prefix>(App.am.Prefixs);

                    foreach (Prefix p in _prefixList)
                    {
                        if (p.Provider == n.Names)
                        {
                            _messageList = new ObservableCollection <Message>(App.am.Messages);

                            if (_messageList.Where(y => y.Sent == "F").Count() > 0)
                            {
                                Console.WriteLine("sending for :" + n.Names);


                                foreach (Message u in _messageList)
                                {
                                    if (u.Sent == "F" && u.Numbers.Contains(p.Pre))
                                    {
                                        //  myQs.Enqueue(n.Comm,u.Numbers,u.Messages);

                                        App.Current.Dispatcher.Invoke((Action) delegate()
                                        {
                                            InputBlock2.Text = InputBlock2.Text + Environment.NewLine + "Number: " + u.Numbers + " : " + u.Messages + "  " + DateTime.Now.ToString();
                                            Scroller.ScrollToBottom();
                                            InputBlock2.ScrollToEnd();
                                        });
                                        try
                                        {
                                            //Sender(DBObject parent, string id, string message, string number, string network)
                                            // if (Messenger.SendUpdate(App.am, u.Id, u.Messages, u.Numbers, n.Names,n.Comm))
                                            //{
                                            if (Messenger.Sender(App.am, u.Id, u.Messages, u.Numbers, n.Names))
                                            {
                                                App.Current.Dispatcher.Invoke((Action) delegate()
                                                {
                                                    InputBlock2.Text = InputBlock2.Text + Environment.NewLine + "Message sent:... " + u.Numbers + " " + DateTime.Now.ToString();
                                                    Scroller.ScrollToBottom();
                                                    InputBlock2.ScrollToEnd();
                                                });
                                            }
                                            else
                                            {
                                                App.Current.Dispatcher.Invoke((Action) delegate()
                                                {
                                                    InputBlock2.Text = InputBlock2.Text + Environment.NewLine + " Message not sent:... " + u.Numbers + " " + DateTime.Now.ToString();
                                                    Scroller.ScrollToBottom();
                                                    InputBlock2.ScrollToEnd();
                                                });
                                            }
                                            Console.WriteLine("Sending process:-number:" + u.Numbers + " : " + u.Messages);
                                        }
                                        catch
                                        {
                                            App.Current.Dispatcher.Invoke((Action) delegate()
                                            {
                                                InputBlock.Text = InputBlock2.Text + Environment.NewLine + "there is an error somewhere....." + DateTime.Now.ToString();
                                                Scroller.ScrollToBottom();
                                                InputBlock2.ScrollToEnd();
                                            });
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }