internal static DeviceStream Create(DeviceConnection owner, string serviceConfiguration = null)
        {
            IntPtr nativeHandle;

            PlatformAdapter.Instance.nabtoStreamOpen(out nativeHandle, owner.Owner.GetNativeHandle(), owner.DeviceId);

            var safeHandle = new SafeStreamHandle(nativeHandle);
            var instance   = new DeviceStream(owner, safeHandle);

            owner.Register(instance);

            if (string.IsNullOrEmpty(serviceConfiguration) == false)
            {
                instance.ConfigureStreamService(serviceConfiguration);
            }

            return(instance);
        }
        internal static Tunnel Create(DeviceConnection owner, int localPort, string device, string remoteHost, int remotePort)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            if (remoteHost == null)
            {
                throw new ArgumentNullException("remoteHost");
            }

            IntPtr nativeHandle;

            PlatformAdapter.Instance.nabtoTunnelOpenTcp(out nativeHandle, owner.Owner.GetNativeHandle(), localPort, device, remoteHost, remotePort);

            var safeHandle = new SafeTunnelHandle(nativeHandle);

            var instance = new Tunnel(safeHandle, owner);

            owner.Register(instance);

            return(instance);
        }