├── .gitignore ├── CONTRIBUTING.md ├── ClientLibrary ├── ClientError.cs ├── ClientException.cs ├── Contract │ ├── Emotion.cs │ └── EmotionScores.cs ├── Microsoft.ProjectOxford.Common.csproj ├── Rectangle.cs └── ServiceClient.cs ├── LICENSE-IMAGE.md ├── LICENSE.md ├── README.md ├── SECURITY.md └── SampleUserControlLibrary ├── Assets └── Microsoft-logo_rgb_c-gray.png ├── Properties └── AssemblyInfo.cs ├── SampleUserControl.xaml ├── SampleUserControl.xaml.cs ├── SampleUserControlLibrary.csproj ├── SampleUserControlLibrary └── Properties │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── SubscriptionKeyPage.xaml └── SubscriptionKeyPage.xaml.cs /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | *.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.pfx 193 | *.publishsettings 194 | node_modules/ 195 | orleans.codegen.cs 196 | 197 | # Since there are multiple workflows, uncomment next line to ignore bower_components 198 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 199 | #bower_components/ 200 | 201 | # RIA/Silverlight projects 202 | Generated_Code/ 203 | 204 | # Backup & report files from converting an old project file 205 | # to a newer Visual Studio version. Backup files are not needed, 206 | # because we have git ;-) 207 | _UpgradeReport_Files/ 208 | Backup*/ 209 | UpgradeLog*.XML 210 | UpgradeLog*.htm 211 | 212 | # SQL Server files 213 | *.mdf 214 | *.ldf 215 | 216 | # Business Intelligence projects 217 | *.rdl.data 218 | *.bim.layout 219 | *.bim_*.settings 220 | 221 | # Microsoft Fakes 222 | FakesAssemblies/ 223 | 224 | # GhostDoc plugin setting file 225 | *.GhostDoc.xml 226 | 227 | # Node.js Tools for Visual Studio 228 | .ntvs_analysis.dat 229 | 230 | # Visual Studio 6 build log 231 | *.plg 232 | 233 | # Visual Studio 6 workspace options file 234 | *.opt 235 | 236 | # Visual Studio LightSwitch build output 237 | **/*.HTMLClient/GeneratedArtifacts 238 | **/*.DesktopClient/GeneratedArtifacts 239 | **/*.DesktopClient/ModelManifest.xml 240 | **/*.Server/GeneratedArtifacts 241 | **/*.Server/ModelManifest.xml 242 | _Pvt_Extensions 243 | 244 | # Paket dependency manager 245 | .paket/paket.exe 246 | paket-files/ 247 | 248 | # FAKE - F# Make 249 | .fake/ 250 | 251 | # JetBrains Rider 252 | .idea/ 253 | *.sln.iml 254 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing to Microsoft Cognitive Services Client Libraries & Samples 2 | =============================================== 3 | So, you want to contribute on a client library or sample for one of the Microsoft Cognitive Services. 4 | Here's what you need to know. 5 | 6 | 1. Each SDK should include both a client library and a sample showing the API in 7 | action 8 | 9 | 2. When working on an SDK, it's important that we are consistent from project to project, so we ask you to follow the coding guidelines below: 10 | 11 | - Windows [(Coding guidelines for C#)](https://msdn.microsoft.com/en-us/library/ff926074.aspx) -- also reference our [common Windows code](https://github.com/Microsoft/Cognitive-common-windows) for building samples 12 | 13 | - Android [(Coding guidelines for 14 | Java)]() 15 | 16 | - iOS Objective-C [(Coding guidelines for 17 | Cocoa)]() 18 | 19 | - Optional: Client Javascript ([Coding guidelines for 20 | npm]()) 21 | 22 | 3. Samples are important for illustrating how to actually call into the API. 23 | Samples should be as visual and reusable as possible. 24 | 25 | - Do: 26 | 27 | - Create a UI sample when possible. 28 | 29 | - Make your sample user friendly. Expect that developers will want to try 30 | different mainline scenarios and key APIs. 31 | 32 | - Create code that's easy for other developers to copy/paste into their 33 | own solutions 34 | 35 | - Consider: 36 | 37 | - Adding UI to allow devs to quickly copy/paste subscription keys, instead 38 | of updating them in the code or using a config file. The 39 | FaceAPI-WPF-Samples.sln provides an example. 40 | 41 | - Don't: 42 | 43 | - Leave your subscription key in the source of samples. You do not want your key to be abused by others. 44 | 45 | Happy coding! 46 | -------------------------------------------------------------------------------- /ClientLibrary/ClientError.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/Cognitive-Common-Windows 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using System; 35 | 36 | namespace Microsoft.ProjectOxford.Common 37 | { 38 | /// 39 | /// Container of ClientError and Error Entity. 40 | /// 41 | public class ClientError 42 | { 43 | /// 44 | /// Gets or sets error code in error entity. 45 | /// 46 | /// 47 | /// The code of client error. 48 | /// 49 | public string Code 50 | { 51 | get; 52 | set; 53 | } 54 | 55 | /// 56 | /// Gets or sets the message. 57 | /// 58 | /// 59 | /// The message. 60 | /// 61 | public string Message 62 | { 63 | get; 64 | set; 65 | } 66 | 67 | /// 68 | /// Gets or sets the request identifier. 69 | /// 70 | /// 71 | /// The request identifier. 72 | /// 73 | public Guid RequestId 74 | { 75 | get; 76 | set; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /ClientLibrary/ClientException.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/Cognitive-Common-Windows 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using System; 35 | using System.Net; 36 | 37 | namespace Microsoft.ProjectOxford.Common 38 | { 39 | /// 40 | /// The Exception will be shown to client. 41 | /// 42 | public class ClientException : Exception 43 | { 44 | /// 45 | /// Initializes a new instance of the class. 46 | /// 47 | public ClientException() 48 | : base() 49 | { 50 | } 51 | 52 | /// 53 | /// Initializes a new instance of the class. 54 | /// 55 | /// The corresponding error message. 56 | public ClientException(string message) 57 | : base(message) 58 | { 59 | this.Error = new ClientError() 60 | { 61 | Code = HttpStatusCode.InternalServerError.ToString(), 62 | Message = message 63 | }; 64 | } 65 | 66 | /// 67 | /// Initializes a new instance of the class. 68 | /// 69 | /// The corresponding error message. 70 | /// The Http Status code. 71 | public ClientException(string message, HttpStatusCode httpStatus) 72 | : base(message) 73 | { 74 | this.HttpStatus = httpStatus; 75 | 76 | this.Error = new ClientError() 77 | { 78 | Code = this.HttpStatus.ToString(), 79 | Message = message 80 | }; 81 | } 82 | 83 | /// 84 | /// Initializes a new instance of the class. 85 | /// 86 | /// The corresponding error message. 87 | /// The inner exception. 88 | public ClientException(string message, Exception innerException) 89 | : base(message, innerException) 90 | { 91 | this.Error = new ClientError() 92 | { 93 | Code = HttpStatusCode.InternalServerError.ToString(), 94 | Message = message 95 | }; 96 | } 97 | 98 | /// 99 | /// Initializes a new instance of the class. 100 | /// 101 | /// The corresponding error message. 102 | /// The error code. 103 | /// The http status. 104 | /// The inner exception. 105 | public ClientException(string message, string errorCode, HttpStatusCode httpStatus, Exception innerException) 106 | : base(message, innerException) 107 | { 108 | this.HttpStatus = httpStatus; 109 | 110 | this.Error = new ClientError() 111 | { 112 | Code = errorCode, 113 | Message = message 114 | }; 115 | } 116 | 117 | /// 118 | /// Initializes a new instance of the class. 119 | /// 120 | /// The error entity. 121 | /// The http status. 122 | public ClientException(ClientError error, HttpStatusCode httpStatus) 123 | : base(error?.Message) 124 | { 125 | this.Error = error; 126 | this.HttpStatus = httpStatus; 127 | } 128 | 129 | /// 130 | /// Gets http status of http response. 131 | /// 132 | /// 133 | /// The HTTP status. 134 | /// 135 | public HttpStatusCode HttpStatus { get; private set; } 136 | 137 | /// 138 | /// Gets or sets the httpError message. 139 | /// 140 | /// 141 | /// The error. 142 | /// 143 | public ClientError Error { get; set; } 144 | 145 | /// 146 | /// Create Client Exception of Bad Request. 147 | /// 148 | /// The corresponding error message. 149 | /// Client Exception Instance. 150 | public static ClientException BadRequest(string message) 151 | { 152 | return new ClientException( 153 | new ClientError() 154 | { 155 | Code = ((int)HttpStatusCode.BadRequest).ToString(), 156 | Message = message 157 | }, 158 | HttpStatusCode.BadRequest); 159 | } 160 | } 161 | } -------------------------------------------------------------------------------- /ClientLibrary/Contract/Emotion.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/Cognitive-Common-Windows 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using System; 35 | using System.Collections.Generic; 36 | using System.Linq; 37 | using System.Text; 38 | using System.Threading.Tasks; 39 | 40 | namespace Microsoft.ProjectOxford.Common.Contract 41 | { 42 | public class Emotion 43 | { 44 | /// 45 | /// Gets or sets the face rectangle. 46 | /// 47 | /// 48 | /// The face rectangle. 49 | /// 50 | public Rectangle FaceRectangle { get; set; } 51 | 52 | /// 53 | /// Gets or sets the emotion scores. 54 | /// 55 | /// 56 | /// The emotion scores. 57 | /// 58 | public EmotionScores Scores { get; set; } 59 | 60 | #region overrides 61 | public override bool Equals(object o) 62 | { 63 | if (o == null) return false; 64 | 65 | var other = o as Emotion; 66 | 67 | if (other == null) return false; 68 | 69 | if (this.FaceRectangle == null) 70 | { 71 | if (other.FaceRectangle != null) return false; 72 | } 73 | else 74 | { 75 | if (!this.FaceRectangle.Equals(other.FaceRectangle)) return false; 76 | } 77 | 78 | if (this.Scores == null) 79 | { 80 | return other.Scores == null; 81 | } 82 | else 83 | { 84 | return this.Scores.Equals(other.Scores); 85 | } 86 | } 87 | 88 | public override int GetHashCode() 89 | { 90 | int r = (FaceRectangle == null) ? 0x33333333 : FaceRectangle.GetHashCode(); 91 | int s = (Scores == null) ? 0xccccccc : Scores.GetHashCode(); 92 | return r ^ s; 93 | } 94 | #endregion 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /ClientLibrary/Contract/EmotionScores.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/Cognitive-Common-Windows 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using System.Collections.Generic; 35 | using System.Linq; 36 | 37 | namespace Microsoft.ProjectOxford.Common.Contract 38 | { 39 | /// 40 | public class EmotionScores 41 | { 42 | /// 43 | /// 44 | /// 45 | public float Anger { get; set; } 46 | 47 | /// 48 | /// 49 | /// 50 | public float Contempt { get; set; } 51 | 52 | /// 53 | /// 54 | /// 55 | public float Disgust { get; set; } 56 | 57 | /// 58 | /// 59 | /// 60 | public float Fear { get; set; } 61 | 62 | /// 63 | /// 64 | /// 65 | public float Happiness { get; set; } 66 | 67 | /// 68 | /// 69 | /// 70 | public float Neutral { get; set; } 71 | 72 | /// 73 | /// 74 | /// 75 | public float Sadness { get; set; } 76 | 77 | /// 78 | /// 79 | /// 80 | public float Surprise { get; set; } 81 | 82 | /// 83 | /// Create a sorted key-value pair of emotions and the corresponding scores, sorted from highest score on down. 84 | /// To make the ordering stable, the score is the primary key, and the name is the secondary key. 85 | /// 86 | public IEnumerable> ToRankedList() 87 | { 88 | return new Dictionary() 89 | { 90 | { "Anger", Anger }, 91 | { "Contempt", Contempt }, 92 | { "Disgust", Disgust }, 93 | { "Fear", Fear }, 94 | { "Happiness", Happiness }, 95 | { "Neutral", Neutral }, 96 | { "Sadness", Sadness }, 97 | { "Surprise", Surprise } 98 | } 99 | .OrderByDescending(kv => kv.Value) 100 | .ThenBy(kv => kv.Key) 101 | .ToList(); 102 | } 103 | 104 | #region overrides 105 | public override bool Equals(object o) 106 | { 107 | if (o == null) return false; 108 | 109 | var other = o as EmotionScores; 110 | if (other == null) return false; 111 | 112 | return this.Anger == other.Anger && 113 | this.Disgust == other.Disgust && 114 | this.Fear == other.Fear && 115 | this.Happiness == other.Happiness && 116 | this.Neutral == other.Neutral && 117 | this.Sadness == other.Sadness && 118 | this.Surprise == other.Surprise; 119 | } 120 | 121 | public override int GetHashCode() 122 | { 123 | return Anger.GetHashCode() ^ 124 | Disgust.GetHashCode() ^ 125 | Fear.GetHashCode() ^ 126 | Happiness.GetHashCode() ^ 127 | Neutral.GetHashCode() ^ 128 | Sadness.GetHashCode() ^ 129 | Surprise.GetHashCode(); 130 | } 131 | #endregion; 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /ClientLibrary/Microsoft.ProjectOxford.Common.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Microsoft 5 | Copyright © 2017 6 | Microsoft Project Oxford Common Types Client Library 7 | https://github.com/Microsoft/ProjectOxford-ClientSDK/blob/master/LICENSE.md 8 | https://github.com/Microsoft/Cognitive-Common-Windows 9 | true 10 | Microsoft Cognitive Services;Project Oxford 11 | netstandard1.1 12 | Microsoft.ProjectOxford.Common 13 | 2.0.0 14 | 15 | 16 | 17 | $(AssemblyOriginatorKeyFile) 18 | true 19 | true 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /ClientLibrary/Rectangle.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/Cognitive-Common-Windows 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | namespace Microsoft.ProjectOxford.Common 35 | { 36 | /// 37 | /// 38 | /// 39 | public class Rectangle 40 | { 41 | /// 42 | /// 43 | /// 44 | public int Left { get; set; } 45 | 46 | /// 47 | /// 48 | /// 49 | public int Top { get; set; } 50 | 51 | /// 52 | /// 53 | /// 54 | public int Width { get; set; } 55 | 56 | /// 57 | /// 58 | /// 59 | public int Height { get; set; } 60 | 61 | #region overrides 62 | public override bool Equals(object o) 63 | { 64 | if (o == null) return false; 65 | 66 | var other = o as Rectangle; 67 | 68 | if (other == null) return false; 69 | 70 | return this.Left == other.Left && 71 | this.Top == other.Top && 72 | this.Width == other.Width && 73 | this.Height == other.Height; 74 | } 75 | 76 | public override int GetHashCode() 77 | { 78 | return Left.GetHashCode() ^ Top.GetHashCode() ^ Width.GetHashCode() ^ Height.GetHashCode(); 79 | } 80 | #endregion 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /ClientLibrary/ServiceClient.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/Cognitive-Common-Windows 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using System; 35 | using System.IO; 36 | using System.Net.Http; 37 | using System.Net.Http.Headers; 38 | using System.Text; 39 | using System.Threading; 40 | using System.Threading.Tasks; 41 | using System.Linq; 42 | 43 | using Newtonsoft.Json; 44 | using Newtonsoft.Json.Serialization; 45 | 46 | namespace Microsoft.ProjectOxford.Common 47 | { 48 | public abstract class ServiceClient : IDisposable 49 | { 50 | protected class UrlRequest 51 | { 52 | public string url { get; set; } 53 | } 54 | 55 | public class WrappedClientError 56 | { 57 | public ClientError Error { get; set; } 58 | } 59 | 60 | #region private/protected members 61 | 62 | /// 63 | /// The default resolver. 64 | /// 65 | protected static CamelCasePropertyNamesContractResolver s_defaultResolver = new CamelCasePropertyNamesContractResolver(); 66 | 67 | protected static JsonSerializerSettings s_settings = new JsonSerializerSettings() 68 | { 69 | DateFormatHandling = DateFormatHandling.IsoDateFormat, 70 | NullValueHandling = NullValueHandling.Ignore, 71 | ContractResolver = s_defaultResolver 72 | }; 73 | 74 | protected HttpClient HttpClient { get; } 75 | 76 | private readonly bool _ownHttpClient; 77 | 78 | private bool _disposed; 79 | 80 | /// 81 | /// Default constructor 82 | /// 83 | protected ServiceClient() : this(new HttpClient(), true) 84 | { 85 | } 86 | 87 | /// 88 | /// Test constructor; use to inject mock clients. 89 | /// 90 | /// Custom HttpClient, for testing. 91 | protected ServiceClient(HttpClient httpClient) : this(httpClient, false) 92 | { 93 | } 94 | 95 | /// 96 | /// Common constructor for default and test. 97 | /// 98 | /// Custom HttpClient, for testing. 99 | /// True if this object owns the HttpClient, false if the caller owns it. 100 | private ServiceClient(HttpClient httpClient, bool ownHttpClient) 101 | { 102 | HttpClient = httpClient; 103 | _ownHttpClient = ownHttpClient; 104 | } 105 | 106 | /// 107 | /// IDisposable.Dispose implementation. 108 | /// 109 | public void Dispose() 110 | { 111 | Dispose(true); 112 | GC.SuppressFinalize(this); 113 | } 114 | 115 | protected virtual void Dispose(bool disposing) 116 | { 117 | if (_disposed) 118 | { 119 | return; 120 | } 121 | 122 | if (disposing && _ownHttpClient) 123 | { 124 | HttpClient.Dispose(); 125 | } 126 | 127 | _disposed = true; 128 | } 129 | 130 | ~ServiceClient() 131 | { 132 | Dispose(false); 133 | } 134 | 135 | /// 136 | /// Root of the API URL. Must not end in slash. 137 | /// 138 | protected string ApiRoot { get; set; } 139 | 140 | /// 141 | /// Header name for authorization. 142 | /// 143 | protected string AuthKey { get; set; } 144 | 145 | /// 146 | /// Header value for authorization. 147 | /// 148 | protected string AuthValue { get; set; } 149 | #endregion 150 | 151 | #region the JSON client 152 | /// 153 | /// Helper method executing a POST REST request. 154 | /// 155 | /// Type of request. 156 | /// Type of response. 157 | /// API URL relative to the apiRoot 158 | /// Content of the HTTP request. 159 | /// Async cancellation token 160 | /// TResponse 161 | /// Service exception 162 | protected Task PostAsync(string apiUrl, TRequest requestBody, CancellationToken cancellationToken) 163 | { 164 | return SendAsync(HttpMethod.Post, apiUrl, requestBody, cancellationToken); 165 | } 166 | 167 | /// 168 | /// Helper method executing a GET REST request. 169 | /// 170 | /// Type of response. 171 | /// API URL relative to the apiRoot 172 | /// Async cancellation token 173 | /// TResponse 174 | /// Service exception 175 | protected Task GetAsync(string apiUrl, CancellationToken cancellationToken) 176 | { 177 | return SendAsync(HttpMethod.Get, apiUrl, null, cancellationToken); 178 | } 179 | 180 | /// 181 | /// Helper method executing a REST request. 182 | /// 183 | /// Type of request. 184 | /// Type of response. 185 | /// HTTP method 186 | /// API URL, generally relative to the ApiRoot 187 | /// Content of the HTTP request 188 | /// Async cancellation token 189 | /// TResponse 190 | /// Service exception 191 | protected Task SendAsync(HttpMethod method, string apiUrl, TRequest requestBody, CancellationToken cancellationToken) 192 | { 193 | bool urlIsRelative = System.Uri.IsWellFormedUriString(apiUrl, System.UriKind.Relative); 194 | 195 | string requestUri = urlIsRelative ? ApiRoot + apiUrl : apiUrl; 196 | var request = new HttpRequestMessage(method, requestUri); 197 | request.Headers.Add(AuthKey, AuthValue); 198 | 199 | if (requestBody != null) 200 | { 201 | if (requestBody is Stream) 202 | { 203 | request.Content = new StreamContent(requestBody as Stream); 204 | request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); 205 | } 206 | else 207 | { 208 | request.Content = new StringContent(JsonConvert.SerializeObject(requestBody, s_settings), Encoding.UTF8, "application/json"); 209 | } 210 | } 211 | 212 | var task = HttpClient.SendAsync(request, cancellationToken) 213 | .ContinueWith(t => GetContent(t.Result) 214 | .ContinueWith(u => GetResponse(t.Result, u.Result))); 215 | 216 | return task.Result; 217 | } 218 | 219 | /// 220 | /// Task to get the HTTP response string. 221 | /// 222 | private Task GetContent(HttpResponseMessage response) 223 | { 224 | if (response.IsSuccessStatusCode) 225 | { 226 | if (response.Content != null) 227 | { 228 | return response.Content.ReadAsStringAsync(); 229 | } 230 | } 231 | else if (response.Content != null && response.Content.Headers.ContentType?.MediaType.Contains("application/json") == true) 232 | { 233 | return response.Content.ReadAsStringAsync(); 234 | } 235 | return Task.FromResult(""); 236 | } 237 | 238 | /// 239 | /// Task to construct the JSON object from the HTTP response. 240 | /// 241 | private TResponse GetResponse(HttpResponseMessage response, string responseContent) 242 | { 243 | if (response.IsSuccessStatusCode) 244 | { 245 | if (!string.IsNullOrWhiteSpace(responseContent)) 246 | { 247 | return JsonConvert.DeserializeObject(responseContent, s_settings); 248 | } 249 | } 250 | else 251 | { 252 | if (response?.Content?.Headers?.ContentType?.MediaType.Contains("application/json") == true) 253 | { 254 | // Some of the endpoints return an top-level 'error' field (WrappedClientError) whereas some will simply 255 | // return the plain ClientError. 256 | var wrappedClientError = JsonConvert.DeserializeObject(responseContent); 257 | if (wrappedClientError?.Error != null) 258 | { 259 | throw new ClientException(wrappedClientError.Error, response.StatusCode); 260 | } 261 | var clientError = JsonConvert.DeserializeObject(responseContent); 262 | if (clientError != null) 263 | { 264 | throw new ClientException(clientError, response.StatusCode); 265 | } 266 | } 267 | 268 | response.EnsureSuccessStatusCode(); 269 | } 270 | return default(TResponse); 271 | } 272 | #endregion 273 | } 274 | } 275 | -------------------------------------------------------------------------------- /LICENSE-IMAGE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) Microsoft Corporation 2 | 3 | All rights reserved. 4 | 5 | Microsoft Cognitive Services Client SDK License for Sample Image 6 | 7 | *This license applies only to the sample images. The SDK code is licensed separately, please refer to [LICENSE]()* 8 | 9 | Microsoft may make sample images available in connection with the SDK for the purposes of illustrating the operation of Microsoft Cognitive Services (https://www.microsoft.com/cognitive-services). If no separate license terms are provided with the images, Microsoft grants you a personal, nonexclusive, revocable, royalty-free right to use the images solely within your organization to test the operation of Microsoft Cognitive Services, provided that you agree to indemnify, hold harmless, and defend Microsoft and its suppliers from and against any claims or lawsuits, including attorneys’ fees, that arise or result from the use or distribution of the images. Except as expressly provided in this section you have no license to modify or distribute the images. 10 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Microsoft Cognitive Services SDK 2 | 3 | Copyright (c) Microsoft Corporation 4 | 5 | All rights reserved. 6 | 7 | *This license applies only to the SDK code. Sample images are licensed separately, please refer to [LICENSE-IMAGE]()* 8 | 9 | MIT License 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 12 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Microsoft Cognitive Services: Windows Common Code 2 | This repository contains code shared between client libraries and samples acrosss different Microsoft Cognitive Services APIs, formerly known as Project Oxford. 3 | * [Learn about Microsoft Cognitive Services](https://www.microsoft.com/cognitive-services) 4 | * [Find more SDKs & Samples](https://www.microsoft.com/cognitive-services/en-us/SDK-Sample) 5 | 6 | 7 | ## Contributing 8 | We welcome contributions. Feel free to file issues and pull requests on the repo and we'll address them as we can. Learn more about how you can help on our [Contribution Rules & Guidelines](). 9 | 10 | You can reach out to us anytime with questions and suggestions using our communities below: 11 | - **Support questions:** [StackOverflow]() 12 | - **Feedback & feature requests:** [Cognitive Services UserVoice Forum]() 13 | 14 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 15 | 16 | 17 | ## License 18 | All Microsoft Cognitive Services SDKs and samples are licensed with the MIT License. For more details, see 19 | [LICENSE](). 20 | 21 | Sample images are licensed separately, please refer to [LICENSE-IMAGE](). 22 | 23 | 24 | ## Developer Code of Conduct 25 | Developers using Cognitive Services, including this sample, are expected to follow the “Developer Code of Conduct for Microsoft Cognitive Services”, found at [http://go.microsoft.com/fwlink/?LinkId=698895](http://go.microsoft.com/fwlink/?LinkId=698895). 26 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd). 40 | 41 | 42 | -------------------------------------------------------------------------------- /SampleUserControlLibrary/Assets/Microsoft-logo_rgb_c-gray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/Cognitive-Common-Windows/edf833fe8586cafd083d8d43a7ae66b64cf2c1c0/SampleUserControlLibrary/Assets/Microsoft-logo_rgb_c-gray.png -------------------------------------------------------------------------------- /SampleUserControlLibrary/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/Cognitive-Common-Windows 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using System.Reflection; 35 | using System.Resources; 36 | using System.Runtime.CompilerServices; 37 | using System.Runtime.InteropServices; 38 | using System.Windows; 39 | 40 | // General Information about an assembly is controlled through the following 41 | // set of attributes. Change these attribute values to modify the information 42 | // associated with an assembly. 43 | [assembly: AssemblyTitle("SampleUserControlLibrary")] 44 | [assembly: AssemblyDescription("")] 45 | [assembly: AssemblyConfiguration("")] 46 | [assembly: AssemblyCompany("")] 47 | [assembly: AssemblyProduct("SampleUserControlLibrary")] 48 | [assembly: AssemblyCopyright("Copyright \u00A9 2015")] 49 | [assembly: AssemblyTrademark("")] 50 | [assembly: AssemblyCulture("")] 51 | 52 | // Setting ComVisible to false makes the types in this assembly not visible 53 | // to COM components. If you need to access a type in this assembly from 54 | // COM, set the ComVisible attribute to true on that type. 55 | [assembly: ComVisible(false)] 56 | 57 | //In order to begin building localizable applications, set 58 | //CultureYouAreCodingWith in your .csproj file 59 | //inside a . For example, if you are using US english 60 | //in your source files, set the to en-US. Then uncomment 61 | //the NeutralResourceLanguage attribute below. Update the "en-US" in 62 | //the line below to match the UICulture setting in the project file. 63 | 64 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 65 | 66 | 67 | [assembly: ThemeInfo( 68 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 69 | //(used if a resource is not found in the page, 70 | // or application resource dictionaries) 71 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 72 | //(used if a resource is not found in the page, 73 | // app, or any theme specific resource dictionaries) 74 | )] 75 | 76 | 77 | // Version information for an assembly consists of the following four values: 78 | // 79 | // Major Version 80 | // Minor Version 81 | // Build Number 82 | // Revision 83 | // 84 | // You can specify all the values or you can default the Build and Revision Numbers 85 | // by using the '*' as shown below: 86 | // [assembly: AssemblyVersion("1.0.*")] 87 | [assembly: AssemblyVersion("1.0.0.0")] 88 | [assembly: AssemblyFileVersion("1.0.0.0")] 89 | -------------------------------------------------------------------------------- /SampleUserControlLibrary/SampleUserControl.xaml: -------------------------------------------------------------------------------- 1 |  10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | Status text goes here 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /SampleUserControlLibrary/SampleUserControl.xaml.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/Cognitive-Common-Windows 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using System; 35 | using System.Globalization; 36 | using System.Windows; 37 | using System.Windows.Controls; 38 | using System.Windows.Data; 39 | 40 | namespace SampleUserControlLibrary 41 | { 42 | public class Scenario 43 | { 44 | public string Title 45 | { 46 | set; 47 | get; 48 | } 49 | 50 | public Type PageClass 51 | { 52 | get; 53 | set; 54 | } 55 | } 56 | 57 | /// 58 | /// Interaction logic for UserControl1.xaml 59 | /// 60 | public partial class SampleScenarios : UserControl 61 | { 62 | public static DependencyProperty SampleTitleProperty = 63 | DependencyProperty.Register("SampleTitle", typeof(string), typeof(SampleScenarios)); 64 | 65 | public static DependencyProperty SampleScenarioListProperty = 66 | DependencyProperty.Register("SampleScenarioList", typeof(Scenario[]), typeof(SampleScenarios)); 67 | 68 | private SubscriptionKeyPage _subscriptionPage; 69 | 70 | public string SampleTitle 71 | { 72 | get { return (string)GetValue(SampleTitleProperty); } 73 | set { SetValue(SampleTitleProperty, value); } 74 | } 75 | 76 | public Scenario[] SampleScenarioList 77 | { 78 | get { return (Scenario[])GetValue(SampleScenarioListProperty); } 79 | set 80 | { 81 | SetValue(SampleScenarioListProperty, value); 82 | _scenarioListBox.ItemsSource = SampleScenarioList; 83 | } 84 | } 85 | 86 | public string SubscriptionKey 87 | { 88 | get; 89 | set; 90 | } 91 | 92 | public string SubscriptionEndpoint 93 | { 94 | get; 95 | set; 96 | } 97 | 98 | public void SetSubscriptionPageEndpoint(string endpoint) 99 | { 100 | _subscriptionPage.SetSubscriptionEndpoint(endpoint); 101 | } 102 | 103 | public SampleScenarios() 104 | { 105 | InitializeComponent(); 106 | _subscriptionPage = new SubscriptionKeyPage(this); 107 | SubscriptionKey = _subscriptionPage.SubscriptionKey; 108 | SubscriptionEndpoint = _subscriptionPage.SubscriptionEndpoint; 109 | 110 | SampleTitle = "Replace SampleNames with SampleScenarios.SampleTitle property"; 111 | 112 | SampleScenarioList = new Scenario[] 113 | { 114 | new Scenario { Title = "Scenario 1: Replace items using SampleScenarios.ScenarioList" }, 115 | new Scenario { Title = "Scenario 2: Replace items using SampleScenarios.ScenarioList" } 116 | }; 117 | 118 | _scenarioListBox.ItemsSource = SampleScenarioList; 119 | 120 | _scenarioFrame.Navigate(_subscriptionPage); 121 | } 122 | 123 | public void Log(string logMessage) 124 | { 125 | if (String.IsNullOrEmpty(logMessage) || logMessage == "\n") 126 | { 127 | _logTextBox.Text += "\n"; 128 | } 129 | else 130 | { 131 | string timeStr = DateTime.Now.ToString("HH:mm:ss.ffffff"); 132 | string messaage = "[" + timeStr + "]: " + logMessage + "\n"; 133 | _logTextBox.Text += messaage; 134 | } 135 | _logTextBox.ScrollToEnd(); 136 | } 137 | 138 | public void ClearLog() 139 | { 140 | _logTextBox.Text = ""; 141 | } 142 | 143 | private void ScenarioChanged(object sender, SelectionChangedEventArgs e) 144 | { 145 | ListBox scenarioListBox = sender as ListBox; 146 | Scenario scenario = scenarioListBox.SelectedItem as Scenario; 147 | ClearLog(); 148 | 149 | if (scenario != null) 150 | { 151 | Page page = Activator.CreateInstance(scenario.PageClass) as Page; 152 | page.DataContext = this.DataContext; 153 | _scenarioFrame.Navigate(page); 154 | } 155 | } 156 | 157 | private void SubscriptionManagementButton_Click(object sender, RoutedEventArgs e) 158 | { 159 | _scenarioFrame.Navigate(_subscriptionPage); 160 | // Reset the selection so that we can get SelectionChangedEvent later. 161 | _scenarioListBox.SelectedIndex = -1; 162 | } 163 | } 164 | 165 | public class ScenarioBindingConverter : IValueConverter 166 | { 167 | object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) 168 | { 169 | Scenario s = value as Scenario; 170 | if (s != null) 171 | { 172 | return s.Title; 173 | } 174 | return null; 175 | } 176 | 177 | object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 178 | { 179 | throw new NotImplementedException(); 180 | } 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /SampleUserControlLibrary/SampleUserControlLibrary.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {735929F0-F8F1-4D93-B027-5D034FA7892B} 8 | library 9 | Properties 10 | SampleUserControlLibrary 11 | SampleUserControlLibrary 12 | v4.5.2 13 | 512 14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 15 | 4 16 | 17 | 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 4.0 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | SubscriptionKeyPage.xaml 57 | 58 | 59 | MSBuild:Compile 60 | Designer 61 | 62 | 63 | SampleUserControl.xaml 64 | Code 65 | 66 | 67 | Designer 68 | MSBuild:Compile 69 | 70 | 71 | 72 | 73 | Code 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 94 | -------------------------------------------------------------------------------- /SampleUserControlLibrary/SampleUserControlLibrary/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SampleUserControlLibrary.Properties { 12 | 13 | 14 | /// 15 | /// A strongly-typed resource class, for looking up localized strings, etc. 16 | /// 17 | // This class was auto-generated by the StronglyTypedResourceBuilder 18 | // class via a tool like ResGen or Visual Studio. 19 | // To add or remove a member, edit your .ResX file then rerun ResGen 20 | // with the /str option, or rebuild your VS project. 21 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 22 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 23 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 24 | internal class Resources { 25 | 26 | private static global::System.Resources.ResourceManager resourceMan; 27 | 28 | private static global::System.Globalization.CultureInfo resourceCulture; 29 | 30 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 31 | internal Resources() { 32 | } 33 | 34 | /// 35 | /// Returns the cached ResourceManager instance used by this class. 36 | /// 37 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 38 | internal static global::System.Resources.ResourceManager ResourceManager { 39 | get { 40 | if ((resourceMan == null)) { 41 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SampleUserControlLibrary.Properties.Resources", typeof(Resources).Assembly); 42 | resourceMan = temp; 43 | } 44 | return resourceMan; 45 | } 46 | } 47 | 48 | /// 49 | /// Overrides the current thread's CurrentUICulture property for all 50 | /// resource lookups using this strongly typed resource class. 51 | /// 52 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 53 | internal static global::System.Globalization.CultureInfo Culture { 54 | get { 55 | return resourceCulture; 56 | } 57 | set { 58 | resourceCulture = value; 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /SampleUserControlLibrary/SampleUserControlLibrary/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /SampleUserControlLibrary/SampleUserControlLibrary/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SampleUserControlLibrary.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /SampleUserControlLibrary/SampleUserControlLibrary/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /SampleUserControlLibrary/SubscriptionKeyPage.xaml: -------------------------------------------------------------------------------- 1 |  10 | 11 | 12 | 29 | 30 | 31 | 32 | To use the service, you need to ensure that you have right subscription key. 33 | Please note that each service (Face, Emotion, Speech, etc) has its own subscription key. 34 | If you do not have key yet, please use the link to get a key first, then paste the key into the textbox below. 35 |