Exemplo n.º 1
0
        public static async Task <PersonGroupOperationStatus> CreatePersonGroup(string PersonGroupName, string PersonGroupId)
        {
            bool rtnStatus = false;
            PersonGroupOperationStatus status = new PersonGroupOperationStatus();
            ////////////////////////////////////////////////////////////////////////////////////
            string uuidSystemID = "";

            try
            {
                ////////////////////////////////////////////////////////////////////////////////////
                status.AttemptedDatabaseOperation = true;
                using (var db = new Facial_Recognition_Library.Data.LiveEduFaceModel())
                {
                    MyPersonGroup PersonGroup = new MyPersonGroup
                    {
                        Name  = PersonGroupName,
                        IDApi = PersonGroupId
                    };
                    status.CompletedDatabaseOperation = MyPersonGroup.AddPersonGroup(db, ref PersonGroup);
                    uuidSystemID = PersonGroup.IDApi;
                }
                status.CompletedDatabaseOperation = true;
                ////////////////////////////////////////////////////////////////////////////////////
                status.AttemptedAPIOperation = true;
                await ProjectOxfordAPI.CreatePersonGroup(PersonGroupId, PersonGroupName, uuidSystemID);

                status.CompletedAPIOperation = true;
                ////////////////////////////////////////////////////////////////////////////////////
            }
            catch (Exception e)
            {
                status.ReasonForFailure = $"Attempts made to update database and api failed : {e.Message}";
            }
            return(status);
        }
Exemplo n.º 2
0
        public static async Task <PersonOperationStatus> CreatePerson(string strPersonGroupId, string strPersonName)
        {
            PersonOperationStatus status = new PersonOperationStatus();
            ////////////////////////////////////////////////////////////////////////////////////
            string strUserData = "";

            try
            {
                ////////////////////////////////////////////////////////////////////////////////////
                status.AttemptedDatabaseOperation = true;
                MyPerson person = new MyPerson();
                using (var db = new Facial_Recognition_Library.Data.LiveEduFaceModel())
                {
                    status.CompletedDatabaseOperation = MyPerson.AddPerson(db, ref person);
                }
                ////////////////////////////////////////////////////////////////////////////////////
                status.AttemptedAPIOperation = true;
                await ProjectOxfordAPI.CreatePerson(strPersonGroupId, strPersonName, strUserData);

                status.CompletedAPIOperation = true;
                ////////////////////////////////////////////////////////////////////////////////////
            }
            catch (Exception e)
            {
                status.ReasonForFailure = $"Attempts made to update database and api failed : {e.Message}";
            }
            return(status);
        }
Exemplo n.º 3
0
        public static ToolStripMenuProcessResult OpenImgFromFileSystem(ref object sender, EventArgs e)
        {
            ToolStripMenuProcessResult methodResult = new ToolStripMenuProcessResult();

            //TODO: Move this to the libary. : openToolStripMenuItem_Click
            string fileLocation = @"W:\Example Pictures\imgNov82017.png";

            var MyCurrentImage = Image.FromFile(fileLocation);

            using (MemoryStream ms = new MemoryStream())
            {
                MyCurrentImage.Save(ms, ImageFormat.Png);
                try
                {
                    Microsoft.ProjectOxford.Face.Contract.Face face;
                    try
                    {
                        var faces = AsyncHelpers.RunSync(() => ProjectOxfordAPI.DetectFace(ms));
                        face = faces.First();
                    }
                    catch (Exception f)
                    {
                        face = new Face();
                    }

                    if (face.FaceId != Guid.Empty)
                    {
                        MyFace newface = new MyFace
                        {
                            FaceID         = face.FaceId,
                            FaceAttributes = Newtonsoft.Json.JsonConvert.SerializeObject(face.FaceAttributes),
                            FaceLandmarks  = Newtonsoft.Json.JsonConvert.SerializeObject(face.FaceLandmarks),
                            FaceRectangle  = Newtonsoft.Json.JsonConvert.SerializeObject(face.FaceRectangle),
                            ImageBytes     = ms.ToArray()
                        };

                        using (var db = new Facial_Recognition_Library.Data.LiveEduFaceModel())
                        {
                            db.MyFaces.Add(newface);
                            db.SaveChanges();

                            foreach (var faceItem in db.MyFaces)
                            {
                                System.Diagnostics.Debug.WriteLine($"{faceItem.FaceID.ToString()} - {faceItem.FaceRectangle}");
                            }
                        }
                    }
                }
                catch (Exception s)
                {
                    //MessageBox.Show(e.Message);
                    //throw e;
                }
            }

            return(methodResult);
        }
Exemplo n.º 4
0
        public static async Task <PersonGroupOperationStatus> DeletePersonGroup(string PersonGroupId)
        {
            bool rtnStatus = false;
            PersonGroupOperationStatus status = new PersonGroupOperationStatus();
            ////////////////////////////////////////////////////////////////////////////////////
            Guid uuidSystemID = Guid.Empty;

            ////////////////////////////////////////////////////////////////////////////////////
            status.AttemptedDatabaseOperation = true;
            try
            {
                using (var db = new Facial_Recognition_Library.Data.LiveEduFaceModel())
                {
                    status.CompletedDatabaseOperation = MyPersonGroup.DeletePersonGroupById(db, PersonGroupId);
                }
                status.CompletedDatabaseOperation = true;
            }
            catch (Exception e)
            {
                status.ReasonForFailure += $"Failed to remove from database {e.Message} |";
            }

            ////////////////////////////////////////////////////////////////////////////////////
            status.AttemptedAPIOperation = true;
            try
            {
                await ProjectOxfordAPI.DeletePersonGroup(PersonGroupId);

                status.CompletedAPIOperation = true;
            }
            catch (Exception e)
            {
                status.ReasonForFailure += $"Failed to remove from api {e.Message} |";
            }
            ////////////////////////////////////////////////////////////////////////////////////
            return(status);
        }