Exemplo n.º 1
0
        public bool TryAddFile(string Filename, out string Newfilename)
        {
            Newfilename = "";

            if (Filename.IsEmpty() || !File.Exists(Filename))
            {
                return(false);
            }

            string fname = Path.GetFileName(Filename);

            Newfilename = Path.Combine(this.FaceStoragePath, fname);

            if (!this.Files.ContainsKey(fname.ToLower()))
            {
                //if in different location, copy it in
                if (!Filename.EqualsIgnoreCase(Newfilename))
                {
                    File.Copy(Filename, Newfilename, true);
                }

                ClsFaceFile ff = new ClsFaceFile(Newfilename);

                ff.OriginalPath = Filename;

                ff.OriginalCamera = GetCamera(ff.OriginalPath, true).Name;

                this.Files.Add(fname.ToLower(), ff);

                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        public bool TryAddFaceFile(ClsImageQueueItem CurImg, out string Newfilename, int MaxFilesPerFace, int MaxFileAgeDays)
        {
            Newfilename = "";

            if (!CurImg.IsValid())
            {
                return(false);
            }

            string fname = Path.GetFileName(CurImg.image_path).ToLower();

            Newfilename = Path.Combine(this.FaceStoragePath, fname);

            if (!this.FilesDic.ContainsKey(fname))
            {
                if (this.FilesDic.Count > 1)
                {
                    //Get the oldest one
                    ClsFaceFile oldest = this.FilesDic.Values.OrderBy(f => f.DateFileModified).First();

                    if (this.FilesDic.Count > MaxFilesPerFace)
                    {
                        string firstname = Path.GetFileName(oldest.FilePath).ToLower();
                        bool   removed   = this.FilesDic.TryRemove(firstname, out ClsFaceFile value);
                        if (removed && oldest.Exists)
                        {
                            File.Delete(oldest.FilePath);
                        }
                    }

                    if ((DateTime.Now - oldest.DateFileModified).TotalDays > MaxFileAgeDays)
                    {
                        //remove the first one
                        string firstname = Path.GetFileName(oldest.FilePath).ToLower();
                        bool   removed   = this.FilesDic.TryRemove(firstname, out ClsFaceFile value);
                        if (removed && oldest.Exists)
                        {
                            File.Delete(oldest.FilePath);
                        }
                    }
                }

                //if in different location, copy it in
                if (!CurImg.image_path.EqualsIgnoreCase(Newfilename))
                {
                    if (!CurImg.CopyFileTo(Newfilename))
                    {
                        return(false);
                    }
                }

                ClsFaceFile ff = new ClsFaceFile(Newfilename, this);

                ff.OriginalPath = CurImg.image_path;

                ff.OriginalCamera = GetCamera(ff.OriginalPath, true).Name;

                this.FilesDic.TryAdd(fname, ff);

                return(true);
            }

            return(false);
        }