├── .gitignore ├── CognitiveServicesDemo.sln ├── CognitiveServicesDemo ├── App_Start │ ├── BundleConfig.cs │ ├── FilterConfig.cs │ └── RouteConfig.cs ├── Areas │ ├── ComputerVision │ │ ├── ComputerVisionAreaRegistration.cs │ │ ├── Controllers │ │ │ ├── ComputerVisionBaseController.cs │ │ │ ├── DescribeController.cs │ │ │ ├── HandwritingController.cs │ │ │ ├── HomeController.cs │ │ │ └── TextController.cs │ │ ├── Models │ │ │ ├── DescribeImageModel.cs │ │ │ ├── HandwritingModel.cs │ │ │ └── RecognizeTextModel.cs │ │ └── Views │ │ │ ├── Describe │ │ │ └── Index.cshtml │ │ │ ├── Handwriting │ │ │ └── Index.cshtml │ │ │ ├── Shared │ │ │ └── _ComputerVisionMenu.cshtml │ │ │ ├── Text │ │ │ └── Index.cshtml │ │ │ ├── _ViewStart.cshtml │ │ │ └── web.config │ ├── Faces │ │ ├── Controllers │ │ │ ├── DetectController.cs │ │ │ ├── FacesBaseController.cs │ │ │ ├── HomeController.cs │ │ │ ├── PeopleController.cs │ │ │ └── PersonGroupsController.cs │ │ ├── FacesAreaRegistration.cs │ │ ├── Models │ │ │ ├── IdentifyFacesModel.cs │ │ │ └── PersonGroupDetailsModel.cs │ │ └── Views │ │ │ ├── Detect │ │ │ ├── Attributes.cshtml │ │ │ ├── Emotions.cshtml │ │ │ ├── Identify.cshtml │ │ │ ├── Index.cshtml │ │ │ └── _UploadWithPersonGroups.cshtml │ │ │ ├── People │ │ │ ├── AddFace.cshtml │ │ │ ├── Details.cshtml │ │ │ ├── Edit.cshtml │ │ │ └── Index.cshtml │ │ │ ├── PersonGroups │ │ │ ├── Create.cshtml │ │ │ ├── Details.cshtml │ │ │ ├── Edit.cshtml │ │ │ └── Index.cshtml │ │ │ ├── Shared │ │ │ └── _FacesMenu.cshtml │ │ │ ├── _ViewStart.cshtml │ │ │ └── web.config │ └── ImageUsingBaseController.cs ├── CognitiveServicesDemo.csproj ├── Content │ ├── Site.css │ ├── bootstrap-theme.css │ ├── bootstrap-theme.css.map │ ├── bootstrap-theme.min.css │ ├── bootstrap-theme.min.css.map │ ├── bootstrap.css │ ├── bootstrap.css.map │ ├── bootstrap.min.css │ └── bootstrap.min.css.map ├── Controllers │ └── HomeController.cs ├── Global.asax ├── Global.asax.cs ├── Models │ └── ErrorModel.cs ├── Properties │ └── AssemblyInfo.cs ├── Scripts │ ├── bootstrap.js │ ├── bootstrap.min.js │ ├── jquery-3.3.1.intellisense.js │ ├── jquery-3.3.1.js │ ├── jquery-3.3.1.min.js │ ├── jquery-3.3.1.min.map │ ├── jquery-3.3.1.slim.js │ ├── jquery-3.3.1.slim.min.js │ ├── jquery-3.3.1.slim.min.map │ ├── jquery.validate-vsdoc.js │ ├── jquery.validate.js │ ├── jquery.validate.min.js │ ├── jquery.validate.unobtrusive.js │ ├── jquery.validate.unobtrusive.min.js │ ├── modernizr-2.8.3.js │ ├── respond.js │ ├── respond.matchmedia.addListener.js │ ├── respond.matchmedia.addListener.min.js │ └── respond.min.js ├── Settings.cs ├── Views │ ├── Home │ │ └── Index.cshtml │ ├── Shared │ │ ├── Error.cshtml │ │ ├── _Layout.cshtml │ │ └── _Upload.cshtml │ ├── Web.config │ └── _ViewStart.cshtml ├── Web.Debug.config ├── Web.Release.config ├── Web.config ├── favicon.ico ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.svg │ ├── glyphicons-halflings-regular.ttf │ ├── glyphicons-halflings-regular.woff │ └── glyphicons-halflings-regular.woff2 └── packages.config └── README.md /.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 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc 262 | /CognitiveServicesDemo/keys.config 263 | -------------------------------------------------------------------------------- /CognitiveServicesDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CognitiveServicesDemo", "CognitiveServicesDemo\CognitiveServicesDemo.csproj", "{4777D685-545A-4C69-8E03-AAAE231C1DD4}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {4777D685-545A-4C69-8E03-AAAE231C1DD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {4777D685-545A-4C69-8E03-AAAE231C1DD4}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {4777D685-545A-4C69-8E03-AAAE231C1DD4}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {4777D685-545A-4C69-8E03-AAAE231C1DD4}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/App_Start/BundleConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web; 2 | using System.Web.Optimization; 3 | 4 | namespace CognitiveServicesDemo 5 | { 6 | public class BundleConfig 7 | { 8 | // For more information on bundling, visit https://go.microsoft.com/fwlink/?LinkId=301862 9 | public static void RegisterBundles(BundleCollection bundles) 10 | { 11 | bundles.Add(new ScriptBundle("~/bundles/jquery").Include( 12 | "~/Scripts/jquery-{version}.js")); 13 | 14 | bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include( 15 | "~/Scripts/jquery.validate*")); 16 | 17 | // Use the development version of Modernizr to develop with and learn from. Then, when you're 18 | // ready for production, use the build tool at https://modernizr.com to pick only the tests you need. 19 | bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( 20 | "~/Scripts/modernizr-*")); 21 | 22 | bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( 23 | "~/Scripts/bootstrap.js", 24 | "~/Scripts/respond.js")); 25 | 26 | bundles.Add(new StyleBundle("~/Content/css").Include( 27 | "~/Content/bootstrap.css", 28 | "~/Content/site.css")); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/App_Start/FilterConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web; 2 | using System.Web.Mvc; 3 | 4 | namespace CognitiveServicesDemo 5 | { 6 | public class FilterConfig 7 | { 8 | public static void RegisterGlobalFilters(GlobalFilterCollection filters) 9 | { 10 | filters.Add(new HandleErrorAttribute()); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/App_Start/RouteConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | using System.Web.Routing; 3 | 4 | namespace CognitiveServicesDemo 5 | { 6 | public class RouteConfig 7 | { 8 | public static void RegisterRoutes(RouteCollection routes) 9 | { 10 | routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 11 | 12 | routes.MapRoute( 13 | name: "Default", 14 | url: "{controller}/{action}/{id}", 15 | defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }, 16 | namespaces: new[] { "CognitiveServicesDemo.Controllers" } 17 | ); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/ComputerVision/ComputerVisionAreaRegistration.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | 3 | namespace CognitiveServicesDemo.Areas.ComputerVision 4 | { 5 | public class ComputerVisionAreaRegistration : AreaRegistration 6 | { 7 | public override string AreaName 8 | { 9 | get 10 | { 11 | return "ComputerVision"; 12 | } 13 | } 14 | 15 | public override void RegisterArea(AreaRegistrationContext context) 16 | { 17 | context.MapRoute( 18 | "ComputerVision_default", 19 | "ComputerVision/{controller}/{action}/{id}", 20 | new { action = "Index", id = UrlParameter.Optional } 21 | ); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/ComputerVision/Controllers/ComputerVisionBaseController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Configuration; 3 | using System.Drawing; 4 | using System.Drawing.Imaging; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Web.Mvc; 8 | using CognitiveServicesDemo.Models; 9 | using Microsoft.ProjectOxford.Vision; 10 | using Microsoft.ProjectOxford.Vision.Contract; 11 | 12 | namespace CognitiveServicesDemo.Areas.ComputerVision.Controllers 13 | { 14 | public abstract class ComputerVisionBaseController : ImageUsingBaseController 15 | { 16 | protected VisionServiceClient VisionServiceClient { get; private set; } 17 | 18 | public ComputerVisionBaseController() 19 | { 20 | var apiKey = ConfigurationManager.AppSettings["CognitiveServicesVisionApiKey"]; 21 | var apiRoot = ConfigurationManager.AppSettings["CognitiveServicesVisionApiUrl"]; 22 | VisionServiceClient = new VisionServiceClient(apiKey, apiRoot); 23 | } 24 | 25 | protected string GetInlineImageWithLines(HandwritingTextResult result) 26 | { 27 | ImageToProcess.Seek(0, SeekOrigin.Begin); 28 | 29 | using (var img = new Bitmap(ImageToProcess)) 30 | // make copy, drawing on indexed pixel format image is not supported 31 | using (var nonIndexedImg = new Bitmap(img.Width, img.Height)) 32 | using (var g = Graphics.FromImage(nonIndexedImg)) 33 | using (var mem = new MemoryStream()) 34 | { 35 | g.DrawImage(img, 0, 0, img.Width, img.Height); 36 | 37 | var i = 0; 38 | 39 | foreach (var line in result.Lines) 40 | { 41 | if(i >= Settings.ImageSquareColors.Length) 42 | { 43 | i = 0; 44 | } 45 | var pen = new Pen(Settings.ImageSquareColors[i], 5); 46 | var points = line.Polygon.Points.Select(pp => new System.Drawing.Point 47 | { 48 | X = pp.X, 49 | Y = pp.Y 50 | }).ToArray(); 51 | 52 | g.DrawPolygon(pen, points); 53 | i++; 54 | } 55 | 56 | nonIndexedImg.Save(mem, ImageFormat.Png); 57 | 58 | var base64 = Convert.ToBase64String(mem.ToArray()); 59 | return String.Format("data:image/png;base64,{0}", base64); 60 | } 61 | } 62 | 63 | protected string GetInlineImageWithLines(OcrResults result) 64 | { 65 | ImageToProcess.Seek(0, SeekOrigin.Begin); 66 | 67 | using (var img = new Bitmap(ImageToProcess)) 68 | // make copy, drawing on indexed pixel format image is not supported 69 | using (var nonIndexedImg = new Bitmap(img.Width, img.Height)) 70 | using (var g = Graphics.FromImage(nonIndexedImg)) 71 | using (var mem = new MemoryStream()) 72 | { 73 | g.DrawImage(img, 0, 0, img.Width, img.Height); 74 | 75 | var i = 0; 76 | 77 | foreach (var region in result.Regions) 78 | foreach (var line in region.Lines) 79 | { 80 | var pen = new Pen(Settings.ImageSquareColors[i], 2); 81 | g.DrawRectangle(pen, new System.Drawing.Rectangle( 82 | line.Rectangle.Left, 83 | line.Rectangle.Top, 84 | line.Rectangle.Width, 85 | line.Rectangle.Height 86 | )); 87 | i++; 88 | if(i >= 10) 89 | { 90 | i = 0; 91 | } 92 | } 93 | 94 | nonIndexedImg.Save(mem, ImageFormat.Png); 95 | 96 | var base64 = Convert.ToBase64String(mem.ToArray()); 97 | return String.Format("data:image/png;base64,{0}", base64); 98 | } 99 | } 100 | 101 | protected override void OnActionExecuting(ActionExecutingContext filterContext) 102 | { 103 | base.OnActionExecuting(filterContext); 104 | 105 | ViewBag.LeftMenu = "_ComputerVisionMenu"; 106 | } 107 | 108 | protected override void OnException(ExceptionContext filterContext) 109 | { 110 | base.OnException(filterContext); 111 | 112 | if (filterContext.ExceptionHandled) 113 | { 114 | return; 115 | } 116 | 117 | var message = filterContext.Exception.Message; 118 | var code = ""; 119 | 120 | if (filterContext.Exception is ClientException) 121 | { 122 | var faex = filterContext.Exception as ClientException; 123 | message = faex.Error.Message; 124 | code = faex.Error.Code; 125 | } 126 | 127 | filterContext.Result = new ViewResult 128 | { 129 | ViewName = "Error", 130 | ViewData = new ViewDataDictionary(filterContext.Controller.ViewData) 131 | { 132 | Model = new ErrorModel { Code = code, Message = message } 133 | } 134 | }; 135 | 136 | filterContext.ExceptionHandled = true; 137 | } 138 | } 139 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/ComputerVision/Controllers/DescribeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using System.Web.Mvc; 4 | using CognitiveServicesDemo.Areas.ComputerVision.Models; 5 | using Microsoft.ProjectOxford.Vision; 6 | 7 | namespace CognitiveServicesDemo.Areas.ComputerVision.Controllers 8 | { 9 | public class DescribeController : ComputerVisionBaseController 10 | { 11 | public async Task Index() 12 | { 13 | if (Request.HttpMethod == "GET") 14 | { 15 | return View("Index"); 16 | } 17 | 18 | var model = new DescribeImageModel(); 19 | 20 | // What features to find on imahe 21 | var features = new[] 22 | { 23 | VisualFeature.Adult, VisualFeature.Categories, VisualFeature.Color, VisualFeature.Description, 24 | VisualFeature.Faces, VisualFeature.ImageType, VisualFeature.Tags 25 | }; 26 | 27 | // Analyze image using copy of input stream 28 | await RunOperationOnImage(async stream => 29 | { 30 | model.Result = await VisionServiceClient.AnalyzeImageAsync(stream, features); 31 | }); 32 | 33 | // Convert image to base64 image string 34 | await RunOperationOnImage(async stream => { 35 | var bytes = new byte[stream.Length]; 36 | 37 | await stream.ReadAsync(bytes, 0, bytes.Length); 38 | 39 | var base64 = Convert.ToBase64String(bytes); 40 | model.ImageDump = String.Format("data:image/png;base64,{0}", base64); 41 | }); 42 | 43 | return View(model); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/ComputerVision/Controllers/HandwritingController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using System.Web.Mvc; 4 | using CognitiveServicesDemo.Areas.ComputerVision.Models; 5 | using Microsoft.ProjectOxford.Vision.Contract; 6 | 7 | namespace CognitiveServicesDemo.Areas.ComputerVision.Controllers 8 | { 9 | public class HandwritingController : ComputerVisionBaseController 10 | { 11 | public async Task Index() 12 | { 13 | if (Request.HttpMethod == "GET") 14 | { 15 | return View(); 16 | } 17 | 18 | var model = new HandwritingModel(); 19 | HandwritingRecognitionOperation op = null; 20 | 21 | await RunOperationOnImage(async stream => 22 | { 23 | op = await VisionServiceClient.CreateHandwritingRecognitionOperationAsync(stream); 24 | }); 25 | 26 | while(true) 27 | { 28 | await Task.Delay(5000); 29 | 30 | var result = await VisionServiceClient.GetHandwritingRecognitionOperationResultAsync(op); 31 | if(result.Status == HandwritingRecognitionOperationStatus.NotStarted || 32 | result.Status == HandwritingRecognitionOperationStatus.Running) 33 | { 34 | continue; 35 | } 36 | 37 | model.Result = result.RecognitionResult; 38 | break; 39 | } 40 | 41 | model.ImageDump = GetInlineImageWithLines(model.Result); 42 | 43 | return View(model); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/ComputerVision/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | 3 | namespace CognitiveServicesDemo.Areas.ComputerVision.Controllers 4 | { 5 | public class HomeController : Controller 6 | { 7 | public ActionResult Index() 8 | { 9 | return RedirectToAction("Index", "Describe"); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/ComputerVision/Controllers/TextController.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using System.Web.Mvc; 3 | using CognitiveServicesDemo.Areas.ComputerVision.Models; 4 | 5 | namespace CognitiveServicesDemo.Areas.ComputerVision.Controllers 6 | { 7 | public class TextController : ComputerVisionBaseController 8 | { 9 | public async Task Index() 10 | { 11 | if (Request.HttpMethod == "GET") 12 | { 13 | return View(); 14 | } 15 | 16 | var model = new RecognizeTextModel(); 17 | 18 | await RunOperationOnImage(async stream => 19 | { 20 | model.Results = await VisionServiceClient.RecognizeTextAsync(stream, detectOrientation: false); 21 | }); 22 | 23 | model.ImageDump = GetInlineImageWithLines(model.Results); 24 | 25 | return View(model); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/ComputerVision/Models/DescribeImageModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.ProjectOxford.Vision.Contract; 2 | 3 | namespace CognitiveServicesDemo.Areas.ComputerVision.Models 4 | { 5 | public class DescribeImageModel 6 | { 7 | public AnalysisResult Result; 8 | public string ImageDump; 9 | } 10 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/ComputerVision/Models/HandwritingModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.ProjectOxford.Vision.Contract; 2 | 3 | namespace CognitiveServicesDemo.Areas.ComputerVision.Models 4 | { 5 | public class HandwritingModel 6 | { 7 | public HandwritingTextResult Result; 8 | public string ImageDump; 9 | } 10 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/ComputerVision/Models/RecognizeTextModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.ProjectOxford.Vision.Contract; 2 | 3 | namespace CognitiveServicesDemo.Areas.ComputerVision.Models 4 | { 5 | public class RecognizeTextModel 6 | { 7 | public OcrResults Results; 8 | public string ImageDump; 9 | } 10 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/ComputerVision/Views/Describe/Index.cshtml: -------------------------------------------------------------------------------- 1 | @model DescribeImageModel 2 | @{ 3 | ViewBag.Title = "Describe image"; 4 | } 5 | 6 |

Describe image

7 | 8 | @Html.Partial("_Upload") 9 |   10 | @if (Model != null && !string.IsNullOrEmpty(Model.ImageDump)) 11 | { 12 | 13 |

Description

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 | 49 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 |
Adult content@Model.Result.Adult.IsAdultContent
Racy content@Model.Result.Adult.IsRacyContent
Categories@string.Join(", ", Model.Result.Categories.Select(c => c.Name + " (" + c.Detail + ")").ToArray())
Accent color@Model.Result.Color.AccentColor
Dominant background color@Model.Result.Color.DominantColorBackground
Dominant foreground color@Model.Result.Color.DominantColorForeground
Dominant colors@string.Join(", ", Model.Result.Color.DominantColors)
Black-white@Model.Result.Color.IsBWImg
Description 50 | @foreach(var cap in Model.Result.Description.Captions) 51 | { 52 | @cap.Text
53 | } 54 |
Clip art type@Model.Result.ImageType.ClipArtType
Line drawing type@Model.Result.ImageType.LineDrawingType
Metadata@Model.Result.Metadata.Format (@Model.Result.Metadata.Width x @Model.Result.Metadata.Height)
Tags@string.Join(", ", Model.Result.Tags.Select(t => t.Name).ToArray())
73 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/ComputerVision/Views/Handwriting/Index.cshtml: -------------------------------------------------------------------------------- 1 | @model HandwritingModel 2 | @{ 3 | ViewBag.Title = "Regognize handwriting"; 4 | var lineCounter = 0; 5 | } 6 | 7 |

Recognize handwriting

8 | 9 | @Html.Partial("_Upload") 10 |

 

11 | @if (Model != null && !string.IsNullOrEmpty(Model.ImageDump)) 12 | { 13 | 14 | 15 |

Texts

16 | 17 |
    18 | @foreach (var line in Model.Result.Lines) 19 | { 20 | if(lineCounter >= Settings.ImageSquareColors.Length) 21 | { 22 | lineCounter = 0; 23 | } 24 |
  1. 25 | @foreach (var word in line.Words) 26 | { 27 | @word.Text 28 | } 29 |
  2. 30 | { 31 | lineCounter++; 32 | } 33 | } 34 |
35 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/ComputerVision/Views/Shared/_ComputerVisionMenu.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = null; 3 | } 4 |
5 |
    6 |
  • @Html.ActionLink("Describe image", "Index", "Describe")
  • 7 |
  • @Html.ActionLink("Recognize text", "Index", "Text")
  • 8 |
  • @Html.ActionLink("Recognize handwriting", "Index", "Handwriting")
  • 9 |
10 |
11 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/ComputerVision/Views/Text/Index.cshtml: -------------------------------------------------------------------------------- 1 | @model RecognizeTextModel 2 | @{ 3 | ViewBag.Title = "Recognize text"; 4 | } 5 | 6 |

Recognize text

7 | 8 | @Html.Partial("_Upload") 9 | 10 | @if (Model != null && !string.IsNullOrEmpty(Model.ImageDump)) 11 | { 12 | 13 | 14 |

Texts

15 | 16 |
    17 | @foreach(var result in Model.Results.Regions) 18 | { 19 |
  1. 20 | @result.BoundingBox 21 |
      22 | @foreach(var line in result.Lines) 23 | { 24 |
    • 25 | @foreach(var word in line.Words) 26 | { 27 | @word.Text 28 | } 29 |
    • 30 | } 31 |
    32 |
  2. 33 | } 34 |
35 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/ComputerVision/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "~/Views/Shared/_Layout.cshtml"; 3 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/ComputerVision/Views/web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 |
7 |
8 | 9 | 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 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Controllers/DetectController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.Drawing.Imaging; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Web.Mvc; 8 | using CognitiveServicesDemo.Areas.Faces.Models; 9 | using Microsoft.ProjectOxford.Face; 10 | using Microsoft.ProjectOxford.Face.Contract; 11 | 12 | namespace CognitiveServicesDemo.Areas.Faces.Controllers 13 | { 14 | public class DetectController : FacesBaseController 15 | { 16 | public async Task Index() 17 | { 18 | ViewBag.Title = "Detect faces"; 19 | 20 | if (Request.HttpMethod == "GET") 21 | { 22 | return View(); 23 | } 24 | 25 | string imageResult = ""; 26 | 27 | await RunOperationOnImage(async stream => 28 | { 29 | var faces = await FaceClient.DetectAsync(stream); 30 | imageResult = GetInlineImageWithFaces(faces); 31 | }); 32 | 33 | return View((object)imageResult); 34 | } 35 | 36 | public async Task Landmarks() 37 | { 38 | ViewBag.Title = "Face landmarks"; 39 | 40 | if (Request.HttpMethod == "GET") 41 | { 42 | return View("Index"); 43 | } 44 | 45 | var imageResult = ""; 46 | var file = Request.Files[0]; 47 | Face[] faces = new Face[] { }; 48 | 49 | await RunOperationOnImage(async stream => 50 | { 51 | faces = await FaceClient.DetectAsync(stream, returnFaceLandmarks: true); 52 | }); 53 | 54 | ImageToProcess.Seek(0, SeekOrigin.Begin); 55 | using (var img = new Bitmap(ImageToProcess)) 56 | // make copy, drawing on indexed pixel format image is not supported 57 | using (var nonIndexedImg = new Bitmap(img.Width, img.Height)) 58 | using (var g = Graphics.FromImage(nonIndexedImg)) 59 | using (var mem = new MemoryStream()) 60 | { 61 | g.DrawImage(img, 0, 0, img.Width, img.Height); 62 | 63 | var pen = new Pen(Color.Red, 5); 64 | 65 | foreach (var face in faces) 66 | { 67 | var props = typeof(FaceLandmarks).GetProperties(); 68 | foreach(var prop in props) 69 | { 70 | if(prop.PropertyType == typeof(FeatureCoordinate)) 71 | { 72 | var coordinate = (FeatureCoordinate)prop.GetValue(face.FaceLandmarks); 73 | var rect = new Rectangle((int)coordinate.X, (int)coordinate.Y, 2, 2); 74 | g.DrawRectangle(pen, rect); 75 | } 76 | } 77 | } 78 | 79 | nonIndexedImg.Save(mem, ImageFormat.Png); 80 | 81 | var base64 = Convert.ToBase64String(mem.ToArray()); 82 | imageResult = String.Format("data:image/png;base64,{0}", base64); 83 | } 84 | 85 | return View("Index",(object)imageResult); 86 | } 87 | 88 | public async Task Identify() 89 | { 90 | var personGroupId = Request["PersonGroupId"]; 91 | var model = new IdentifyFacesModel(); 92 | 93 | var groups = await FaceClient.ListPersonGroupsAsync(); 94 | model.PersonGroups = groups.Select(g => new SelectListItem 95 | { 96 | Value = g.PersonGroupId, 97 | Text = g.Name 98 | }).ToList(); 99 | 100 | if (Request.HttpMethod == "GET") 101 | { 102 | return View(model); 103 | } 104 | 105 | Face[] faces = new Face[] { }; 106 | Guid[] faceIds = new Guid[] { }; 107 | IdentifyResult[] results = new IdentifyResult[] { }; 108 | 109 | await RunOperationOnImage(async stream => 110 | { 111 | faces = await FaceClient.DetectAsync(stream); 112 | faceIds = faces.Select(f => f.FaceId).ToArray(); 113 | 114 | if (faceIds.Count() > 0) 115 | { 116 | results = await FaceClient.IdentifyAsync(personGroupId, faceIds); 117 | } 118 | }); 119 | 120 | if (faceIds.Length == 0) 121 | { 122 | model.Error = "No faces detected"; 123 | return View(model); 124 | } 125 | 126 | foreach (var result in results) 127 | { 128 | var identifiedFace = new IdentifiedFace(); 129 | identifiedFace.Face = faces.FirstOrDefault(f => f.FaceId == result.FaceId); 130 | 131 | foreach(var candidate in result.Candidates) 132 | { 133 | var person = await FaceClient.GetPersonAsync(personGroupId, candidate.PersonId); 134 | identifiedFace.PersonCandidates.Add(person.PersonId, person.Name); 135 | } 136 | 137 | identifiedFace.Color = Settings.ImageSquareColors[model.IdentifiedFaces.Count]; 138 | model.IdentifiedFaces.Add(identifiedFace); 139 | } 140 | 141 | model.ImageDump = GetInlineImageWithFaces(model.IdentifiedFaces.Select(f => f.Face)); 142 | return View(model); 143 | } 144 | 145 | public async Task Emotions() 146 | { 147 | var personGroupId = Request["PersonGroupId"]; 148 | var model = new IdentifyFacesModel(); 149 | 150 | var groups = await FaceClient.ListPersonGroupsAsync(); 151 | model.PersonGroups = groups.Select(g => new SelectListItem 152 | { 153 | Value = g.PersonGroupId, 154 | Text = g.Name 155 | }).ToList(); 156 | model.PersonGroups.Insert(0, new SelectListItem { Text = "", Value = "" }); 157 | 158 | 159 | if (Request.HttpMethod == "GET") 160 | { 161 | return View(model); 162 | } 163 | 164 | Face[] faces = new Face[] { }; 165 | Guid[] faceIds = new Guid[] { }; 166 | IdentifyResult[] results = new IdentifyResult[] { }; 167 | 168 | await RunOperationOnImage(async stream => 169 | { 170 | var emotionsType = new[] { FaceAttributeType.Emotion }; 171 | faces = await FaceClient.DetectAsync(stream, returnFaceAttributes: emotionsType); 172 | faceIds = faces.Select(f => f.FaceId).ToArray(); 173 | 174 | if (faceIds.Length > 0 && !string.IsNullOrEmpty(personGroupId)) 175 | { 176 | results = await FaceClient.IdentifyAsync(personGroupId, faceIds); 177 | } 178 | }); 179 | 180 | if (faceIds.Length == 0) 181 | { 182 | model.Error = "No faces detected"; 183 | return View(model); 184 | } 185 | 186 | if (!string.IsNullOrEmpty(personGroupId)) 187 | { 188 | foreach (var result in results) 189 | { 190 | var identifiedFace = new IdentifiedFace(); 191 | identifiedFace.Face = faces.FirstOrDefault(f => f.FaceId == result.FaceId); 192 | 193 | foreach (var candidate in result.Candidates) 194 | { 195 | var person = await FaceClient.GetPersonAsync(personGroupId, candidate.PersonId); 196 | 197 | identifiedFace.PersonCandidates.Add(person.PersonId, person.Name); 198 | } 199 | 200 | model.IdentifiedFaces.Add(identifiedFace); 201 | identifiedFace.Color = Settings.ImageSquareColors[model.IdentifiedFaces.Count]; 202 | } 203 | } 204 | else 205 | { 206 | foreach(var face in faces) 207 | { 208 | var identifiedFace = new IdentifiedFace { Face = face }; 209 | model.IdentifiedFaces.Add(identifiedFace); 210 | 211 | identifiedFace.Color = Settings.ImageSquareColors[model.IdentifiedFaces.Count]; 212 | } 213 | } 214 | 215 | 216 | model.ImageDump = GetInlineImageWithIdentifiedFaces(model.IdentifiedFaces); 217 | 218 | return View(model); 219 | } 220 | 221 | public async Task Attributes() 222 | { 223 | var personGroupId = Request["PersonGroupId"]; 224 | var model = new IdentifyFacesModel(); 225 | 226 | var groups = await FaceClient.ListPersonGroupsAsync(); 227 | model.PersonGroups = groups.Select(g => new SelectListItem 228 | { 229 | Value = g.PersonGroupId, 230 | Text = g.Name 231 | }).ToList(); 232 | model.PersonGroups.Insert(0, new SelectListItem { Text = "", Value = "" }); 233 | 234 | if (Request.HttpMethod == "GET") 235 | { 236 | return View(model); 237 | } 238 | 239 | Face[] faces = new Face[] { }; 240 | Guid[] faceIds = new Guid[] { }; 241 | IdentifyResult[] results = new IdentifyResult[] { }; 242 | var faceAttributeTypes = new[] { 243 | FaceAttributeType.Accessories, FaceAttributeType.Age, FaceAttributeType.Blur, 244 | FaceAttributeType.Exposure, FaceAttributeType.FacialHair, FaceAttributeType.Gender, 245 | FaceAttributeType.Glasses, FaceAttributeType.Hair, FaceAttributeType.HeadPose, 246 | FaceAttributeType.Makeup, FaceAttributeType.Noise, FaceAttributeType.Occlusion, 247 | FaceAttributeType.Smile 248 | }; 249 | 250 | await RunOperationOnImage(async stream => 251 | { 252 | faces = await FaceClient.DetectAsync(stream, returnFaceAttributes: faceAttributeTypes); 253 | faceIds = faces.Select(f => f.FaceId).ToArray(); 254 | 255 | if (faceIds.Length > 0 && !string.IsNullOrEmpty(personGroupId)) 256 | { 257 | results = await FaceClient.IdentifyAsync(personGroupId, faceIds); 258 | } 259 | }); 260 | 261 | if (faceIds.Length == 0) 262 | { 263 | model.Error = "No faces detected"; 264 | return View(model); 265 | } 266 | 267 | if (!string.IsNullOrEmpty(personGroupId)) 268 | { 269 | foreach (var result in results) 270 | { 271 | var identifiedFace = new IdentifiedFace(); 272 | identifiedFace.Face = faces.FirstOrDefault(f => f.FaceId == result.FaceId); 273 | 274 | foreach (var candidate in result.Candidates) 275 | { 276 | var person = await FaceClient.GetPersonAsync(personGroupId, candidate.PersonId); 277 | 278 | identifiedFace.PersonCandidates.Add(person.PersonId, person.Name); 279 | } 280 | 281 | identifiedFace.Color = Settings.ImageSquareColors[model.IdentifiedFaces.Count]; 282 | model.IdentifiedFaces.Add(identifiedFace); 283 | } 284 | } 285 | else 286 | { 287 | foreach (var face in faces) 288 | { 289 | var identifiedFace = new IdentifiedFace { Face = face }; 290 | model.IdentifiedFaces.Add(identifiedFace); 291 | 292 | identifiedFace.Color = Settings.ImageSquareColors[model.IdentifiedFaces.Count]; 293 | } 294 | } 295 | 296 | model.ImageDump = GetInlineImageWithIdentifiedFaces(model.IdentifiedFaces); 297 | 298 | return View(model); 299 | } 300 | } 301 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Controllers/FacesBaseController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Drawing; 5 | using System.Drawing.Imaging; 6 | using System.IO; 7 | using System.Web.Mvc; 8 | using CognitiveServicesDemo.Areas.Faces.Models; 9 | using CognitiveServicesDemo.Models; 10 | using Microsoft.ProjectOxford.Face; 11 | using Microsoft.ProjectOxford.Face.Contract; 12 | 13 | namespace CognitiveServicesDemo.Areas.Faces.Controllers 14 | { 15 | public abstract class FacesBaseController : ImageUsingBaseController 16 | { 17 | protected FaceServiceClient FaceClient { get; private set; } 18 | 19 | public FacesBaseController() 20 | { 21 | var apiKey = ConfigurationManager.AppSettings["CognitiveServicesFaceApiKey"]; 22 | var apiRoot = ConfigurationManager.AppSettings["CognitiveServicesFaceApiUrl"]; 23 | FaceClient = new FaceServiceClient(apiKey, apiRoot); 24 | } 25 | 26 | protected string GetInlineImageWithFaces(IEnumerable faces) 27 | { 28 | ImageToProcess.Seek(0, SeekOrigin.Begin); 29 | 30 | using (var img = new Bitmap(ImageToProcess)) 31 | // make copy, drawing on indexed pixel format image is not supported 32 | using (var nonIndexedImg = new Bitmap(img.Width, img.Height)) 33 | using (var g = Graphics.FromImage(nonIndexedImg)) 34 | using (var mem = new MemoryStream()) 35 | { 36 | g.DrawImage(img, 0, 0, img.Width, img.Height); 37 | 38 | var i = 0; 39 | 40 | foreach (var face in faces) 41 | { 42 | var pen = new Pen(Settings.ImageSquareColors[i], 5); 43 | var faceRectangle = face.FaceRectangle; 44 | var rectangle = new Rectangle(faceRectangle.Left, 45 | faceRectangle.Top, 46 | faceRectangle.Width, 47 | faceRectangle.Height); 48 | 49 | g.DrawRectangle(pen, rectangle); 50 | i++; 51 | } 52 | 53 | nonIndexedImg.Save(mem, ImageFormat.Png); 54 | 55 | var base64 = Convert.ToBase64String(mem.ToArray()); 56 | return String.Format("data:image/png;base64,{0}", base64); 57 | } 58 | } 59 | 60 | protected string GetInlineImageWithIdentifiedFaces(IEnumerable faces) 61 | { 62 | ImageToProcess.Seek(0, SeekOrigin.Begin); 63 | 64 | using (var img = new Bitmap(ImageToProcess)) 65 | // make copy, drawing on indexed pixel format image is not supported 66 | using (var nonIndexedImg = new Bitmap(img.Width, img.Height)) 67 | using (var g = Graphics.FromImage(nonIndexedImg)) 68 | using (var mem = new MemoryStream()) 69 | { 70 | g.DrawImage(img, 0, 0, img.Width, img.Height); 71 | 72 | var i = 0; 73 | 74 | foreach (var face in faces) 75 | { 76 | var pen = new Pen(face.Color, 5); 77 | var faceRectangle = face.Face.FaceRectangle; 78 | var rectangle = new Rectangle(faceRectangle.Left, 79 | faceRectangle.Top, 80 | faceRectangle.Width, 81 | faceRectangle.Height); 82 | 83 | g.DrawRectangle(pen, rectangle); 84 | i++; 85 | } 86 | 87 | nonIndexedImg.Save(mem, ImageFormat.Png); 88 | 89 | var base64 = Convert.ToBase64String(mem.ToArray()); 90 | return String.Format("data:image/png;base64,{0}", base64); 91 | } 92 | } 93 | 94 | protected override void OnActionExecuting(ActionExecutingContext filterContext) 95 | { 96 | base.OnActionExecuting(filterContext); 97 | 98 | ViewBag.LeftMenu = "_FacesMenu"; 99 | } 100 | 101 | protected override void OnException(ExceptionContext filterContext) 102 | { 103 | base.OnException(filterContext); 104 | 105 | if(filterContext.ExceptionHandled) 106 | { 107 | return; 108 | } 109 | 110 | var message = filterContext.Exception.Message; 111 | var code = ""; 112 | 113 | if (filterContext.Exception is FaceAPIException) 114 | { 115 | var faex = filterContext.Exception as FaceAPIException; 116 | message = faex.ErrorMessage; 117 | code = faex.ErrorCode; 118 | } 119 | 120 | filterContext.Result = new ViewResult 121 | { 122 | ViewName = "Error", 123 | ViewData = new ViewDataDictionary(filterContext.Controller.ViewData) 124 | { 125 | Model = new ErrorModel { Code = code, Message = message } 126 | } 127 | }; 128 | 129 | filterContext.ExceptionHandled = true; 130 | } 131 | 132 | protected override void Dispose(bool disposing) 133 | { 134 | base.Dispose(disposing); 135 | 136 | if(FaceClient != null) 137 | { 138 | FaceClient.Dispose(); 139 | FaceClient = null; 140 | } 141 | } 142 | } 143 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | 3 | namespace CognitiveServicesDemo.Areas.Faces.Controllers 4 | { 5 | public class HomeController : Controller 6 | { 7 | public ActionResult Index() 8 | { 9 | return RedirectToAction("Index", "Detect"); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Controllers/PeopleController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Threading.Tasks; 4 | using System.Web.Mvc; 5 | using Microsoft.ProjectOxford.Face; 6 | using Microsoft.ProjectOxford.Face.Contract; 7 | 8 | namespace CognitiveServicesDemo.Areas.Faces.Controllers 9 | { 10 | public class PeopleController : FacesBaseController 11 | { 12 | public async Task Index(string id) 13 | { 14 | if(string.IsNullOrEmpty(id)) 15 | { 16 | return HttpNotFound("Person group ID is missing"); 17 | } 18 | 19 | var model = await FaceClient.ListPersonsAsync(id); 20 | ViewBag.PersonGroupId = id; 21 | 22 | return View(model); 23 | } 24 | 25 | public async Task Details(string id, Guid? personId) 26 | { 27 | if(string.IsNullOrEmpty(id)) 28 | { 29 | return HttpNotFound(); 30 | } 31 | 32 | if(personId == null) 33 | { 34 | return HttpNotFound(); 35 | } 36 | 37 | var model = await FaceClient.GetPersonAsync(id, personId.Value); 38 | ViewBag.PersonGroupId = id; 39 | 40 | return View(model); 41 | } 42 | 43 | public ActionResult Create(string id) 44 | { 45 | ViewBag.PersonGroupId = id; 46 | 47 | return View("Edit", new Person()); 48 | } 49 | 50 | [HttpPost] 51 | public async Task Create(Person person) 52 | { 53 | return await Edit(person); 54 | } 55 | 56 | public async Task Edit(string id, Guid personId) 57 | { 58 | ViewBag.PersonGroupId = id; 59 | 60 | var model = await FaceClient.GetPersonAsync(id, personId); 61 | 62 | return View(model); 63 | } 64 | 65 | [HttpPost] 66 | public async Task Edit(Person person) 67 | { 68 | var personGroupId = Request.Form["PersonGroupId"]; 69 | if(string.IsNullOrEmpty(personGroupId)) 70 | { 71 | return HttpNotFound("PersonGroupId is missing"); 72 | } 73 | 74 | if(!ModelState.IsValid) 75 | { 76 | ViewBag.PersonGroupId = personGroupId; 77 | return View(person); 78 | } 79 | 80 | try 81 | { 82 | if (person.PersonId == Guid.Empty) 83 | { 84 | await FaceClient.CreatePersonAsync(personGroupId, person.Name, person.UserData); 85 | } 86 | else 87 | { 88 | await FaceClient.UpdatePersonAsync(personGroupId, person.PersonId, person.Name, person.UserData); 89 | } 90 | 91 | return RedirectToAction("Index", new { id = personGroupId }); 92 | } 93 | catch (FaceAPIException fex) 94 | { 95 | ModelState.AddModelError(string.Empty, fex.ErrorMessage); 96 | } 97 | 98 | return View(person); 99 | } 100 | 101 | [HttpGet] 102 | public ActionResult AddFace(string id, string personId) 103 | { 104 | return View(); 105 | } 106 | 107 | [HttpPost] 108 | public async Task AddFace() 109 | { 110 | var id = Request["id"]; 111 | var personId = Guid.Parse(Request["personId"]); 112 | 113 | try 114 | { 115 | Request.Files[0].InputStream.Seek(0,SeekOrigin.Begin); 116 | await FaceClient.AddPersonFaceAsync(id, personId, Request.Files[0].InputStream); 117 | } 118 | catch (Exception ex) 119 | { 120 | ViewBag.Error = ex.Message; 121 | return View(); 122 | } 123 | 124 | return RedirectToAction("Index", new { id = id }); 125 | } 126 | 127 | [HttpGet] 128 | public async Task Delete(string id, string personId) 129 | { 130 | var personGuid = Guid.Parse(Request["personId"]); 131 | await FaceClient.DeletePersonAsync(id, personGuid); 132 | return RedirectToAction("Index", new { id = id }); 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Controllers/PersonGroupsController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using System.Web.Mvc; 4 | using CognitiveServicesDemo.Areas.Faces.Models; 5 | using Microsoft.ProjectOxford.Face; 6 | using Microsoft.ProjectOxford.Face.Contract; 7 | 8 | namespace CognitiveServicesDemo.Areas.Faces.Controllers 9 | { 10 | public class PersonGroupsController : FacesBaseController 11 | { 12 | public async Task Index() 13 | { 14 | var groups = await FaceClient.ListPersonGroupsAsync(); 15 | 16 | return View(groups); 17 | } 18 | 19 | public async Task Details(string id) 20 | { 21 | if(string.IsNullOrEmpty(id)) 22 | { 23 | 24 | } 25 | 26 | var model = new PersonGroupDetailsModel(); 27 | model.PersonGroup = await FaceClient.GetPersonGroupAsync(id); 28 | 29 | try 30 | { 31 | model.TrainingStatus = await FaceClient.GetPersonGroupTrainingStatusAsync(id); 32 | } 33 | catch (FaceAPIException fex) 34 | { 35 | ModelState.AddModelError(string.Empty, fex.ErrorMessage); 36 | } 37 | 38 | return View(model); 39 | } 40 | 41 | [HttpGet] 42 | public ActionResult Create() 43 | { 44 | return View(new PersonGroup()); 45 | } 46 | 47 | [HttpPost] 48 | public async Task Create(PersonGroup model) 49 | { 50 | try 51 | { 52 | await FaceClient.CreatePersonGroupAsync(model.PersonGroupId, model.Name, model.UserData); 53 | } 54 | catch (FaceAPIException fex) 55 | { 56 | ModelState.AddModelError(string.Empty, fex.ErrorMessage); 57 | return View(model); 58 | } 59 | catch (Exception ex) 60 | { 61 | ModelState.AddModelError(string.Empty, ex.Message); 62 | return View(model); 63 | } 64 | 65 | return RedirectToAction("Index"); 66 | } 67 | 68 | [HttpGet] 69 | public async Task Edit(string id) 70 | { 71 | var model = await FaceClient.GetPersonGroupAsync(id); 72 | 73 | return View(model); 74 | } 75 | 76 | [HttpPost] 77 | public async Task Edit(PersonGroup model) 78 | { 79 | await FaceClient.UpdatePersonGroupAsync(model.PersonGroupId, model.Name, model.UserData); 80 | 81 | return RedirectToAction("Index"); 82 | } 83 | 84 | public async Task Train(string id) 85 | { 86 | await FaceClient.TrainPersonGroupAsync(id); 87 | 88 | return RedirectToAction("Details", new { id = id }); 89 | } 90 | 91 | [HttpGet] 92 | public async Task Delete(string id) 93 | { 94 | await FaceClient.DeletePersonGroupAsync(id); 95 | return RedirectToAction("Index", new { id = id }); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/FacesAreaRegistration.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | 3 | namespace CognitiveServicesDemo.Areas.Faces 4 | { 5 | public class FacesAreaRegistration : AreaRegistration 6 | { 7 | public override string AreaName 8 | { 9 | get 10 | { 11 | return "Faces"; 12 | } 13 | } 14 | 15 | public override void RegisterArea(AreaRegistrationContext context) 16 | { 17 | context.MapRoute( 18 | "Faces_default", 19 | "Faces/{controller}/{action}/{id}", 20 | new { action = "Index", id = UrlParameter.Optional } 21 | ); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Models/IdentifyFacesModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.Web.Mvc; 5 | using Microsoft.ProjectOxford.Common.Contract; 6 | using Microsoft.ProjectOxford.Face.Contract; 7 | 8 | namespace CognitiveServicesDemo.Areas.Faces.Models 9 | { 10 | public class IdentifyFacesModel 11 | { 12 | public IList PersonGroups = new List(); 13 | public IList IdentifiedFaces = new List(); 14 | public string ImageDump; 15 | public string Error; 16 | } 17 | 18 | public class IdentifiedFace 19 | { 20 | public Face Face; 21 | public Color Color; 22 | public EmotionScores Emotions; 23 | 24 | public IDictionary PersonCandidates = new Dictionary(); 25 | 26 | public string GetHtmlColor() 27 | { 28 | return "#" + Color.R.ToString("X2") + Color.G.ToString("X2") + Color.B.ToString("X2"); 29 | 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Models/PersonGroupDetailsModel.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.ProjectOxford.Face.Contract; 2 | 3 | namespace CognitiveServicesDemo.Areas.Faces.Models 4 | { 5 | public class PersonGroupDetailsModel 6 | { 7 | public PersonGroup PersonGroup; 8 | public TrainingStatus TrainingStatus; 9 | } 10 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Views/Detect/Attributes.cshtml: -------------------------------------------------------------------------------- 1 | @model IdentifyFacesModel 2 | @{ 3 | ViewBag.Title = "Face attributes"; 4 | var groups = (PersonGroup[])ViewBag.PersonGroups; 5 | } 6 | 16 |

Face attributes

17 | 18 | @if (Model.Error != null) 19 | { 20 | @Model.Error 21 | } 22 | 23 | @Html.Partial("_UploadWithPersonGroups", Model.PersonGroups) 24 | 25 | @if (Model.ImageDump != null) 26 | { 27 |
28 | 29 |

Faces

30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | @foreach (var face in Model.IdentifiedFaces) 60 | { 61 | 62 | 66 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | @if (face.Face.FaceAttributes.Hair.HairColor.Length > 0) 86 | { 87 | 90 | } 91 | else 92 | { 93 | 94 | } 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | } 108 | 109 |
PersonAccessoriesAgeBlurExposureBeardMoustacheSideburnsGenderGlassesBaldHair colorHair invisibleHead pose pitchHead pose rollHead pose yawEye makeupLips makeupNoiseEye occludedForehead occludedMouth occludedSmile
63 |
64 | @string.Join(", ", face.PersonCandidates.Select(p => p.Value).ToArray()) 65 |
67 | @if (face.Face.FaceAttributes.Accessories != null) 68 | { 69 | foreach (var accessory in face.Face.FaceAttributes.Accessories) 70 | { 71 | @accessory.Type 72 | } 73 | } 74 |   75 | @face.Face.FaceAttributes.Age.ToString("0")@face.Face.FaceAttributes.Blur.BlurLevel@face.Face.FaceAttributes.Exposure.ExposureLevel@face.Face.FaceAttributes.FacialHair.Beard.ToString("0")%@face.Face.FaceAttributes.FacialHair.Moustache.ToString("0")%@face.Face.FaceAttributes.FacialHair.Sideburns.ToString("0")%@face.Face.FaceAttributes.Gender@face.Face.FaceAttributes.Glasses@face.Face.FaceAttributes.Hair.Bald.ToString("0")% 88 | @string.Join(", ", face.Face.FaceAttributes.Hair.HairColor.Select(c => c.Color.ToString())) 89 |  @face.Face.FaceAttributes.Hair.Invisible@face.Face.FaceAttributes.HeadPose.Pitch@face.Face.FaceAttributes.HeadPose.Roll@face.Face.FaceAttributes.HeadPose.Yaw@face.Face.FaceAttributes.Makeup.EyeMakeup@face.Face.FaceAttributes.Makeup.LipMakeup@face.Face.FaceAttributes.Noise.NoiseLevel@face.Face.FaceAttributes.Occlusion.EyeOccluded@face.Face.FaceAttributes.Occlusion.ForeheadOccluded@face.Face.FaceAttributes.Occlusion.MouthOccluded@face.Face.FaceAttributes.Smile
110 | } 111 | @section scripts { 112 | 157 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Views/Detect/Emotions.cshtml: -------------------------------------------------------------------------------- 1 | @model IdentifyFacesModel 2 | @{ 3 | ViewBag.Title = "Emotions"; 4 | var groups = (PersonGroup[])ViewBag.PersonGroups; 5 | } 6 | 7 |

Emotions

8 | 9 | @if (Model.Error != null) 10 | { 11 | @Model.Error 12 | } 13 | 14 | @Html.Partial("_UploadWithPersonGroups", Model.PersonGroups) 15 | 16 | @if (Model.ImageDump != null) 17 | { 18 |
19 | 20 |

Faces

21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | @foreach (var face in Model.IdentifiedFaces) 38 | { 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | } 52 | 53 |
PersonAngerContemptDisgustFearHappinessNeutralSadnessSurprise
@string.Join(", ", face.PersonCandidates.Select(p => p.Value).ToArray())@face.Face.FaceAttributes.Emotion.Anger@face.Face.FaceAttributes.Emotion.Contempt@face.Face.FaceAttributes.Emotion.Disgust@face.Face.FaceAttributes.Emotion.Fear@face.Face.FaceAttributes.Emotion.Happiness@face.Face.FaceAttributes.Emotion.Neutral@face.Face.FaceAttributes.Emotion.Sadness@face.Face.FaceAttributes.Emotion.Surprise
54 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Views/Detect/Identify.cshtml: -------------------------------------------------------------------------------- 1 | @model IdentifyFacesModel 2 | @{ 3 | ViewBag.Title = "Identify"; 4 | var groups = (PersonGroup[])ViewBag.PersonGroups; 5 | } 6 | 7 |

Identify

8 | 9 | @if (Model.Error != null) 10 | { 11 | @Model.Error 12 | } 13 | 14 | @Html.Partial("_UploadWithPersonGroups", Model.PersonGroups) 15 | 16 | @if (Model.ImageDump != null) 17 | { 18 |
19 | 20 |

Faces

21 | foreach (var face in Model.IdentifiedFaces) 22 | { 23 |
24 | @string.Join(", ", face.PersonCandidates.Select(p => p.Value).ToArray())
25 | } 26 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Views/Detect/Index.cshtml: -------------------------------------------------------------------------------- 1 | @model string 2 | 3 |

@ViewBag.Title

4 | 5 | @Html.Partial("_Upload") 6 | 7 | @if (Model != null) 8 | { 9 | 10 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Views/Detect/_UploadWithPersonGroups.cshtml: -------------------------------------------------------------------------------- 1 | @model IList 2 | @{ 3 | Layout = null; 4 | } 5 |
6 | Upload photo to analyze:
7 |
8 | @Html.DropDownList("personGroupId", Model) 9 |
10 | 11 |
12 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Views/People/AddFace.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewBag.Title = "AddFace"; 3 | } 4 | 5 |

Add face

6 | 7 | @if (ViewBag.Error != null) 8 | { 9 | @ViewBag.Error 10 | } 11 | 12 |
13 | Upload person face:
14 | 15 | 16 | 17 |
18 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Views/People/Details.cshtml: -------------------------------------------------------------------------------- 1 | @model Person 2 | @{ 3 | ViewBag.Title = "Details"; 4 | } 5 | 6 |

Person details

7 | 8 |
9 |
10 |
11 | 12 |
13 | @Html.DisplayNameFor(model => model.PersonId) 14 |
15 |
16 | @Html.DisplayFor(model => model.PersonId) 17 |
18 | 19 |
20 | @Html.DisplayNameFor(model => model.Name) 21 |
22 |
23 | @Html.DisplayFor(model => model.Name) 24 |
25 | 26 |
27 | @Html.DisplayNameFor(model => model.UserData) 28 |
29 |
30 | @Html.DisplayFor(model => model.UserData) 31 |
32 | 33 |
34 | @Html.DisplayNameFor(model => model.PersistedFaceIds) 35 |
36 |
37 | @foreach (var id in Model.PersistedFaceIds) 38 | { 39 | @id
40 | } 41 |
42 |
43 |
44 |

45 | @Html.ActionLink("Back to List", "Index", new { id = Request.RequestContext.RouteData.Values["id"] }) 46 |

-------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Views/People/Edit.cshtml: -------------------------------------------------------------------------------- 1 | @model Person 2 | @{ 3 | var title = "Edit person"; 4 | var isNew = (Model.PersonId == Guid.Empty); 5 | 6 | if (isNew) 7 | { 8 | title = "Add person"; 9 | } 10 | ViewBag.Title = title; 11 | 12 | } 13 | 14 |

@title

15 | 16 | @using (Html.BeginForm()) 17 | { 18 | @Html.AntiForgeryToken() 19 | 20 |
21 |
22 | @Html.ValidationSummary(false, null, new { @class = "text-danger" }) 23 | 24 |
25 | @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" }) 26 |
27 | @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } }) 28 | @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" }) 29 |
30 |
31 | 32 |
33 | @Html.LabelFor(model => model.UserData, htmlAttributes: new { @class = "control-label col-md-2" }) 34 |
35 | @Html.TextAreaFor(model => model.UserData, new { htmlAttributes = new { @class = "form-control" } }) 36 | @Html.ValidationMessageFor(model => model.UserData, "", new { @class = "text-danger" }) 37 |
38 |
39 | 40 | 41 | @Html.HiddenFor(m => m.PersonId); 42 | 43 |
44 |
45 | 46 |
47 |
48 |
49 | } 50 | 51 |
52 | @Html.ActionLink("Back to List", "Index", "People", new { id = ViewBag.PersonGroupId }, null) 53 |
-------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Views/People/Index.cshtml: -------------------------------------------------------------------------------- 1 | @model IEnumerable 2 | @{ 3 | ViewBag.Title = "People"; 4 | } 5 | 6 |

People

7 | 8 |

9 | @Html.ActionLink("Create New", "Create", new { id = ViewBag.PersonGroupId }) 10 |

11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | @foreach (var item in Model) 20 | { 21 | 22 | 23 | 24 | 30 | 31 | } 32 |
IDName
@item.PersonId@item.Name 25 | @Html.ActionLink("Details", "Details", new { id = ViewBag.PersonGroupId, personId = item.PersonId }) | 26 | @Html.ActionLink("Edit", "Edit", new { id = ViewBag.PersonGroupId, personId = item.PersonId }) | 27 | @Html.ActionLink("Add face", "AddFace", new { id = ViewBag.PersonGroupId, personId = item.PersonId }) | 28 | @Html.ActionLink("Delete", "Delete", new { id = ViewBag.PersonGroupId, personId = item.PersonId }) 29 |
-------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Views/PersonGroups/Create.cshtml: -------------------------------------------------------------------------------- 1 | @model PersonGroup 2 | @{ 3 | ViewBag.Title = "Create person group"; 4 | } 5 | 6 |

Create person group

7 | 8 | @using (Html.BeginForm()) 9 | { 10 | @Html.AntiForgeryToken() 11 | 12 |
13 |
14 | @Html.ValidationSummary(false, null, new { @class = "text-danger" }) 15 | 16 |
17 | @Html.LabelFor(model => model.PersonGroupId, htmlAttributes: new { @class = "control-label col-md-2" }) 18 |
19 | @Html.EditorFor(model => model.PersonGroupId, new { htmlAttributes = new { @class = "form-control" } }) 20 | @Html.ValidationMessageFor(model => model.PersonGroupId, "", new { @class = "text-danger" }) 21 |
22 |
23 | 24 |
25 | @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" }) 26 |
27 | @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } }) 28 | @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" }) 29 |
30 |
31 | 32 |
33 | @Html.LabelFor(model => model.UserData, htmlAttributes: new { @class = "control-label col-md-2" }) 34 |
35 | @Html.TextAreaFor(model => model.UserData, new { htmlAttributes = new { @class = "form-control" } }) 36 | @Html.ValidationMessageFor(model => model.UserData, "", new { @class = "text-danger" }) 37 |
38 |
39 | 40 |
41 |
42 | 43 |
44 |
45 |
46 | } 47 | 48 |
49 | @Html.ActionLink("Back to List", "PersonGroups") 50 |
-------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Views/PersonGroups/Details.cshtml: -------------------------------------------------------------------------------- 1 | @model PersonGroupDetailsModel 2 | @{ 3 | ViewBag.Title = "Person group " + Model.PersonGroup.Name; 4 | } 5 | 6 |

Person group details

7 | 8 |
9 | @Html.ValidationSummary(false, null, new { @class = "text-danger" }) 10 |
11 |
12 | 13 |
14 | @Html.DisplayNameFor(model => model.PersonGroup.PersonGroupId) 15 |
16 |
17 | @Html.DisplayFor(model => model.PersonGroup.PersonGroupId) 18 |
19 | 20 |
21 | @Html.DisplayNameFor(model => model.PersonGroup.Name) 22 |
23 |
24 | @Html.DisplayFor(model => model.PersonGroup.Name) 25 |
26 | 27 |
28 | @Html.DisplayNameFor(model => model.PersonGroup.UserData) 29 |
30 |
31 | @Html.DisplayFor(model => model.PersonGroup.UserData) 32 |
33 |
34 | @if (Model.TrainingStatus == null) 35 | { 36 |
37 | TrainingStatus 38 |
39 |
40 | None 41 |
42 | } 43 | else 44 | { 45 |
46 | TrainingStatus 47 |
48 |
49 | @Model.TrainingStatus.Status 50 |
51 | 52 |
53 | Created 54 |
55 |
56 | @Model.TrainingStatus.CreatedDateTime 57 |
58 | 59 |
60 | Last actitivity 61 |
62 |
63 | @Model.TrainingStatus.LastActionDateTime 64 |
65 | 66 |
67 | Message 68 |
69 |
70 | @Model.TrainingStatus.Message 71 |
72 | } 73 | 74 |
75 |
76 |

77 | @Html.ActionLink("Back to List", "Index") 78 |

-------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Views/PersonGroups/Edit.cshtml: -------------------------------------------------------------------------------- 1 | @model PersonGroup 2 | @{ 3 | ViewBag.Title = "Edit person group"; 4 | } 5 | 6 |

Create person group

7 | 8 | @using (Html.BeginForm()) 9 | { 10 | @Html.AntiForgeryToken() 11 | 12 |
13 |
14 | @Html.ValidationSummary(false, null, new { @class = "text-danger" }) 15 | @Html.HiddenFor(m => m.PersonGroupId) 16 | 17 |
18 | @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" }) 19 |
20 | @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } }) 21 | @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" }) 22 |
23 |
24 | 25 |
26 | @Html.LabelFor(model => model.UserData, htmlAttributes: new { @class = "control-label col-md-2" }) 27 |
28 | @Html.TextAreaFor(model => model.UserData, new { htmlAttributes = new { @class = "form-control" } }) 29 | @Html.ValidationMessageFor(model => model.UserData, "", new { @class = "text-danger" }) 30 |
31 |
32 | 33 |
34 |
35 | 36 |
37 |
38 |
39 | } 40 | 41 |
42 | @Html.ActionLink("Back to List", "PersonGroups") 43 |
-------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Views/PersonGroups/Index.cshtml: -------------------------------------------------------------------------------- 1 | @model IEnumerable 2 | @{ 3 | ViewBag.Title = "Person groups"; 4 | } 5 | 6 |

Person groups

7 | 8 |

9 | @Html.ActionLink("Create New", "Create") 10 |

11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | @foreach (var item in Model) 20 | { 21 | 22 | 23 | 24 | 31 | 32 | } 33 |
IDName
@item.PersonGroupId@item.Name 25 | @Html.ActionLink("Details", "Details", new { id = item.PersonGroupId }) | 26 | @Html.ActionLink("Edit", "Edit", new { id = item.PersonGroupId }) | 27 | @Html.ActionLink("Train", "Train", new { id = item.PersonGroupId }) | 28 | @Html.ActionLink("People", "Index", "People", new { id = item.PersonGroupId }, new { }) | 29 | @Html.ActionLink("Delete", "Delete", new { id = item.PersonGroupId }) 30 |
-------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Views/Shared/_FacesMenu.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = null; 3 | } 4 |
5 |
    6 |
  • @Html.ActionLink("Detect faces", "Index", "Detect")
  • 7 |
  • @Html.ActionLink("Landmarks", "Landmarks", "Detect")
  • 8 |
  • @Html.ActionLink("Identify faces", "Identify", "Detect")
  • 9 |
  • @Html.ActionLink("Emotions", "Emotions", "Detect")
  • 10 |
  • @Html.ActionLink("Attributes", "Attributes", "Detect")
  • 11 |
  • @Html.ActionLink("Person groups", "Index", "PersonGroups")
  • 12 |
13 |
-------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "~/Views/Shared/_Layout.cshtml"; 3 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/Faces/Views/web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 |
7 |
8 | 9 | 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 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/Areas/ImageUsingBaseController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.Drawing.Drawing2D; 4 | using System.IO; 5 | using System.Threading.Tasks; 6 | using System.Web.Mvc; 7 | 8 | namespace CognitiveServicesDemo.Areas 9 | { 10 | public abstract class ImageUsingBaseController : Controller 11 | { 12 | protected Stream ImageToProcess = new MemoryStream(); 13 | 14 | protected void ResizeImage(Stream fromStream, Stream toStream) 15 | { 16 | var image = Image.FromStream(fromStream); 17 | 18 | if (image.Width <= 1200) 19 | { 20 | fromStream.Seek(0, SeekOrigin.Begin); 21 | fromStream.CopyTo(toStream); 22 | image.Dispose(); 23 | return; 24 | } 25 | var scaleFactor = 1200 / (double)image.Width; 26 | var newWidth = 1200; 27 | var newHeight = (int)(image.Height * scaleFactor); 28 | var thumbnailBitmap = new Bitmap(newWidth, newHeight); 29 | 30 | var thumbnailGraph = Graphics.FromImage(thumbnailBitmap); 31 | thumbnailGraph.CompositingQuality = CompositingQuality.HighQuality; 32 | thumbnailGraph.SmoothingMode = SmoothingMode.HighQuality; 33 | thumbnailGraph.InterpolationMode = InterpolationMode.HighQualityBicubic; 34 | 35 | var imageRectangle = new Rectangle(0, 0, newWidth, newHeight); 36 | thumbnailGraph.DrawImage(image, imageRectangle); 37 | 38 | thumbnailBitmap.Save(toStream, image.RawFormat); 39 | 40 | thumbnailGraph.Dispose(); 41 | thumbnailBitmap.Dispose(); 42 | image.Dispose(); 43 | 44 | toStream.Seek(0, SeekOrigin.Begin); 45 | } 46 | 47 | protected async Task RunOperationOnImage(Func func) 48 | { 49 | ImageToProcess.Seek(0, SeekOrigin.Begin); 50 | 51 | using (var temporaryStream = new MemoryStream()) 52 | { 53 | ImageToProcess.CopyTo(temporaryStream); 54 | temporaryStream.Seek(0, SeekOrigin.Begin); 55 | await func(temporaryStream); 56 | } 57 | } 58 | 59 | protected override void OnActionExecuting(ActionExecutingContext filterContext) 60 | { 61 | base.OnActionExecuting(filterContext); 62 | 63 | if (Request.Files.Count > 0) 64 | { 65 | ResizeImage(Request.Files[0].InputStream, ImageToProcess); 66 | } 67 | } 68 | 69 | protected override void Dispose(bool disposing) 70 | { 71 | base.Dispose(disposing); 72 | 73 | if (ImageToProcess != null) 74 | { 75 | ImageToProcess.Dispose(); 76 | ImageToProcess = null; 77 | } 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/CognitiveServicesDemo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | Debug 8 | AnyCPU 9 | 10 | 11 | 2.0 12 | {4777D685-545A-4C69-8E03-AAAE231C1DD4} 13 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 14 | Library 15 | Properties 16 | CognitiveServicesDemo 17 | CognitiveServicesDemo 18 | v4.7 19 | false 20 | true 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | true 33 | full 34 | false 35 | bin\ 36 | DEBUG;TRACE 37 | prompt 38 | 4 39 | 40 | 41 | true 42 | pdbonly 43 | true 44 | bin\ 45 | TRACE 46 | prompt 47 | 4 48 | 49 | 50 | 51 | ..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll 52 | True 53 | 54 | 55 | ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll 56 | 57 | 58 | 59 | ..\packages\Microsoft.ProjectOxford.Common.1.0.324\lib\portable-net45+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\Microsoft.ProjectOxford.Common.dll 60 | True 61 | 62 | 63 | ..\packages\Microsoft.ProjectOxford.Face.1.3.0\lib\portable-net45+wp80+win8+wpa81+aspnetcore50\Microsoft.ProjectOxford.Face.dll 64 | 65 | 66 | ..\packages\Microsoft.ProjectOxford.Vision.1.0.393\lib\portable-net45+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\Microsoft.ProjectOxford.Vision.dll 67 | 68 | 69 | ..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | ..\packages\System.IO.4.3.0\lib\net462\System.IO.dll 78 | 79 | 80 | ..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll 81 | 82 | 83 | ..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll 84 | True 85 | 86 | 87 | ..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll 88 | True 89 | 90 | 91 | ..\packages\System.Runtime.4.3.1\lib\net462\System.Runtime.dll 92 | 93 | 94 | 95 | ..\packages\System.Runtime.Serialization.Primitives.4.3.0\lib\net46\System.Runtime.Serialization.Primitives.dll 96 | 97 | 98 | ..\packages\System.Security.Cryptography.Algorithms.4.3.1\lib\net463\System.Security.Cryptography.Algorithms.dll 99 | 100 | 101 | ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll 102 | 103 | 104 | ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll 105 | 106 | 107 | ..\packages\System.Security.Cryptography.X509Certificates.4.3.2\lib\net461\System.Security.Cryptography.X509Certificates.dll 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.Helpers.dll 118 | 119 | 120 | ..\packages\Microsoft.AspNet.Mvc.5.2.7\lib\net45\System.Web.Mvc.dll 121 | 122 | 123 | ..\packages\Microsoft.AspNet.Razor.3.2.7\lib\net45\System.Web.Razor.dll 124 | 125 | 126 | 127 | ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.dll 128 | 129 | 130 | ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Deployment.dll 131 | 132 | 133 | ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Razor.dll 134 | 135 | 136 | 137 | 138 | 139 | True 140 | ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll 141 | 142 | 143 | 144 | 145 | ..\packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.Web.Optimization.dll 146 | 147 | 148 | 149 | ..\packages\WebGrease.1.6.0\lib\WebGrease.dll 150 | True 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | Global.asax 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | Web.config 239 | 240 | 241 | Web.config 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 10.0 264 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | True 277 | True 278 | 28883 279 | / 280 | http://localhost:28883/ 281 | False 282 | False 283 | 284 | 285 | False 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 294 | 295 | 296 | 297 | 298 | 299 | 305 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/Content/Site.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 50px; 3 | padding-bottom: 20px; 4 | } 5 | 6 | /* Set padding to keep content from hitting the edges */ 7 | .body-content { 8 | padding-left: 15px; 9 | padding-right: 15px; 10 | } 11 | 12 | /* Override the default bootstrap behavior where horizontal description lists 13 | will truncate terms that are too long to fit in the left column 14 | */ 15 | .dl-horizontal dt { 16 | white-space: normal; 17 | } 18 | 19 | /* Set width on the form input elements since they're 100% wide by default */ 20 | input, 21 | select, 22 | textarea { 23 | max-width: 280px; 24 | } 25 | 26 | th { padding: 3px; } 27 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | 3 | namespace CognitiveServicesDemo.Controllers 4 | { 5 | public class HomeController : Controller 6 | { 7 | public ActionResult Index() 8 | { 9 | return View(); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="CognitiveServicesDemo.MvcApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System.Web; 2 | using System.Web.Mvc; 3 | using System.Web.Optimization; 4 | using System.Web.Routing; 5 | 6 | namespace CognitiveServicesDemo 7 | { 8 | public class MvcApplication : HttpApplication 9 | { 10 | 11 | protected void Application_Start() 12 | { 13 | AreaRegistration.RegisterAllAreas(); 14 | FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 15 | RouteConfig.RegisterRoutes(RouteTable.Routes); 16 | BundleConfig.RegisterBundles(BundleTable.Bundles); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/Models/ErrorModel.cs: -------------------------------------------------------------------------------- 1 | namespace CognitiveServicesDemo.Models 2 | { 3 | public class ErrorModel 4 | { 5 | public string Code; 6 | public string Message; 7 | } 8 | } -------------------------------------------------------------------------------- /CognitiveServicesDemo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("CognitiveServicesDemo")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("CognitiveServicesDemo")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("aea878df-a397-4ce2-94d9-f2242fd6415a")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/Scripts/jquery.validate.min.js: -------------------------------------------------------------------------------- 1 | /*! jQuery Validation Plugin - v1.17.0 - 7/29/2017 2 | * https://jqueryvalidation.org/ 3 | * Copyright (c) 2017 Jörn Zaefferer; Licensed MIT */ 4 | !function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof module&&module.exports?module.exports=a(require("jquery")):a(jQuery)}(function(a){a.extend(a.fn,{validate:function(b){if(!this.length)return void(b&&b.debug&&window.console&&console.warn("Nothing selected, can't validate, returning nothing."));var c=a.data(this[0],"validator");return c?c:(this.attr("novalidate","novalidate"),c=new a.validator(b,this[0]),a.data(this[0],"validator",c),c.settings.onsubmit&&(this.on("click.validate",":submit",function(b){c.submitButton=b.currentTarget,a(this).hasClass("cancel")&&(c.cancelSubmit=!0),void 0!==a(this).attr("formnovalidate")&&(c.cancelSubmit=!0)}),this.on("submit.validate",function(b){function d(){var d,e;return c.submitButton&&(c.settings.submitHandler||c.formSubmitted)&&(d=a("").attr("name",c.submitButton.name).val(a(c.submitButton).val()).appendTo(c.currentForm)),!c.settings.submitHandler||(e=c.settings.submitHandler.call(c,c.currentForm,b),d&&d.remove(),void 0!==e&&e)}return c.settings.debug&&b.preventDefault(),c.cancelSubmit?(c.cancelSubmit=!1,d()):c.form()?c.pendingRequest?(c.formSubmitted=!0,!1):d():(c.focusInvalid(),!1)})),c)},valid:function(){var b,c,d;return a(this[0]).is("form")?b=this.validate().form():(d=[],b=!0,c=a(this[0].form).validate(),this.each(function(){b=c.element(this)&&b,b||(d=d.concat(c.errorList))}),c.errorList=d),b},rules:function(b,c){var d,e,f,g,h,i,j=this[0];if(null!=j&&(!j.form&&j.hasAttribute("contenteditable")&&(j.form=this.closest("form")[0],j.name=this.attr("name")),null!=j.form)){if(b)switch(d=a.data(j.form,"validator").settings,e=d.rules,f=a.validator.staticRules(j),b){case"add":a.extend(f,a.validator.normalizeRule(c)),delete f.messages,e[j.name]=f,c.messages&&(d.messages[j.name]=a.extend(d.messages[j.name],c.messages));break;case"remove":return c?(i={},a.each(c.split(/\s/),function(a,b){i[b]=f[b],delete f[b]}),i):(delete e[j.name],f)}return g=a.validator.normalizeRules(a.extend({},a.validator.classRules(j),a.validator.attributeRules(j),a.validator.dataRules(j),a.validator.staticRules(j)),j),g.required&&(h=g.required,delete g.required,g=a.extend({required:h},g)),g.remote&&(h=g.remote,delete g.remote,g=a.extend(g,{remote:h})),g}}}),a.extend(a.expr.pseudos||a.expr[":"],{blank:function(b){return!a.trim(""+a(b).val())},filled:function(b){var c=a(b).val();return null!==c&&!!a.trim(""+c)},unchecked:function(b){return!a(b).prop("checked")}}),a.validator=function(b,c){this.settings=a.extend(!0,{},a.validator.defaults,b),this.currentForm=c,this.init()},a.validator.format=function(b,c){return 1===arguments.length?function(){var c=a.makeArray(arguments);return c.unshift(b),a.validator.format.apply(this,c)}:void 0===c?b:(arguments.length>2&&c.constructor!==Array&&(c=a.makeArray(arguments).slice(1)),c.constructor!==Array&&(c=[c]),a.each(c,function(a,c){b=b.replace(new RegExp("\\{"+a+"\\}","g"),function(){return c})}),b)},a.extend(a.validator,{defaults:{messages:{},groups:{},rules:{},errorClass:"error",pendingClass:"pending",validClass:"valid",errorElement:"label",focusCleanup:!1,focusInvalid:!0,errorContainer:a([]),errorLabelContainer:a([]),onsubmit:!0,ignore:":hidden",ignoreTitle:!1,onfocusin:function(a){this.lastActive=a,this.settings.focusCleanup&&(this.settings.unhighlight&&this.settings.unhighlight.call(this,a,this.settings.errorClass,this.settings.validClass),this.hideThese(this.errorsFor(a)))},onfocusout:function(a){this.checkable(a)||!(a.name in this.submitted)&&this.optional(a)||this.element(a)},onkeyup:function(b,c){var d=[16,17,18,20,35,36,37,38,39,40,45,144,225];9===c.which&&""===this.elementValue(b)||a.inArray(c.keyCode,d)!==-1||(b.name in this.submitted||b.name in this.invalid)&&this.element(b)},onclick:function(a){a.name in this.submitted?this.element(a):a.parentNode.name in this.submitted&&this.element(a.parentNode)},highlight:function(b,c,d){"radio"===b.type?this.findByName(b.name).addClass(c).removeClass(d):a(b).addClass(c).removeClass(d)},unhighlight:function(b,c,d){"radio"===b.type?this.findByName(b.name).removeClass(c).addClass(d):a(b).removeClass(c).addClass(d)}},setDefaults:function(b){a.extend(a.validator.defaults,b)},messages:{required:"This field is required.",remote:"Please fix this field.",email:"Please enter a valid email address.",url:"Please enter a valid URL.",date:"Please enter a valid date.",dateISO:"Please enter a valid date (ISO).",number:"Please enter a valid number.",digits:"Please enter only digits.",equalTo:"Please enter the same value again.",maxlength:a.validator.format("Please enter no more than {0} characters."),minlength:a.validator.format("Please enter at least {0} characters."),rangelength:a.validator.format("Please enter a value between {0} and {1} characters long."),range:a.validator.format("Please enter a value between {0} and {1}."),max:a.validator.format("Please enter a value less than or equal to {0}."),min:a.validator.format("Please enter a value greater than or equal to {0}."),step:a.validator.format("Please enter a multiple of {0}.")},autoCreateRanges:!1,prototype:{init:function(){function b(b){!this.form&&this.hasAttribute("contenteditable")&&(this.form=a(this).closest("form")[0],this.name=a(this).attr("name"));var c=a.data(this.form,"validator"),d="on"+b.type.replace(/^validate/,""),e=c.settings;e[d]&&!a(this).is(e.ignore)&&e[d].call(c,this,b)}this.labelContainer=a(this.settings.errorLabelContainer),this.errorContext=this.labelContainer.length&&this.labelContainer||a(this.currentForm),this.containers=a(this.settings.errorContainer).add(this.settings.errorLabelContainer),this.submitted={},this.valueCache={},this.pendingRequest=0,this.pending={},this.invalid={},this.reset();var c,d=this.groups={};a.each(this.settings.groups,function(b,c){"string"==typeof c&&(c=c.split(/\s/)),a.each(c,function(a,c){d[c]=b})}),c=this.settings.rules,a.each(c,function(b,d){c[b]=a.validator.normalizeRule(d)}),a(this.currentForm).on("focusin.validate focusout.validate keyup.validate",":text, [type='password'], [type='file'], select, textarea, [type='number'], [type='search'], [type='tel'], [type='url'], [type='email'], [type='datetime'], [type='date'], [type='month'], [type='week'], [type='time'], [type='datetime-local'], [type='range'], [type='color'], [type='radio'], [type='checkbox'], [contenteditable], [type='button']",b).on("click.validate","select, option, [type='radio'], [type='checkbox']",b),this.settings.invalidHandler&&a(this.currentForm).on("invalid-form.validate",this.settings.invalidHandler)},form:function(){return this.checkForm(),a.extend(this.submitted,this.errorMap),this.invalid=a.extend({},this.errorMap),this.valid()||a(this.currentForm).triggerHandler("invalid-form",[this]),this.showErrors(),this.valid()},checkForm:function(){this.prepareForm();for(var a=0,b=this.currentElements=this.elements();b[a];a++)this.check(b[a]);return this.valid()},element:function(b){var c,d,e=this.clean(b),f=this.validationTargetFor(e),g=this,h=!0;return void 0===f?delete this.invalid[e.name]:(this.prepareElement(f),this.currentElements=a(f),d=this.groups[f.name],d&&a.each(this.groups,function(a,b){b===d&&a!==f.name&&(e=g.validationTargetFor(g.clean(g.findByName(a))),e&&e.name in g.invalid&&(g.currentElements.push(e),h=g.check(e)&&h))}),c=this.check(f)!==!1,h=h&&c,c?this.invalid[f.name]=!1:this.invalid[f.name]=!0,this.numberOfInvalids()||(this.toHide=this.toHide.add(this.containers)),this.showErrors(),a(b).attr("aria-invalid",!c)),h},showErrors:function(b){if(b){var c=this;a.extend(this.errorMap,b),this.errorList=a.map(this.errorMap,function(a,b){return{message:a,element:c.findByName(b)[0]}}),this.successList=a.grep(this.successList,function(a){return!(a.name in b)})}this.settings.showErrors?this.settings.showErrors.call(this,this.errorMap,this.errorList):this.defaultShowErrors()},resetForm:function(){a.fn.resetForm&&a(this.currentForm).resetForm(),this.invalid={},this.submitted={},this.prepareForm(),this.hideErrors();var b=this.elements().removeData("previousValue").removeAttr("aria-invalid");this.resetElements(b)},resetElements:function(a){var b;if(this.settings.unhighlight)for(b=0;a[b];b++)this.settings.unhighlight.call(this,a[b],this.settings.errorClass,""),this.findByName(a[b].name).removeClass(this.settings.validClass);else a.removeClass(this.settings.errorClass).removeClass(this.settings.validClass)},numberOfInvalids:function(){return this.objectLength(this.invalid)},objectLength:function(a){var b,c=0;for(b in a)void 0!==a[b]&&null!==a[b]&&a[b]!==!1&&c++;return c},hideErrors:function(){this.hideThese(this.toHide)},hideThese:function(a){a.not(this.containers).text(""),this.addWrapper(a).hide()},valid:function(){return 0===this.size()},size:function(){return this.errorList.length},focusInvalid:function(){if(this.settings.focusInvalid)try{a(this.findLastActive()||this.errorList.length&&this.errorList[0].element||[]).filter(":visible").focus().trigger("focusin")}catch(b){}},findLastActive:function(){var b=this.lastActive;return b&&1===a.grep(this.errorList,function(a){return a.element.name===b.name}).length&&b},elements:function(){var b=this,c={};return a(this.currentForm).find("input, select, textarea, [contenteditable]").not(":submit, :reset, :image, :disabled").not(this.settings.ignore).filter(function(){var d=this.name||a(this).attr("name");return!d&&b.settings.debug&&window.console&&console.error("%o has no name assigned",this),this.hasAttribute("contenteditable")&&(this.form=a(this).closest("form")[0],this.name=d),!(d in c||!b.objectLength(a(this).rules()))&&(c[d]=!0,!0)})},clean:function(b){return a(b)[0]},errors:function(){var b=this.settings.errorClass.split(" ").join(".");return a(this.settings.errorElement+"."+b,this.errorContext)},resetInternals:function(){this.successList=[],this.errorList=[],this.errorMap={},this.toShow=a([]),this.toHide=a([])},reset:function(){this.resetInternals(),this.currentElements=a([])},prepareForm:function(){this.reset(),this.toHide=this.errors().add(this.containers)},prepareElement:function(a){this.reset(),this.toHide=this.errorsFor(a)},elementValue:function(b){var c,d,e=a(b),f=b.type;return"radio"===f||"checkbox"===f?this.findByName(b.name).filter(":checked").val():"number"===f&&"undefined"!=typeof b.validity?b.validity.badInput?"NaN":e.val():(c=b.hasAttribute("contenteditable")?e.text():e.val(),"file"===f?"C:\\fakepath\\"===c.substr(0,12)?c.substr(12):(d=c.lastIndexOf("/"),d>=0?c.substr(d+1):(d=c.lastIndexOf("\\"),d>=0?c.substr(d+1):c)):"string"==typeof c?c.replace(/\r/g,""):c)},check:function(b){b=this.validationTargetFor(this.clean(b));var c,d,e,f,g=a(b).rules(),h=a.map(g,function(a,b){return b}).length,i=!1,j=this.elementValue(b);if("function"==typeof g.normalizer?f=g.normalizer:"function"==typeof this.settings.normalizer&&(f=this.settings.normalizer),f){if(j=f.call(b,j),"string"!=typeof j)throw new TypeError("The normalizer should return a string value.");delete g.normalizer}for(d in g){e={method:d,parameters:g[d]};try{if(c=a.validator.methods[d].call(this,j,b,e.parameters),"dependency-mismatch"===c&&1===h){i=!0;continue}if(i=!1,"pending"===c)return void(this.toHide=this.toHide.not(this.errorsFor(b)));if(!c)return this.formatAndAdd(b,e),!1}catch(k){throw this.settings.debug&&window.console&&console.log("Exception occurred when checking element "+b.id+", check the '"+e.method+"' method.",k),k instanceof TypeError&&(k.message+=". Exception occurred when checking element "+b.id+", check the '"+e.method+"' method."),k}}if(!i)return this.objectLength(g)&&this.successList.push(b),!0},customDataMessage:function(b,c){return a(b).data("msg"+c.charAt(0).toUpperCase()+c.substring(1).toLowerCase())||a(b).data("msg")},customMessage:function(a,b){var c=this.settings.messages[a];return c&&(c.constructor===String?c:c[b])},findDefined:function(){for(var a=0;aWarning: No message defined for "+b.name+""),e=/\$?\{(\d+)\}/g;return"function"==typeof d?d=d.call(this,c.parameters,b):e.test(d)&&(d=a.validator.format(d.replace(e,"{$1}"),c.parameters)),d},formatAndAdd:function(a,b){var c=this.defaultMessage(a,b);this.errorList.push({message:c,element:a,method:b.method}),this.errorMap[a.name]=c,this.submitted[a.name]=c},addWrapper:function(a){return this.settings.wrapper&&(a=a.add(a.parent(this.settings.wrapper))),a},defaultShowErrors:function(){var a,b,c;for(a=0;this.errorList[a];a++)c=this.errorList[a],this.settings.highlight&&this.settings.highlight.call(this,c.element,this.settings.errorClass,this.settings.validClass),this.showLabel(c.element,c.message);if(this.errorList.length&&(this.toShow=this.toShow.add(this.containers)),this.settings.success)for(a=0;this.successList[a];a++)this.showLabel(this.successList[a]);if(this.settings.unhighlight)for(a=0,b=this.validElements();b[a];a++)this.settings.unhighlight.call(this,b[a],this.settings.errorClass,this.settings.validClass);this.toHide=this.toHide.not(this.toShow),this.hideErrors(),this.addWrapper(this.toShow).show()},validElements:function(){return this.currentElements.not(this.invalidElements())},invalidElements:function(){return a(this.errorList).map(function(){return this.element})},showLabel:function(b,c){var d,e,f,g,h=this.errorsFor(b),i=this.idOrName(b),j=a(b).attr("aria-describedby");h.length?(h.removeClass(this.settings.validClass).addClass(this.settings.errorClass),h.html(c)):(h=a("<"+this.settings.errorElement+">").attr("id",i+"-error").addClass(this.settings.errorClass).html(c||""),d=h,this.settings.wrapper&&(d=h.hide().show().wrap("<"+this.settings.wrapper+"/>").parent()),this.labelContainer.length?this.labelContainer.append(d):this.settings.errorPlacement?this.settings.errorPlacement.call(this,d,a(b)):d.insertAfter(b),h.is("label")?h.attr("for",i):0===h.parents("label[for='"+this.escapeCssMeta(i)+"']").length&&(f=h.attr("id"),j?j.match(new RegExp("\\b"+this.escapeCssMeta(f)+"\\b"))||(j+=" "+f):j=f,a(b).attr("aria-describedby",j),e=this.groups[b.name],e&&(g=this,a.each(g.groups,function(b,c){c===e&&a("[name='"+g.escapeCssMeta(b)+"']",g.currentForm).attr("aria-describedby",h.attr("id"))})))),!c&&this.settings.success&&(h.text(""),"string"==typeof this.settings.success?h.addClass(this.settings.success):this.settings.success(h,b)),this.toShow=this.toShow.add(h)},errorsFor:function(b){var c=this.escapeCssMeta(this.idOrName(b)),d=a(b).attr("aria-describedby"),e="label[for='"+c+"'], label[for='"+c+"'] *";return d&&(e=e+", #"+this.escapeCssMeta(d).replace(/\s+/g,", #")),this.errors().filter(e)},escapeCssMeta:function(a){return a.replace(/([\\!"#$%&'()*+,.\/:;<=>?@\[\]^`{|}~])/g,"\\$1")},idOrName:function(a){return this.groups[a.name]||(this.checkable(a)?a.name:a.id||a.name)},validationTargetFor:function(b){return this.checkable(b)&&(b=this.findByName(b.name)),a(b).not(this.settings.ignore)[0]},checkable:function(a){return/radio|checkbox/i.test(a.type)},findByName:function(b){return a(this.currentForm).find("[name='"+this.escapeCssMeta(b)+"']")},getLength:function(b,c){switch(c.nodeName.toLowerCase()){case"select":return a("option:selected",c).length;case"input":if(this.checkable(c))return this.findByName(c.name).filter(":checked").length}return b.length},depend:function(a,b){return!this.dependTypes[typeof a]||this.dependTypes[typeof a](a,b)},dependTypes:{"boolean":function(a){return a},string:function(b,c){return!!a(b,c.form).length},"function":function(a,b){return a(b)}},optional:function(b){var c=this.elementValue(b);return!a.validator.methods.required.call(this,c,b)&&"dependency-mismatch"},startRequest:function(b){this.pending[b.name]||(this.pendingRequest++,a(b).addClass(this.settings.pendingClass),this.pending[b.name]=!0)},stopRequest:function(b,c){this.pendingRequest--,this.pendingRequest<0&&(this.pendingRequest=0),delete this.pending[b.name],a(b).removeClass(this.settings.pendingClass),c&&0===this.pendingRequest&&this.formSubmitted&&this.form()?(a(this.currentForm).submit(),this.submitButton&&a("input:hidden[name='"+this.submitButton.name+"']",this.currentForm).remove(),this.formSubmitted=!1):!c&&0===this.pendingRequest&&this.formSubmitted&&(a(this.currentForm).triggerHandler("invalid-form",[this]),this.formSubmitted=!1)},previousValue:function(b,c){return c="string"==typeof c&&c||"remote",a.data(b,"previousValue")||a.data(b,"previousValue",{old:null,valid:!0,message:this.defaultMessage(b,{method:c})})},destroy:function(){this.resetForm(),a(this.currentForm).off(".validate").removeData("validator").find(".validate-equalTo-blur").off(".validate-equalTo").removeClass("validate-equalTo-blur")}},classRuleSettings:{required:{required:!0},email:{email:!0},url:{url:!0},date:{date:!0},dateISO:{dateISO:!0},number:{number:!0},digits:{digits:!0},creditcard:{creditcard:!0}},addClassRules:function(b,c){b.constructor===String?this.classRuleSettings[b]=c:a.extend(this.classRuleSettings,b)},classRules:function(b){var c={},d=a(b).attr("class");return d&&a.each(d.split(" "),function(){this in a.validator.classRuleSettings&&a.extend(c,a.validator.classRuleSettings[this])}),c},normalizeAttributeRule:function(a,b,c,d){/min|max|step/.test(c)&&(null===b||/number|range|text/.test(b))&&(d=Number(d),isNaN(d)&&(d=void 0)),d||0===d?a[c]=d:b===c&&"range"!==b&&(a[c]=!0)},attributeRules:function(b){var c,d,e={},f=a(b),g=b.getAttribute("type");for(c in a.validator.methods)"required"===c?(d=b.getAttribute(c),""===d&&(d=!0),d=!!d):d=f.attr(c),this.normalizeAttributeRule(e,g,c,d);return e.maxlength&&/-1|2147483647|524288/.test(e.maxlength)&&delete e.maxlength,e},dataRules:function(b){var c,d,e={},f=a(b),g=b.getAttribute("type");for(c in a.validator.methods)d=f.data("rule"+c.charAt(0).toUpperCase()+c.substring(1).toLowerCase()),this.normalizeAttributeRule(e,g,c,d);return e},staticRules:function(b){var c={},d=a.data(b.form,"validator");return d.settings.rules&&(c=a.validator.normalizeRule(d.settings.rules[b.name])||{}),c},normalizeRules:function(b,c){return a.each(b,function(d,e){if(e===!1)return void delete b[d];if(e.param||e.depends){var f=!0;switch(typeof e.depends){case"string":f=!!a(e.depends,c.form).length;break;case"function":f=e.depends.call(c,c)}f?b[d]=void 0===e.param||e.param:(a.data(c.form,"validator").resetElements(a(c)),delete b[d])}}),a.each(b,function(d,e){b[d]=a.isFunction(e)&&"normalizer"!==d?e(c):e}),a.each(["minlength","maxlength"],function(){b[this]&&(b[this]=Number(b[this]))}),a.each(["rangelength","range"],function(){var c;b[this]&&(a.isArray(b[this])?b[this]=[Number(b[this][0]),Number(b[this][1])]:"string"==typeof b[this]&&(c=b[this].replace(/[\[\]]/g,"").split(/[\s,]+/),b[this]=[Number(c[0]),Number(c[1])]))}),a.validator.autoCreateRanges&&(null!=b.min&&null!=b.max&&(b.range=[b.min,b.max],delete b.min,delete b.max),null!=b.minlength&&null!=b.maxlength&&(b.rangelength=[b.minlength,b.maxlength],delete b.minlength,delete b.maxlength)),b},normalizeRule:function(b){if("string"==typeof b){var c={};a.each(b.split(/\s/),function(){c[this]=!0}),b=c}return b},addMethod:function(b,c,d){a.validator.methods[b]=c,a.validator.messages[b]=void 0!==d?d:a.validator.messages[b],c.length<3&&a.validator.addClassRules(b,a.validator.normalizeRule(b))},methods:{required:function(b,c,d){if(!this.depend(d,c))return"dependency-mismatch";if("select"===c.nodeName.toLowerCase()){var e=a(c).val();return e&&e.length>0}return this.checkable(c)?this.getLength(b,c)>0:b.length>0},email:function(a,b){return this.optional(b)||/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(a)},url:function(a,b){return this.optional(b)||/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[\/?#]\S*)?$/i.test(a)},date:function(a,b){return this.optional(b)||!/Invalid|NaN/.test(new Date(a).toString())},dateISO:function(a,b){return this.optional(b)||/^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test(a)},number:function(a,b){return this.optional(b)||/^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(a)},digits:function(a,b){return this.optional(b)||/^\d+$/.test(a)},minlength:function(b,c,d){var e=a.isArray(b)?b.length:this.getLength(b,c);return this.optional(c)||e>=d},maxlength:function(b,c,d){var e=a.isArray(b)?b.length:this.getLength(b,c);return this.optional(c)||e<=d},rangelength:function(b,c,d){var e=a.isArray(b)?b.length:this.getLength(b,c);return this.optional(c)||e>=d[0]&&e<=d[1]},min:function(a,b,c){return this.optional(b)||a>=c},max:function(a,b,c){return this.optional(b)||a<=c},range:function(a,b,c){return this.optional(b)||a>=c[0]&&a<=c[1]},step:function(b,c,d){var e,f=a(c).attr("type"),g="Step attribute on input type "+f+" is not supported.",h=["text","number","range"],i=new RegExp("\\b"+f+"\\b"),j=f&&!i.test(h.join()),k=function(a){var b=(""+a).match(/(?:\.(\d+))?$/);return b&&b[1]?b[1].length:0},l=function(a){return Math.round(a*Math.pow(10,e))},m=!0;if(j)throw new Error(g);return e=k(d),(k(b)>e||l(b)%l(d)!==0)&&(m=!1),this.optional(c)||m},equalTo:function(b,c,d){var e=a(d);return this.settings.onfocusout&&e.not(".validate-equalTo-blur").length&&e.addClass("validate-equalTo-blur").on("blur.validate-equalTo",function(){a(c).valid()}),b===e.val()},remote:function(b,c,d,e){if(this.optional(c))return"dependency-mismatch";e="string"==typeof e&&e||"remote";var f,g,h,i=this.previousValue(c,e);return this.settings.messages[c.name]||(this.settings.messages[c.name]={}),i.originalMessage=i.originalMessage||this.settings.messages[c.name][e],this.settings.messages[c.name][e]=i.message,d="string"==typeof d&&{url:d}||d,h=a.param(a.extend({data:b},d.data)),i.old===h?i.valid:(i.old=h,f=this,this.startRequest(c),g={},g[c.name]=b,a.ajax(a.extend(!0,{mode:"abort",port:"validate"+c.name,dataType:"json",data:g,context:f.currentForm,success:function(a){var d,g,h,j=a===!0||"true"===a;f.settings.messages[c.name][e]=i.originalMessage,j?(h=f.formSubmitted,f.resetInternals(),f.toHide=f.errorsFor(c),f.formSubmitted=h,f.successList.push(c),f.invalid[c.name]=!1,f.showErrors()):(d={},g=a||f.defaultMessage(c,{method:e,parameters:b}),d[c.name]=i.message=g,f.invalid[c.name]=!0,f.showErrors(d)),i.valid=j,f.stopRequest(c,j)}},d)),"pending")}}});var b,c={};return a.ajaxPrefilter?a.ajaxPrefilter(function(a,b,d){var e=a.port;"abort"===a.mode&&(c[e]&&c[e].abort(),c[e]=d)}):(b=a.ajax,a.ajax=function(d){var e=("mode"in d?d:a.ajaxSettings).mode,f=("port"in d?d:a.ajaxSettings).port;return"abort"===e?(c[f]&&c[f].abort(),c[f]=b.apply(this,arguments),c[f]):b.apply(this,arguments)}),a}); -------------------------------------------------------------------------------- /CognitiveServicesDemo/Scripts/jquery.validate.unobtrusive.js: -------------------------------------------------------------------------------- 1 | // Unobtrusive validation support library for jQuery and jQuery Validate 2 | // Copyright (c) .NET Foundation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 4 | // @version v3.2.11 5 | 6 | /*jslint white: true, browser: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, newcap: true, immed: true, strict: false */ 7 | /*global document: false, jQuery: false */ 8 | 9 | (function (factory) { 10 | if (typeof define === 'function' && define.amd) { 11 | // AMD. Register as an anonymous module. 12 | define("jquery.validate.unobtrusive", ['jquery-validation'], factory); 13 | } else if (typeof module === 'object' && module.exports) { 14 | // CommonJS-like environments that support module.exports 15 | module.exports = factory(require('jquery-validation')); 16 | } else { 17 | // Browser global 18 | jQuery.validator.unobtrusive = factory(jQuery); 19 | } 20 | }(function ($) { 21 | var $jQval = $.validator, 22 | adapters, 23 | data_validation = "unobtrusiveValidation"; 24 | 25 | function setValidationValues(options, ruleName, value) { 26 | options.rules[ruleName] = value; 27 | if (options.message) { 28 | options.messages[ruleName] = options.message; 29 | } 30 | } 31 | 32 | function splitAndTrim(value) { 33 | return value.replace(/^\s+|\s+$/g, "").split(/\s*,\s*/g); 34 | } 35 | 36 | function escapeAttributeValue(value) { 37 | // As mentioned on http://api.jquery.com/category/selectors/ 38 | return value.replace(/([!"#$%&'()*+,./:;<=>?@\[\\\]^`{|}~])/g, "\\$1"); 39 | } 40 | 41 | function getModelPrefix(fieldName) { 42 | return fieldName.substr(0, fieldName.lastIndexOf(".") + 1); 43 | } 44 | 45 | function appendModelPrefix(value, prefix) { 46 | if (value.indexOf("*.") === 0) { 47 | value = value.replace("*.", prefix); 48 | } 49 | return value; 50 | } 51 | 52 | function onError(error, inputElement) { // 'this' is the form element 53 | var container = $(this).find("[data-valmsg-for='" + escapeAttributeValue(inputElement[0].name) + "']"), 54 | replaceAttrValue = container.attr("data-valmsg-replace"), 55 | replace = replaceAttrValue ? $.parseJSON(replaceAttrValue) !== false : null; 56 | 57 | container.removeClass("field-validation-valid").addClass("field-validation-error"); 58 | error.data("unobtrusiveContainer", container); 59 | 60 | if (replace) { 61 | container.empty(); 62 | error.removeClass("input-validation-error").appendTo(container); 63 | } 64 | else { 65 | error.hide(); 66 | } 67 | } 68 | 69 | function onErrors(event, validator) { // 'this' is the form element 70 | var container = $(this).find("[data-valmsg-summary=true]"), 71 | list = container.find("ul"); 72 | 73 | if (list && list.length && validator.errorList.length) { 74 | list.empty(); 75 | container.addClass("validation-summary-errors").removeClass("validation-summary-valid"); 76 | 77 | $.each(validator.errorList, function () { 78 | $("
  • ").html(this.message).appendTo(list); 79 | }); 80 | } 81 | } 82 | 83 | function onSuccess(error) { // 'this' is the form element 84 | var container = error.data("unobtrusiveContainer"); 85 | 86 | if (container) { 87 | var replaceAttrValue = container.attr("data-valmsg-replace"), 88 | replace = replaceAttrValue ? $.parseJSON(replaceAttrValue) : null; 89 | 90 | container.addClass("field-validation-valid").removeClass("field-validation-error"); 91 | error.removeData("unobtrusiveContainer"); 92 | 93 | if (replace) { 94 | container.empty(); 95 | } 96 | } 97 | } 98 | 99 | function onReset(event) { // 'this' is the form element 100 | var $form = $(this), 101 | key = '__jquery_unobtrusive_validation_form_reset'; 102 | if ($form.data(key)) { 103 | return; 104 | } 105 | // Set a flag that indicates we're currently resetting the form. 106 | $form.data(key, true); 107 | try { 108 | $form.data("validator").resetForm(); 109 | } finally { 110 | $form.removeData(key); 111 | } 112 | 113 | $form.find(".validation-summary-errors") 114 | .addClass("validation-summary-valid") 115 | .removeClass("validation-summary-errors"); 116 | $form.find(".field-validation-error") 117 | .addClass("field-validation-valid") 118 | .removeClass("field-validation-error") 119 | .removeData("unobtrusiveContainer") 120 | .find(">*") // If we were using valmsg-replace, get the underlying error 121 | .removeData("unobtrusiveContainer"); 122 | } 123 | 124 | function validationInfo(form) { 125 | var $form = $(form), 126 | result = $form.data(data_validation), 127 | onResetProxy = $.proxy(onReset, form), 128 | defaultOptions = $jQval.unobtrusive.options || {}, 129 | execInContext = function (name, args) { 130 | var func = defaultOptions[name]; 131 | func && $.isFunction(func) && func.apply(form, args); 132 | }; 133 | 134 | if (!result) { 135 | result = { 136 | options: { // options structure passed to jQuery Validate's validate() method 137 | errorClass: defaultOptions.errorClass || "input-validation-error", 138 | errorElement: defaultOptions.errorElement || "span", 139 | errorPlacement: function () { 140 | onError.apply(form, arguments); 141 | execInContext("errorPlacement", arguments); 142 | }, 143 | invalidHandler: function () { 144 | onErrors.apply(form, arguments); 145 | execInContext("invalidHandler", arguments); 146 | }, 147 | messages: {}, 148 | rules: {}, 149 | success: function () { 150 | onSuccess.apply(form, arguments); 151 | execInContext("success", arguments); 152 | } 153 | }, 154 | attachValidation: function () { 155 | $form 156 | .off("reset." + data_validation, onResetProxy) 157 | .on("reset." + data_validation, onResetProxy) 158 | .validate(this.options); 159 | }, 160 | validate: function () { // a validation function that is called by unobtrusive Ajax 161 | $form.validate(); 162 | return $form.valid(); 163 | } 164 | }; 165 | $form.data(data_validation, result); 166 | } 167 | 168 | return result; 169 | } 170 | 171 | $jQval.unobtrusive = { 172 | adapters: [], 173 | 174 | parseElement: function (element, skipAttach) { 175 | /// 176 | /// Parses a single HTML element for unobtrusive validation attributes. 177 | /// 178 | /// The HTML element to be parsed. 179 | /// [Optional] true to skip attaching the 180 | /// validation to the form. If parsing just this single element, you should specify true. 181 | /// If parsing several elements, you should specify false, and manually attach the validation 182 | /// to the form when you are finished. The default is false. 183 | var $element = $(element), 184 | form = $element.parents("form")[0], 185 | valInfo, rules, messages; 186 | 187 | if (!form) { // Cannot do client-side validation without a form 188 | return; 189 | } 190 | 191 | valInfo = validationInfo(form); 192 | valInfo.options.rules[element.name] = rules = {}; 193 | valInfo.options.messages[element.name] = messages = {}; 194 | 195 | $.each(this.adapters, function () { 196 | var prefix = "data-val-" + this.name, 197 | message = $element.attr(prefix), 198 | paramValues = {}; 199 | 200 | if (message !== undefined) { // Compare against undefined, because an empty message is legal (and falsy) 201 | prefix += "-"; 202 | 203 | $.each(this.params, function () { 204 | paramValues[this] = $element.attr(prefix + this); 205 | }); 206 | 207 | this.adapt({ 208 | element: element, 209 | form: form, 210 | message: message, 211 | params: paramValues, 212 | rules: rules, 213 | messages: messages 214 | }); 215 | } 216 | }); 217 | 218 | $.extend(rules, { "__dummy__": true }); 219 | 220 | if (!skipAttach) { 221 | valInfo.attachValidation(); 222 | } 223 | }, 224 | 225 | parse: function (selector) { 226 | /// 227 | /// Parses all the HTML elements in the specified selector. It looks for input elements decorated 228 | /// with the [data-val=true] attribute value and enables validation according to the data-val-* 229 | /// attribute values. 230 | /// 231 | /// Any valid jQuery selector. 232 | 233 | // $forms includes all forms in selector's DOM hierarchy (parent, children and self) that have at least one 234 | // element with data-val=true 235 | var $selector = $(selector), 236 | $forms = $selector.parents() 237 | .addBack() 238 | .filter("form") 239 | .add($selector.find("form")) 240 | .has("[data-val=true]"); 241 | 242 | $selector.find("[data-val=true]").each(function () { 243 | $jQval.unobtrusive.parseElement(this, true); 244 | }); 245 | 246 | $forms.each(function () { 247 | var info = validationInfo(this); 248 | if (info) { 249 | info.attachValidation(); 250 | } 251 | }); 252 | } 253 | }; 254 | 255 | adapters = $jQval.unobtrusive.adapters; 256 | 257 | adapters.add = function (adapterName, params, fn) { 258 | /// Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation. 259 | /// The name of the adapter to be added. This matches the name used 260 | /// in the data-val-nnnn HTML attribute (where nnnn is the adapter name). 261 | /// [Optional] An array of parameter names (strings) that will 262 | /// be extracted from the data-val-nnnn-mmmm HTML attributes (where nnnn is the adapter name, and 263 | /// mmmm is the parameter name). 264 | /// The function to call, which adapts the values from the HTML 265 | /// attributes into jQuery Validate rules and/or messages. 266 | /// 267 | if (!fn) { // Called with no params, just a function 268 | fn = params; 269 | params = []; 270 | } 271 | this.push({ name: adapterName, params: params, adapt: fn }); 272 | return this; 273 | }; 274 | 275 | adapters.addBool = function (adapterName, ruleName) { 276 | /// Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation, where 277 | /// the jQuery Validate validation rule has no parameter values. 278 | /// The name of the adapter to be added. This matches the name used 279 | /// in the data-val-nnnn HTML attribute (where nnnn is the adapter name). 280 | /// [Optional] The name of the jQuery Validate rule. If not provided, the value 281 | /// of adapterName will be used instead. 282 | /// 283 | return this.add(adapterName, function (options) { 284 | setValidationValues(options, ruleName || adapterName, true); 285 | }); 286 | }; 287 | 288 | adapters.addMinMax = function (adapterName, minRuleName, maxRuleName, minMaxRuleName, minAttribute, maxAttribute) { 289 | /// Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation, where 290 | /// the jQuery Validate validation has three potential rules (one for min-only, one for max-only, and 291 | /// one for min-and-max). The HTML parameters are expected to be named -min and -max. 292 | /// The name of the adapter to be added. This matches the name used 293 | /// in the data-val-nnnn HTML attribute (where nnnn is the adapter name). 294 | /// The name of the jQuery Validate rule to be used when you only 295 | /// have a minimum value. 296 | /// The name of the jQuery Validate rule to be used when you only 297 | /// have a maximum value. 298 | /// The name of the jQuery Validate rule to be used when you 299 | /// have both a minimum and maximum value. 300 | /// [Optional] The name of the HTML attribute that 301 | /// contains the minimum value. The default is "min". 302 | /// [Optional] The name of the HTML attribute that 303 | /// contains the maximum value. The default is "max". 304 | /// 305 | return this.add(adapterName, [minAttribute || "min", maxAttribute || "max"], function (options) { 306 | var min = options.params.min, 307 | max = options.params.max; 308 | 309 | if (min && max) { 310 | setValidationValues(options, minMaxRuleName, [min, max]); 311 | } 312 | else if (min) { 313 | setValidationValues(options, minRuleName, min); 314 | } 315 | else if (max) { 316 | setValidationValues(options, maxRuleName, max); 317 | } 318 | }); 319 | }; 320 | 321 | adapters.addSingleVal = function (adapterName, attribute, ruleName) { 322 | /// Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation, where 323 | /// the jQuery Validate validation rule has a single value. 324 | /// The name of the adapter to be added. This matches the name used 325 | /// in the data-val-nnnn HTML attribute(where nnnn is the adapter name). 326 | /// [Optional] The name of the HTML attribute that contains the value. 327 | /// The default is "val". 328 | /// [Optional] The name of the jQuery Validate rule. If not provided, the value 329 | /// of adapterName will be used instead. 330 | /// 331 | return this.add(adapterName, [attribute || "val"], function (options) { 332 | setValidationValues(options, ruleName || adapterName, options.params[attribute]); 333 | }); 334 | }; 335 | 336 | $jQval.addMethod("__dummy__", function (value, element, params) { 337 | return true; 338 | }); 339 | 340 | $jQval.addMethod("regex", function (value, element, params) { 341 | var match; 342 | if (this.optional(element)) { 343 | return true; 344 | } 345 | 346 | match = new RegExp(params).exec(value); 347 | return (match && (match.index === 0) && (match[0].length === value.length)); 348 | }); 349 | 350 | $jQval.addMethod("nonalphamin", function (value, element, nonalphamin) { 351 | var match; 352 | if (nonalphamin) { 353 | match = value.match(/\W/g); 354 | match = match && match.length >= nonalphamin; 355 | } 356 | return match; 357 | }); 358 | 359 | if ($jQval.methods.extension) { 360 | adapters.addSingleVal("accept", "mimtype"); 361 | adapters.addSingleVal("extension", "extension"); 362 | } else { 363 | // for backward compatibility, when the 'extension' validation method does not exist, such as with versions 364 | // of JQuery Validation plugin prior to 1.10, we should use the 'accept' method for 365 | // validating the extension, and ignore mime-type validations as they are not supported. 366 | adapters.addSingleVal("extension", "extension", "accept"); 367 | } 368 | 369 | adapters.addSingleVal("regex", "pattern"); 370 | adapters.addBool("creditcard").addBool("date").addBool("digits").addBool("email").addBool("number").addBool("url"); 371 | adapters.addMinMax("length", "minlength", "maxlength", "rangelength").addMinMax("range", "min", "max", "range"); 372 | adapters.addMinMax("minlength", "minlength").addMinMax("maxlength", "minlength", "maxlength"); 373 | adapters.add("equalto", ["other"], function (options) { 374 | var prefix = getModelPrefix(options.element.name), 375 | other = options.params.other, 376 | fullOtherName = appendModelPrefix(other, prefix), 377 | element = $(options.form).find(":input").filter("[name='" + escapeAttributeValue(fullOtherName) + "']")[0]; 378 | 379 | setValidationValues(options, "equalTo", element); 380 | }); 381 | adapters.add("required", function (options) { 382 | // jQuery Validate equates "required" with "mandatory" for checkbox elements 383 | if (options.element.tagName.toUpperCase() !== "INPUT" || options.element.type.toUpperCase() !== "CHECKBOX") { 384 | setValidationValues(options, "required", true); 385 | } 386 | }); 387 | adapters.add("remote", ["url", "type", "additionalfields"], function (options) { 388 | var value = { 389 | url: options.params.url, 390 | type: options.params.type || "GET", 391 | data: {} 392 | }, 393 | prefix = getModelPrefix(options.element.name); 394 | 395 | $.each(splitAndTrim(options.params.additionalfields || options.element.name), function (i, fieldName) { 396 | var paramName = appendModelPrefix(fieldName, prefix); 397 | value.data[paramName] = function () { 398 | var field = $(options.form).find(":input").filter("[name='" + escapeAttributeValue(paramName) + "']"); 399 | // For checkboxes and radio buttons, only pick up values from checked fields. 400 | if (field.is(":checkbox")) { 401 | return field.filter(":checked").val() || field.filter(":hidden").val() || ''; 402 | } 403 | else if (field.is(":radio")) { 404 | return field.filter(":checked").val() || ''; 405 | } 406 | return field.val(); 407 | }; 408 | }); 409 | 410 | setValidationValues(options, "remote", value); 411 | }); 412 | adapters.add("password", ["min", "nonalphamin", "regex"], function (options) { 413 | if (options.params.min) { 414 | setValidationValues(options, "minlength", options.params.min); 415 | } 416 | if (options.params.nonalphamin) { 417 | setValidationValues(options, "nonalphamin", options.params.nonalphamin); 418 | } 419 | if (options.params.regex) { 420 | setValidationValues(options, "regex", options.params.regex); 421 | } 422 | }); 423 | adapters.add("fileextensions", ["extensions"], function (options) { 424 | setValidationValues(options, "extension", options.params.extensions); 425 | }); 426 | 427 | $(function () { 428 | $jQval.unobtrusive.parse(document); 429 | }); 430 | 431 | return $jQval.unobtrusive; 432 | })); 433 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/Scripts/jquery.validate.unobtrusive.min.js: -------------------------------------------------------------------------------- 1 | // Unobtrusive validation support library for jQuery and jQuery Validate 2 | // Copyright (c) .NET Foundation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 4 | // @version v3.2.11 5 | !function(a){"function"==typeof define&&define.amd?define("jquery.validate.unobtrusive",["jquery-validation"],a):"object"==typeof module&&module.exports?module.exports=a(require("jquery-validation")):jQuery.validator.unobtrusive=a(jQuery)}(function(a){function e(a,e,n){a.rules[e]=n,a.message&&(a.messages[e]=a.message)}function n(a){return a.replace(/^\s+|\s+$/g,"").split(/\s*,\s*/g)}function t(a){return a.replace(/([!"#$%&'()*+,.\/:;<=>?@\[\\\]^`{|}~])/g,"\\$1")}function r(a){return a.substr(0,a.lastIndexOf(".")+1)}function i(a,e){return 0===a.indexOf("*.")&&(a=a.replace("*.",e)),a}function o(e,n){var r=a(this).find("[data-valmsg-for='"+t(n[0].name)+"']"),i=r.attr("data-valmsg-replace"),o=i?a.parseJSON(i)!==!1:null;r.removeClass("field-validation-valid").addClass("field-validation-error"),e.data("unobtrusiveContainer",r),o?(r.empty(),e.removeClass("input-validation-error").appendTo(r)):e.hide()}function d(e,n){var t=a(this).find("[data-valmsg-summary=true]"),r=t.find("ul");r&&r.length&&n.errorList.length&&(r.empty(),t.addClass("validation-summary-errors").removeClass("validation-summary-valid"),a.each(n.errorList,function(){a("
  • ").html(this.message).appendTo(r)}))}function s(e){var n=e.data("unobtrusiveContainer");if(n){var t=n.attr("data-valmsg-replace"),r=t?a.parseJSON(t):null;n.addClass("field-validation-valid").removeClass("field-validation-error"),e.removeData("unobtrusiveContainer"),r&&n.empty()}}function l(e){var n=a(this),t="__jquery_unobtrusive_validation_form_reset";if(!n.data(t)){n.data(t,!0);try{n.data("validator").resetForm()}finally{n.removeData(t)}n.find(".validation-summary-errors").addClass("validation-summary-valid").removeClass("validation-summary-errors"),n.find(".field-validation-error").addClass("field-validation-valid").removeClass("field-validation-error").removeData("unobtrusiveContainer").find(">*").removeData("unobtrusiveContainer")}}function u(e){var n=a(e),t=n.data(v),r=a.proxy(l,e),i=f.unobtrusive.options||{},u=function(n,t){var r=i[n];r&&a.isFunction(r)&&r.apply(e,t)};return t||(t={options:{errorClass:i.errorClass||"input-validation-error",errorElement:i.errorElement||"span",errorPlacement:function(){o.apply(e,arguments),u("errorPlacement",arguments)},invalidHandler:function(){d.apply(e,arguments),u("invalidHandler",arguments)},messages:{},rules:{},success:function(){s.apply(e,arguments),u("success",arguments)}},attachValidation:function(){n.off("reset."+v,r).on("reset."+v,r).validate(this.options)},validate:function(){return n.validate(),n.valid()}},n.data(v,t)),t}var m,f=a.validator,v="unobtrusiveValidation";return f.unobtrusive={adapters:[],parseElement:function(e,n){var t,r,i,o=a(e),d=o.parents("form")[0];d&&(t=u(d),t.options.rules[e.name]=r={},t.options.messages[e.name]=i={},a.each(this.adapters,function(){var n="data-val-"+this.name,t=o.attr(n),s={};void 0!==t&&(n+="-",a.each(this.params,function(){s[this]=o.attr(n+this)}),this.adapt({element:e,form:d,message:t,params:s,rules:r,messages:i}))}),a.extend(r,{__dummy__:!0}),n||t.attachValidation())},parse:function(e){var n=a(e),t=n.parents().addBack().filter("form").add(n.find("form")).has("[data-val=true]");n.find("[data-val=true]").each(function(){f.unobtrusive.parseElement(this,!0)}),t.each(function(){var a=u(this);a&&a.attachValidation()})}},m=f.unobtrusive.adapters,m.add=function(a,e,n){return n||(n=e,e=[]),this.push({name:a,params:e,adapt:n}),this},m.addBool=function(a,n){return this.add(a,function(t){e(t,n||a,!0)})},m.addMinMax=function(a,n,t,r,i,o){return this.add(a,[i||"min",o||"max"],function(a){var i=a.params.min,o=a.params.max;i&&o?e(a,r,[i,o]):i?e(a,n,i):o&&e(a,t,o)})},m.addSingleVal=function(a,n,t){return this.add(a,[n||"val"],function(r){e(r,t||a,r.params[n])})},f.addMethod("__dummy__",function(a,e,n){return!0}),f.addMethod("regex",function(a,e,n){var t;return!!this.optional(e)||(t=new RegExp(n).exec(a),t&&0===t.index&&t[0].length===a.length)}),f.addMethod("nonalphamin",function(a,e,n){var t;return n&&(t=a.match(/\W/g),t=t&&t.length>=n),t}),f.methods.extension?(m.addSingleVal("accept","mimtype"),m.addSingleVal("extension","extension")):m.addSingleVal("extension","extension","accept"),m.addSingleVal("regex","pattern"),m.addBool("creditcard").addBool("date").addBool("digits").addBool("email").addBool("number").addBool("url"),m.addMinMax("length","minlength","maxlength","rangelength").addMinMax("range","min","max","range"),m.addMinMax("minlength","minlength").addMinMax("maxlength","minlength","maxlength"),m.add("equalto",["other"],function(n){var o=r(n.element.name),d=n.params.other,s=i(d,o),l=a(n.form).find(":input").filter("[name='"+t(s)+"']")[0];e(n,"equalTo",l)}),m.add("required",function(a){"INPUT"===a.element.tagName.toUpperCase()&&"CHECKBOX"===a.element.type.toUpperCase()||e(a,"required",!0)}),m.add("remote",["url","type","additionalfields"],function(o){var d={url:o.params.url,type:o.params.type||"GET",data:{}},s=r(o.element.name);a.each(n(o.params.additionalfields||o.element.name),function(e,n){var r=i(n,s);d.data[r]=function(){var e=a(o.form).find(":input").filter("[name='"+t(r)+"']");return e.is(":checkbox")?e.filter(":checked").val()||e.filter(":hidden").val()||"":e.is(":radio")?e.filter(":checked").val()||"":e.val()}}),e(o,"remote",d)}),m.add("password",["min","nonalphamin","regex"],function(a){a.params.min&&e(a,"minlength",a.params.min),a.params.nonalphamin&&e(a,"nonalphamin",a.params.nonalphamin),a.params.regex&&e(a,"regex",a.params.regex)}),m.add("fileextensions",["extensions"],function(a){e(a,"extension",a.params.extensions)}),a(function(){f.unobtrusive.parse(document)}),f.unobtrusive}); -------------------------------------------------------------------------------- /CognitiveServicesDemo/Scripts/respond.js: -------------------------------------------------------------------------------- 1 | /*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license */ 2 | /*! NOTE: If you're already including a window.matchMedia polyfill via Modernizr or otherwise, you don't need this part */ 3 | (function(w) { 4 | "use strict"; 5 | w.matchMedia = w.matchMedia || function(doc, undefined) { 6 | var bool, docElem = doc.documentElement, refNode = docElem.firstElementChild || docElem.firstChild, fakeBody = doc.createElement("body"), div = doc.createElement("div"); 7 | div.id = "mq-test-1"; 8 | div.style.cssText = "position:absolute;top:-100em"; 9 | fakeBody.style.background = "none"; 10 | fakeBody.appendChild(div); 11 | return function(q) { 12 | div.innerHTML = '­'; 13 | docElem.insertBefore(fakeBody, refNode); 14 | bool = div.offsetWidth === 42; 15 | docElem.removeChild(fakeBody); 16 | return { 17 | matches: bool, 18 | media: q 19 | }; 20 | }; 21 | }(w.document); 22 | })(this); 23 | 24 | /*! Respond.js v1.4.0: min/max-width media query polyfill. (c) Scott Jehl. MIT Lic. j.mp/respondjs */ 25 | (function(w) { 26 | "use strict"; 27 | var respond = {}; 28 | w.respond = respond; 29 | respond.update = function() {}; 30 | var requestQueue = [], xmlHttp = function() { 31 | var xmlhttpmethod = false; 32 | try { 33 | xmlhttpmethod = new w.XMLHttpRequest(); 34 | } catch (e) { 35 | xmlhttpmethod = new w.ActiveXObject("Microsoft.XMLHTTP"); 36 | } 37 | return function() { 38 | return xmlhttpmethod; 39 | }; 40 | }(), ajax = function(url, callback) { 41 | var req = xmlHttp(); 42 | if (!req) { 43 | return; 44 | } 45 | req.open("GET", url, true); 46 | req.onreadystatechange = function() { 47 | if (req.readyState !== 4 || req.status !== 200 && req.status !== 304) { 48 | return; 49 | } 50 | callback(req.responseText); 51 | }; 52 | if (req.readyState === 4) { 53 | return; 54 | } 55 | req.send(null); 56 | }; 57 | respond.ajax = ajax; 58 | respond.queue = requestQueue; 59 | respond.regex = { 60 | media: /@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi, 61 | keyframes: /@(?:\-(?:o|moz|webkit)\-)?keyframes[^\{]+\{(?:[^\{\}]*\{[^\}\{]*\})+[^\}]*\}/gi, 62 | urls: /(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g, 63 | findStyles: /@media *([^\{]+)\{([\S\s]+?)$/, 64 | only: /(only\s+)?([a-zA-Z]+)\s?/, 65 | minw: /\([\s]*min\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/, 66 | maxw: /\([\s]*max\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/ 67 | }; 68 | respond.mediaQueriesSupported = w.matchMedia && w.matchMedia("only all") !== null && w.matchMedia("only all").matches; 69 | if (respond.mediaQueriesSupported) { 70 | return; 71 | } 72 | var doc = w.document, docElem = doc.documentElement, mediastyles = [], rules = [], appendedEls = [], parsedSheets = {}, resizeThrottle = 30, head = doc.getElementsByTagName("head")[0] || docElem, base = doc.getElementsByTagName("base")[0], links = head.getElementsByTagName("link"), lastCall, resizeDefer, eminpx, getEmValue = function() { 73 | var ret, div = doc.createElement("div"), body = doc.body, originalHTMLFontSize = docElem.style.fontSize, originalBodyFontSize = body && body.style.fontSize, fakeUsed = false; 74 | div.style.cssText = "position:absolute;font-size:1em;width:1em"; 75 | if (!body) { 76 | body = fakeUsed = doc.createElement("body"); 77 | body.style.background = "none"; 78 | } 79 | docElem.style.fontSize = "100%"; 80 | body.style.fontSize = "100%"; 81 | body.appendChild(div); 82 | if (fakeUsed) { 83 | docElem.insertBefore(body, docElem.firstChild); 84 | } 85 | ret = div.offsetWidth; 86 | if (fakeUsed) { 87 | docElem.removeChild(body); 88 | } else { 89 | body.removeChild(div); 90 | } 91 | docElem.style.fontSize = originalHTMLFontSize; 92 | if (originalBodyFontSize) { 93 | body.style.fontSize = originalBodyFontSize; 94 | } 95 | ret = eminpx = parseFloat(ret); 96 | return ret; 97 | }, applyMedia = function(fromResize) { 98 | var name = "clientWidth", docElemProp = docElem[name], currWidth = doc.compatMode === "CSS1Compat" && docElemProp || doc.body[name] || docElemProp, styleBlocks = {}, lastLink = links[links.length - 1], now = new Date().getTime(); 99 | if (fromResize && lastCall && now - lastCall < resizeThrottle) { 100 | w.clearTimeout(resizeDefer); 101 | resizeDefer = w.setTimeout(applyMedia, resizeThrottle); 102 | return; 103 | } else { 104 | lastCall = now; 105 | } 106 | for (var i in mediastyles) { 107 | if (mediastyles.hasOwnProperty(i)) { 108 | var thisstyle = mediastyles[i], min = thisstyle.minw, max = thisstyle.maxw, minnull = min === null, maxnull = max === null, em = "em"; 109 | if (!!min) { 110 | min = parseFloat(min) * (min.indexOf(em) > -1 ? eminpx || getEmValue() : 1); 111 | } 112 | if (!!max) { 113 | max = parseFloat(max) * (max.indexOf(em) > -1 ? eminpx || getEmValue() : 1); 114 | } 115 | if (!thisstyle.hasquery || (!minnull || !maxnull) && (minnull || currWidth >= min) && (maxnull || currWidth <= max)) { 116 | if (!styleBlocks[thisstyle.media]) { 117 | styleBlocks[thisstyle.media] = []; 118 | } 119 | styleBlocks[thisstyle.media].push(rules[thisstyle.rules]); 120 | } 121 | } 122 | } 123 | for (var j in appendedEls) { 124 | if (appendedEls.hasOwnProperty(j)) { 125 | if (appendedEls[j] && appendedEls[j].parentNode === head) { 126 | head.removeChild(appendedEls[j]); 127 | } 128 | } 129 | } 130 | appendedEls.length = 0; 131 | for (var k in styleBlocks) { 132 | if (styleBlocks.hasOwnProperty(k)) { 133 | var ss = doc.createElement("style"), css = styleBlocks[k].join("\n"); 134 | ss.type = "text/css"; 135 | ss.media = k; 136 | head.insertBefore(ss, lastLink.nextSibling); 137 | if (ss.styleSheet) { 138 | ss.styleSheet.cssText = css; 139 | } else { 140 | ss.appendChild(doc.createTextNode(css)); 141 | } 142 | appendedEls.push(ss); 143 | } 144 | } 145 | }, translate = function(styles, href, media) { 146 | var qs = styles.replace(respond.regex.keyframes, "").match(respond.regex.media), ql = qs && qs.length || 0; 147 | href = href.substring(0, href.lastIndexOf("/")); 148 | var repUrls = function(css) { 149 | return css.replace(respond.regex.urls, "$1" + href + "$2$3"); 150 | }, useMedia = !ql && media; 151 | if (href.length) { 152 | href += "/"; 153 | } 154 | if (useMedia) { 155 | ql = 1; 156 | } 157 | for (var i = 0; i < ql; i++) { 158 | var fullq, thisq, eachq, eql; 159 | if (useMedia) { 160 | fullq = media; 161 | rules.push(repUrls(styles)); 162 | } else { 163 | fullq = qs[i].match(respond.regex.findStyles) && RegExp.$1; 164 | rules.push(RegExp.$2 && repUrls(RegExp.$2)); 165 | } 166 | eachq = fullq.split(","); 167 | eql = eachq.length; 168 | for (var j = 0; j < eql; j++) { 169 | thisq = eachq[j]; 170 | mediastyles.push({ 171 | media: thisq.split("(")[0].match(respond.regex.only) && RegExp.$2 || "all", 172 | rules: rules.length - 1, 173 | hasquery: thisq.indexOf("(") > -1, 174 | minw: thisq.match(respond.regex.minw) && parseFloat(RegExp.$1) + (RegExp.$2 || ""), 175 | maxw: thisq.match(respond.regex.maxw) && parseFloat(RegExp.$1) + (RegExp.$2 || "") 176 | }); 177 | } 178 | } 179 | applyMedia(); 180 | }, makeRequests = function() { 181 | if (requestQueue.length) { 182 | var thisRequest = requestQueue.shift(); 183 | ajax(thisRequest.href, function(styles) { 184 | translate(styles, thisRequest.href, thisRequest.media); 185 | parsedSheets[thisRequest.href] = true; 186 | w.setTimeout(function() { 187 | makeRequests(); 188 | }, 0); 189 | }); 190 | } 191 | }, ripCSS = function() { 192 | for (var i = 0; i < links.length; i++) { 193 | var sheet = links[i], href = sheet.href, media = sheet.media, isCSS = sheet.rel && sheet.rel.toLowerCase() === "stylesheet"; 194 | if (!!href && isCSS && !parsedSheets[href]) { 195 | if (sheet.styleSheet && sheet.styleSheet.rawCssText) { 196 | translate(sheet.styleSheet.rawCssText, href, media); 197 | parsedSheets[href] = true; 198 | } else { 199 | if (!/^([a-zA-Z:]*\/\/)/.test(href) && !base || href.replace(RegExp.$1, "").split("/")[0] === w.location.host) { 200 | if (href.substring(0, 2) === "//") { 201 | href = w.location.protocol + href; 202 | } 203 | requestQueue.push({ 204 | href: href, 205 | media: media 206 | }); 207 | } 208 | } 209 | } 210 | } 211 | makeRequests(); 212 | }; 213 | ripCSS(); 214 | respond.update = ripCSS; 215 | respond.getEmValue = getEmValue; 216 | function callMedia() { 217 | applyMedia(true); 218 | } 219 | if (w.addEventListener) { 220 | w.addEventListener("resize", callMedia, false); 221 | } else if (w.attachEvent) { 222 | w.attachEvent("onresize", callMedia); 223 | } 224 | })(this); -------------------------------------------------------------------------------- /CognitiveServicesDemo/Scripts/respond.matchmedia.addListener.js: -------------------------------------------------------------------------------- 1 | /*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license */ 2 | /*! NOTE: If you're already including a window.matchMedia polyfill via Modernizr or otherwise, you don't need this part */ 3 | (function(w) { 4 | "use strict"; 5 | w.matchMedia = w.matchMedia || function(doc, undefined) { 6 | var bool, docElem = doc.documentElement, refNode = docElem.firstElementChild || docElem.firstChild, fakeBody = doc.createElement("body"), div = doc.createElement("div"); 7 | div.id = "mq-test-1"; 8 | div.style.cssText = "position:absolute;top:-100em"; 9 | fakeBody.style.background = "none"; 10 | fakeBody.appendChild(div); 11 | return function(q) { 12 | div.innerHTML = '­'; 13 | docElem.insertBefore(fakeBody, refNode); 14 | bool = div.offsetWidth === 42; 15 | docElem.removeChild(fakeBody); 16 | return { 17 | matches: bool, 18 | media: q 19 | }; 20 | }; 21 | }(w.document); 22 | })(this); 23 | 24 | /*! matchMedia() polyfill addListener/removeListener extension. Author & copyright (c) 2012: Scott Jehl. Dual MIT/BSD license */ 25 | (function(w) { 26 | "use strict"; 27 | if (w.matchMedia && w.matchMedia("all").addListener) { 28 | return false; 29 | } 30 | var localMatchMedia = w.matchMedia, hasMediaQueries = localMatchMedia("only all").matches, isListening = false, timeoutID = 0, queries = [], handleChange = function(evt) { 31 | w.clearTimeout(timeoutID); 32 | timeoutID = w.setTimeout(function() { 33 | for (var i = 0, il = queries.length; i < il; i++) { 34 | var mql = queries[i].mql, listeners = queries[i].listeners || [], matches = localMatchMedia(mql.media).matches; 35 | if (matches !== mql.matches) { 36 | mql.matches = matches; 37 | for (var j = 0, jl = listeners.length; j < jl; j++) { 38 | listeners[j].call(w, mql); 39 | } 40 | } 41 | } 42 | }, 30); 43 | }; 44 | w.matchMedia = function(media) { 45 | var mql = localMatchMedia(media), listeners = [], index = 0; 46 | mql.addListener = function(listener) { 47 | if (!hasMediaQueries) { 48 | return; 49 | } 50 | if (!isListening) { 51 | isListening = true; 52 | w.addEventListener("resize", handleChange, true); 53 | } 54 | if (index === 0) { 55 | index = queries.push({ 56 | mql: mql, 57 | listeners: listeners 58 | }); 59 | } 60 | listeners.push(listener); 61 | }; 62 | mql.removeListener = function(listener) { 63 | for (var i = 0, il = listeners.length; i < il; i++) { 64 | if (listeners[i] === listener) { 65 | listeners.splice(i, 1); 66 | } 67 | } 68 | }; 69 | return mql; 70 | }; 71 | })(this); 72 | 73 | /*! Respond.js v1.4.0: min/max-width media query polyfill. (c) Scott Jehl. MIT Lic. j.mp/respondjs */ 74 | (function(w) { 75 | "use strict"; 76 | var respond = {}; 77 | w.respond = respond; 78 | respond.update = function() {}; 79 | var requestQueue = [], xmlHttp = function() { 80 | var xmlhttpmethod = false; 81 | try { 82 | xmlhttpmethod = new w.XMLHttpRequest(); 83 | } catch (e) { 84 | xmlhttpmethod = new w.ActiveXObject("Microsoft.XMLHTTP"); 85 | } 86 | return function() { 87 | return xmlhttpmethod; 88 | }; 89 | }(), ajax = function(url, callback) { 90 | var req = xmlHttp(); 91 | if (!req) { 92 | return; 93 | } 94 | req.open("GET", url, true); 95 | req.onreadystatechange = function() { 96 | if (req.readyState !== 4 || req.status !== 200 && req.status !== 304) { 97 | return; 98 | } 99 | callback(req.responseText); 100 | }; 101 | if (req.readyState === 4) { 102 | return; 103 | } 104 | req.send(null); 105 | }; 106 | respond.ajax = ajax; 107 | respond.queue = requestQueue; 108 | respond.regex = { 109 | media: /@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi, 110 | keyframes: /@(?:\-(?:o|moz|webkit)\-)?keyframes[^\{]+\{(?:[^\{\}]*\{[^\}\{]*\})+[^\}]*\}/gi, 111 | urls: /(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g, 112 | findStyles: /@media *([^\{]+)\{([\S\s]+?)$/, 113 | only: /(only\s+)?([a-zA-Z]+)\s?/, 114 | minw: /\([\s]*min\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/, 115 | maxw: /\([\s]*max\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/ 116 | }; 117 | respond.mediaQueriesSupported = w.matchMedia && w.matchMedia("only all") !== null && w.matchMedia("only all").matches; 118 | if (respond.mediaQueriesSupported) { 119 | return; 120 | } 121 | var doc = w.document, docElem = doc.documentElement, mediastyles = [], rules = [], appendedEls = [], parsedSheets = {}, resizeThrottle = 30, head = doc.getElementsByTagName("head")[0] || docElem, base = doc.getElementsByTagName("base")[0], links = head.getElementsByTagName("link"), lastCall, resizeDefer, eminpx, getEmValue = function() { 122 | var ret, div = doc.createElement("div"), body = doc.body, originalHTMLFontSize = docElem.style.fontSize, originalBodyFontSize = body && body.style.fontSize, fakeUsed = false; 123 | div.style.cssText = "position:absolute;font-size:1em;width:1em"; 124 | if (!body) { 125 | body = fakeUsed = doc.createElement("body"); 126 | body.style.background = "none"; 127 | } 128 | docElem.style.fontSize = "100%"; 129 | body.style.fontSize = "100%"; 130 | body.appendChild(div); 131 | if (fakeUsed) { 132 | docElem.insertBefore(body, docElem.firstChild); 133 | } 134 | ret = div.offsetWidth; 135 | if (fakeUsed) { 136 | docElem.removeChild(body); 137 | } else { 138 | body.removeChild(div); 139 | } 140 | docElem.style.fontSize = originalHTMLFontSize; 141 | if (originalBodyFontSize) { 142 | body.style.fontSize = originalBodyFontSize; 143 | } 144 | ret = eminpx = parseFloat(ret); 145 | return ret; 146 | }, applyMedia = function(fromResize) { 147 | var name = "clientWidth", docElemProp = docElem[name], currWidth = doc.compatMode === "CSS1Compat" && docElemProp || doc.body[name] || docElemProp, styleBlocks = {}, lastLink = links[links.length - 1], now = new Date().getTime(); 148 | if (fromResize && lastCall && now - lastCall < resizeThrottle) { 149 | w.clearTimeout(resizeDefer); 150 | resizeDefer = w.setTimeout(applyMedia, resizeThrottle); 151 | return; 152 | } else { 153 | lastCall = now; 154 | } 155 | for (var i in mediastyles) { 156 | if (mediastyles.hasOwnProperty(i)) { 157 | var thisstyle = mediastyles[i], min = thisstyle.minw, max = thisstyle.maxw, minnull = min === null, maxnull = max === null, em = "em"; 158 | if (!!min) { 159 | min = parseFloat(min) * (min.indexOf(em) > -1 ? eminpx || getEmValue() : 1); 160 | } 161 | if (!!max) { 162 | max = parseFloat(max) * (max.indexOf(em) > -1 ? eminpx || getEmValue() : 1); 163 | } 164 | if (!thisstyle.hasquery || (!minnull || !maxnull) && (minnull || currWidth >= min) && (maxnull || currWidth <= max)) { 165 | if (!styleBlocks[thisstyle.media]) { 166 | styleBlocks[thisstyle.media] = []; 167 | } 168 | styleBlocks[thisstyle.media].push(rules[thisstyle.rules]); 169 | } 170 | } 171 | } 172 | for (var j in appendedEls) { 173 | if (appendedEls.hasOwnProperty(j)) { 174 | if (appendedEls[j] && appendedEls[j].parentNode === head) { 175 | head.removeChild(appendedEls[j]); 176 | } 177 | } 178 | } 179 | appendedEls.length = 0; 180 | for (var k in styleBlocks) { 181 | if (styleBlocks.hasOwnProperty(k)) { 182 | var ss = doc.createElement("style"), css = styleBlocks[k].join("\n"); 183 | ss.type = "text/css"; 184 | ss.media = k; 185 | head.insertBefore(ss, lastLink.nextSibling); 186 | if (ss.styleSheet) { 187 | ss.styleSheet.cssText = css; 188 | } else { 189 | ss.appendChild(doc.createTextNode(css)); 190 | } 191 | appendedEls.push(ss); 192 | } 193 | } 194 | }, translate = function(styles, href, media) { 195 | var qs = styles.replace(respond.regex.keyframes, "").match(respond.regex.media), ql = qs && qs.length || 0; 196 | href = href.substring(0, href.lastIndexOf("/")); 197 | var repUrls = function(css) { 198 | return css.replace(respond.regex.urls, "$1" + href + "$2$3"); 199 | }, useMedia = !ql && media; 200 | if (href.length) { 201 | href += "/"; 202 | } 203 | if (useMedia) { 204 | ql = 1; 205 | } 206 | for (var i = 0; i < ql; i++) { 207 | var fullq, thisq, eachq, eql; 208 | if (useMedia) { 209 | fullq = media; 210 | rules.push(repUrls(styles)); 211 | } else { 212 | fullq = qs[i].match(respond.regex.findStyles) && RegExp.$1; 213 | rules.push(RegExp.$2 && repUrls(RegExp.$2)); 214 | } 215 | eachq = fullq.split(","); 216 | eql = eachq.length; 217 | for (var j = 0; j < eql; j++) { 218 | thisq = eachq[j]; 219 | mediastyles.push({ 220 | media: thisq.split("(")[0].match(respond.regex.only) && RegExp.$2 || "all", 221 | rules: rules.length - 1, 222 | hasquery: thisq.indexOf("(") > -1, 223 | minw: thisq.match(respond.regex.minw) && parseFloat(RegExp.$1) + (RegExp.$2 || ""), 224 | maxw: thisq.match(respond.regex.maxw) && parseFloat(RegExp.$1) + (RegExp.$2 || "") 225 | }); 226 | } 227 | } 228 | applyMedia(); 229 | }, makeRequests = function() { 230 | if (requestQueue.length) { 231 | var thisRequest = requestQueue.shift(); 232 | ajax(thisRequest.href, function(styles) { 233 | translate(styles, thisRequest.href, thisRequest.media); 234 | parsedSheets[thisRequest.href] = true; 235 | w.setTimeout(function() { 236 | makeRequests(); 237 | }, 0); 238 | }); 239 | } 240 | }, ripCSS = function() { 241 | for (var i = 0; i < links.length; i++) { 242 | var sheet = links[i], href = sheet.href, media = sheet.media, isCSS = sheet.rel && sheet.rel.toLowerCase() === "stylesheet"; 243 | if (!!href && isCSS && !parsedSheets[href]) { 244 | if (sheet.styleSheet && sheet.styleSheet.rawCssText) { 245 | translate(sheet.styleSheet.rawCssText, href, media); 246 | parsedSheets[href] = true; 247 | } else { 248 | if (!/^([a-zA-Z:]*\/\/)/.test(href) && !base || href.replace(RegExp.$1, "").split("/")[0] === w.location.host) { 249 | if (href.substring(0, 2) === "//") { 250 | href = w.location.protocol + href; 251 | } 252 | requestQueue.push({ 253 | href: href, 254 | media: media 255 | }); 256 | } 257 | } 258 | } 259 | } 260 | makeRequests(); 261 | }; 262 | ripCSS(); 263 | respond.update = ripCSS; 264 | respond.getEmValue = getEmValue; 265 | function callMedia() { 266 | applyMedia(true); 267 | } 268 | if (w.addEventListener) { 269 | w.addEventListener("resize", callMedia, false); 270 | } else if (w.attachEvent) { 271 | w.attachEvent("onresize", callMedia); 272 | } 273 | })(this); -------------------------------------------------------------------------------- /CognitiveServicesDemo/Scripts/respond.matchmedia.addListener.min.js: -------------------------------------------------------------------------------- 1 | /*! Respond.js v1.4.2: min/max-width media query polyfill * Copyright 2013 Scott Jehl 2 | * Licensed under https://github.com/scottjehl/Respond/blob/master/LICENSE-MIT 3 | * */ 4 | 5 | !function(a){"use strict";a.matchMedia=a.matchMedia||function(a){var b,c=a.documentElement,d=c.firstElementChild||c.firstChild,e=a.createElement("body"),f=a.createElement("div");return f.id="mq-test-1",f.style.cssText="position:absolute;top:-100em",e.style.background="none",e.appendChild(f),function(a){return f.innerHTML='­',c.insertBefore(e,d),b=42===f.offsetWidth,c.removeChild(e),{matches:b,media:a}}}(a.document)}(this),function(a){"use strict";if(a.matchMedia&&a.matchMedia("all").addListener)return!1;var b=a.matchMedia,c=b("only all").matches,d=!1,e=0,f=[],g=function(){a.clearTimeout(e),e=a.setTimeout(function(){for(var c=0,d=f.length;d>c;c++){var e=f[c].mql,g=f[c].listeners||[],h=b(e.media).matches;if(h!==e.matches){e.matches=h;for(var i=0,j=g.length;j>i;i++)g[i].call(a,e)}}},30)};a.matchMedia=function(e){var h=b(e),i=[],j=0;return h.addListener=function(b){c&&(d||(d=!0,a.addEventListener("resize",g,!0)),0===j&&(j=f.push({mql:h,listeners:i})),i.push(b))},h.removeListener=function(a){for(var b=0,c=i.length;c>b;b++)i[b]===a&&i.splice(b,1)},h}}(this),function(a){"use strict";function b(){u(!0)}var c={};a.respond=c,c.update=function(){};var d=[],e=function(){var b=!1;try{b=new a.XMLHttpRequest}catch(c){b=new a.ActiveXObject("Microsoft.XMLHTTP")}return function(){return b}}(),f=function(a,b){var c=e();c&&(c.open("GET",a,!0),c.onreadystatechange=function(){4!==c.readyState||200!==c.status&&304!==c.status||b(c.responseText)},4!==c.readyState&&c.send(null))};if(c.ajax=f,c.queue=d,c.regex={media:/@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi,keyframes:/@(?:\-(?:o|moz|webkit)\-)?keyframes[^\{]+\{(?:[^\{\}]*\{[^\}\{]*\})+[^\}]*\}/gi,urls:/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,findStyles:/@media *([^\{]+)\{([\S\s]+?)$/,only:/(only\s+)?([a-zA-Z]+)\s?/,minw:/\([\s]*min\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/,maxw:/\([\s]*max\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/},c.mediaQueriesSupported=a.matchMedia&&null!==a.matchMedia("only all")&&a.matchMedia("only all").matches,!c.mediaQueriesSupported){var g,h,i,j=a.document,k=j.documentElement,l=[],m=[],n=[],o={},p=30,q=j.getElementsByTagName("head")[0]||k,r=j.getElementsByTagName("base")[0],s=q.getElementsByTagName("link"),t=function(){var a,b=j.createElement("div"),c=j.body,d=k.style.fontSize,e=c&&c.style.fontSize,f=!1;return b.style.cssText="position:absolute;font-size:1em;width:1em",c||(c=f=j.createElement("body"),c.style.background="none"),k.style.fontSize="100%",c.style.fontSize="100%",c.appendChild(b),f&&k.insertBefore(c,k.firstChild),a=b.offsetWidth,f?k.removeChild(c):c.removeChild(b),k.style.fontSize=d,e&&(c.style.fontSize=e),a=i=parseFloat(a)},u=function(b){var c="clientWidth",d=k[c],e="CSS1Compat"===j.compatMode&&d||j.body[c]||d,f={},o=s[s.length-1],r=(new Date).getTime();if(b&&g&&p>r-g)return a.clearTimeout(h),h=a.setTimeout(u,p),void 0;g=r;for(var v in l)if(l.hasOwnProperty(v)){var w=l[v],x=w.minw,y=w.maxw,z=null===x,A=null===y,B="em";x&&(x=parseFloat(x)*(x.indexOf(B)>-1?i||t():1)),y&&(y=parseFloat(y)*(y.indexOf(B)>-1?i||t():1)),w.hasquery&&(z&&A||!(z||e>=x)||!(A||y>=e))||(f[w.media]||(f[w.media]=[]),f[w.media].push(m[w.rules]))}for(var C in n)n.hasOwnProperty(C)&&n[C]&&n[C].parentNode===q&&q.removeChild(n[C]);n.length=0;for(var D in f)if(f.hasOwnProperty(D)){var E=j.createElement("style"),F=f[D].join("\n");E.type="text/css",E.media=D,q.insertBefore(E,o.nextSibling),E.styleSheet?E.styleSheet.cssText=F:E.appendChild(j.createTextNode(F)),n.push(E)}},v=function(a,b,d){var e=a.replace(c.regex.keyframes,"").match(c.regex.media),f=e&&e.length||0;b=b.substring(0,b.lastIndexOf("/"));var g=function(a){return a.replace(c.regex.urls,"$1"+b+"$2$3")},h=!f&&d;b.length&&(b+="/"),h&&(f=1);for(var i=0;f>i;i++){var j,k,n,o;h?(j=d,m.push(g(a))):(j=e[i].match(c.regex.findStyles)&&RegExp.$1,m.push(RegExp.$2&&g(RegExp.$2))),n=j.split(","),o=n.length;for(var p=0;o>p;p++)k=n[p],l.push({media:k.split("(")[0].match(c.regex.only)&&RegExp.$2||"all",rules:m.length-1,hasquery:k.indexOf("(")>-1,minw:k.match(c.regex.minw)&&parseFloat(RegExp.$1)+(RegExp.$2||""),maxw:k.match(c.regex.maxw)&&parseFloat(RegExp.$1)+(RegExp.$2||"")})}u()},w=function(){if(d.length){var b=d.shift();f(b.href,function(c){v(c,b.href,b.media),o[b.href]=!0,a.setTimeout(function(){w()},0)})}},x=function(){for(var b=0;b #mq-test-1 { width: 42px; }',c.insertBefore(e,d),b=42===f.offsetWidth,c.removeChild(e),{matches:b,media:a}}}(a.document)}(this),function(a){"use strict";function b(){u(!0)}var c={};a.respond=c,c.update=function(){};var d=[],e=function(){var b=!1;try{b=new a.XMLHttpRequest}catch(c){b=new a.ActiveXObject("Microsoft.XMLHTTP")}return function(){return b}}(),f=function(a,b){var c=e();c&&(c.open("GET",a,!0),c.onreadystatechange=function(){4!==c.readyState||200!==c.status&&304!==c.status||b(c.responseText)},4!==c.readyState&&c.send(null))};if(c.ajax=f,c.queue=d,c.regex={media:/@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi,keyframes:/@(?:\-(?:o|moz|webkit)\-)?keyframes[^\{]+\{(?:[^\{\}]*\{[^\}\{]*\})+[^\}]*\}/gi,urls:/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,findStyles:/@media *([^\{]+)\{([\S\s]+?)$/,only:/(only\s+)?([a-zA-Z]+)\s?/,minw:/\([\s]*min\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/,maxw:/\([\s]*max\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/},c.mediaQueriesSupported=a.matchMedia&&null!==a.matchMedia("only all")&&a.matchMedia("only all").matches,!c.mediaQueriesSupported){var g,h,i,j=a.document,k=j.documentElement,l=[],m=[],n=[],o={},p=30,q=j.getElementsByTagName("head")[0]||k,r=j.getElementsByTagName("base")[0],s=q.getElementsByTagName("link"),t=function(){var a,b=j.createElement("div"),c=j.body,d=k.style.fontSize,e=c&&c.style.fontSize,f=!1;return b.style.cssText="position:absolute;font-size:1em;width:1em",c||(c=f=j.createElement("body"),c.style.background="none"),k.style.fontSize="100%",c.style.fontSize="100%",c.appendChild(b),f&&k.insertBefore(c,k.firstChild),a=b.offsetWidth,f?k.removeChild(c):c.removeChild(b),k.style.fontSize=d,e&&(c.style.fontSize=e),a=i=parseFloat(a)},u=function(b){var c="clientWidth",d=k[c],e="CSS1Compat"===j.compatMode&&d||j.body[c]||d,f={},o=s[s.length-1],r=(new Date).getTime();if(b&&g&&p>r-g)return a.clearTimeout(h),h=a.setTimeout(u,p),void 0;g=r;for(var v in l)if(l.hasOwnProperty(v)){var w=l[v],x=w.minw,y=w.maxw,z=null===x,A=null===y,B="em";x&&(x=parseFloat(x)*(x.indexOf(B)>-1?i||t():1)),y&&(y=parseFloat(y)*(y.indexOf(B)>-1?i||t():1)),w.hasquery&&(z&&A||!(z||e>=x)||!(A||y>=e))||(f[w.media]||(f[w.media]=[]),f[w.media].push(m[w.rules]))}for(var C in n)n.hasOwnProperty(C)&&n[C]&&n[C].parentNode===q&&q.removeChild(n[C]);n.length=0;for(var D in f)if(f.hasOwnProperty(D)){var E=j.createElement("style"),F=f[D].join("\n");E.type="text/css",E.media=D,q.insertBefore(E,o.nextSibling),E.styleSheet?E.styleSheet.cssText=F:E.appendChild(j.createTextNode(F)),n.push(E)}},v=function(a,b,d){var e=a.replace(c.regex.keyframes,"").match(c.regex.media),f=e&&e.length||0;b=b.substring(0,b.lastIndexOf("/"));var g=function(a){return a.replace(c.regex.urls,"$1"+b+"$2$3")},h=!f&&d;b.length&&(b+="/"),h&&(f=1);for(var i=0;f>i;i++){var j,k,n,o;h?(j=d,m.push(g(a))):(j=e[i].match(c.regex.findStyles)&&RegExp.$1,m.push(RegExp.$2&&g(RegExp.$2))),n=j.split(","),o=n.length;for(var p=0;o>p;p++)k=n[p],l.push({media:k.split("(")[0].match(c.regex.only)&&RegExp.$2||"all",rules:m.length-1,hasquery:k.indexOf("(")>-1,minw:k.match(c.regex.minw)&&parseFloat(RegExp.$1)+(RegExp.$2||""),maxw:k.match(c.regex.maxw)&&parseFloat(RegExp.$1)+(RegExp.$2||"")})}u()},w=function(){if(d.length){var b=d.shift();f(b.href,function(c){v(c,b.href,b.media),o[b.href]=!0,a.setTimeout(function(){w()},0)})}},x=function(){for(var b=0;b 6 |

    ASP.NET

    7 |

    ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.

    8 |

    Learn more »

    9 | 10 | 11 |
    12 |
    13 |

    Getting started

    14 |

    15 | ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that 16 | enables a clean separation of concerns and gives you full control over markup 17 | for enjoyable, agile development. 18 |

    19 |

    Learn more »

    20 |
    21 |
    22 |

    Get more libraries

    23 |

    NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.

    24 |

    Learn more »

    25 |
    26 |
    27 |

    Web Hosting

    28 |

    You can easily find a web hosting company that offers the right mix of features and price for your applications.

    29 |

    Learn more »

    30 |
    31 |
    -------------------------------------------------------------------------------- /CognitiveServicesDemo/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @model ErrorModel 2 | 3 | 4 | 5 | 6 | Error 7 | 8 | 9 |
    10 |

    Error @(Model?.Code)

    11 |

    @(Model?.Message)

    12 |
    13 | 14 | 15 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | @ViewBag.Title - CognitiveServicesDemo 7 | @Styles.Render("~/Content/css") 8 | @Scripts.Render("~/bundles/modernizr") 9 | 10 | 11 | 30 |
    31 |
    32 | @if (ViewBag.LeftMenu != null) 33 | { 34 | @Html.Partial((string)ViewBag.LeftMenu) 35 |
    36 | @RenderBody() 37 |
    38 | } 39 | else 40 | { 41 |
    42 | @RenderBody() 43 |
    44 | } 45 |
    46 |
    47 |
    48 |

    © 2017 - Gunnar Peipman

    49 |
    50 |
    51 | 52 | @Scripts.Render("~/bundles/jquery") 53 | @Scripts.Render("~/bundles/bootstrap") 54 | @RenderSection("scripts", required: false) 55 | 56 | 57 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/Views/Shared/_Upload.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = null; 3 | } 4 |
    5 | Upload photo to analyze:
    6 | 7 |
    -------------------------------------------------------------------------------- /CognitiveServicesDemo/Views/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 |
    7 |
    8 | 9 | 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 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "~/Views/Shared/_Layout.cshtml"; 3 | } 4 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/Web.Debug.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/Web.Release.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 6 | 7 | 8 | 9 | 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 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /CognitiveServicesDemo/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpeipman/CognitiveServicesDemo/f04bd31247de628902bdc787a8d23127646943a5/CognitiveServicesDemo/favicon.ico -------------------------------------------------------------------------------- /CognitiveServicesDemo/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpeipman/CognitiveServicesDemo/f04bd31247de628902bdc787a8d23127646943a5/CognitiveServicesDemo/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /CognitiveServicesDemo/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpeipman/CognitiveServicesDemo/f04bd31247de628902bdc787a8d23127646943a5/CognitiveServicesDemo/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /CognitiveServicesDemo/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpeipman/CognitiveServicesDemo/f04bd31247de628902bdc787a8d23127646943a5/CognitiveServicesDemo/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /CognitiveServicesDemo/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpeipman/CognitiveServicesDemo/f04bd31247de628902bdc787a8d23127646943a5/CognitiveServicesDemo/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /CognitiveServicesDemo/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CognitiveServicesDemo 2 | 3 | This solution contains ASP.NET MVC web application that demonstrates Microsoft Cognitive Services. This is on-going work and in case of any bugs or feature requests please report the new issue. 4 | 5 | ## Getting started 6 | 7 | 1. Log in to Azure Portal 8 | 2. Create new Cognitive Services Face API and Computer Vision API accounts 9 | 3. Clone or download solution 10 | 4. At web application root folder create file keys.config 11 | 5. Add your API keys to this file 12 | 6. Set API end-points in web.config file 13 | 7. Run web application 14 | 15 | ## Example keys.config 16 | 17 | ```xml 18 | 19 | 20 | 21 | 22 | 23 | ``` 24 | --------------------------------------------------------------------------------