Пример #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>
        /// 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();
            }
        }
Пример #3
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();
        }
Пример #4
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();
            }
        }
Пример #5
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();
            }
        }
Пример #6
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);
            }
        }