private static void RunInDebugMode() { ConfigureDebugLogging(); Console.WriteLine("Running in debug"); var deviceMonitor = new DeviceMonitor(ConfigurationManager.ConnectionStrings["MetroMonitorData"].ConnectionString); deviceMonitor.Initialise(); deviceMonitor.Start(); Console.WriteLine("Press <enter> to stop or 'cls' and <enter> to clear the log"); while (true) { var command = Console.ReadLine() ?? ""; switch (command) { case "cls": Console.Clear(); break; default: deviceMonitor.Stop(); return; } } }
public void AdbKilledTest() { var dummyAdbServer = new DummyAdbServer(); AdbServer.Instance = dummyAdbServer; this.Socket.WaitForNewData = true; using (DeviceMonitor monitor = new DeviceMonitor(this.Socket)) { base.RunTest( new AdbResponse[] { AdbResponse.OK, AdbResponse.OK }, ResponseMessages( DummyAdbSocket.ServerDisconnected, string.Empty), Requests( "host:track-devices", "host:track-devices"), () => { monitor.Start(); Assert.True(this.Socket.DidReconnect); Assert.True(dummyAdbServer.WasRestarted); }); } }
public void StartInitialDeviceListTest() { this.Socket.WaitForNewData = true; using (DeviceMonitor monitor = new DeviceMonitor(this.Socket)) { DeviceMonitorSink sink = new DeviceMonitorSink(monitor); Assert.Equal(0, monitor.Devices.Count); base.RunTest( OkResponse, ResponseMessages("169.254.109.177:5555\tdevice\n"), Requests("host:track-devices"), () => { monitor.Start(); Assert.Equal(1, monitor.Devices.Count); Assert.Equal("169.254.109.177:5555", monitor.Devices.ElementAt(0).Serial); Assert.Single(sink.ConnectedEvents); Assert.Equal("169.254.109.177:5555", sink.ConnectedEvents[0].Device.Serial); Assert.Empty(sink.ChangedEvents); Assert.Empty(sink.DisconnectedEvents); }); } }
public static void MonitorDevicesConnection(EventHandler <DeviceDataEventArgs> eventHandler) { var monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort))); monitor.DeviceChanged += eventHandler; monitor.DeviceDisconnected += eventHandler; monitor.Start(); }
public void DisposeMonitorTest() { using (DeviceMonitor monitor = new DeviceMonitor(new AdbSocket(AdbServer.Instance.EndPoint))) { monitor.Start(); Thread.Sleep(1000); } }
private void Form1_Shown(object sender, EventArgs e) { new Thread(new ThreadStart(() => { MessageBox.Show(new Form() { TopMost = true }, "Hello!\nThis is a powerful tool for advanced users, and allows them to perform a LOT of stuff.\nIn order to start, you need ADB installed and running\n(adb devices)\nFor more info and updates, go to 'https://github.com/adryzz/'", "AdbLiveTweaks", MessageBoxButtons.OK); })).Start(); Monitor.Start(); }
void TestDeviceConnect() { var monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort))); monitor.DeviceConnected += Monitor_DeviceConnected; monitor.DeviceDisconnected += Monitor_DeviceDisconnected; monitor.Start(); }
private void Moniter() { var monitor = new DeviceMonitor(AdbSocket); monitor.DeviceConnected += this.OnDeviceConnected; monitor.DeviceDisconnected += this.onDeviceDisConnected; monitor.Start(); }
public static void StartAdbMonitor() { var monitor = new DeviceMonitor(new AdbSocket(AdbServer.Instance.EndPoint)); monitor.DeviceConnected += Monitor_DeviceConnected; monitor.DeviceDisconnected += Monitor_DeviceDisconnected; monitor.DeviceChanged += Monitor_DeviceChanged; monitor.Start(); }
protected override void OnStart(string[] args) { Logger.Info(i => i("Initialising Device Monitor")); _deviceMonitor = new DeviceMonitor(ConfigurationManager.ConnectionStrings["MetroMonitorData"].ConnectionString); _deviceMonitor.Initialise(); _deviceMonitor.Start(); Logger.Info(i => i("Service Successfully Started")); }
public void Start_ForInvoked_CallsStart( DeviceMonitor sut, [Freeze] IWatcher watcher) { sut.Start(); watcher.Received() .Start(); }
private static void ListenForDevices() { var sock = new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort); _monitor = new DeviceMonitor(new AdbSocket(sock)); _monitor.DeviceConnected += OnDeviceConnected; _monitor.DeviceDisconnected += OnDeviceDisconnected; _monitor.Start(); }
internal void InitDeviceMonitor() { if (!DeviceMonitor.IsRunning) { DeviceMonitor.Start(); } DeviceMonitor.DeviceConnected += OnDeviceConnected; DeviceMonitor.DeviceDisconnected += OnDeviceDisconnected; DeviceMonitor.DeviceChanged += OnDeviceChanged; }
/// <summary> /// Initialize Adb Server and Monitor /// </summary> public static void InitializeAdbServer(string path) { Server.StartServer(Path.GetFullPath(Path.Combine(path)), restartServerIfNewer: false); var monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort))); Instance = CustomMonitor.Instance; monitor.DeviceConnected += OnDeviceConnected; monitor.DeviceChanged += OnDeviceChanged; monitor.DeviceDisconnected += OnDeviceDisconnected; monitor.Start(); }
private void StartDeviceMonitor() { if (monitor == null) { CreateDeviceMonitor(); monitor.Start(); } else { monitor = null; CreateDeviceMonitor(); monitor.Start(); } }
/// <summary> /// Perform the action. /// </summary> protected override void DoWork() { // Listen for devices deviceMonitor.Start(); deviceMonitor.WaitForInitialUpdate(); // Perform the connect connecting = true; var adb = new Adb { Logger = LogOutput }; adb.Connect(host, port, Adb.Timeout.Connect); }
public void DeviceChangedTest() { this.Socket.WaitForNewData = true; using (DeviceMonitor monitor = new DeviceMonitor(this.Socket)) { DeviceMonitorSink sink = new DeviceMonitorSink(monitor); Assert.AreEqual(0, monitor.Devices.Count); // Start the monitor, detect the initial device. base.RunTest( OkResponse, ResponseMessages("169.254.109.177:5555\toffline\n"), Requests("host:track-devices"), () => { monitor.Start(); Assert.AreEqual(1, monitor.Devices.Count); Assert.AreEqual(DeviceState.Offline, monitor.Devices.ElementAt(0).State); Assert.AreEqual(1, sink.ConnectedEvents.Count); Assert.AreEqual(0, sink.ChangedEvents.Count); Assert.AreEqual(0, sink.DisconnectedEvents.Count); }); this.Socket.ResponseMessages.Clear(); this.Socket.Responses.Clear(); this.Socket.Requests.Clear(); // Device disconnects var eventWaiter = sink.CreateEventSignal(); base.RunTest( NoResponses, ResponseMessages("169.254.109.177:5555\tdevice\n"), Requests(), () => { eventWaiter.WaitOne(1000); Assert.AreEqual(1, monitor.Devices.Count); Assert.AreEqual(DeviceState.Online, monitor.Devices.ElementAt(0).State); Assert.AreEqual(1, sink.ConnectedEvents.Count); Assert.AreEqual(1, sink.ChangedEvents.Count); Assert.AreEqual(0, sink.DisconnectedEvents.Count); Assert.AreEqual("169.254.109.177:5555", sink.ChangedEvents[0].Device.Serial); }); } }
public void DeviceChangedTest() { using (DeviceMonitor monitor = new DeviceMonitor(this.Socket)) { DeviceMonitorSink sink = new DeviceMonitorSink(monitor); Assert.AreEqual(0, monitor.Devices.Count); // Start the monitor, detect the initial device. base.RunTest( OkResponse, ResponseMessages("169.254.109.177:5555\toffline\n"), Requests("host:track-devices"), () => { monitor.Start(); Assert.AreEqual(1, monitor.Devices.Count); Assert.AreEqual(DeviceState.Offline, monitor.Devices.ElementAt(0).State); Assert.AreEqual(1, sink.ConnectedEvents.Count); Assert.AreEqual(0, sink.ChangedEvents.Count); Assert.AreEqual(0, sink.DisconnectedEvents.Count); }); this.Socket.ResponseMessages.Clear(); this.Socket.Responses.Clear(); this.Socket.Requests.Clear(); // Device disconnects var eventWaiter = sink.CreateEventSignal(); base.RunTest( NoResponses, ResponseMessages("169.254.109.177:5555\tdevice\n"), Requests(), () => { eventWaiter.WaitOne(1000); Assert.AreEqual(1, monitor.Devices.Count); Assert.AreEqual(DeviceState.Online, monitor.Devices.ElementAt(0).State); Assert.AreEqual(1, sink.ConnectedEvents.Count); Assert.AreEqual(1, sink.ChangedEvents.Count); Assert.AreEqual(0, sink.DisconnectedEvents.Count); Assert.AreEqual("169.254.109.177:5555", sink.ChangedEvents[0].Device.Serial); }); } }
public static void Run(string[] args) { Application.Init(ref args); GtkSharp.GstreamerSharp.ObjectManager.Initialize(); _pipeline = CreatePipeline("cam_pipeline"); var bus = _pipeline.Bus; bus.AddWatch(OnBusMessage); _devMon = new DeviceMonitor(); var caps = new Caps("video/x-raw"); var filtId = _devMon.AddFilter("Video/Source", caps); if (!_devMon.Start()) { "Device monitor cannot start".PrintErr(); return; } if (_devMon.Devices.Length == 0) { Console.WriteLine("No video sources"); } else { Console.WriteLine($"Video devices count = {_devMon.Devices.Length}"); foreach (var dev in _devMon.Devices) { DumpDevice(dev); } var cam = _devMon.Devices.FirstOrDefault(d => d.DeviceClass == "Video/Source"); if (cam != null) { Console.WriteLine("Cam found"); ShowCamera(cam.DisplayName); } } var devMonBus = _devMon.Bus; devMonBus.AddWatch(OnBusMessage); var loop = new GLib.MainLoop(); loop.Run(); }
internal AdbClient() { AdbServer.Instance.StartServer("adb.exe", false); if (!AdbServer.Instance.GetStatus().IsRunning) { throw new Exception("No ADB server running!"); } this.client = (ExtAdbClient)ExtAdbClient.Instance; this.monitor = new DeviceMonitor(new AdbSocket(client.EndPoint)); monitor.DeviceChanged += OnDeviceChanged; monitor.DeviceConnected += OnDeviceConnected; monitor.DeviceDisconnected += OnDeviceDisconnected; monitor.Start(); }
static void Main(string[] args) { //at startup, initialize logger Log.Logger = new LoggerConfiguration().MinimumLevel.Information().WriteTo.Console().WriteTo.File("Logs/log.txt", rollingInterval: RollingInterval.Day, rollOnFileSizeLimit: true).CreateLogger(); //after initializing the logger, test the log by saying "Application Started" Log.Information("Application Started"); //then, log the version of Dokan Log.Information($"Using driver version {Dokan.DriverVersion} and Dokan version {Dokan.Version}"); //then initialize the devices monitor Monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort))); Monitor.DeviceConnected += Monitor_DeviceConnected; Monitor.DeviceDisconnected += Monitor_DeviceDisconnected; Monitor.DeviceChanged += Monitor_DeviceChanged; Monitor.Start(); Application.Run(); }
public MainWindow() { InitializeComponent(); AdbServer server = new AdbServer(); StartServerResult result = server.StartServer(@"C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe", restartServerIfNewer: false); txtStatus.Text = "Adb Status : " + result.ToString(); txtIP.Text = Properties.Settings.Default.LastIp; GetListOfDevices(); var monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort))); monitor.DeviceConnected += this.OnDeviceConnected; monitor.DeviceDisconnected += Monitor_DeviceDisconnected; monitor.Start(); }
/// <SUMMARY> /// Start accepting connections. /// A false return value tell you that the port is not available. /// </SUMMARY> public bool Start() { try { if (_ip.Equals("127.0.0.1") && _port.Equals(15555)) { DeviceMonitor.Start();//if device connect,reverse port 15555 } _listener.Bind(new IPEndPoint(IPAddress.Parse(_ip), _port)); _listener.Listen(100); _listener.BeginAccept(ConnectionReady, null); return(true); } catch { return(false); } }
public StartServerResult Initialize() { var config = Program.config; if (config[s].ContainsKey("path")) { return(StartServerResult.AlreadyRunning); } server = new AdbServer(); var result = server.StartServer(config[s]["path"], restartServerIfNewer: false); // Logger.Trace("ADB Connected Devices: {}", AdbClient.Instance.GetDevices().ToJson()); var monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort))); monitor.DeviceConnected += OnDeviceConnected; monitor.DeviceChanged += DeviceChanged; monitor.DeviceDisconnected += DeviceDisconnected; Task.Factory.StartNew(() => monitor.Start()); return(result); }
static void Main(string[] args) { var monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort))); monitor.Start(); var o = Observable .FromEventPattern <DeviceDataEventArgs>(m => monitor.DeviceConnected += m, m => monitor.DeviceConnected -= m) .Select(n => n?.EventArgs?.Device) .DistinctUntilChanged(n => n?.Serial) .Do(n => { if (n == null) { return; } try { if (Process.GetProcessesByName("scrcpy-noconsole")?.Any(b => b.StartInfo.Arguments.Contains(n.Serial)) == true) { return; } } catch (Exception) { } var u = new ProcessStartInfo("scrcpy-noconsole.exe", $@"-s {n.Serial}") { WorkingDirectory = Environment.CurrentDirectory }; Console.WriteLine($"Starting scrcpy for: {n.Serial}:{n.Name}"); Process.Start(u); }) .Subscribe(); Console.ReadKey(); monitor?.Dispose(); o?.Dispose(); }
private void backgroundWorkerStartServer_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { var result = (StartServerResult)e.Result; if (AdbServer.Instance.GetStatus().IsRunning) { deviceMonitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort))); deviceMonitor.DeviceConnected += OnDeviceConnected; deviceMonitor.DeviceDisconnected += OnDeviceDisconnected; deviceMonitor.Start(); buttonServerStop.Enabled = true; WriteLog($"Server started with result: {result.ToString()}"); WriteLog($"ADB version: {AdbServer.Instance.GetStatus().Version}"); } else { WriteLog($"Server NOT started with result: {result.ToString()}"); buttonServerStart.Enabled = true; } }
public AdbManager() { assembly = GetType().Assembly; isWindows = System.Runtime.InteropServices.RuntimeInformation .IsOSPlatform(OSPlatform.Windows); adbOutPath = Path.Combine(Directory.GetParent(assembly.Location).FullName, (isWindows ? "adb.exe" : "adb")); UnloadADB(); LoadADB(); AdbServer server = new AdbServer(); StartServerResult serverResult = server.StartServer(adbOutPath, true); adbVersion = AdbClient.Instance.GetAdbVersion(); adbRefreshTimer = new Timer(state => { try { listOfDevices = AdbClient.Instance.GetDevices(); } catch (Exception e) { Console.WriteLine(e); } }, null, 0, 2000); deviceMonitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort))); deviceMonitor.DeviceConnected += (sender, args) => { addAdbLogToQueue(args.Device); }; deviceMonitor.DeviceDisconnected += (sender, args) => { removeAdbLogFromQuene(args.Device); }; deviceMonitor.DeviceChanged += (sender, args) => { }; deviceMonitor.Start(); }
public AdbWrapper() { if (File.Exists(@"adb\adb.exe")) { _server = new AdbServer(); _server.StartServer(@"adb\adb.exe", restartServerIfNewer: false); ConnectToAndroid(); // Initialize device monitor var monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort))); monitor.DeviceDisconnected += this.OnDeviceDisconnected; monitor.Start(); } else { ConsoleLogger.Write("adb.exe not found.", textColor: ConsoleColor.Red); ConsoleLogger.Write("Did you extract everything from the zip?"); ConsoleLogger.Write("Press Enter to exit."); Console.ReadLine(); Environment.Exit(0); } }
/// <summary> /// Connects the specified device. /// </summary> /// <param name="device">The device.</param> public void Connect( string device ) { try { if ( DeviceMonitor != null ) { DeviceMonitor.Stop ( ); DeviceMonitor = null; } DeviceMonitor = new DeviceMonitor ( device ); DeviceMonitor.Connected += ( s, e ) => { if ( this.Connected != null ) { this.State = e.State; this.Connected ( this, e ); } }; DeviceMonitor.Disconnected += ( s, e ) => { Disconnect ( e.Device ); if ( this.Disconnected != null ) { this.State = e.State; this.Disconnected ( this, e ); } }; DeviceMonitor.DeviceStateChanged += ( s, e ) => { if ( this.DeviceStateChanged != null ) { this.State = e.State; this.DeviceStateChanged ( this, e ); } }; DeviceMonitor.Start ( ); } catch ( Exception ex ) { this.LogError ( ex.Message, ex ); State = DeviceState.Unknown; } }
static void Main() { var scanner = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? (IScanner) new PingAndArp() : (IScanner) new NMapScanner(); Console.WriteLine($"Inital IP scan of {SubnetAddress} using {scanner.GetType().Name}"); var sw = Stopwatch.StartNew(); var online = scanner.Scan(SubnetAddress).Online; foreach (var entry in online) { Console.WriteLine($"\t{entry.Ip}\t{entry.Mac}"); } Console.WriteLine($"Scan tool {sw.Elapsed}"); Console.WriteLine(); var devices = DeviceList.CreateFromFile("devices.json"); if (devices.Devices.Count(d => d.Type == DeviceType.HueBridge) != 1) { throw new Exception("Exactly one Hue Bridge must be defined in devices.json"); } devices.ProcessDiscovery(online); var hue = (HueBridge)devices.Devices.First(d => d.Type == DeviceType.HueBridge); Console.WriteLine("Bridge:"); Console.WriteLine($"\t{hue.Name,-30}\t{hue.Mac}\t{hue.OnlineStatus.Ip}\t{hue.OnlineStatus.Status}"); if (hue.OnlineStatus.Status != OnlineStatusOnline.Online) { throw new Exception("Hue Bridge is not online"); } Console.WriteLine(); var lights = hue.GetLights(); Console.WriteLine("Lights:"); foreach (var light in lights) { Console.WriteLine($"\t{light.Name,-30}\t{light.TurnedOn}"); } Console.WriteLine(); var groups = hue.GetGroups(); Console.WriteLine("Groups:"); foreach (var grp in groups) { Console.WriteLine($"\t{grp.Name,-30}\t{grp.TurnedOn}"); } Console.WriteLine(); var switchable = groups.Concat <ISwitchable>(lights).ToList(); devices.UpdateDevices(switchable); Console.WriteLine("TVs:"); var tvs = new DeviceList(devices.Devices.Where(d => d.Type == DeviceType.Tv)); tvs.ProcessDiscovery(online); foreach (var tv in tvs.Devices.Cast <Tv>()) { Console.WriteLine($"\t{tv.Name,-30}\t{tv.Mac}\t{tv.OnlineStatus.Status}\t{String.Join(',', tv.ControlNames)}"); } Console.WriteLine(); var monitor = new DeviceMonitor(SubnetAddress, scanner, tvs); monitor.DeviceChanged += (sender, data) => { Console.WriteLine($"\t{DateTime.Now:T}\t{data.Device.Name}\t{data.FromStatus}\t->\t{data.ToStatus}"); if (!(data.Device is Tv tv)) { return; } switch (data.ToStatus) { case OnlineStatusOnline.Online: foreach (var sw in tv.ControlDevices) { sw.TurnOn(); Console.WriteLine($"\t{DateTime.Now:T}\t{sw.Name} turned on"); } break; case OnlineStatusOnline.Offline: foreach (var sw in tv.ControlDevices) { sw.TurnOff(); Console.WriteLine($"\t{DateTime.Now:T}\t{sw.Name} turned off"); } break; } }; monitor.Start(); var waitEvent = new ManualResetEvent(false); Console.CancelKeyPress += (sender, args) => { waitEvent.Set(); args.Cancel = true; }; Console.WriteLine("DeviceMonitor started, Ctrl-C to stop"); waitEvent.WaitOne(); monitor.Stop(); Console.WriteLine("DeviceMonitor stopped"); }
static void Main(string[] args) { Trace.Listeners.Add(new TextWriterTraceListener(errorFileName)); Trace.AutoFlush = true; if (args.Any(c => c.ToLower() == "/armobs")) { if (args.Length == 1) { var obs32List = Process.GetProcessesByName("obs32"); var obs64List = Process.GetProcessesByName("obs64"); if (obs32List.Length == 0 && obs64List.Length == 0) { //No OBS found. Cancel operation. File.Delete(OBSUtils.obswszip); return; } List <Process> obsProcesses = new List <Process>(); obsProcesses.AddRange(obs32List); obsProcesses.AddRange(obs64List); if (obsProcesses.Count != 1) { //Multiple OBS instances found. Cancel operation. File.Delete(OBSUtils.obswszip); return; } var obsProcess = obsProcesses.First(); string path = OBSUtils.GetProcessPath(obsProcess.Id); string zipTempPath = Path.GetFileNameWithoutExtension(OBSUtils.obswszip); OBSUtils.ExtractZip(OBSUtils.obswszip, zipTempPath); OBSUtils.DirectoryCopy(zipTempPath, OBSUtils.GetPathFromOBSExecutable(path), true); File.Delete(OBSUtils.obswszip); Directory.Delete(zipTempPath, true); var obsGlobalFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "obs-studio", "global.ini"); if (File.Exists(obsGlobalFilePath) && !File.ReadAllText(obsGlobalFilePath).Contains("[WebsocketAPI]")) { Trace.WriteLine("File exist and not contain web socket."); while (!obsProcess.HasExited) { StringBuilder sb = new StringBuilder(); sb.AppendLine(Texts.rm.GetString("OBSINTEGRATIONINSTALL", Texts.cultereinfo)); sb.AppendLine(""); sb.AppendLine(Texts.rm.GetString("OBSINTEGRATIONAPPLY", Texts.cultereinfo)); MessageBox.Show(sb.ToString()); } using (StreamWriter outputFile = new StreamWriter(obsGlobalFilePath)) { outputFile.WriteLine(""); outputFile.WriteLine("[WebsocketAPI]"); outputFile.WriteLine("ServerPort=4444"); outputFile.WriteLine("DebugEnabled=false"); outputFile.WriteLine("AlertsEnabled=false"); outputFile.WriteLine("AuthRequired=false"); } bool shouldRepeat = true; while (shouldRepeat) { var obs32List2 = Process.GetProcessesByName("obs32"); var obs64List2 = Process.GetProcessesByName("obs64"); shouldRepeat = obs32List2.Length == 0 && obs64List2.Length == 0; if (!shouldRepeat) { break; } StringBuilder sb = new StringBuilder(); sb.AppendLine(Texts.rm.GetString("OBSINTEGRATIONINSTALLSUCESSFULL", Texts.cultereinfo)); sb.AppendLine(""); sb.AppendLine(Texts.rm.GetString("OBSINTEGRATIONCONFIRMOBS", Texts.cultereinfo)); MessageBox.Show(sb.ToString()); } } return; } } #if FORCE_SILENCE Silent = true; #else Silent = args.Any(c => c.ToLower() == "/s"); #endif const string appName = "DisplayButtons"; bool createdNew; mutex = new Mutex(true, appName, out createdNew); if (!createdNew) { //app is already running! Exiting the application if (MessageBox.Show(Texts.rm.GetString("ALREADYDISPLAYBUTTONISOPEN", Texts.cultereinfo), Texts.rm.GetString("ALREADYDISPLAYBUTTONISOPENTITLE", Texts.cultereinfo), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { var myapp = Process.GetProcessesByName(Assembly.GetCallingAssembly().GetName().Name); List <Process> obsProcesses = new List <Process>(); obsProcesses.AddRange(myapp); if (obsProcesses.Count > 1) { var last = obsProcesses.First(); last.Kill(); } } //return; } Application.ThreadException += Application_ThreadException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; EventXml.LoadSettings(); ApplicationSettingsManager.LoadSettings(); Texts.initilizeLang(); errorText = String.Format(Texts.rm.GetString("INTEGRATIONERROROCURRED", Texts.cultereinfo), errorFileName); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); OBSUtils.PrepareOBSIntegration(); if (ApplicationSettingsManager.Settings.FirstRun) { FirstSetupForm firstRunForm = new FirstSetupForm(); Application.Run(firstRunForm); if (!firstRunForm.FinishedSetup) { return; } } // EnsureBrowserEmulationEnabled("DisplayButtons.exe"); new WebBrowserInstanceHelper().SetBrowserFeatureControl(); dynamic form = Activator.CreateInstance(FindType("DisplayButtons.Forms.ActionHelperForms.MainFormMenuOption")) as Form; if (form.ShowDialog() == DialogResult.OK) { Initilizator.mode = 0; Initilizator.ServerThread = new ServerThread(); Initilizator.ServerThread.Start(); Debug.WriteLine("MODO SOCKET CLIENT"); } else { // Silent = true; Debug.WriteLine("MODO USB"); Initilizator.mode = 1; Adbserver = new AdbServer(); Adbserver.StartServer(Path.Combine(Application.StartupPath, @"Data\adb\adb.exe"), restartServerIfNewer: true); monitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort))); client = new AdbClient(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort), Factories.AdbSocketFactory); monitor.DeviceConnected += MainForm.DeviceAdbConnected; monitor.DeviceDisconnected += MainForm.DeviceAdbDisconnected; monitor.Start(); if (client.GetDevices().Count == 1) { Debug.WriteLine("ONE DEVICE"); // client.ExecuteRemoteCommand("am start -a android.intent.action.VIEW -e mode 1 net.nickac.DisplayButtons/.MainActivity", client.GetDevices().First(), null); DevicePersistManager.PersistUsbMode(client.GetDevices().First()); // client.CreateForward(client.GetDevices().First(), "tcp:5095", "tcp:5095", true); Initilizator.ClientThread = new ClientThread(); Initilizator.ClientThread.Start(); } else { Initilizator.ClientThread = new ClientThread(); } } Application.Run(new MainForm()); //Application.Run(new MainFormMenuOption()); OBSUtils.Disconnect(); if (Initilizator.mode == 1) { foreach (var device in client.GetDevices().ToList()) { // client.ExecuteRemoteCommand("am force-stop net.nickac.DisplayButtons", device, null); // client.ExecuteRemoteCommand("kill-server", device, null); // client.KillAdb(); } } // client.KillAdb(); EventXml.SaveSettings(); ApplicationSettingsManager.SaveSettings(); DevicePersistManager.SaveDevices(); NetworkChange.NetworkAddressChanged -= NetworkChange_NetworkAddressChanged; NetworkChange.NetworkAvailabilityChanged -= NetworkChange_NetworkAddressChanged; Trace.Flush(); }
public void StartInitialDeviceListTest() { using (DeviceMonitor monitor = new DeviceMonitor(this.Socket)) { DeviceMonitorSink sink = new DeviceMonitorSink(monitor); Assert.AreEqual(0, monitor.Devices.Count); base.RunTest( OkResponse, ResponseMessages("169.254.109.177:5555\tdevice\n"), Requests("host:track-devices"), () => { monitor.Start(); Assert.AreEqual(1, monitor.Devices.Count); Assert.AreEqual("169.254.109.177:5555", monitor.Devices.ElementAt(0).Serial); Assert.AreEqual(1, sink.ConnectedEvents.Count); Assert.AreEqual("169.254.109.177:5555", sink.ConnectedEvents[0].Device.Serial); Assert.AreEqual(0, sink.ChangedEvents.Count); Assert.AreEqual(0, sink.DisconnectedEvents.Count); }); } }