Example #1
0
        public IEnumerable <AvdTarget> ListTargets()
        {
            var r = new List <AvdTarget>();

            var lines = run("list", "target");

            var str = string.Join("\n", lines);

            var matches = rxListTargets.Matches(str);

            if (matches != null && matches.Count > 0)
            {
                foreach (Match m in matches)
                {
                    // Parse out the id further from: `18 or "pixel"`
                    var idstr = m.Groups?["id"]?.Value;
                    int?idnum = null;

                    var idRx = rxIdOr.Match(idstr);

                    if (idRx != null && idRx.Success && int.TryParse(idRx.Groups?["num"]?.Value, out var idInt))
                    {
                        idnum = idInt;
                        idstr = idRx.Groups?["str"]?.Value ?? idstr;
                    }

                    var a = new AvdTarget
                    {
                        Name      = m.Groups?["name"]?.Value,
                        Id        = idstr,
                        NumericId = idnum,
                        Type      = m.Groups?["type"]?.Value
                    };

                    if (int.TryParse(m.Groups?["api"]?.Value, out var api))
                    {
                        a.ApiLevel = api;
                    }
                    if (int.TryParse(m.Groups?["revision"]?.Value, out var rev))
                    {
                        a.Revision = rev;
                    }

                    if (!string.IsNullOrWhiteSpace(a.Id) && a.ApiLevel > 0)
                    {
                        r.Add(a);
                    }
                }
            }

            return(r);
        }
        public IEnumerable <AvdTarget> ListTargets()
        {
            var r = new List <AvdTarget>();

            var lines = run("list", "target");

            var str = string.Join("\n", lines);

            var matches = rxListTargets.Matches(str);

            if (matches != null && matches.Count > 0)
            {
                foreach (Match m in matches)
                {
                    var a = new AvdTarget
                    {
                        Name = m.Groups?["name"]?.Value,
                        Id   = m.Groups?["id"]?.Value,
                        Type = m.Groups?["type"]?.Value
                    };

                    if (int.TryParse(m.Groups?["api"]?.Value, out var api))
                    {
                        a.ApiLevel = api;
                    }
                    if (int.TryParse(m.Groups?["revision"]?.Value, out var rev))
                    {
                        a.Revision = rev;
                    }

                    if (!string.IsNullOrWhiteSpace(a.Id) && a.ApiLevel > 0)
                    {
                        r.Add(a);
                    }
                }
            }

            return(r);
        }