Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
renaming projects. Added NetworkStream throughout
  • Loading branch information
peterfoot committed Dec 29, 2017
1 parent 51e6ca0 commit b5b6ae5
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 7 deletions.
@@ -1,17 +1,17 @@


Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15 # Visual Studio 15
VisualStudioVersion = 15.0.26730.12 VisualStudioVersion = 15.0.27130.2010
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InTheHand.Devices.Bluetooth", "InTheHand.Devices.Bluetooth\InTheHand.Devices.Bluetooth.csproj", "{D7C44908-581A-4523-91EC-4079B20E34C7}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InTheHand.Bluetooth", "InTheHand.Devices.Bluetooth\InTheHand.Bluetooth.csproj", "{D7C44908-581A-4523-91EC-4079B20E34C7}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InTheHand.Devices.Bluetooth.Win32", "InTheHand.Devices.Bluetooth.Win32\InTheHand.Devices.Bluetooth.Win32.csproj", "{15851D1E-6757-49EA-9A28-BEBAF5C9A3E0}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InTheHand.Bluetooth.Win32", "InTheHand.Devices.Bluetooth.Win32\InTheHand.Bluetooth.Win32.csproj", "{15851D1E-6757-49EA-9A28-BEBAF5C9A3E0}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InTheHand.Devices.Bluetooth.Android", "InTheHand.Devices.Bluetooth.Android\InTheHand.Devices.Bluetooth.Android.csproj", "{37A94CE9-B217-4226-82F6-110EC34DA0DA}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InTheHand.Bluetooth.Android", "InTheHand.Devices.Bluetooth.Android\InTheHand.Bluetooth.Android.csproj", "{37A94CE9-B217-4226-82F6-110EC34DA0DA}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InTheHand.Devices.Bluetooth.iOS", "InTheHand.Devices.Bluetooth.iOS\InTheHand.Devices.Bluetooth.iOS.csproj", "{33149B35-24E1-4F2D-9B8B-1FC89A894DD2}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InTheHand.Bluetooth.iOS", "InTheHand.Devices.Bluetooth.iOS\InTheHand.Bluetooth.iOS.csproj", "{33149B35-24E1-4F2D-9B8B-1FC89A894DD2}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InTheHand.Devices.Bluetooth.UWP", "InTheHand.Devices.Bluetooth.UWP\InTheHand.Devices.Bluetooth.UWP.csproj", "{FDAFE908-FF81-43F4-94C0-A403D6A453B2}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InTheHand.Bluetooth.UWP", "InTheHand.Devices.Bluetooth.UWP\InTheHand.Bluetooth.UWP.csproj", "{FDAFE908-FF81-43F4-94C0-A403D6A453B2}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Expand Up @@ -219,6 +219,9 @@
<Compile Include="..\InTheHand.Devices.Bluetooth\Enumeration\DeviceWatcherStatus.cs"> <Compile Include="..\InTheHand.Devices.Bluetooth\Enumeration\DeviceWatcherStatus.cs">
<Link>Enumeration\DeviceWatcherStatus.cs</Link> <Link>Enumeration\DeviceWatcherStatus.cs</Link>
</Compile> </Compile>
<Compile Include="..\InTheHand.Devices.Bluetooth\NetworkStream.cs">
<Link>NetworkStream.cs</Link>
</Compile>
<Compile Include="..\InTheHand.Devices.Bluetooth\Radios\Radio.Android.cs"> <Compile Include="..\InTheHand.Devices.Bluetooth\Radios\Radio.Android.cs">
<Link>Radios\Radio.Android.cs</Link> <Link>Radios\Radio.Android.cs</Link>
</Compile> </Compile>
Expand All @@ -237,7 +240,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="InTheHand.Pontoon"> <PackageReference Include="InTheHand.Pontoon">
<Version>10.2017.8.23</Version> <Version>10.2017.10.1</Version>
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
Expand Down
Expand Up @@ -285,6 +285,9 @@
<None Include="..\InTheHand.Devices.Bluetooth\Enumeration\DeviceWatcherStatus.cs"> <None Include="..\InTheHand.Devices.Bluetooth\Enumeration\DeviceWatcherStatus.cs">
<Link>Enumeration\DeviceWatcherStatus.cs</Link> <Link>Enumeration\DeviceWatcherStatus.cs</Link>
</None> </None>
<Compile Include="..\InTheHand.Devices.Bluetooth\NetworkStream.cs">
<Link>NetworkStream.cs</Link>
</Compile>
<Compile Include="..\InTheHand.Devices.Bluetooth\Radios\Radio.cs"> <Compile Include="..\InTheHand.Devices.Bluetooth\Radios\Radio.cs">
<Link>Radios\Radio.cs</Link> <Link>Radios\Radio.cs</Link>
</Compile> </Compile>
Expand Down
Expand Up @@ -160,6 +160,9 @@
<Compile Include="..\InTheHand.Devices.Bluetooth\Enumeration\DeviceWatcherStatus.cs"> <Compile Include="..\InTheHand.Devices.Bluetooth\Enumeration\DeviceWatcherStatus.cs">
<Link>Enumeration\DeviceWatcherStatus.cs</Link> <Link>Enumeration\DeviceWatcherStatus.cs</Link>
</Compile> </Compile>
<Compile Include="..\InTheHand.Devices.Bluetooth\NetworkStream.cs">
<Link>NetworkStream.cs</Link>
</Compile>
<Compile Include="..\InTheHand.Devices.Bluetooth\Radios\Radio.cs"> <Compile Include="..\InTheHand.Devices.Bluetooth\Radios\Radio.cs">
<Link>Radios\Radio.cs</Link> <Link>Radios\Radio.cs</Link>
</Compile> </Compile>
Expand Down
@@ -0,0 +1,241 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="NetworkStream.cs" company="In The Hand Ltd">
// Copyright (c) 2017 In The Hand Ltd, All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System;
using System.IO;

#if __ANDROID__
using Android.Bluetooth;
#elif WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
using Windows.Networking.Sockets;
#endif

namespace InTheHand.Networking.Sockets
{
/// <summary>
/// Provides the underlying stream of data for network access.
/// </summary>
/// <remarks>
/// <para/><list type="table">
/// <listheader><term>Platform</term><description>Version supported</description></listheader>
/// <item><term>Android</term><description>Android 4.4 and later</description></item>
/// <item><term>Windows UWP</term><description>Windows 10</description></item>
/// <item><term>Windows Store</term><description>Windows 8.1 or later</description></item>
/// <item><term>Windows Phone Store</term><description>Windows Phone 8.1 or later</description></item></list>
/// </remarks>
/// <seealso cref="System.Net.Sockets.NetworkStream"/>
public sealed class NetworkStream : Stream
{
#if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
private StreamSocket _socket;
private Stream _inputStream;
private Stream _outputStream;

/// <summary>
/// Creates a new instance of the NetworkStream for the specified <see cref="StreamSocket"/>
/// </summary>
/// <param name="socket"></param>
public NetworkStream(StreamSocket socket)
{
_socket = socket;
_inputStream = _socket.InputStream.AsStreamForRead();
_outputStream = _socket.OutputStream.AsStreamForWrite();
}

#elif __ANDROID__
private BluetoothSocket _socket;

/// <summary>
/// Creates a new instance of the NetworkStream for the specified <see cref="BluetoothSocket"/>
/// </summary>
/// <param name="socket"></param>
public NetworkStream(BluetoothSocket socket)
{
_socket = socket;
}
#endif

/// <summary>
/// Gets a value that indicates whether the NetworkStream supports reading.
/// </summary>
public override bool CanRead
{
get
{
#if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
return _inputStream.CanRead;

#elif __ANDROID__
return _socket.InputStream.CanRead;

#else
return false;
#endif
}
}

/// <summary>
/// Gets a value that indicates whether the stream supports seeking. This property is not currently supported.This property always returns false.
/// </summary>
public override bool CanSeek
{
get
{
return false;
}
}

/// <summary>
/// Gets a value that indicates whether the NetworkStream supports writing.
/// </summary>
public override bool CanWrite
{
get
{
#if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
return _outputStream.CanWrite;

#elif __ANDROID__
return _socket.OutputStream.CanWrite;

#else
return false;
#endif
}
}

/// <summary>
/// Gets the length of the data available on the stream.
/// This property is not currently supported and always throws a NotSupportedException.
/// </summary>
public override long Length
{
get
{
#if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
return _inputStream.Length;

#elif __ANDROID__
return _socket.InputStream.Length;

#else
return 0;
#endif
}
}

/// <summary>
/// Gets or sets the current position in the stream.
/// This property is not currently supported and always throws a NotSupportedException.
/// </summary>
public override long Position
{
get
{
return 0;
}

set
{
throw new NotSupportedException();
}
}

/// <summary>
/// Flushes data from the stream.
/// </summary>
public override void Flush()
{
#if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
_outputStream.Flush();

#elif __ANDROID__
_socket.OutputStream.Flush();
#endif
}

/// <summary>
/// Reads data from the NetworkStream.
/// </summary>
/// <param name="buffer"></param>
/// <param name="offset"></param>
/// <param name="count"></param>
/// <returns></returns>
public override int Read(byte[] buffer, int offset, int count)
{
#if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
return _inputStream.Read(buffer, offset, count);

#elif __ANDROID__
return _socket.InputStream.Read(buffer, offset, count);

#else
return 0;
#endif
}

/// <summary>
/// Sets the current position of the stream to the given value.
/// This method is not currently supported and always throws a NotSupportedException.
/// </summary>
/// <param name="offset"></param>
/// <param name="origin"></param>
/// <returns></returns>
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotSupportedException();
}

/// <summary>
/// Sets the length of the stream.
/// This method always throws a NotSupportedException.
/// </summary>
/// <param name="value"></param>
public override void SetLength(long value)
{
throw new NotSupportedException();
}

/// <summary>
/// Writes data to the NetworkStream.
/// </summary>
/// <param name="buffer"></param>
/// <param name="offset"></param>
/// <param name="count"></param>
public override void Write(byte[] buffer, int offset, int count)
{
#if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
_outputStream.Write(buffer, offset, count);

#elif __ANDROID__
_socket.OutputStream.Write(buffer, offset, count);
#endif
}

/// <summary>
/// Releases the unmanaged resources used by the NetworkStream and optionally releases the managed resources.
/// </summary>
/// <param name="disposing"></param>
protected override void Dispose(bool disposing)
{
#if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
_outputStream?.Dispose();
_outputStream = null;
_inputStream?.Dispose();
_outputStream = null;
_socket?.Dispose();
_socket = null;

#elif __ANDROID__
_socket?.Close();
_socket?.Dispose();
_socket = null;
#endif

base.Dispose(disposing);
}
}
}

0 comments on commit b5b6ae5

Please sign in to comment.