static void Main(string[] args) { try { { AndroidPhone phone = new AndroidPhone(); phone.Call(); } { IPhone phone = new ApplePhone(); phone.Call(); } { IPhone phone = ObjectFactory.CreateInstance(); phone.Call(); } { //IocTest.Show(); } { } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadKey(); }
/// <summary> /// Async Bluetooth Stream Listener waiting and reading messages on the specified Stream. /// On message received, the function will try to parse it based on the device type /// and store it to the Azure Database in its specific table. /// </summary> /// <param name="btDevice"></param> /// <returns></returns> private async Task BluetoothStreamListener(BluetoothDevice btDevice) { if (!Bluetooth.devicesStreams.Keys.Contains(btDevice)) { //failed to connect to device return; } Stream s = Bluetooth.devicesStreams[btDevice]; while (true) { byte[] buffer = new byte[1]; string result = ""; string bufferChar = ""; while (!bufferChar.Equals("}")) { try { s.Read(buffer, 0, 1); } catch (Exception e) { continue; } bufferChar = Encoding.UTF8.GetString(buffer); result += bufferChar; } Console.WriteLine(result); LoTDevice device; if (btDevice.DeviceType.Equals(BluetoothDevice.DEVICE_ENGDUINO)) { device = new Engduino(); } else if (btDevice.DeviceType.Equals(BluetoothDevice.DEVICE_ANDROIDPHONE)) { device = new AndroidPhone(); } else { //maybe print the message in the console continue; } device.MAC = btDevice.DeviceAddress; try { device.parseMessage(result); } catch (Exception e) { logger.Log("Failed to parse message: " + result + " for device: " + btDevice.DeviceName); continue; } try { await mobileService.WriteDevice(device); } catch (HttpRequestException ex) { logger.Log("No internet connection on writing to Azure MS.", ex.ToString()); } catch (Exception e) { logger.Log("Failed to write to Azure MS.", e.ToString()); } } }
internal static void OnInit() { if (!GameObject.Find(nameof(MobilePlatform))) { GameObject gameObject = new GameObject(nameof(MobilePlatform)); DontDestroyOnLoad(gameObject); gameObject.AddComponent <MobilePlatform>(); if (IsAndroid) { Android = new AndroidPhone(); } } }
private static void Example2() { var androidPhone = new AndroidPhone(); var androidUsbCable = new AndroidUsbCable { UsbPowerSource = new WallSocketToUsbPowerSourceAdapter { WallSocketPowerSource = new WallSocketPowerSource() } }; var cts = new CancellationTokenSource(); Task task = androidPhone.Recharge(androidUsbCable, cts.Token).ContinueWith( t => Console.WriteLine(androidPhone.Battery) ); cts.CancelAfter(10000); task.Wait(); }
static void Main() { var wp1 = new WindowsPhone("Lumia 620"); var wp2 = new WindowsPhone("Lumia 1020"); var wp3 = new WindowsPhone("Lumia 930"); var android1 = new AndroidPhone("Nexus 4"); var android2 = new AndroidPhone("Nexus 5"); var android3 = new AndroidPhone("Galaxy 3"); var observer = new Messages(); //Подписываем на уведомления Windows Phone девайсы observer.ContentChanged += wp1.Update; observer.ContentChanged += wp2.Update; observer.ContentChanged += wp3.Update; //Подписываем на уведомления Android девайсы observer.ContentChanged += android1.Update; observer.ContentChanged += android2.Update; observer.ContentChanged += android3.Update; //Первое PUSH уведомление observer.MessageAvailable(); //Удаляем из рассылки Lumia 620 и Nexus 4 observer.ContentChanged -= wp1.Update; observer.ContentChanged -= android1.Update; Console.WriteLine("\n---Были удалены некоторые девайсы из рассылки---"); //Второе PUSH уведомление observer.MessageAvailable(); Console.WriteLine("\n---Третья рассылка---"); //Третья рассылка observer.MessageAvailable(); }
/// <summary> /// The main entry point for the application. /// </summary> static void Main() { #region Generate and show QR //Find our local IP-address IPHostEntry host; string localIP = ""; host = Dns.GetHostEntry(Dns.GetHostName()); foreach (IPAddress ip in host.AddressList) { if (ip.AddressFamily == AddressFamily.InterNetwork) { localIP = ip.ToString(); } } QRCodeGenerator.ShowQRCode(localIP + "/" + 1337, 120, 120, ImageFormat.Png);//120 are ok dimensions #endregion AndroidPhone phone = new AndroidPhone(); DesktopController controller = new DesktopController(phone, new OsInterface()); SerializeManager serializeManager = new SerializeManager(); serializeManager.RegisterSerilizer(new TouchEventSerializer()); serializeManager.RegisterSerilizer(new SensorEventSerializer()); serializeManager.RegisterSerilizer(new StringSerializer()); serializeManager.RegisterSerilizer(new HardwareButtonSerializer()); IServer server = new Server(serializeManager); server.ConnectionTimeout = 5000; server.Start(1337); TouchDecoder decoder = new TouchDecoder(); phone.Tap += () => controller.LeftClick(); phone.Up += () => controller.mouseUp(); phone.MultiTap += (x) => { if (x == 2) controller.RightClick(); }; phone.Down += () => controller.mouseDown(); phone.Move += (x, y) => controller.MoveMouse(moveSpeed(x), moveSpeed(y)); phone.MulitiMove += (c, x, y) => controller.VerticalScroll(y * 10); phone.Pinch += (x) => { InputSimulator.SimulateKeyDown(VirtualKeyCode.CONTROL); controller.VerticalScroll(x); InputSimulator.SimulateKeyUp(VirtualKeyCode.CONTROL); }; int bytesRecived = 0; long totalbytesRecived = 0; System.Timers.Timer timer = new System.Timers.Timer(1000); timer.AutoReset = true; timer.Elapsed += (s,e) => { Console.Title = "Total Recived: " + totalbytesRecived + " Current ByteRate: " + ((double)bytesRecived) / 1000; totalbytesRecived += bytesRecived; bytesRecived = 0; }; timer.Start(); server.Connected += (x, y) => Console.WriteLine("A connection was recived"); server.Recived += (x, message) => { if (message.Message is IPhoneMessage) { phone.ProcessMessage((IPhoneMessage)message.Message); } else if(message.Message is String) { controller.NetworkedText(message.Message.ToString()); } else if (message.Message is HardwareButtonEvent) { int id = ((HardwareButtonEvent)message.Message).ID; if (id == HardwareButtonEvent.VOLUME_UP) controller.IncreaseVolume(); else if (id == HardwareButtonEvent.VOLUME_DOWN) controller.DecreaseVolume(); else System.Diagnostics.Process.Start("http://www.google.com"); } }; server.Dissconnected += (x, y) => Console.WriteLine("Oh no we dced ;("); }