public ConnectWindow() { InitializeComponent(); _udpDiscoveryClient = new UdpDiscoveryClient( ready => { }, (name, address) => Dispatcher.Invoke((Action)(() => { if (address.Contains(":?/")) // Android emulator, so use forwarded ports { // todo: use telnet to discover already set up port forwards, instead of hardcoding address = address.Replace(":?/", String.Format(":{0}/", HttpForwardedHostPort)); } var deviceItem = new MainWindow.DeviceItem { DeviceAddress = address, DeviceName = name, DeviceType = name.StartsWith("ProtoPad Service on ANDROID Device ") ? MainWindow.DeviceTypes.Android : MainWindow.DeviceTypes.iOS }; if (!DevicesList.Items.Cast<object>().Any(i => (i as MainWindow.DeviceItem).DeviceAddress == deviceItem.DeviceAddress)) { DevicesList.Items.Add(deviceItem); } DevicesList.IsEnabled = true; //LogToResultsWindow("Found '{0}' on {1}", name, address); }))); _dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); _dispatcherTimer.Tick += (s, a) => { if (_ticksPassed > 2) { _dispatcherTimer.Stop(); if (DevicesList.Items.Count == 1) DevicesList.SelectedIndex = 0; } _udpDiscoveryClient.SendServerPing(); _ticksPassed++; }; _dispatcherTimer.Interval = TimeSpan.FromMilliseconds(200); FindApps(); }
public MainWindow() { InitializeComponent(); _currentDevice = new DeviceItem { DeviceAddress = "http://192.168.1.104:8080/", DeviceName = "Yarvik", DeviceType = DeviceTypes.Android }; // NOTE: Make sure that you've read through the add-on language's 'Getting Started' topic // since it tells you how to set up an ambient parse request dispatcher and an ambient // code repository within your application OnStartup code, and add related cleanup in your // application OnExit code. These steps are essential to having the add-on perform well. // Initialize the project assembly (enables support for automated IntelliPrompt features) _projectAssembly = new CSharpProjectAssembly("SampleBrowser"); var assemblyLoader = new BackgroundWorker(); assemblyLoader.DoWork += DotNetProjectAssemblyReferenceLoader; assemblyLoader.RunWorkerAsync(); // Load the .NET Languages Add-on C# language and register the project assembly on it var language = new CSharpSyntaxLanguage(); language.RegisterProjectAssembly(_projectAssembly); CodeEditor.Document.Language = language; CodeEditor.Document.Language.RegisterService(new IndicatorQuickInfoProvider()); CodeEditor.PreviewKeyDown += (sender, args) => { if (args.Key != Key.Enter || (Keyboard.Modifiers & ModifierKeys.Control) != ModifierKeys.Control) return; SendCodeButton_Click(null,null); args.Handled = true; }; _udpDiscoveryClient = new UdpDiscoveryClient( // ready => Dispatcher.Invoke((Action) (() => SendCodeButton.IsEnabled = ready)), ready => { }, (name, address) => Dispatcher.Invoke(() => { if (address.Contains("?")) address = address.Replace("?", AndroidPort); var deviceItem = new DeviceItem { DeviceAddress = address, DeviceName = name, DeviceType = name.StartsWith("ProtoPad Service on ANDROID Device ") ? DeviceTypes.Android : DeviceTypes.iOS }; if (!DevicesComboBox.Items.Cast<object>().Any(i => (i as DeviceItem).DeviceAddress == deviceItem.DeviceAddress)) { DevicesComboBox.Items.Add(deviceItem); } DevicesComboBox.IsEnabled = true; //ResultTextBox.Text += String.Format("Found '{0}' on {1}", name, address); })); ResultTextBox.Navigated += (sender, args) => { var htmlDocument = ResultTextBox.Document as HTMLDocument; _htmlHolder = htmlDocument.getElementById("wrapallthethings") as HTMLDivElementClass; _htmlWindow = htmlDocument.parentWindow; _udpDiscoveryClient.SendServerPing(); var ticksPassed = 0; var dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); dispatcherTimer.Tick += (s, a) => { if (ticksPassed > 2) { dispatcherTimer.Stop(); if (DevicesComboBox.Items.Count == 1) { DevicesComboBox.SelectedIndex = 0; } } _udpDiscoveryClient.SendServerPing(); ticksPassed++; }; dispatcherTimer.Interval = TimeSpan.FromMilliseconds(200); dispatcherTimer.Start(); }; ResultTextBox.NavigateToString(Properties.Resources.ResultHtmlWrap); }