Represents an adb forward specification as used by the various adb port forwarding functions.
        /// <summary>
        /// Creates a <see cref="ForwardSpec"/> from its <see cref="string"/> representation.
        /// </summary>
        /// <param name="spec">
        /// A <see cref="string"/> which represents a <see cref="ForwardSpec"/>.
        /// </param>
        /// <returns>
        /// A <see cref="ForwardSpec"/> which represents <paramref name="spec"/>.
        /// </returns>
        public static ForwardSpec Parse(string spec)
        {
            if (spec == null)
            {
                throw new ArgumentNullException(nameof(spec));
            }

            var parts = spec.Split(new char[] { ':' }, 2, StringSplitOptions.RemoveEmptyEntries);

            if (parts.Length != 2)
            {
                throw new ArgumentOutOfRangeException(nameof(spec));
            }

            if (!Mappings.ContainsKey(parts[0]))
            {
                throw new ArgumentOutOfRangeException(nameof(spec));
            }

            var protocol = Mappings[parts[0]];

            ForwardSpec value = new ForwardSpec();

            value.Protocol = protocol;

            int intValue;

            bool isInt = int.TryParse(parts[1], out intValue);

            switch (protocol)
            {
            case ForwardProtocol.JavaDebugWireProtocol:
                if (!isInt)
                {
                    throw new ArgumentOutOfRangeException(nameof(spec));
                }

                value.ProcessId = intValue;
                break;

            case ForwardProtocol.Tcp:
                if (!isInt)
                {
                    throw new ArgumentOutOfRangeException(nameof(spec));
                }

                value.Port = intValue;
                break;

            case ForwardProtocol.LocalAbstract:
            case ForwardProtocol.LocalFilesystem:
            case ForwardProtocol.LocalReserved:
            case ForwardProtocol.Device:
                value.SocketName = parts[1];
                break;
            }

            return(value);
        }
Beispiel #2
0
 /// <inheritdoc/>
 public void CreateForward(DeviceData device, ForwardSpec local, ForwardSpec remote, bool allowRebind)
 {
     this.CreateForward(device, local?.ToString(), remote?.ToString(), allowRebind);
 }
Beispiel #3
0
 /// <inheritdoc/>
 public int CreateForward(DeviceData device, ForwardSpec local, ForwardSpec remote, bool allowRebind)
 {
     return(this.CreateForward(device, local?.ToString(), remote?.ToString(), allowRebind));
 }
Beispiel #4
0
 /// <inheritdoc/>
 public void CreateForward(DeviceData device, ForwardSpec local, ForwardSpec remote, bool allowRebind)
 {
     this.CreateForward(device, local?.ToString(), remote?.ToString(), allowRebind);
 }
        /// <summary>
        /// Creates a <see cref="ForwardSpec"/> from its <see cref="string"/> representation.
        /// </summary>
        /// <param name="spec">
        /// A <see cref="string"/> which represents a <see cref="ForwardSpec"/>.
        /// </param>
        /// <returns>
        /// A <see cref="ForwardSpec"/> which represents <paramref name="spec"/>.
        /// </returns>
        public static ForwardSpec Parse(string spec)
        {
            if (spec == null)
            {
                throw new ArgumentNullException(nameof(spec));
            }

            var parts = spec.Split(new char[] { ':' }, 2, StringSplitOptions.RemoveEmptyEntries);

            if (parts.Length != 2)
            {
                throw new ArgumentOutOfRangeException(nameof(spec));
            }

            if (!Mappings.ContainsKey(parts[0]))
            {
                throw new ArgumentOutOfRangeException(nameof(spec));
            }

            var protocol = Mappings[parts[0]];

            ForwardSpec value = new ForwardSpec();
            value.Protocol = protocol;

            int intValue;

            bool isInt = int.TryParse(parts[1], out intValue);

            switch (protocol)
            {
                case ForwardProtocol.JavaDebugWireProtocol:
                    if (!isInt)
                    {
                        throw new ArgumentOutOfRangeException(nameof(spec));
                    }

                    value.ProcessId = intValue;
                    break;

                case ForwardProtocol.Tcp:
                    if (!isInt)
                    {
                        throw new ArgumentOutOfRangeException(nameof(spec));
                    }

                    value.Port = intValue;
                    break;

                case ForwardProtocol.LocalAbstract:
                case ForwardProtocol.LocalFilesystem:
                case ForwardProtocol.LocalReserved:
                case ForwardProtocol.Device:
                    value.SocketName = parts[1];
                    break;
            }

            return value;
        }