public bool ValidatePerson(byte[] photo, out MembershipPerson person, support.Algorithm algorithm, out double runTime)
        {
            person = null;
            string err = "";
            int    predictedPersonID = -1;

            runTime = -1;
            using (var dbContext = new DBContext())
            {
                Dictionary <int, List <byte[]> > photoStreams = dbContext.GetAllPersonsPhotos();
                DateTime timeStart = DateTime.Now;
                if (photoStreams != null &&
                    photoStreams.Count != 0 &&
                    photo != null &&
                    (algorithm == support.Algorithm.EigenFaces ?
                     EigenFaces.ProcessImageSample(out err, out predictedPersonID, photoStreams, photo) :
                     FisherFaces.ProcessImageSample(out err, out predictedPersonID, photoStreams, photo)) &&
                    predictedPersonID >= 0)
                {
                    runTime = (DateTime.Now - timeStart).TotalSeconds;
                    person  = GetPerson(predictedPersonID);
                    return(person != null);
                }
            }
            return(false);
        }
        public MembershipPerson CreatePerson(MembershipPerson person)
        {
            var dbContext = new DBContext();

            dbContext.AddPerson(person.person);
            return(GetPerson(person.person.PersonID));
        }
        public override MembershipUser GetUser(object providerPersonKey, bool userIsOnline)
        {
            var dbContext = new DBContext();
            var user      = dbContext.GetUser((int)providerPersonKey);

            if (user != null)
            {
                var memUser = new MembershipPerson("CustomMembershipProvider", user,
                                                   string.Empty, string.Empty,
                                                   true, false, DateTime.MinValue,
                                                   DateTime.MinValue,
                                                   DateTime.MinValue,
                                                   DateTime.Now, DateTime.Now);
                return(memUser);
            }
            return(null);
        }
        public override void UpdateUser(MembershipUser _user)
        {
            var dbContext = new DBContext();
            MembershipPerson personData = (_user as MembershipPerson);
            User             usr        = dbContext.GetUser(personData.person.PersonID);

            if (usr == null)
            {
                usr        = new User();
                usr.Person = dbContext.GetPerson(personData.person.PersonID);
                if (usr.Person == null)
                {
                    return;
                }
            }
            usr.Person.Avatar    = personData.person.Avatar;
            usr.Person.Name      = personData.person.Name;
            usr.Person.Gender    = personData.person.Gender;
            usr.UserName         = personData.UserName;
            usr.UserEmailAddress = personData.Email;

            IQueryable <Photo> photos = (from p in dbContext.Photos where p.PersonID == usr.Person.PersonID select p);

            foreach (Photo p in photos)
            {
                System.Collections.Generic.IEnumerable <Photo> ps = personData.person.Photos.Select(x => x).Where(x => x.PhotoID == p.PhotoID);
                if (ps.Count() == 0)
                {
                    dbContext.Entry(p).State = System.Data.EntityState.Deleted;
                }
                else
                {
                    p.PhotoStream = ps.First().PhotoStream;
                }
            }
            IEnumerable <Photo> photosToAdd = personData.person.Photos.Where(x => x.PhotoID == 0).Select(x => x);

            foreach (Photo p in photosToAdd)
            {
                dbContext.AddPhoto(p);
            }
            dbContext.SaveChanges();
        }
        public MembershipPerson GetPerson(object providerPersonKey)
        {
            var  dbContext = new DBContext();
            var  person    = dbContext.GetPerson((int)providerPersonKey);
            User usr       = new User();

            usr.Person = person;
            if (person != null)
            {
                var memPerson = new MembershipPerson("CustomMembershipProvider", usr,
                                                     string.Empty, string.Empty,
                                                     true, false, DateTime.MinValue,
                                                     DateTime.MinValue,
                                                     DateTime.MinValue,
                                                     DateTime.Now, DateTime.Now);
                return(memPerson);
            }
            return(null);
        }
コード例 #6
0
 /// <summary>
 /// Convert buf array of image to URL /Home/ImageLoader?ImageID=...
 /// </summary>
 /// <returns></returns>
 public ActionResult ImageLoader()
 {
     FaceRecognitionSystem.Infrastructure.MembershipPerson usr = null;
     byte[] buf = null;
     if ((Request.QueryString["ShowComparedPhoto"] != null) && (Session["ComparedPhoto"] != null))
     {
         buf = Session["ComparedPhoto"] as byte[];
     }
     else
     if ((Request.QueryString["ImageID"] != null) && (Session["PersonForReview"] != null))
     {
         usr = Session["PersonForReview"] as MembershipPerson;
         if (Request.QueryString["ImageID"] == "Avatar")
         {
             buf = usr.person.Avatar;
         }
         else
         {
             FaceRecognitionSystem.Entities.Photo p = usr.person.Photos.Select(x => x)
                                                      .Where(x => x.PhotoID.ToString() == Request.QueryString["ImageID"]).First();
             buf = p.PhotoStream;
         }
     }
     if (buf != null)
     {
         Response.Buffer  = true;
         Response.Charset = "";
         Response.Cache.SetCacheability(HttpCacheability.NoCache);
         Response.ContentType = "image/jpeg";;
         Response.AddHeader("content-disposition", "attachment;filename=Photo_" + Request.QueryString["ImageID"]);
         Response.BinaryWrite(buf);
         Response.Flush();
         Response.End();
     }
     return(View());
 }
コード例 #7
0
 public void UpdateUser(FaceRecognitionSystem.Infrastructure.MembershipPerson usr)
 {
     (_provider as CustomMembershipProvider).UpdateUser(usr);
 }