Skip to content

Commit 4f0b178

Browse files
authored
Merge pull request #22 from nitinme/master
Merging samples
2 parents bca9495 + 982b000 commit 4f0b178

File tree

179 files changed

+11372
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+11372
-0
lines changed

dotnet/InkRecognition/quickstart/example-ink-strokes.json

Lines changed: 159 additions & 0 deletions
Large diffs are not rendered by default.

dotnet/InkRecognition/quickstart/example-response.json

Lines changed: 900 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using System;
2+
using System.IO;
3+
using System.Net;
4+
using System.Net.Http;
5+
using System.Net.Http.Headers;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using Newtonsoft.Json;
9+
using Newtonsoft.Json.Linq;
10+
11+
namespace ConsoleApp7
12+
{
13+
class Program
14+
{
15+
// Replace the subscriptionKey string with your valid subscription key.
16+
const string subscriptionKey = "YOUR_SUBSCRIPTION_KEY";
17+
18+
// Replace the dataPath string with a path to the JSON formatted ink stroke data.
19+
const string dataPath = @"PATH_TO_INK_STROKE_DATA";
20+
21+
// URI information for ink recognition:
22+
const string endpoint = "https://api.cognitive.microsoft.com";
23+
const string inkRecognitionUrl = "/inkrecognizer/v1.0-preview/recognize";
24+
25+
static async Task<string> Request(string apiAddress, string endpoint, string subscriptionKey, string requestData)
26+
{
27+
28+
using (HttpClient client = new HttpClient { BaseAddress = new Uri(apiAddress) })
29+
{
30+
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
31+
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
32+
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);
33+
34+
var content = new StringContent(requestData, Encoding.UTF8, "application/json");
35+
var res = await client.PutAsync(endpoint, content);
36+
if (res.IsSuccessStatusCode)
37+
{
38+
return await res.Content.ReadAsStringAsync();
39+
}
40+
else
41+
{
42+
return $"ErrorCode: {res.StatusCode}";
43+
}
44+
}
45+
46+
}
47+
48+
static void recognizeInk(string requestData)
49+
{
50+
51+
//construct the request
52+
var result = Request(
53+
endpoint,
54+
inkRecognitionUrl,
55+
subscriptionKey,
56+
requestData).Result;
57+
58+
dynamic jsonObj = Newtonsoft.Json.JsonConvert.DeserializeObject(result);
59+
System.Console.WriteLine(jsonObj);
60+
}
61+
62+
public static JObject LoadJson(string fileLocation)
63+
{
64+
65+
var jsonObj = new JObject();
66+
67+
using (StreamReader file = File.OpenText(fileLocation))
68+
using (JsonTextReader reader = new JsonTextReader(file))
69+
{
70+
jsonObj = (JObject)JToken.ReadFrom(reader);
71+
}
72+
return jsonObj;
73+
}
74+
75+
static void Main(string[] args)
76+
{
77+
78+
var requestData = LoadJson(dataPath);
79+
string requestString = requestData.ToString(Newtonsoft.Json.Formatting.None);
80+
recognizeInk(requestString);
81+
System.Console.WriteLine("\nPress any key to exit ");
82+
System.Console.ReadKey();
83+
}
84+
}
85+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## [project-title] Changelog
2+
3+
<a name="x.y.z"></a>
4+
# x.y.z (yyyy-mm-dd)
5+
6+
*Features*
7+
* ...
8+
9+
*Bug Fixes*
10+
* ...
11+
12+
*Breaking Changes*
13+
* ...
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributing to [project-title]
2+
3+
This project welcomes contributions and suggestions. Most contributions require you to agree to a
4+
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
5+
the rights to use your contribution. For details, visit https://cla.microsoft.com.
6+
7+
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
8+
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
9+
provided by the bot. You will only need to do this once across all repos using our CLA.
10+
11+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
12+
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
13+
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
14+
15+
- [Code of Conduct](#coc)
16+
- [Issues and Bugs](#issue)
17+
- [Feature Requests](#feature)
18+
- [Submission Guidelines](#submit)
19+
20+
## <a name="coc"></a> Code of Conduct
21+
Help us keep this project open and inclusive. Please read and follow our [Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
22+
23+
## <a name="issue"></a> Found an Issue?
24+
If you find a bug in the source code or a mistake in the documentation, you can help us by
25+
[submitting an issue](#submit-issue) to the GitHub Repository. Even better, you can
26+
[submit a Pull Request](#submit-pr) with a fix.
27+
28+
## <a name="feature"></a> Want a Feature?
29+
You can *request* a new feature by [submitting an issue](#submit-issue) to the GitHub
30+
Repository. If you would like to *implement* a new feature, please submit an issue with
31+
a proposal for your work first, to be sure that we can use it.
32+
33+
* **Small Features** can be crafted and directly [submitted as a Pull Request](#submit-pr).
34+
35+
## <a name="submit"></a> Submission Guidelines
36+
37+
### <a name="submit-issue"></a> Submitting an Issue
38+
Before you submit an issue, search the archive, maybe your question was already answered.
39+
40+
If your issue appears to be a bug, and hasn't been reported, open a new issue.
41+
Help us to maximize the effort we can spend fixing issues and adding new
42+
features, by not reporting duplicate issues. Providing the following information will increase the
43+
chances of your issue being dealt with quickly:
44+
45+
* **Overview of the Issue** - if an error is being thrown a non-minified stack trace helps
46+
* **Version** - what version is affected (e.g. 0.1.2)
47+
* **Motivation for or Use Case** - explain what are you trying to do and why the current behavior is a bug for you
48+
* **Browsers and Operating System** - is this a problem with all browsers?
49+
* **Reproduce the Error** - provide a live example or a unambiguous set of steps
50+
* **Related Issues** - has a similar issue been reported before?
51+
* **Suggest a Fix** - if you can't fix the bug yourself, perhaps you can point to what might be
52+
causing the problem (line of code or commit)
53+
54+
You can file new issues by providing the above information at the corresponding repository's issues link: https://github.com/[organization-name]/[repository-name]/issues/new].
55+
56+
### <a name="submit-pr"></a> Submitting a Pull Request (PR)
57+
Before you submit your Pull Request (PR) consider the following guidelines:
58+
59+
* Search the repository (https://github.com/[organization-name]/[repository-name]/pulls) for an open or closed PR
60+
that relates to your submission. You don't want to duplicate effort.
61+
62+
* Make your changes in a new git fork:
63+
64+
* Commit your changes using a descriptive commit message
65+
* Push your fork to GitHub:
66+
* In GitHub, create a pull request
67+
* If we suggest changes then:
68+
* Make the required updates.
69+
* Rebase your fork and force push to your GitHub repository (this will update your Pull Request):
70+
71+
```shell
72+
git rebase master -i
73+
git push -f
74+
```
75+
76+
That's it! Thank you for your contribution!
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Microsoft Corporation. All rights reserved.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
topic: sample
3+
languages:
4+
- csharp
5+
products:
6+
- uwp
7+
- windows
8+
- azure
9+
---
10+
11+
# Ink Recognizer Cognitive Service C# UWP Sample
12+
13+
![Build passing](https://img.shields.io/badge/build-passing-brightgreen.svg) ![License](https://img.shields.io/badge/license-MIT-green.svg)
14+
15+
Ink Recognizer Cognitive Service provides recognition of digital ink. It takes the digital ink stroke data as input and provides a document tree with individual recognition units as output. This project has sample code to demonstrate a few ways developers can take advantage of the service.
16+
17+
## Features
18+
19+
This project framework provides the following features:
20+
21+
* Capturing very basic inking input.
22+
* Creating the JSON payload using the JSON schema used by Ink Recognizer.
23+
* Calling the Ink Recognizer REST APIs with the JSON payload
24+
* Parsing the JSON response from the service, build the document tree and parse it.
25+
26+
## Contents
27+
28+
| File/folder | Description |
29+
|-------------|-------------|
30+
| `src` | Sample source code. |
31+
| `README.md` | This README file. |
32+
| `LICENSE` | The license for the sample. |
33+
34+
## Prerequisites
35+
36+
- Install [Visual Studio] (https://docs.microsoft.com/en-us/visualstudio/install/install-visual-studio)
37+
- Requires subscription key from [Azure Cognitive Services] (https://docs.microsoft.com/en-us/azure/cognitive-services/authentication)
38+
39+
## Build the sample
40+
41+
1. Clone or download this sample repository
42+
2. Start Visual Studio and select **File > Open > Project/Solution**
43+
3. Replace "[YOUR SUBSCRIPTION KEY]" in NoteTaker.xaml.cs with valid subscription key
44+
4. Press Ctrl+Shift+B, or select **Build > Build Solution**
45+
46+
## Run the sample
47+
48+
The next steps depend on whether you just want to deploy the sample or you want to both deploy and run it.
49+
50+
### Deploying the sample
51+
Select Build > Deploy Solution.
52+
53+
### Debugging and running the sample
54+
To debug the sample and then run it, press F5 or select Debug > Start Debugging. To run the sample without debugging, press Ctrl+F5 or select Debug > Start Without Debugging.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Application
2+
x:Class="NoteTaker.App"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:NoteTaker">
6+
7+
</Application>
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Runtime.InteropServices.WindowsRuntime;
6+
using Windows.ApplicationModel;
7+
using Windows.ApplicationModel.Activation;
8+
using Windows.Foundation;
9+
using Windows.Foundation.Collections;
10+
using Windows.UI.Xaml;
11+
using Windows.UI.Xaml.Controls;
12+
using Windows.UI.Xaml.Controls.Primitives;
13+
using Windows.UI.Xaml.Data;
14+
using Windows.UI.Xaml.Input;
15+
using Windows.UI.Xaml.Media;
16+
using Windows.UI.Xaml.Navigation;
17+
18+
namespace NoteTaker
19+
{
20+
/// <summary>
21+
/// Provides application-specific behavior to supplement the default Application class.
22+
/// </summary>
23+
sealed partial class App : Application
24+
{
25+
/// <summary>
26+
/// Initializes the singleton application object. This is the first line of authored code
27+
/// executed, and as such is the logical equivalent of main() or WinMain().
28+
/// </summary>
29+
public App()
30+
{
31+
this.InitializeComponent();
32+
this.Suspending += OnSuspending;
33+
}
34+
35+
/// <summary>
36+
/// Invoked when the application is launched normally by the end user. Other entry points
37+
/// will be used such as when the application is launched to open a specific file.
38+
/// </summary>
39+
/// <param name="e">Details about the launch request and process.</param>
40+
protected override void OnLaunched(LaunchActivatedEventArgs e)
41+
{
42+
Frame rootFrame = Window.Current.Content as Frame;
43+
44+
// Do not repeat app initialization when the Window already has content,
45+
// just ensure that the window is active
46+
if (rootFrame == null)
47+
{
48+
// Create a Frame to act as the navigation context and navigate to the first page
49+
rootFrame = new Frame();
50+
51+
rootFrame.NavigationFailed += OnNavigationFailed;
52+
53+
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
54+
{
55+
//TODO: Load state from previously suspended application
56+
}
57+
58+
// Place the frame in the current Window
59+
Window.Current.Content = rootFrame;
60+
}
61+
62+
if (e.PrelaunchActivated == false)
63+
{
64+
if (rootFrame.Content == null)
65+
{
66+
// When the navigation stack isn't restored navigate to the first page,
67+
// configuring the new page by passing required information as a navigation
68+
// parameter
69+
rootFrame.Navigate(typeof(NoteTaker), e.Arguments);
70+
}
71+
// Ensure the current window is active
72+
Window.Current.Activate();
73+
}
74+
}
75+
76+
/// <summary>
77+
/// Invoked when Navigation to a certain page fails
78+
/// </summary>
79+
/// <param name="sender">The Frame which failed navigation</param>
80+
/// <param name="e">Details about the navigation failure</param>
81+
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
82+
{
83+
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
84+
}
85+
86+
/// <summary>
87+
/// Invoked when application execution is being suspended. Application state is saved
88+
/// without knowing whether the application will be terminated or resumed with the contents
89+
/// of memory still intact.
90+
/// </summary>
91+
/// <param name="sender">The source of the suspend request.</param>
92+
/// <param name="e">Details about the suspend request.</param>
93+
private void OnSuspending(object sender, SuspendingEventArgs e)
94+
{
95+
var deferral = e.SuspendingOperation.GetDeferral();
96+
//TODO: Save application state and stop any background activity
97+
deferral.Complete();
98+
}
99+
}
100+
}
2.94 KB
Loading

0 commit comments

Comments
 (0)