private async void AppBarButtonPersonGroupRefresh_Click(object sender, RoutedEventArgs e)
        {
            this.IsEnabled = false;
            personGroupProgressRing.IsActive = true;

            //appbarEditPersonGroupButton.IsEnabled = false;
            appbarPersonGroupNextButton.IsEnabled   = false;
            appbarDeletePersonGroupButton.IsEnabled = false;

            List <PersonGroups> personGroups = await PersonGroupCmds.ListPersonGroups();

            personGroupListView.ItemsSource = personGroups;
            //personGroupListView.DisplayMemberPath = "name";
            globals.gPersonGroupList = personGroups;

            personGroupProgressRing.IsActive = false;
            this.IsEnabled = true;
        }
예제 #2
0
        //private async Task btnFileQuery_Click()
        //{
        //    StorageFile file = null;
        //    if (webcam.IsInitialized())
        //    {
        //        // Stores current frame from webcam feed in a temporary folder
        //        file = await webcam.CapturePhoto();
        //        FaceQuery(file);
        //    }
        //    else
        //    {
        //        if (!webcam.IsInitialized())
        //        {
        //            // The webcam has not been fully initialized for whatever reason:
        //            Debug.WriteLine("Unable to analyze visitor at door as the camera failed to initlialize properly.");
        //            await speech.Read(SpeechContants.NoCameraMessage);
        //        }
        //    }

        //    FaceQuery(file);
        //    btnFileQuery.IsEnabled = true;
        //}
        private async void FaceQuery(StorageFile file)
        {
            CloudBlockBlob blob         = null;
            string         blobFileName = null;

            if (null != file)
            {
                progressRingMainPage.IsActive = true;
                BitmapImage         bitmapImage = new BitmapImage();
                IRandomAccessStream fileStream  = await file.OpenAsync(FileAccessMode.Read);

                bitmapImage.SetSource(fileStream);

                blobFileName = System.Guid.NewGuid() + "." + file.Name.Split('.').Last <string>();

                await HttpHandler.tempContainer.CreateIfNotExistsAsync();

                BlobContainerPermissions permissions = new BlobContainerPermissions();
                permissions.PublicAccess = BlobContainerPublicAccessType.Blob;
                await HttpHandler.tempContainer.SetPermissionsAsync(permissions);

                blob = HttpHandler.tempContainer.GetBlockBlobReference(blobFileName);
                await blob.DeleteIfExistsAsync();

                await blob.UploadFromFileAsync(file);

                string              uri        = "https://api.projectoxford.ai/face/v1.0/detect?returnFaceId=true";
                string              jsonString = "{\"url\":\"" + HttpHandler.storagePath + "visitors/" + blobFileName + "\"}";
                HttpContent         content    = new StringContent(jsonString, Encoding.UTF8, "application/json");
                HttpResponseMessage response   = await HttpHandler.client.PostAsync(uri, content);

                if (response.IsSuccessStatusCode)
                {
                    string responseBody = await response.Content.ReadAsStringAsync();

                    if (null == globals.gPersonGroupList)
                    {
                        globals.gPersonGroupList = await PersonGroupCmds.ListPersonGroups();
                    }

                    List <string> names = await VisitorCmds.CheckVisitorFace(responseBody, globals.gPersonGroupList);

                    if (0 == names.Count)
                    {
                        await speech.Read(SpeechContants.VisitorNotRecognizedMessage);
                    }
                    else
                    {
                        UnlockDoor(string.Join(", ", names.ToArray()));
                    }
                }
                else
                {
                    string responseBody = await response.Content.ReadAsStringAsync();

                    globals.ShowJsonErrorPopup(responseBody);
                }

                await blob.DeleteAsync();

                progressRingMainPage.IsActive = false;
            }
        }