Пример #1
0
    private IEnumerator CreatePerson(string name)
    {
        modalPanel.ShowProgress("Saving data, Please Wait ...");
        Person p = null;

        AsyncTask <bool> task = new AsyncTask <bool>(() =>
        {
            try
            {
                // update data in the cloud
                CloudUserManager groupMgr = CloudUserManager.Instance;

                if (groupMgr != null && persons != null)
                {
                    p = groupMgr.AddUserToGroup(name, string.Empty);
                    return(true);
                }

                return(false);
            }
            catch (Exception ex)
            {
                Debug.LogError("Failed to process task: " + ex.Message + "\n" + ex.StackTrace);
                return(false);
            }
        });

        task.Start();
        yield return(null);

        while (task.State == TaskState.Running)
        {
            yield return(null);
        }

        modalPanel.Hide();

        if (!task.Result)
        {
            modalPanel.ShowMessage("Error saving data!");
        }
        else
        {
            HidePersonDetails();

            if (p != null)
            {
                persons.Add(p);
                InstantiatePersonPanel(p);
            }
        }

        yield return(null);
    }
Пример #2
0
    // Creates new user and adds it to the user group
    private IEnumerator AddUserToGroup(Face face, string userName, string userInfo)
    {
        CloudUserManager userManager = CloudUserManager.Instance;

        if (texCamShot && userManager && face != null && userName != null && userName.Trim() != string.Empty)
        {
            SetHintText("Wait...");
            yield return(null);

            FaceRectangle faceRect   = face.faceRectangle;
            byte[]        imageBytes = texCamShot.EncodeToJPG();
            yield return(null);

            AsyncTask <Person> task = new AsyncTask <Person>(() => {
                return(userManager.AddUserToGroup(userName.Trim(), userInfo, imageBytes, faceRect));
            });

            task.Start();
            yield return(null);

            while (task.State == TaskState.Running)
            {
                yield return(null);
            }

            // Get the resulting person
            Person person = task.Result;

            if (!string.IsNullOrEmpty(task.ErrorMessage))
            {
                SetHintText(task.ErrorMessage);
                Debug.LogError(task.ErrorMessage);
            }
            else if (person != null && person.persistedFaceIds != null && person.persistedFaceIds.Length > 0)
            {
                string faceId     = face.faceId;
                bool   bFaceFound = false;

                for (int i = 0; i < faces.Length; i++)
                {
                    if (faces[i].faceId == faceId)
                    {
                        if (faces[i].candidate == null || faces[i].candidate.person == null)
                        {
                            faces[i].candidate = new Candidate();

                            faces[i].candidate.personId   = person.personId;
                            faces[i].candidate.confidence = 1f;
                            faces[i].candidate.person     = person;
                        }

                        bFaceFound = true;
                        break;
                    }
                }

                if (!bFaceFound)
                {
                    Debug.Log(string.Format("Face {0} not found.", faceId));
                }

                SetHintText(string.Format("'{0}' created successfully.", userName.Trim()));
                ShowIdentityResult();
            }
            else
            {
                SetHintText("User could not be created.");
            }
        }

        yield return(null);
    }