Exemple #1
0
        public override bool Execute()
        {
            Log.LogTaskName("DetectDebugNetworkConfiguration");
            Log.LogTaskProperty("DebugOverWiFi", DebugOverWiFi);
            Log.LogTaskProperty("DebuggerHosts", DebuggerHosts);
            Log.LogTaskProperty("SdkIsSimulator", SdkIsSimulator);

            var ips = new List <string> ();

            if (SdkIsSimulator)
            {
                ips.Add(IPAddress.Loopback.ToString());
            }
            else if (DebugOverWiFi)
            {
                string [] hosts = null;

                if (!string.IsNullOrEmpty(DebuggerHosts))
                {
                    hosts = DebuggerHosts.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                }

                if (hosts == null || hosts.Length == 0)
                {
                    try {
                        ips.AddRange(Dns.GetHostEntry(Dns.GetHostName()).AddressList.Select((v) => v.ToString()));
                    } catch {
                        Log.LogError("Could not resolve host IPs for WiFi debugger settings");
                        return(false);
                    }
                }
                else
                {
                    foreach (var host in hosts)
                    {
                        IPAddress ip;

                        if (IPAddress.TryParse(host, out ip))
                        {
                            ips.Add(ip.ToString());
                        }
                    }
                }

                if (ips == null || ips.Count == 0)
                {
                    Log.LogError("This machine does not have any network adapters. This is required when debugging or profiling on device over WiFi.");
                    return(false);
                }
            }

            DebugIPAddresses = string.Join(";", ips.ToArray());

            Log.LogTaskProperty("DebugIPAddresses", DebugIPAddresses);

            return(!Log.HasLoggedErrors);
        }
        public override bool Execute()
        {
            var path = Path.Combine(AppBundleDir, "MonoTouchDebugConfiguration.txt");
            var ips  = new List <IPAddress> ();

            Log.LogTaskName("CreateDebugConfiguration");
            Log.LogTaskProperty("AppBundleDir", AppBundleDir);
            Log.LogTaskProperty("DebugOverWiFi", DebugOverWiFi);
            Log.LogTaskProperty("DebuggerHosts", DebuggerHosts);
            Log.LogTaskProperty("DebuggerPort", DebuggerPort);
            Log.LogTaskProperty("SdkIsSimulator", SdkIsSimulator);

            if (SdkIsSimulator)
            {
                ips.Add(IPAddress.Loopback);
            }
            else if (DebugOverWiFi)
            {
                string[] hosts = null;

                if (!string.IsNullOrEmpty(DebuggerHosts))
                {
                    hosts = DebuggerHosts.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                }

                if (hosts == null || hosts.Length == 0)
                {
                    try {
                        ips.AddRange(Dns.GetHostEntry(Dns.GetHostName()).AddressList);
                    } catch {
                        Log.LogError("Could not resolve host IPs for WiFi debugger settings");
                        return(false);
                    }
                }
                else
                {
                    foreach (var host in hosts)
                    {
                        IPAddress ip;

                        if (IPAddress.TryParse(host, out ip))
                        {
                            ips.Add(ip);
                        }
                    }
                }

                if (ips == null || ips.Count == 0)
                {
                    Log.LogError("This machine does not have any network adapters. This is required when debugging or profiling on device over WiFi.");
                    return(false);
                }
            }

            try {
                using (var stream = new FileStream(path, FileMode.Create, FileAccess.Write)) {
                    using (var writer = new StreamWriter(stream)) {
                        var added = new HashSet <string> ();
                        foreach (var ip in ips)
                        {
                            string str = ip.ToString();

                            if (added.Contains(str))
                            {
                                continue;
                            }

                            writer.WriteLine("IP: {0}", str);
                            added.Add(str);
                        }

                        if (!DebugOverWiFi && !SdkIsSimulator)
                        {
                            writer.WriteLine("USB Debugging: 1");
                        }

                        writer.WriteLine("Port: {0}", DebuggerPort);
                    }
                }
            } catch (Exception ex) {
                Log.LogError(ex.Message);
            }

            return(!Log.HasLoggedErrors);
        }
Exemple #3
0
        public override bool Execute()
        {
            if (SdkIsSimulator)
            {
                DebugIPAddresses = IPAddress.Loopback.ToString();
            }
            else if (DebugOverWiFi)
            {
                var       ips   = new List <string> ();
                string [] hosts = null;

                if (!string.IsNullOrEmpty(DebuggerHosts))
                {
                    hosts = DebuggerHosts.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                }

                if (hosts == null || hosts.Length == 0)
                {
                    var properties = IPGlobalProperties.GetIPGlobalProperties();
                    var hostName   = properties.HostName;

                    try {
                        var entry = Dns.GetHostEntry(hostName);

                        ips.AddRange(entry.AddressList.Select(v => v.ToString()));
                    } catch {
                        using (var socket = new Socket(SocketType.Dgram, ProtocolType.Udp)) {
                            try {
                                socket.Connect("8.8.8.8", 53);

                                var ipEndPoint = (IPEndPoint)socket.LocalEndPoint;

                                ips.Add(ipEndPoint.Address.ToString());
                            } catch {
                                Log.LogError(7001, null, MSBStrings.E7001);
                                return(false);
                            }
                        }
                    }
                }
                else
                {
                    foreach (var host in hosts)
                    {
                        IPAddress ip;

                        if (IPAddress.TryParse(host, out ip))
                        {
                            ips.Add(ip.ToString());
                        }
                    }
                }

                if (ips == null || ips.Count == 0)
                {
                    Log.LogError(7002, null, MSBStrings.E7002);
                    return(false);
                }

                DebugIPAddresses = string.Join(";", ips);
            }

            Log.LogTaskProperty("DebugIPAddresses", DebugIPAddresses);

            return(!Log.HasLoggedErrors);
        }
Exemple #4
0
        public override bool Execute()
        {
            var ips = new List <string> ();

            if (SdkIsSimulator)
            {
                ips.Add(IPAddress.Loopback.ToString());
            }
            else if (DebugOverWiFi)
            {
                string [] hosts = null;

                if (!string.IsNullOrEmpty(DebuggerHosts))
                {
                    hosts = DebuggerHosts.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                }

                if (hosts == null || hosts.Length == 0)
                {
                    var properties = IPGlobalProperties.GetIPGlobalProperties();
                    var hostName   = properties.HostName;

                    try {
                        var entry = Dns.GetHostEntry(hostName);

                        ips.AddRange(entry.AddressList.Select(v => v.ToString()));
                    } catch {
                        using (var socket = new Socket(SocketType.Dgram, ProtocolType.Udp)) {
                            try {
                                socket.Connect("8.8.8.8", 53);

                                var ipEndPoint = (IPEndPoint)socket.LocalEndPoint;

                                ips.Add(ipEndPoint.Address.ToString());
                            } catch {
                                Log.MTError(7001, "Could not resolve host IPs for WiFi debugger settings.");
                                return(false);
                            }
                        }
                    }
                }
                else
                {
                    foreach (var host in hosts)
                    {
                        IPAddress ip;

                        if (IPAddress.TryParse(host, out ip))
                        {
                            ips.Add(ip.ToString());
                        }
                    }
                }

                if (ips == null || ips.Count == 0)
                {
                    Log.MTError(7002, "This machine does not have any network adapters. This is required when debugging or profiling on device over WiFi.");
                    return(false);
                }
            }

            DebugIPAddresses = string.Join(";", ips.ToArray());

            Log.LogTaskProperty("DebugIPAddresses", DebugIPAddresses);

            return(!Log.HasLoggedErrors);
        }