Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #126 from JongHeonChoi/master
Browse files Browse the repository at this point in the history
Added implementation for Tizen.NET
  • Loading branch information
jamesmontemagno authored Nov 30, 2017
2 parents 4c30004 + e337850 commit c038565
Show file tree
Hide file tree
Showing 10 changed files with 633 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Get started by reading through the [Connectivity Plugin documentation](https://j
|Xamarin.Mac|All|
|.NET 4.5/WPF|All|
|.NET Core|2.0+|
|Tizen|4.0+|

### Created By: [@JamesMontemagno](http://twitter.com/jamesmontemagno)
* Twitter: [@JamesMontemagno](http://twitter.com/jamesmontemagno)
Expand Down
5 changes: 5 additions & 0 deletions nuget/Plugin.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
</group>
<group targetFramework="xamarinwatchos">
</group>
<group targetFramework="tizen40">
</group>
</dependencies>
</metadata>
<files>
Expand Down Expand Up @@ -79,5 +81,8 @@
<!--Net Core 2.0-->
<file src="src\Connectivity.Plugin.NetCore\bin\Release\netcoreapp2.0\Plugin.Connectivity.*" target="lib\netcoreapp2.0" />

<!--Tizen-->
<file src="src\Connectivity.Plugin.Tizen\bin\Release\tizen40\Plugin.Connectivity.*" target="lib\tizen40" />

</files>
</package>
36 changes: 36 additions & 0 deletions src/Connectivity.Plugin.Tizen/Connectivity.Plugin.Tizen.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<!-- Property Group for Tizen Project -->
<PropertyGroup>
<TargetFramework>tizen40</TargetFramework>
<TizenCreateTpkOnBuild>false</TizenCreateTpkOnBuild>
<AssemblyName>Plugin.Connectivity</AssemblyName>
<RootNamespace>Plugin.Connectivity</RootNamespace>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>portable</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>None</DebugType>
</PropertyGroup>

<!-- Include Nuget Package for Tizen Project building -->
<ItemGroup>
<PackageReference Include="Tizen.NET" Version="4.0.0">
<ExcludeAssets>Runtime</ExcludeAssets>
</PackageReference>
<PackageReference Include="Tizen.NET.Sdk" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Connectivity.Plugin\CrossConnectivity.cs">
<Link>CrossConnectivity.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Connectivity.Plugin.Abstractions\Connectivity.Plugin.Abstractions.csproj">
<Project>{503c3c83-390a-48ef-845c-df4c928cb4a9}</Project>
<Name>Connectivity.Plugin.Abstractions</Name>
</ProjectReference>
</ItemGroup>
</Project>
209 changes: 209 additions & 0 deletions src/Connectivity.Plugin.Tizen/ConnectivityImplementation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
using Plugin.Connectivity.Abstractions;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Sockets;
using System.Threading.Tasks;
using Tizen.Network.Connection;
using Tizen.System;

namespace Plugin.Connectivity
{
/// <summary>
/// Connectivity Implementation
/// </summary>
public class ConnectivityImplementation : BaseConnectivity
{
private static ConnectionProfile _connectionProfile;
private static WiFiProfile _wiFiProfile;

static bool isWiFiSupported = false;
static bool isEthernetSupported = false;
static bool isCellularSupported = false;
static bool isBluetoothSupported = false;

public ConnectivityImplementation()
{
Init();

ConnectionManager.ConnectionTypeChanged += (s, e) =>
{
GetIsConnected();

OnConnectivityChanged(new ConnectivityChangedEventArgs { IsConnected = isConnected });

var connectionTypes = this.ConnectionTypes.ToArray();
OnConnectivityTypeChanged(new ConnectivityTypeChangedEventArgs { IsConnected = isConnected, ConnectionTypes = connectionTypes });
};
}

public void Init()
{
_connectionProfile = null;
_wiFiProfile = null;

Information.TryGetValue("http://tizen.org/feature/network.wifi", out isWiFiSupported);
Information.TryGetValue("http://tizen.org/feature/network.ethernet", out isEthernetSupported);
Information.TryGetValue("http://tizen.org/feature/network.telephony", out isCellularSupported);
Information.TryGetValue("http://tizen.org/feature/network.bluetooth", out isBluetoothSupported);
}

public static async void SetUpMaxSpeed()
{
var list = await ConnectionProfileManager.GetProfileListAsync(ProfileListType.Registered);
foreach (var item in list)
{
_connectionProfile = item;
break;
}
_wiFiProfile = (WiFiProfile)_connectionProfile;
}

/// <summary>
/// Retrieves a list of available bandwidths for the platform.
/// Only active connections.
/// </summary>
public static IEnumerable<UInt64> GetBandWidths()
{
SetUpMaxSpeed();

int _maxSpeed = 0;
if (_wiFiProfile != null)
{
if (ConnectionManager.WiFiState == ConnectionState.Connected)
{
try
{
_maxSpeed = _wiFiProfile.MaxSpeed;
}
catch (Exception e)
{
Debug.WriteLine("Unable to get connected state - error: {0}", e);
}
}
}

return new UInt64[] { (UInt64)_maxSpeed };
}

/// <summary>
/// Bandwidths
/// </summary>
public override IEnumerable<UInt64> Bandwidths => GetBandWidths();

/// <summary>
/// Connection types
/// </summary>
public override IEnumerable<Abstractions.ConnectionType> ConnectionTypes
{
get
{
yield return isWiFiSupported ? Abstractions.ConnectionType.WiFi : Abstractions.ConnectionType.Other;
yield return isCellularSupported ? Abstractions.ConnectionType.Cellular : Abstractions.ConnectionType.Other;
yield return isBluetoothSupported ? Abstractions.ConnectionType.Bluetooth : Abstractions.ConnectionType.Other;
yield return isEthernetSupported ? Abstractions.ConnectionType.Desktop : Abstractions.ConnectionType.Other;
}
}

private bool isConnected;
public bool GetIsConnected()
{
switch (ConnectionManager.CurrentConnection.Type)
{
case Tizen.Network.Connection.ConnectionType.WiFi:
if (ConnectionState.Connected == ConnectionManager.CurrentConnection.State)
{
isConnected = true;
}
break;
case Tizen.Network.Connection.ConnectionType.Cellular:
if (ConnectionState.Connected == ConnectionManager.CurrentConnection.State)
{
isConnected = true;
}
break;
default:
isConnected = false;
break;
}
return isConnected;
}

/// <summary>
/// Is Connected
/// </summary>
public override bool IsConnected => GetIsConnected();

/// <summary>
/// Is Reachable
/// </summary>
/// <param name="host"></param>
/// <param name="msTimeout"></param>
/// <returns></returns>
public override async Task<bool> IsReachable(string host, int msTimeout = 5000)
{
if (string.IsNullOrEmpty(host))
throw new ArgumentNullException(nameof(host));

if (!IsConnected)
return false;

return await IsRemoteReachable(host, 80, msTimeout);
}

/// <summary>
/// IsReachable
/// </summary>
/// <param name="host"></param>
/// <param name="port"></param>
/// <param name="msTimeout"></param>
/// <returns></returns>
public override async Task<bool> IsRemoteReachable(string host, int port = 80, int msTimeout = 10000)
{
host = host.Replace("http://www.", string.Empty).
Replace("http://", string.Empty).
Replace("https://www.", string.Empty).
Replace("https://", string.Empty).
TrimEnd('/');
try
{
using (var client = new TcpClient())
{
client.ReceiveTimeout = msTimeout;
await client.ConnectAsync(host, port);
}

return true;
}
catch
{
return false;
}
}

private bool disposed = false;

/// <summary>
/// Dispose
/// </summary>
/// <param name="disposing"></param>
public override void Dispose(bool disposing)
{
if (!disposed)
{
if (disposing)
{
if (_wiFiProfile != null)
_wiFiProfile.Dispose();

if (_connectionProfile != null)
_connectionProfile.Dispose();
}

disposed = true;
}
base.Dispose(disposing);
}
}
}
72 changes: 68 additions & 4 deletions src/Connectivity.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.14
VisualStudioVersion = 15.0.27004.2009
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Connectivity.Plugin.iOS", "Connectivity.Plugin.iOS\Connectivity.Plugin.iOS.csproj", "{2882AEEB-D4CD-4EB9-8A6C-6653B33681F0}"
EndProject
Expand All @@ -25,9 +25,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Connectivity.Plugin.Mac", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Connectivity.Plugin.tvOS", "Connectivity.Plugin.tvOS\Connectivity.Plugin.tvOS.csproj", "{44087DE8-D645-4F7B-A655-20EEA65EF209}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Connectivity.Plugin", "Connectivity.Plugin\Connectivity.Plugin.csproj", "{03BD57BD-F8BB-4CE8-922D-18B4A0C55D97}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connectivity.Plugin", "Connectivity.Plugin\Connectivity.Plugin.csproj", "{03BD57BD-F8BB-4CE8-922D-18B4A0C55D97}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Connectivity.Plugin.Abstractions", "Connectivity.Plugin.Abstractions\Connectivity.Plugin.Abstractions.csproj", "{3B973815-8CEB-49B1-81EA-E1DA53CD4197}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connectivity.Plugin.Abstractions", "Connectivity.Plugin.Abstractions\Connectivity.Plugin.Abstractions.csproj", "{3B973815-8CEB-49B1-81EA-E1DA53CD4197}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{E3D0F8BC-839C-4041-BD0A-124E887B30EA}"
EndProject
Expand All @@ -39,7 +39,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Android", "Android", "{17E9
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Windows", "Windows", "{45EDC062-F956-4874-AF36-7C73B2E374D1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Connectivity.Plugin.NetCore", "Connectivity.Plugin.NetCore\Connectivity.Plugin.NetCore.csproj", "{01B3D7B0-9F6F-4859-961D-C00DA27A4123}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connectivity.Plugin.NetCore", "Connectivity.Plugin.NetCore\Connectivity.Plugin.NetCore.csproj", "{01B3D7B0-9F6F-4859-961D-C00DA27A4123}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connectivity.Plugin.Tizen", "Connectivity.Plugin.Tizen\Connectivity.Plugin.Tizen.csproj", "{090D4620-B80B-4A6B-A518-80345AD68A41}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tizen", "Tizen", "{3FAB994D-E91F-4C8E-8D31-F08A172D7E47}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Expand Down Expand Up @@ -555,6 +559,62 @@ Global
{01B3D7B0-9F6F-4859-961D-C00DA27A4123}.Release|x64.Build.0 = Release|Any CPU
{01B3D7B0-9F6F-4859-961D-C00DA27A4123}.Release|x86.ActiveCfg = Release|Any CPU
{01B3D7B0-9F6F-4859-961D-C00DA27A4123}.Release|x86.Build.0 = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Ad-Hoc|Any CPU.ActiveCfg = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Ad-Hoc|Any CPU.Build.0 = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Ad-Hoc|ARM.ActiveCfg = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Ad-Hoc|ARM.Build.0 = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Ad-Hoc|iPhone.Build.0 = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Ad-Hoc|iPhoneSimulator.Build.0 = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Ad-Hoc|Mixed Platforms.ActiveCfg = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Ad-Hoc|Mixed Platforms.Build.0 = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Ad-Hoc|x64.ActiveCfg = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Ad-Hoc|x64.Build.0 = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Ad-Hoc|x86.ActiveCfg = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Ad-Hoc|x86.Build.0 = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.AppStore|Any CPU.ActiveCfg = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.AppStore|Any CPU.Build.0 = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.AppStore|ARM.ActiveCfg = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.AppStore|ARM.Build.0 = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.AppStore|iPhone.ActiveCfg = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.AppStore|iPhone.Build.0 = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.AppStore|iPhoneSimulator.ActiveCfg = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.AppStore|iPhoneSimulator.Build.0 = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.AppStore|Mixed Platforms.ActiveCfg = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.AppStore|Mixed Platforms.Build.0 = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.AppStore|x64.ActiveCfg = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.AppStore|x64.Build.0 = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.AppStore|x86.ActiveCfg = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.AppStore|x86.Build.0 = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Debug|Any CPU.Build.0 = Debug|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Debug|ARM.ActiveCfg = Debug|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Debug|ARM.Build.0 = Debug|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Debug|iPhone.Build.0 = Debug|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Debug|x64.ActiveCfg = Debug|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Debug|x64.Build.0 = Debug|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Debug|x86.ActiveCfg = Debug|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Debug|x86.Build.0 = Debug|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Release|Any CPU.ActiveCfg = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Release|Any CPU.Build.0 = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Release|ARM.ActiveCfg = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Release|ARM.Build.0 = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Release|iPhone.ActiveCfg = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Release|iPhone.Build.0 = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Release|x64.ActiveCfg = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Release|x64.Build.0 = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Release|x86.ActiveCfg = Release|Any CPU
{090D4620-B80B-4A6B-A518-80345AD68A41}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -570,5 +630,9 @@ Global
{3B973815-8CEB-49B1-81EA-E1DA53CD4197} = {E3D0F8BC-839C-4041-BD0A-124E887B30EA}
{B302BD77-2E10-4889-876A-2589AA1BDB67} = {C10AD1AD-62A7-46DB-87C8-A50459ABAB33}
{01B3D7B0-9F6F-4859-961D-C00DA27A4123} = {45EDC062-F956-4874-AF36-7C73B2E374D1}
{090D4620-B80B-4A6B-A518-80345AD68A41} = {3FAB994D-E91F-4C8E-8D31-F08A172D7E47}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9A8B13BA-18DA-452C-94A7-B3C3F6492988}
EndGlobalSection
EndGlobal
Loading

0 comments on commit c038565

Please sign in to comment.