예제 #1
0
 private void ScanNetwork()
 {
     Dispatcher.Invoke(() =>
     {
         NetworkScanner.ScanAvailableDevices();
     });
 }
예제 #2
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         AddVersionNumber();
         CheckForUpdates();
         LoadOptions();
         NetworkScanner.PublishDevice();
         NetworkScanner.ScanAvailableDevices();
         NetworkScanner.OnScanCompleted   += NetworkScanner_OnScanCompleted;
         NetworkScanner.OnClientConnected += NetworkScanner_OnClientConnected;
         Dispatcher.Invoke(() =>
         {
             chc_AutoShare.IsChecked      = Parameters.IsAutoShareEnabled;
             chc_EnableControls.IsChecked = Parameters.IsControlsEnabled;
             IsControlsEnabled            = Parameters.IsControlsEnabled;
         });
         if (Parameters.IsAutoShareEnabled)
         {
             //if (ServiceBot)
             //{
             Task.Run(() =>
             {
                 try
                 {
                     bool noIP = true;
                     while (noIP)
                     {
                         var localIP = NetworkScanner.MyIP;
                         if (localIP != null)
                         {
                             char[] splitter = { '.' };
                             var ipBlocks    = localIP.ToString().Split(splitter);
                             if (string.Equals(ipBlocks[0], "192") && string.Equals(ipBlocks[1], "168"))
                             {
                                 noIP = false;
                             }
                         }
                         Thread.Sleep(500);
                     }
                     btn_Share_Click(null, null);
                 }
                 catch (Exception exc)
                 {
                     Debug.WriteLine("Exception in loading: " + exc.ToString());
                 }
             });
             //}
             //else
             //{
             //    btn_Share_Click(null, null);
             //}
         }
     }
     catch
     {
         Debug.WriteLine("Failed when initializing ");
     }
 }
 private void btn_Scan_Click(object sender, RoutedEventArgs e)
 {
     NetworkScanner.OnScanCompleted += NetworkScanner_OnScanCompleted;
     Dispatcher.Invoke(() =>
     {
         NetworkScanner.ScanAvailableDevices();
     });
     Task.Run(() =>
     {
         while (NetworkScanner.IsScanning)
         {
             ShowDevices();
             Thread.Sleep(100);
         }
     });
 }
예제 #4
0
        private void btn_Connect_Click(object sender, RoutedEventArgs e)
        {
            Reset();
            if (!IsConnectedToServer)
            {
                string ip = txt_IP.Text;
                if (SelectedIndex != -1)
                {
                    Main.StartReceiving(NetworkScanner.PublisherDevices[SelectedIndex].IP);
                }
                else
                {
                    Main.StartReceiving(txt_IP.Text);
                }
                StartUiTimer();
                IsConnectedToServer = true;
                if (IsConnectedToServer)
                {
                    btn_Connect.Content = "Disconnect";
                }

                txt_IP.Focusable = false;
                txt_IP.IsEnabled = false;
            }
            else
            {
                IsConnectedToServer = false;
                btn_Connect.Content = "Connect";
                Main.StopReceiving();
                RemoteControl.StopSendingCommands();
                NetworkScanner.ScanAvailableDevices();
                txt_IP.Focusable = true;
                txt_IP.IsEnabled = true;
                SelectedIndex    = -1;
            }
            imageBox.Focus();
        }
예제 #5
0
 private void Btn_Refresh_Click(object sender, RoutedEventArgs e)
 {
     NetworkScanner.ScanAvailableDevices();
 }
예제 #6
0
    private static void ReceiverCoreFcn()
    {
        Stopwatch watch = Stopwatch.StartNew();

        while (IsReceiverThreadEnabled)
        {
            if (IsSubDataReceived)
            {
                IsSubDataReceived = false;
                Stopwatch stp       = Stopwatch.StartNew();
                byte[]    timeBytes = new byte[16];
                byte[]    receivedData;
                lock (Lck_SubReceivedData)
                {
                    receivedData = new byte[SubReceivedData.Length];
                    SubReceivedData.CopyTo(receivedData, 0);
                }

                Array.Copy(receivedData, 0, timeBytes, 0, timeBytes.Length);
                string   timeString  = Encoding.ASCII.GetString(timeBytes);
                TimeSpan SentTime    = TimeSpan.Parse(timeString);
                TimeSpan CurrentTime = DateTime.UtcNow.TimeOfDay;
                PublisherTimeBase     += (CurrentTime - SubscriberPreviousTime);
                SubscriberPreviousTime = CurrentTime;
                double deltaTime = PublisherTimeBase.TotalMilliseconds - SentTime.TotalMilliseconds;
                if (Ping <= 0)
                {
                    Ping = deltaTime;
                }
                Ping = Ping * 0.99 + 0.01 * deltaTime;
                byte[] ScreenBytes = new byte[receivedData.Length - timeBytes.Length];
                Array.Copy(receivedData, timeBytes.Length, ScreenBytes, 0, ScreenBytes.Length);
                ScreenImage         = ImageProcessing.ImageFromByteArray(ScreenBytes);
                TotalBytesReceived += receivedData.Length;
                FpsCounter++;
                if (SubStopwatch.ElapsedMilliseconds >= 1000)
                {
                    UpdateStats(TotalBytesReceived, SubStopwatch.Elapsed.TotalSeconds);
                    TotalBytesReceived = 0;
                    SubStopwatch.Restart();
                }
                IsImageShowed = true;
                ScanCounter   = 0;
            }
            else
            {
                ScanCounter++;
                if (IsScanEnabled)
                {
                    NetworkScanner.ScanAvailableDevices();
                    IsScanEnabled = false;
                }
            }
            while (watch.Elapsed.TotalSeconds <= CommunicationPeriod)
            {
                Thread.Sleep(1);
            }
            watch.Restart();
        }
        Debug.WriteLine("While loop in Subscriber Core Fcn is broken");
    }