private static void InitImagesAfterChangeGroom()
        {
            List <ImageEntity> images = ImageEntity.Get();

            for (int i = 0; i < images.Count; i++)
            {
                var  res     = InitImages.getResultFacePP(images[i].url);
                bool isGroom = InitImages.IsGroom(res);
                ImageEntity.UpdateIsGroom(images[i].url, isGroom);
            }
        }
        public static WebResult <List <ImageEntity> > InsertGroom(List <String> base64arr)
        {
            List <ImageEntity> images = null;

            try
            {
                images = Images.GetImages().Value;
                if (base64arr.Count == 2)
                {
                    var          base64     = Regex.Replace(base64arr[0], @"^data:image\/[a-zA-Z]+;base64,", string.Empty);
                    byte[]       byteArray  = System.Convert.FromBase64String(base64);
                    MemoryStream stream     = new MemoryStream(byteArray);
                    string       urlStorage = InitImages.SendToStorage(base64arr[1], stream);
                    if (urlStorage == "")
                    {
                        return new WebResult <List <ImageEntity> >()
                               {
                                   Status  = false,
                                   Message = "failed to load image",
                                   Value   = images
                               }
                    }
                    ;
                    GroomEntity groom = new GroomEntity();
                    groom.url = urlStorage;
                    string token = getFaceToken(urlStorage);
                    if (token == "")
                    {
                        return new WebResult <List <ImageEntity> >()
                               {
                                   Status  = false,
                                   Message = "failed",
                                   Value   = images
                               }
                    }
                    ;
                    groom.token = token;
                    groom.name  = base64arr[1];
                    if (GroomEntity.Get().ToList().Count > 0)
                    {
                        GroomEntity.RemoveAll();

                        groom.Add();
                        InitImagesAfterChangeGroom();
                        images = Images.GetImages().Value;
                        return(new WebResult <List <ImageEntity> >()
                        {
                            Status = true,
                            Message = "Ok",
                            Value = images
                        });
                    }
                    groom.Add();
                    return(new WebResult <List <ImageEntity> >()
                    {
                        Status = true,
                        Message = "Ok",
                        Value = Images.GetImages().Value
                    });
                }


                return(new WebResult <List <ImageEntity> >()
                {
                    Status = false,
                    Message = "That's not an image",
                    Value = images
                });
            }
            catch (Exception e)
            {
                return(new WebResult <List <ImageEntity> >()
                {
                    Status = false,
                    Message = e.Message,
                    Value = images
                });
            }
        }
Exemplo n.º 3
0
        public static WebResult <bool> InsertGroom()
        {
            try
            {
                HttpResponseMessage response = new HttpResponseMessage();
                var httpRequest = HttpContext.Current.Request;
                List <Entities.ImageEntity> images = new List <Entities.ImageEntity>();
                if (httpRequest.Files.Count == 1)
                {
                    var postedFile = httpRequest.Files[0];
                    if (string.Equals(postedFile.ContentType, "image/jpg", StringComparison.OrdinalIgnoreCase) ||
                        string.Equals(postedFile.ContentType, "image/jpeg", StringComparison.OrdinalIgnoreCase) ||
                        string.Equals(postedFile.ContentType, "image/pjpeg", StringComparison.OrdinalIgnoreCase) ||
                        string.Equals(postedFile.ContentType, "image/gif", StringComparison.OrdinalIgnoreCase) ||
                        string.Equals(postedFile.ContentType, "image/x-png", StringComparison.OrdinalIgnoreCase) ||
                        string.Equals(postedFile.ContentType, "image/png", StringComparison.OrdinalIgnoreCase))
                    {
                        string urlStorage = InitImages.SendToStorage(postedFile.FileName, postedFile.InputStream);
                        if (urlStorage == "")
                        {
                            return new WebResult <bool>()
                                   {
                                       Status  = false,
                                       Message = "failed to load image",
                                       Value   = false
                                   }
                        }
                        ;
                        Groom groom = new Groom();
                        groom.url = urlStorage;
                        string token = getFaceToken(urlStorage);
                        if (token == "")
                        {
                            return new WebResult <bool>()
                                   {
                                       Status  = false,
                                       Message = "failed",
                                       Value   = false
                                   }
                        }
                        ;
                        groom.token = token;
                        groom.name  = postedFile.FileName;
                        DB.Grooms.Add(groom);
                        if (DB.SaveChanges() > 0)
                        {
                            return new WebResult <bool>()
                                   {
                                       Status  = true,
                                       Message = "Ok",
                                       Value   = true
                                   }
                        }
                        ;
                    }
                }

                return(new WebResult <bool>()
                {
                    Status = false,
                    Message = "That's not an image",
                    Value = false
                });
            }
            catch (Exception e)
            {
                return(new WebResult <bool>()
                {
                    Status = false,
                    Message = e.Message,
                    Value = false
                });
            }
        }