コード例 #1
0
        public void BuildIndexAsync(string root, string alias)
        {
            if (Directory.Exists(root) == false)
            {
                throw new System.IO.DirectoryNotFoundException(INVALID_ROOT_MESSAGE);
            }

            DirectoryInfo directory = new DirectoryInfo(root);
            TrackedFolder folder    = new TrackedFolder()
            {
                FullPath = directory.FullName,
                Name     = directory.Name
            };

            using (DbModelContainer db = new DbModelContainer())
            {
                db.Indices.Add(new Index()
                {
                    Alias = alias,
                    Root  = folder
                });
                db.SaveChanges();
            }

            Thread thread = new Thread(() =>
            {
                DigDirectory(directory, folder.Id);
            });

            thread.Start();
        }
コード例 #2
0
        /// <summary>
        /// Checks for a list of outstanding files and returns them
        /// if found.  This method only returns the top 1000 of pending files
        /// in order to deal with performance issues with EF
        /// </summary>
        /// <returns>An IEnumerable of outstanding files to process</returns>
        private IEnumerable <TrackedFile> GetOutstandingFiles()
        {
            using (DbModelContainer db = new DbModelContainer())
            {
                db.Database.CommandTimeout = 120;

                IEnumerable <TrackedFilesDue_Result> procedureResults
                    = db.TrackedFilesDue(1000, this.Id);

                List <TrackedFile> fileResults = new List <TrackedFile>();

                foreach (TrackedFilesDue_Result result in procedureResults)
                {
                    fileResults.Add((TrackedFile)result);
                }

                return(fileResults);

                //SearchJob job = db.SearchJobs.Find(this.Id);

                //List<TrackedFile> workingFiles = new List<TrackedFile>();

                //IEnumerable<TrackedFile> pendingFiles = job.PendingFiles;

                //foreach (TrackedFile file in job.PendingFiles)
                //{
                //    workingFiles.Add(file);
                //    if (workingFiles.Count == 1000) break;
                //}

                //return workingFiles;
            }
        }
コード例 #3
0
        /// <summary>
        /// Gets the list of simple strings to check against
        /// </summary>
        /// <returns></returns>
        private IEnumerable <string> GetRegExToCheck()
        {
            using (DbModelContainer db = new DbModelContainer())
            {
                //See comments in GetStringsToCheck

                return(db.SearchJobs.Find(Id).Regexes
                       .Select(s => s.Content).ToList());
            }
        }
コード例 #4
0
        /// <summary>
        /// Changes the status of the search job, and updates
        /// the DB to match.
        /// </summary>
        /// <param name="newStatus">The new status</param>
        private void ChangeStatus(SearchStatus newStatus)
        {
            using (DbModelContainer db = new DbModelContainer())
            {
                db.SearchJobs.Attach(this);

                this.Status = newStatus;

                db.SaveChanges();
            }
        }
コード例 #5
0
        /// <summary>
        /// Marks the file as completed so that it doesn't get interrogated repeatedly
        /// </summary>
        /// <param name="file"></param>
        private void MarkFileDone(TrackedFile file)
        {
            using (DbModelContainer db = new DbModelContainer())
            {
                //Remove was giving poor performance for large result
                //sets, presumably because of how EF handles junction
                //tables, so a SPROC does it.

                db.MarkFileDone(file.Id, this.Id);
            }
        }
コード例 #6
0
        /// <summary>
        /// Gets the list of regexes to check against
        /// </summary>
        /// <returns></returns>
        private IEnumerable <string> GetStringsToCheck()
        {
            using (DbModelContainer db = new DbModelContainer())
            {
                //can't use attach here but need to search manually because
                //multiple threads will be working from the same object, and
                //we can't have multiple db contexts attaching the same
                //entity, this is not the same issue as for MarkFileDone

                return(db.SearchJobs.Find(Id).SearchStrings
                       .Select(s => s.Content).ToList());
            }
        }
コード例 #7
0
        public void BuildIndexAsync(string root, string alias)
        {
            IsRunning = true;

            Thread thread = new Thread(() =>
            {
                if (Directory.Exists(root) == false)
                {
                    throw new System.IO.DirectoryNotFoundException(INVALID_ROOT_MESSAGE);
                }

                DirectoryInfo directory = new DirectoryInfo(root);
                TrackedFolder folder    = new TrackedFolder()
                {
                    FullPath = directory.FullName,
                    Name     = directory.Name
                };

                using (DbModelContainer db = new DbModelContainer())
                {
                    Index index = new Index()
                    {
                        Alias = alias,
                        Root  = folder
                    };

                    db.Indices.Add(index);

                    db.SaveChanges();

                    //temporarily assign this index object the ID of the
                    //newly created one for use in dig directory
                    this.Id    = index.Id;
                    this.Alias = alias;
                }


                DigDirectory(directory, folder.Id);
                IsRunning = false;
            });

            thread.Start();
        }
コード例 #8
0
        public void ChangePassword(string newPassword)
        {
            string salt = GetNewSalt();

            string hash = HashPasswordAndSalt(newPassword, salt);

            using (DbModelContainer db = new DbModelContainer())
            {
                User user = db.Users.Find(Id);

                user.Salt           = salt;
                user.Hash           = hash;
                user.NewPasswordDue = false;

                this.Salt = salt;
                this.Hash = hash;

                db.SaveChanges();
            }
        }
コード例 #9
0
        /// <summary>
        /// Categorises the file as having matches at least
        /// one of the supplied regexes or strings, using
        /// the category assigned to this search job
        /// </summary>
        /// <param name="file">the file to categorise</param>
        private void CategoriseFile(TrackedFile file)
        {
            using (DbModelContainer db = new DbModelContainer())
            {
                //Can't use attach here as was getting exceptions to do
                //with EF graph tracking.  I think the way that the
                //converter works between the SPROC for getting due files
                //and tracked files causes the issue, not a major issue
                //to do it this way though, has no other bearing on the
                //rest of the code

                TrackedFile fileToMark = db.TrackedFiles.Find(file.Id);
                SearchJob   job        = db.SearchJobs.Find(this.Id);
                Category    category   = db.Categories.Find(job.Category.Id);

                fileToMark.Categories.Add(category);

                db.SaveChanges();
            }
        }
コード例 #10
0
        //TODO: put something in here about checking to cancel,
        //including adding an attribute to the entity model for
        //sys admin to mark.

        private void DigDirectory(DirectoryInfo directory, int parentID)
        {
            IEnumerable <FileInfo>      files;
            IEnumerable <DirectoryInfo> subFolders;


            List <TrackedFile> trackedFiles = new List <TrackedFile>();

            try
            {
                files = directory.GetFiles();

                foreach (FileInfo file in files)
                {
                    trackedFiles.Add(new TrackedFile()
                    {
                        Name            = file.Name,
                        FullPath        = file.FullName,
                        Created         = file.CreationTime,
                        LastSeen        = file.LastWriteTime,
                        Extension       = file.Extension,
                        TrackedFolderId = parentID,
                        Length          = file.Length,
                        TrackForUpdates = false,
                        IndexId         = this.Id
                    });


                    RunningFileCount++;
                }
            }
            catch (Exception)
            {
                //some exceptions for protected files etc.
                //nothing to do with it really.
            }

            List <TrackedFolder> trackedFolders = new List <TrackedFolder>();

            try
            {
                subFolders = directory.EnumerateDirectories();
                foreach (DirectoryInfo folder in subFolders)
                {
                    trackedFolders.Add(new TrackedFolder()
                    {
                        Name            = folder.Name,
                        FullPath        = folder.FullName,
                        TrackedFolderId = parentID,
                    });
                }
            }
            catch (Exception)
            {
                //as per for file.
            }

            using (DbModelContainer db = new DbModelContainer())
            {
                db.Database.CommandTimeout = 1800;

                db.TrackedFolders.AddRange(trackedFolders);
                db.TrackedFiles.AddRange(trackedFiles);
                db.SaveChanges();
            }

            foreach (TrackedFolder trackedFolder in trackedFolders)
            {
                DirectoryInfo subFolder = new DirectoryInfo(trackedFolder.FullPath);
                DigDirectory(subFolder, trackedFolder.Id);
            }
        }