static void Main() { // Catchall for all uncaught exceptions !! AppDomain.CurrentDomain.UnhandledException += delegate(object sender, UnhandledExceptionEventArgs args) { // Application.Restart(); var exception = (Exception)args.ExceptionObject; MessageBox.Show("FATAL: Unhandled - " + exception.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); }; try { TXTrecords.Add("machineName", System.Environment.MachineName); TXTrecords.Add("osVersion", System.Environment.OSVersion.VersionString); TXTrecords.Add("userid", System.Environment.UserName); #if USE_BLUETOOTH if (BluetoothRadio.IsSupported) { try { TXTrecords.Add("bluetooth", BluetoothRadio.PrimaryRadio.LocalAddress.ToString("C").Replace(":", "-").ToLower()); } catch { TXTrecords.Add("bluetooth", "NotSupported"); } } else #endif TXTrecords.Add("bluetooth", "NotSupported"); allScreen = Screen.AllScreens; for (int i=0; i < allScreen.Length; i++) TXTrecords.Add("screen" + i, allScreen[i].Bounds.X + "x" + allScreen[i].Bounds.Y + "x" + allScreen[i].Bounds.Width + "x" + allScreen[i].Bounds.Height); // TXTrecords.Add("screenWidth", System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width.ToString()); // TXTrecords.Add("screenHeight", System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height.ToString()); TcpListener ctrlAddr = new TcpListener(IPAddress.Any, 0 ); ctrlAddr.Start(); IPEndPoint sep = (IPEndPoint)ctrlAddr.LocalEndpoint; Debug.Assert(sep.Port != 0); String id, nm; using (RegistryKey dcs = Registry.CurrentUser.CreateSubKey("Software").CreateSubKey("FXPAL").CreateSubKey("DisplayCast").CreateSubKey("Player")) { if (dcs.GetValue("uid") == null) dcs.SetValue("uid", System.Guid.NewGuid().ToString("D")); id = dcs.GetValue("uid").ToString(); if (dcs.GetValue("name") == null) dcs.SetValue("name", System.Environment.UserName); nm = dcs.GetValue("Name").ToString(); TXTrecords.Remove("name"); TXTrecords.Add("name", nm); } try { nsPublisher = new NetService(Shared.DisplayCastGlobals.BONJOURDOMAIN, Shared.DisplayCastGlobals.PLAYER, id, sep.Port); nsPublisher.DidPublishService += new NetService.ServicePublished(publishService_DidPublishService); nsPublisher.DidNotPublishService += new NetService.ServiceNotPublished(publishService_DidNotPublishService); nsPublisher.TXTRecordData = NetService.DataFromTXTRecordDictionary(TXTrecords); nsPublisher.AllowApplicationForms = true; nsPublisher.Publish(); } catch { MessageBox.Show("Apple Bonjour not installed. Pick up a local copy from https://developer.apple.com/opensource/", "FATAL", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } // PlayerRemoteControl rc = new PlayerRemoteControl(ctrlAddr); // Thread ctrlThread = new Thread(new ThreadStart(rc.process)); // ctrlThread.Name = "processNewControl"; // ctrlThread.Start(); ctrlAddr.BeginAcceptTcpClient(ctrlBeginAcceptTcpClient, ctrlAddr); MSE = new QueryMSE(); myMac = getWIFIMACAddress(); // if (myMac == null) // myMac = displaycast; if (myMac != null) { using (RegistryKey dcs = Registry.CurrentUser.CreateSubKey("Software").CreateSubKey("FXPAL").CreateSubKey("DisplayCast").CreateSubKey("Player")) { discloseLocation = Convert.ToBoolean(dcs.GetValue("discloseLocation", false)); } locThread = new Thread(new ThreadStart(monitorMyLocation)); locThread.Start(); } } catch (Exception e) { MessageBox.Show("FATAL: Unhandled - " + e.StackTrace , "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } try { streamerList = new StreamerList(); Application.Run(streamerList); } catch (Exception e) { MessageBox.Show("FATAL: Cannot start streamerList - " + e.StackTrace); Environment.Exit(1); } }
static void Main() { // Catchall for all uncaught exceptions !! AppDomain.CurrentDomain.UnhandledException += delegate(object sender, UnhandledExceptionEventArgs args) { // Application.Restart(); var exception = (Exception)args.ExceptionObject; MessageBox.Show("FATAL: Unhandled - " + exception.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); }; try { TXTrecords.Add("machineName", System.Environment.MachineName); TXTrecords.Add("osVersion", System.Environment.OSVersion.VersionString); TXTrecords.Add("userid", System.Environment.UserName); #if USE_BLUETOOTH if (BluetoothRadio.IsSupported) { try { TXTrecords.Add("bluetooth", BluetoothRadio.PrimaryRadio.LocalAddress.ToString("C").Replace(":", "-").ToLower()); } catch { TXTrecords.Add("bluetooth", "NotSupported"); } } else #endif TXTrecords.Add("bluetooth", "NotSupported"); allScreen = Screen.AllScreens; for (int i = 0; i < allScreen.Length; i++) { TXTrecords.Add("screen" + i, allScreen[i].Bounds.X + "x" + allScreen[i].Bounds.Y + "x" + allScreen[i].Bounds.Width + "x" + allScreen[i].Bounds.Height); } // TXTrecords.Add("screenWidth", System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width.ToString()); // TXTrecords.Add("screenHeight", System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height.ToString()); TcpListener ctrlAddr = new TcpListener(IPAddress.Any, 0); ctrlAddr.Start(); IPEndPoint sep = (IPEndPoint)ctrlAddr.LocalEndpoint; Debug.Assert(sep.Port != 0); String id, nm; using (RegistryKey dcs = Registry.CurrentUser.CreateSubKey("Software").CreateSubKey("FXPAL").CreateSubKey("DisplayCast").CreateSubKey("Player")) { if (dcs.GetValue("uid") == null) { dcs.SetValue("uid", System.Guid.NewGuid().ToString("D")); } id = dcs.GetValue("uid").ToString(); if (dcs.GetValue("name") == null) { dcs.SetValue("name", System.Environment.UserName); } nm = dcs.GetValue("Name").ToString(); TXTrecords.Remove("name"); TXTrecords.Add("name", nm); } try { nsPublisher = new NetService(Shared.DisplayCastGlobals.BONJOURDOMAIN, Shared.DisplayCastGlobals.PLAYER, id, sep.Port); nsPublisher.DidPublishService += new NetService.ServicePublished(publishService_DidPublishService); nsPublisher.DidNotPublishService += new NetService.ServiceNotPublished(publishService_DidNotPublishService); nsPublisher.TXTRecordData = NetService.DataFromTXTRecordDictionary(TXTrecords); nsPublisher.AllowApplicationForms = true; nsPublisher.Publish(); } catch { MessageBox.Show("Apple Bonjour not installed. Pick up a local copy from https://developer.apple.com/opensource/", "FATAL", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } // PlayerRemoteControl rc = new PlayerRemoteControl(ctrlAddr); // Thread ctrlThread = new Thread(new ThreadStart(rc.process)); // ctrlThread.Name = "processNewControl"; // ctrlThread.Start(); ctrlAddr.BeginAcceptTcpClient(ctrlBeginAcceptTcpClient, ctrlAddr); MSE = new QueryMSE(); myMac = getWIFIMACAddress(); // if (myMac == null) // myMac = displaycast; if (myMac != null) { using (RegistryKey dcs = Registry.CurrentUser.CreateSubKey("Software").CreateSubKey("FXPAL").CreateSubKey("DisplayCast").CreateSubKey("Player")) { discloseLocation = Convert.ToBoolean(dcs.GetValue("discloseLocation", false)); } locThread = new Thread(new ThreadStart(monitorMyLocation)); locThread.Start(); } } catch (Exception e) { MessageBox.Show("FATAL: Unhandled - " + e.StackTrace, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } try { streamerList = new StreamerList(); Application.Run(streamerList); } catch (Exception e) { MessageBox.Show("FATAL: Cannot start streamerList - " + e.StackTrace); Environment.Exit(1); } }