Ejemplo n.º 1
0
        private RbMessage DeleteFace(RbHeader rbh, JObject appInfo, JObject jo_input)
        {
            var storageAccount   = (appInfo["StorageAccount"] ?? "").ToString();
            var storageKey       = (appInfo["StorageKey"] ?? "").ToString();
            var storageContainer = (appInfo["StorageContainer"] ?? "").ToString();
            var faceApiKey       = (appInfo["FaceApiKey"] ?? "").ToString();

            AppBody appbody = new AppBody();

            appbody.PersonId      = (jo_input["PersonId"] ?? "").ToString();
            appbody.PersonGroupId = (jo_input["PersonGroupId"] ?? "").ToString();

            var facePerson         = new HwsMicrosoftFaceApi.Person.Client(faceApiKey);
            var personDeleteResult = facePerson.Delete(appbody.PersonGroupId, appbody.PersonId);

            if (personDeleteResult.apiResult.IsSuccessStatusCode)
            {
                var personGroup = new HwsMicrosoftFaceApi.PersonGroup.Client(faceApiKey);
                personGroup.Train(appbody.PersonGroupId);

                PersonInfoModel.Find(appbody.PersonId).Delete();
            }
            else
            {
                appbody.Code = ERROR_CODE;
            }

            return(GetRbMessage(rbh, appbody));
        }
Ejemplo n.º 2
0
        private AppResult CreateOrUpdatePersonInfo(AppBody _appbody)
        {
            AppResult appResult = new AppResult();
            ApiResult apiResult = new ApiResult();

            apiResult.IsSuccessStatusCode = true;

            var now = DateTime.UtcNow;

            foreach (var personInfo in _appbody.PersonInfos)
            {
                try
                {
                    var model          = PersonInfoModel.Find(personInfo.PersonId);
                    var lastDetectedAt = model.LastDetectedAt.HasValue ? model.LastDetectedAt.Value : now;
                    var registeredAt   = model.CreatedAt.HasValue ? model.CreatedAt.Value : now;

                    model.PersonGroupId  = _appbody.PersonGroupId;
                    model.PersonId       = personInfo.PersonId;
                    model.PersonName     = personInfo.PersonName ?? model.PersonName;
                    model.PersonNameYomi = personInfo.PersonNameYomi ?? model.PersonNameYomi;
                    model.LastDetectedAt = now;
                    model.Save();

                    personInfo.PersonName     = model.PersonName;
                    personInfo.PersonNameYomi = model.PersonNameYomi;
                    personInfo.LastDetectedAt = (long)lastDetectedAt.Subtract(UnixEpoch).TotalSeconds;
                    personInfo.RegisteredAt   = (long)registeredAt.Subtract(UnixEpoch).TotalSeconds;
                }
                catch (Exception ex)
                {
                    apiResult.IsSuccessStatusCode = false;
                    apiResult.Message             = ex.Message;
                }
            }

            appResult.apiResult = apiResult;
            appResult.appBody   = _appbody;

            return(appResult);
        }