Ejemplo n.º 1
0
        protected override ScannedFiles GetFromSQLDb(byte processType)
        {
            FilesYetToProcessTableAdapter filesYetToProcessTableAdapter = new FilesYetToProcessTableAdapter();
            ScannedFile  scannedfile  = new ScannedFile();
            ScannedFiles scannedfiles = new ScannedFiles();

            ApplicationSettings appSettings = new ApplicationSettings();

            filesYetToProcessTableAdapter.Connection.ConnectionString = appSettings.getDbConnectionString();
            dsFFC.FilesYetToProcessDataTable filesYetToProcess = filesYetToProcessTableAdapter.GetData(processType);
            foreach (dsFFC.FilesYetToProcessRow file in filesYetToProcess.Rows)
            {
                scannedfile                         = new ScannedFile();
                scannedfile.FileId                  = file.fileId;
                scannedfile.Filename                = file.fileName;
                scannedfile.Filepath                = file.filePath;
                scannedfile.LastWriteTime           = file.lastWriteTime;
                scannedfile.LastAccessTime          = file.lastAccessedDate;
                scannedfile.Filesize                = file.fileSize;
                scannedfile.doUpdateRequireOnRescan = true;
                scannedfile.performedAction         = processType == 1 ? enums.ActionToPerform.FileForNextIteration : enums.ActionToPerform.FileFailedToDelete;
                scannedfiles.Add(scannedfile);
            }

            return(scannedfiles);
        }
Ejemplo n.º 2
0
        protected void SaveToCSV(ScannedFile file, byte processType)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add(new DataColumn("Current Date", typeof(String)));
            dt.Columns.Add(new DataColumn("Current Time", typeof(String)));
            dt.Columns.Add(new DataColumn("File Deleted", typeof(String)));
            dt.Columns.Add(new DataColumn("Date Accessed", typeof(String)));
            dt.Columns.Add(new DataColumn("Date Modified", typeof(String)));
            dt.Columns.Add(new DataColumn("Date Created", typeof(String)));
            dt.Columns.Add(new DataColumn("File Size", typeof(String)));
            dt.Columns.Add(new DataColumn("Process Type", typeof(String)));

            DataRow scannedFile = dt.NewRow();

            scannedFile[0] = DateTime.Now.Date.ToString("MM/dd/yyyy");
            scannedFile[1] = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString();
            scannedFile[2] = file.Filepath + file.Filename;
            scannedFile[3] = file.LastAccessTime.ToString();
            scannedFile[4] = file.LastWriteTime.ToString();
            scannedFile[5] = file.CreationTime.ToString();
            scannedFile[6] = (file.Filesize / 1024).ToString();
            scannedFile[7] = processType.ToString();

            dt.Rows.Add(scannedFile);
            dt.AcceptChanges();

            //WriteToCSV(dt);
        }
Ejemplo n.º 3
0
        public int Update(ScannedFile file, byte processType, string comments)
        {
            FilesYetToProcessTableAdapter filesYetToProcessTableAdapter = new FilesYetToProcessTableAdapter();
            ApplicationSettings           appSettings = new ApplicationSettings();

            filesYetToProcessTableAdapter.Connection.ConnectionString = appSettings.getDbConnectionString();
            return(filesYetToProcessTableAdapter.updateFileWhichWasYetToProcess(comments, processType, file.Filename, file.Filepath, file.FileId));
        }
        /// <summary>
        /// <b>Description:</b>
        /// Accepts file system as parameter, this will save file information to database
        /// of only file which was failed to delete. Since, saving could be to different
        /// table other than next iteration or deleted files, this will help to build
        /// report for those files where were failed to delete.
        /// </summary>
        /// <param name="file"></param>
        public override bool SaveFile(ScannedFile file)
        {
            FileYetToProcessDbManager dbManager = new FileYetToProcessDbManager();

            dbManager.DatabaseType  = DatabaseType;
            dbManager.SaveToCSVFile = SaveToCSVFile;
            dbManager.Save(file, 2);
            return(true);
        }
Ejemplo n.º 5
0
 public void Save(ScannedFile file, byte processType)
 {
     if (DatabaseType == DatabaseTypeEnum.SQLDatabase)
     {
         SaveToSQLDb(file, processType);
     }
     else if (DatabaseType == DatabaseTypeEnum.CSVDatabase)
     {
         SaveToCSV(file, processType);
     }
 }
Ejemplo n.º 6
0
        protected override void SaveToSQLDb(ScannedFile file)
        {
            FilesDeletedTableAdapter filesDeletedTableAdapter = new FilesDeletedTableAdapter();
            ApplicationSettings      appSettings = new ApplicationSettings();

            filesDeletedTableAdapter.Connection.ConnectionString = appSettings.getDbConnectionString();
            filesDeletedTableAdapter.Insert(file.Filename, file.Filepath, DateTime.Now, String.Empty, "SYSTEM", file.LastAccessTime, file.LastWriteTime, file.Filesize);
            if (file.doUpdateRequireOnRescan)
            {
                FileYetToProcessDbManager yetToProcess = new FileYetToProcessDbManager();
                yetToProcess.Update(file, 0, "deleted on " + DateTime.Now.ToString());
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// <b>Description:</b>
        /// This will iterate the file system on the given path.
        /// Prepare the list of files which has passed fileAgeToValidate limit and to be
        /// deleted.
        /// Prepare the list of files which yet to pass fileAgeToValidate limit and to be
        /// stored.
        /// Check File is not open.
        /// Delete the file.
        /// if file has passed fileAgeToValidate and still cannot be deleted, mark file as
        /// failed to delete and record to database.
        /// Return the list.
        /// </summary>
        /// <param name="directoryLocation"></param>
        /// <param name="enumFileProperty"></param>
        /// <param name="fileAgeToValidate"></param>
        public ScannedFiles ScanFiles(string directoryLocation, FileDateProperty enumFileProperty, int fileAgeToValidate)
        {

            //create an array of files using FileInfo object
            FileInfo[] directoryFiles;

            //Create a Directory object using DirectoryInfo 
            DirectoryInfo currentDirectory = new DirectoryInfo(directoryLocation);

            //get all files for the current directory
            directoryFiles = currentDirectory.GetFiles("*.*");

            //iterate through the directory and print the files
            foreach (FileInfo file in directoryFiles)
            {
                ScannedFile scannedFileInfo = new ScannedFile();
                //get details of each file using file object
                scannedFileInfo.Filename = file.FullName.Replace(file.DirectoryName+@"\", String.Empty);
                scannedFileInfo.Filesize = file.Length;
                scannedFileInfo.LastWriteTime = file.LastWriteTime;
                scannedFileInfo.LastAccessTime = file.LastAccessTime;
                scannedFileInfo.CreationTime = file.CreationTime;
                scannedFileInfo.Filepath = file.DirectoryName + @"\";
                _filesToProcess.Add(scannedFileInfo);
            }

            //get sub-folders for the current directory
            DirectoryInfo[] subDirectories = currentDirectory.GetDirectories("*.*");

            //This is the code that calls 
            //the getDirsFiles (calls itself recursively)
            //This is also the stopping point 
            //(End Condition) for this recursion function 
            //as it loops through until 
            //reaches the child folder and then stops.
            foreach (DirectoryInfo subDirectory in subDirectories)
            {
                ScanFiles(subDirectory.FullName, enumFileProperty, fileAgeToValidate);
            }

            return _filesToProcess;
        }
Ejemplo n.º 8
0
        protected override void SaveToSQLDb(ScannedFile file, byte processType)
        {
            FilesYetToProcessTableAdapter filesYetToProcessTableAdapter = new FilesYetToProcessTableAdapter();
            ApplicationSettings           appSettings = new ApplicationSettings();

            filesYetToProcessTableAdapter.Connection.ConnectionString = appSettings.getDbConnectionString();
            if (!file.doUpdateRequireOnRescan)
            {
                filesYetToProcessTableAdapter.Insert(file.Filename, file.Filepath, DateTime.Now, String.Empty, "SYSTEM", processType, file.LastAccessTime, file.LastWriteTime, file.Filesize);
            }
            else
            {
                //only when failed to delete. this could be file no longer exists in directory.
                if (processType == 2)
                {
                    string comments = "No action taken, this could be file no longer exists in directory or inaccessible.";
                    this.Update(file, 3, comments);
                }
            }
        }
Ejemplo n.º 9
0
        protected override ScannedFiles GetFromSQLDb()
        {
            FilesDeletedTableAdapter filesDeletedTableAdapter = new FilesDeletedTableAdapter();
            ScannedFile  scannedfile  = new ScannedFile();
            ScannedFiles scannedfiles = new ScannedFiles();

            ApplicationSettings appSettings = new ApplicationSettings();

            filesDeletedTableAdapter.Connection.ConnectionString = appSettings.getDbConnectionString();
            dsFFC.FilesDeletedDataTable filesDeleted = filesDeletedTableAdapter.GetData();
            foreach (dsFFC.FilesDeletedRow file in filesDeleted.Rows)
            {
                scannedfile                 = new ScannedFile();
                scannedfile.Filename        = file.fileName;
                scannedfile.Filepath        = file.filePath;
                scannedfile.performedAction = enums.ActionToPerform.FileDeleted;
                scannedfiles.Add(scannedfile);
            }

            return(scannedfiles);
        }
        public void AddFile(ActionToPerform action, ScannedFile fileInfo)
        {
            switch (action)
            {
            case ActionToPerform.FileFailedToDelete:
                objBaseScannedFile = FilesFailedToDelete.GetInstance();
                break;

            case ActionToPerform.FileForNextIteration:
                objBaseScannedFile = FilesForNextIteration.GetInstance();
                break;

            case ActionToPerform.FileDeleted:
                objBaseScannedFile = FilesDeleted.GetInstance();
                break;
            }
            objBaseScannedFile.AddFile(fileInfo);
            objBaseScannedFile.DatabaseType  = DatabaseType;
            objBaseScannedFile.SaveToCSVFile = SaveToCSVFile;
            objBaseScannedFile.SaveFile();
        }
Ejemplo n.º 11
0
 public abstract bool SaveFile(ScannedFile file);
Ejemplo n.º 12
0
 public virtual void AddFile(ScannedFile file)
 {
     _files.Add(file); _currentFile = file;
 }
Ejemplo n.º 13
0
 protected virtual void SaveToSQLDb(ScannedFile file, byte processType)
 {
 }
Ejemplo n.º 14
0
 protected virtual void SaveToSQLDb(ScannedFile file)
 {
 }