Ejemplo n.º 1
0
        //3.2.2
        //public event Action<ServiceResult<DevicePara>> OnFaceUpdateCompleted;
        public void FaceUpdate(string ipAddress, string passport, faceinfo face, Action <Exception> failFunc)
        {
            var url = "http://" + ipAddress + ":8090/face/update";

            KeyValuePair <String, String>[] data = new KeyValuePair <string, string> [4];
            data[0] = new KeyValuePair <string, string>("pass", passport);
            data[1] = new KeyValuePair <string, string>("personId", face.personid);
            data[2] = new KeyValuePair <string, string>("faceId", face.faceid);
            data[3] = new KeyValuePair <string, string>("imgBase64", face.imagebase64);
            web.Post(data, url,
                     (response, exp) =>
            {
                if (null != response)
                {
                    var ret = JsonSerializer <ServiceResult <int> > .Deserialize(response);
                    if (ret != null)
                    {
                        if (null != OnFaceUpdateCompleted)
                        {
                            OnFaceUpdateCompleted(ret);
                        }
                    }
                    else
                    {
                        failFunc(new Exception("Failed in face update!"));
                    }
                }
                else if (null != exp)
                {
                    failFunc(exp);
                }
            });
        }
Ejemplo n.º 2
0
        /**********************************************
        *
        *  implementation 照片管理接口 3.2
        *
        **********************************************/
        public async Task <ServiceResult <string> > FaceCreate(Camera camera, faceinfo face)
        {
            System.Diagnostics.Debug.Assert(camera != null);
            var url = string.Format("http://{0}:{1}/face/create", camera.IP, camera.Port);

            KeyValuePair <String, String>[] data = new KeyValuePair <string, string> [4];
            data[0] = new KeyValuePair <string, string>("pass", camera.Pwd);
            data[1] = new KeyValuePair <string, string>("personId", face.personid);
            data[2] = new KeyValuePair <string, string>("faceId", face.faceid);
            data[3] = new KeyValuePair <string, string>("imgBase64", face.imagebase64);
            var response = await web.Post(data, url);

            if (!string.IsNullOrEmpty(response))
            {
                var ret = JsonSerializer <ServiceResult <string> > .Deserialize(response);

                if (ret != null)
                {
                    return(ret);
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        async Task <PhotoImageQueryItem[]> CreatePersonToCamera(Employee entity, EmployeeCameraRelation c)
        {
            List <PhotoImageQueryItem> list = new List <PhotoImageQueryItem>();
            var ret = await service.personCreate(c.Camera, new Person()
            {
                id = entity.Code, idcardnum = entity.IDCard, name = entity.Name
            });

            if (ret.success)
            {
                try
                {
                    c.PersonID      = ret.data == null ? null : ret.data.id;
                    c.FirstPhotoID  = null;
                    c.SecondPhotoID = null;
                    c.ThirdPhotoID  = null;
                    if (entity.FirstPhoto != null)
                    {
                        var fi = new faceinfo()
                        {
                            faceid      = entity.FirstPhoto.ID.ToString().Replace("-", ""),
                            personid    = c.PersonID,
                            imagebase64 = Utils.Base64Converter.File2String(entity.FirstPhoto.FilePath)
                        };
                        var photo = await service.FaceCreate(c.Camera, fi);

                        if (photo.success)
                        {
                            c.FirstPhotoID = fi.faceid;
                            var item = new PhotoImageQueryItem()
                            {
                                Camera       = c.Camera,
                                PersonID     = c.PersonID,
                                FaceID       = c.FirstPhotoID,
                                PhotoImageID = entity.FirstPhoto.ID,
                            };
                            list.Add(item);
                        }
                        else
                        {
                            throw new Exception(string.Format("上传第一张照片到设备({0})失败", c.Camera.IP));
                        }
                    }
                    if (entity.SecondPhoto != null)
                    {
                        var fi = new faceinfo()
                        {
                            faceid      = entity.SecondPhoto.ID.ToString().Replace("-", ""),
                            personid    = c.PersonID,
                            imagebase64 = Utils.Base64Converter.File2String(entity.SecondPhoto.FilePath)
                        };
                        var photo = await service.FaceCreate(c.Camera, fi);

                        if (photo.success)
                        {
                            c.SecondPhotoID = fi.faceid;
                            var item = new PhotoImageQueryItem()
                            {
                                Camera       = c.Camera,
                                PersonID     = c.PersonID,
                                FaceID       = c.SecondPhotoID,
                                PhotoImageID = entity.SecondPhoto.ID,
                            };
                            list.Add(item);
                        }
                        else
                        {
                            throw new Exception(string.Format("上传第二张照片到设备({0})失败", c.Camera.IP));
                        }
                    }
                    if (entity.ThirdPhoto != null)
                    {
                        var fi = new faceinfo()
                        {
                            faceid      = entity.ThirdPhoto.ID.ToString().Replace("-", ""),
                            personid    = c.PersonID,
                            imagebase64 = Utils.Base64Converter.File2String(entity.ThirdPhoto.FilePath)
                        };
                        var photo = await service.FaceCreate(c.Camera, fi);

                        if (photo.success)
                        {
                            c.ThirdPhotoID = fi.faceid;
                            var item = new PhotoImageQueryItem()
                            {
                                Camera       = c.Camera,
                                PersonID     = c.PersonID,
                                FaceID       = c.ThirdPhotoID,
                                PhotoImageID = entity.ThirdPhoto.ID,
                            };
                            list.Add(item);
                        }
                        else
                        {
                            throw new Exception(string.Format("上传第三张照片到设备({0})失败", c.Camera.IP));
                        }
                    }

                    c.Status = 1;
                }
                catch (Exception exp)
                {
                    System.Diagnostics.Debug.WriteLine(exp);
                    throw exp;
                }
                //
            }

            return(list.ToArray());
        }