Пример #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));
        }
Пример #2
0
        public JArrayString ProcessMessage(RbAppMasterCache rbappmc, RbAppRouterCache rbapprc, RbHeader rbh, string rbBodyString)
        {
            var results = new JArray();

            var appInfo          = JsonConvert.DeserializeObject <JObject>(rbappmc.AppInfo);
            var connectionString = (appInfo["SqlConnectionString"] ?? "").ToString();

            PersonInfoModel.Connection(connectionString);
            PersonFaceInfoModel.Connection(connectionString);

            var       rbBody    = JsonConvert.DeserializeObject <JObject>(rbBodyString);
            RbMessage rbMessage = null;

            if (rbh.MessageId == "GetFaceInfo")
            {
                rbMessage = GetFaceInfo(rbh, appInfo, rbBody);
            }
            else if (rbh.MessageId == "RegisterFace")
            {
                rbMessage = ResisterPersonFace(rbh, appInfo, rbBody);
            }
            else if (rbh.MessageId == "DeleteFace")
            {
                rbMessage = DeleteFace(rbh, appInfo, rbBody);
            }
            results.Add(JsonConvert.DeserializeObject <JObject>(JsonConvert.SerializeObject(rbMessage)));

            return(new JArrayString(results));
        }
Пример #3
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);
        }
        private static PersonInfoModel Build(IQueryable <PersonInfo> records)
        {
            if (records.Count() == 0)
            {
                return(PersonInfoModel.New());
            }

            var model = PersonInfoModel.New();

            model.Id             = records.First <PersonInfo>().Id;
            model.PersonGroupId  = records.First <PersonInfo>().PersonGroupId;
            model.PersonId       = records.First <PersonInfo>().PersonId;
            model.PersonName     = records.First <PersonInfo>().PersonName;
            model.PersonNameYomi = records.First <PersonInfo>().PersonNameYomi;
            model.IsDeleted      = (bool)(records.First <PersonInfo>().IsDeleted.HasValue ? records.First <PersonInfo>().IsDeleted : false);
            model.LastDetectedAt = records.First <PersonInfo>().LastDetectedAt;
            model.CreatedAt      = records.First <PersonInfo>().CreatedAt;
            model.UpdatedAt      = records.First <PersonInfo>().UpdatedAt;

            return(model);
        }