Skip to content

Commit

Permalink
Support iOS, Android, windows desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
Wayne Gu committed Jun 24, 2016
1 parent e5146a2 commit e32fd72
Show file tree
Hide file tree
Showing 54 changed files with 1,652 additions and 119 deletions.
204 changes: 204 additions & 0 deletions HttpLibrary.Net.sln

Large diffs are not rendered by default.

17 changes: 14 additions & 3 deletions examples/HttpLibraryUWPTest/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel Orientation="Vertical" Background="White">
<Grid Background="White">

<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
Expand All @@ -17,8 +22,14 @@
<TextBox x:Name="textBoxUri" Text="http://192.168.82.121/About.html" VerticalAlignment="Center" Margin="0,0,10,0" Grid.Column="1" ScrollViewer.HorizontalScrollBarVisibility="Auto"/>
<Button Content="Query" Click="OnClickQuery" Grid.Column="2"/>
</Grid>
<TextBlock x:Name="webTextBlock" Text="Web content" ScrollViewer.HorizontalScrollBarVisibility="Visible" />
</StackPanel>

<ScrollViewer HorizontalScrollMode="Enabled" Grid.Row="1" VerticalScrollMode="Enabled">
<TextBlock x:Name="webTextBlock" Text="Web content" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" TextWrapping="Wrap"/>
</ScrollViewer>



</Grid>


</Page>
6 changes: 6 additions & 0 deletions examples/HttpLibraryWin32Test/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
50 changes: 50 additions & 0 deletions examples/HttpLibraryWin32Test/HtmlRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using HttpLibrary.Common;
using HttpLibrary.Http;
using HttpLibrary.Requesting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HttpLibraryWin32Test
{
class HtmlRequest : Request
{
public HtmlRequest(string uri) : base(RequestPriority.Normal)
{
Uri = uri;

}

protected override void Encode()
{
HttpRequest = new HttpRequest(Uri, HttpConst.HttpMethod_Get);

}
protected override void CreateResponse()
{
Response = new HtmlResponse();
}
}

class HtmlResponse : Response
{
public string Html
{
get;
private set;
}

protected override void Decode()
{
ResponseStream.Seek(0, SeekOrigin.Begin);
using (var reader = new StreamReader(ResponseStream, Encoding.UTF8))
{
Html = reader.ReadToEnd();
}
}
}

}
71 changes: 71 additions & 0 deletions examples/HttpLibraryWin32Test/HttpLibraryWin32Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{84364106-78F5-48EC-8060-A2D9781C2243}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HttpLibraryWin32Test</RootNamespace>
<AssemblyName>HttpLibraryWin32Test</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="HtmlRequest.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\HttpLibrary.Net\HttpLibrary.Net.csproj">
<Project>{67f9d3a8-f71e-4428-913f-c37ae82cdb24}</Project>
<Name>HttpLibrary.Net</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\HttpLibrary.Platform.Win32\HttpLibrary.Platform.Win32.csproj">
<Project>{44d5400f-02be-4b8e-840e-cc4a4c112c33}</Project>
<Name>HttpLibrary.Platform.Win32</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
48 changes: 48 additions & 0 deletions examples/HttpLibraryWin32Test/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using HttpLibrary.Platform.Win32;
using HttpLibrary.Requesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace HttpLibraryWin32Test
{
class Program
{
static RequestQueue reqQueue;
static void Main(string[] args)
{
reqQueue = new RequestQueue(new HttpLibraryPlatformWin32());

var task = GetWebResource(args[0]);

task.Wait();

Console.WriteLine(task.Result);
}

private static async Task<string> GetWebResource(string uri)
{
var req = new HtmlRequest(uri);

await reqQueue.SendRequestAsync(req);

string content;
var response = req.Response as HtmlResponse;
if (response.IsSucceeded)
{
content = response.Html;
}
else
{
content = response.Exception.ToString();
}

return content;


}
}
}
36 changes: 36 additions & 0 deletions examples/HttpLibraryWin32Test/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("HttpLibraryWin32Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HttpLibraryWin32Test")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("84364106-78f5-48ec-8060-a2d9781c2243")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HttpLibraryXamarinTest;
using HttpLibrary.Interop;
using HttpLibrary.Platform.Android;
using Xamarin.Forms;
using Android.Content;

[assembly: Dependency(typeof(HttpLibraryXamarinTest.Droid.HttpLibrarySettings))]

namespace HttpLibraryXamarinTest.Droid
{
class HttpLibrarySettings : IHttpLibrarySettings
{
private HttpLibraryPlatformAndroid httpLibraryPlatform = new HttpLibraryPlatformAndroid();

public HttpLibrarySettings()
{
var appName = GetApplicationName(Forms.Context);
if(!string.IsNullOrEmpty(appName))
{
HttpLibraryPlaform.DeviceInfo.Application = appName;
}
}
public IHttpLibraryPlatform HttpLibraryPlaform
{
get
{
return httpLibraryPlatform;
}
}

private static String GetApplicationName(Context context)
{
var appName = context.GetString(Resource.String.ApplicationName);
var versionName = context.PackageManager.GetPackageInfo(context.PackageName, 0).VersionName;
return appName + "/" + versionName;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="HttpLibrarySettings.cs" />
<Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.Designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand All @@ -115,11 +116,22 @@
<None Include="Properties\AndroidManifest.xml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\HttpLibrary.Net\HttpLibrary.Net.csproj">
<Project>{67f9d3a8-f71e-4428-913f-c37ae82cdb24}</Project>
<Name>HttpLibrary.Net</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\src\HttpLibrary.Platform.Android\HttpLibrary.Platform.Android.csproj">
<Project>{0968c421-81a1-4fc3-9235-c3e03e853e7c}</Project>
<Name>HttpLibrary.Platform.Android</Name>
</ProjectReference>
<ProjectReference Include="..\HttpLibraryXamarinTest\HttpLibraryXamarinTest.csproj">
<Project>{a9497183-167d-46dd-91f7-35ee313678c5}</Project>
<Name>HttpLibraryXamarinTest</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\values\strings.xml" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<Import Project="..\..\..\packages\Xamarin.Forms.2.0.0.6482\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\..\..\packages\Xamarin.Forms.2.0.0.6482\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicat
{
protected override void OnCreate(Bundle bundle)
{
System.Diagnostics.Trace.WriteLine(Build.Model);
base.OnCreate(bundle);

global::Xamarin.Forms.Forms.Init(this, bundle);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" package="com.wayne.httplibrary" android:versionName="0.0.0.1" android:versionCode="1">
<uses-sdk android:minSdkVersion="15" />
<application android:label="$safeprojectname$"></application>
</manifest>
<application android:label="HttpLibraryXamarinText" android:icon="@drawable/icon"></application>
</manifest>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<string name="Hello">Hello World!</string>
<string name="ApplicationName">HttpLibraryXamarinTest</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
this.DebugSettings.EnableFrameRateCounter = true;
//this.DebugSettings.EnableFrameRateCounter = true;
}
#endif

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HttpLibraryXamarinTest;
using HttpLibrary.Interop;
using HttpLibrary.Platform.UWP;
using Xamarin.Forms;

[assembly: Dependency(typeof(HttpLibraryXamarinTest.UWP.HttpLibrarySettings))]

namespace HttpLibraryXamarinTest.UWP
{
class HttpLibrarySettings : IHttpLibrarySettings
{
private HttpLibraryPlatformUWP httpLibraryPlatform = new HttpLibraryPlatformUWP();
public IHttpLibraryPlatform HttpLibraryPlaform
{
get
{
return httpLibraryPlatform;
}
}
}
}
Loading

0 comments on commit e32fd72

Please sign in to comment.