-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add quick and dirty WcfSample.Android application.
We have to wait for dotnet/sdk#491 (as per http://www.natemcmaster.com/blog/2017/03/09/vs2015-to-vs2017-upgrade/) until we get better support for Xamarin.Android projects in dotnet/sdk. For now the project is excluded from the build. Enthusiasts may reactivate it in VS - Build - Configuration Manager.
- Loading branch information
Showing
16 changed files
with
591 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Any raw assets you want to be deployed with your application can be placed in | ||
this directory (and child directories) and given a Build Action of "AndroidAsset". | ||
|
||
These files will be deployed with you package and will be accessible using Android's | ||
AssetManager, like this: | ||
|
||
public class ReadAsset : Activity | ||
{ | ||
protected override void OnCreate (Bundle bundle) | ||
{ | ||
base.OnCreate (bundle); | ||
|
||
InputStream input = Assets.Open ("my_asset.txt"); | ||
} | ||
} | ||
|
||
Additionally, some Android functions will automatically load asset files: | ||
|
||
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright (c) on/off it-solutions gmbh. All rights reserved. | ||
// Licensed under the MIT license. See license.txt file in the project root for license information. | ||
|
||
namespace WcfSample | ||
{ | ||
using System; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using global::Android.App; | ||
using global::Android.OS; | ||
using global::Android.Widget; | ||
using InfoCarrier.Core.Client; | ||
using InfoCarrier.Core.Common; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
[Activity(Label = "WcfSample.Android", MainLauncher = true, Icon = "@mipmap/icon")] | ||
public class MainActivity : Activity | ||
{ | ||
protected override void OnCreate(Bundle savedInstanceState) | ||
{ | ||
base.OnCreate(savedInstanceState); | ||
|
||
// Set our view from the "main" layout resource | ||
this.SetContentView(Resource.Layout.Main); | ||
|
||
// Get our button from the layout resource, | ||
// and attach an event to it | ||
Button button = this.FindViewById<Button>(Resource.Id.myButton); | ||
|
||
button.Click += this.Button_Click; | ||
} | ||
|
||
private async void Button_Click(object sender, EventArgs e) | ||
{ | ||
var consoleTextView = this.FindViewById<TextView>(Resource.Id.textConsole); | ||
void ConsoleWriteLine(string line) | ||
{ | ||
consoleTextView.Text += $"{line}\n"; | ||
} | ||
|
||
consoleTextView.Text = ""; | ||
|
||
try | ||
{ | ||
string serverUrl = this.FindViewById<TextView>(Resource.Id.editServerUrl).Text; | ||
var optionsBuilder = new DbContextOptionsBuilder(); | ||
optionsBuilder.UseInfoCarrierBackend(new WcfBackendXamarinImpl(serverUrl)); | ||
var options = optionsBuilder.Options; | ||
|
||
// Select and update | ||
using (var context = new BloggingContext(options)) | ||
{ | ||
Post myBlogPost = await ( | ||
from blog in context.Blogs | ||
from post in blog.Posts | ||
join owner in context.Users on blog.OwnerId equals owner.Id | ||
where owner.Name == "hi-its-me" | ||
where post.Title == "my-blog-post" | ||
select post).SingleAsync(); | ||
|
||
ConsoleWriteLine($@"Blog post '{myBlogPost.Title}' is retrieved."); | ||
|
||
myBlogPost.CreationDate = DateTime.Now; | ||
await context.SaveChangesAsync(); | ||
ConsoleWriteLine($@"CreationDate is set to '{myBlogPost.CreationDate}'."); | ||
} | ||
} | ||
catch (Exception exception) | ||
{ | ||
ConsoleWriteLine(exception.ToString()); | ||
} | ||
} | ||
|
||
// Xamarin.Android implementation of asynchronous WCF method calls is broken in a very | ||
// weird way (throws no exception but just never executes the continuation after await). | ||
// We have to simulate asynchrony by calling synchronous methods on the thread pool. | ||
private class WcfBackendXamarinImpl : WcfBackendImpl | ||
{ | ||
public WcfBackendXamarinImpl(string serverUrl) | ||
: base (serverUrl) | ||
{ | ||
} | ||
|
||
public override async Task<QueryDataResult> QueryDataAsync(QueryDataRequest request, DbContext dbContext, CancellationToken cancellationToken) | ||
=> await Task.Run(() => this.QueryData(request, dbContext), cancellationToken); | ||
|
||
public override async Task<SaveChangesResult> SaveChangesAsync(SaveChangesRequest request, CancellationToken cancellationToken) | ||
=> await Task.Run(() => this.SaveChanges(request), cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:versionCode="1" | ||
android:versionName="1.0" | ||
package="WcfSample.Android.WcfSample.Android"> | ||
<uses-sdk android:minSdkVersion="21" /> | ||
<application android:allowBackup="true" android:icon="@mipmap/icon" android:label="@string/app_name"> | ||
</application> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) on/off it-solutions gmbh. All rights reserved. | ||
// Licensed under the MIT license. See license.txt file in the project root for license information. | ||
|
||
using System.Reflection; | ||
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("WcfSample.Android")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("WcfSample.Android")] | ||
[assembly: AssemblyCopyright("Copyright © 2017")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
[assembly: ComVisible(false)] | ||
|
||
// 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")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
Images, layout descriptions, binary blobs and string dictionaries can be included | ||
in your application as resource files. Various Android APIs are designed to | ||
operate on the resource IDs instead of dealing with images, strings or binary blobs | ||
directly. | ||
|
||
For example, a sample Android app that contains a user interface layout (main.axml), | ||
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) | ||
would keep its resources in the "Resources" directory of the application: | ||
|
||
Resources/ | ||
drawable/ | ||
icon.png | ||
|
||
layout/ | ||
main.axml | ||
|
||
values/ | ||
strings.xml | ||
|
||
In order to get the build system to recognize Android resources, set the build action to | ||
"AndroidResource". The native Android APIs do not operate directly with filenames, but | ||
instead operate on resource IDs. When you compile an Android application that uses resources, | ||
the build system will package the resources for distribution and generate a class called "R" | ||
(this is an Android convention) that contains the tokens for each one of the resources | ||
included. For example, for the above Resources layout, this is what the R class would expose: | ||
|
||
public class R { | ||
public class drawable { | ||
public const int icon = 0x123; | ||
} | ||
|
||
public class layout { | ||
public const int main = 0x456; | ||
} | ||
|
||
public class strings { | ||
public const int first_string = 0xabc; | ||
public const int second_string = 0xbcd; | ||
} | ||
} | ||
|
||
You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main | ||
to reference the layout/main.axml file, or R.strings.first_string to reference the first | ||
string in the dictionary file values/strings.xml. |
118 changes: 118 additions & 0 deletions
118
sample/WcfSample.Android/Resources/Resource.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
<TextView | ||
android:text="Server URL" | ||
android:textAppearance="?android:attr/textAppearanceLarge" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" /> | ||
<EditText | ||
android:text="10.0.2.2:8080" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:id="@+id/editServerUrl" /> | ||
<Button | ||
android:id="@+id/myButton" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="@string/hello" /> | ||
<EditText | ||
android:id="@+id/textConsole" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:scrollbars="vertical" | ||
android:enabled="false" /> | ||
</LinearLayout> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, Click Me!</string> | ||
<string name="app_name">WcfSample.Android</string> | ||
</resources> |
Oops, something went wrong.