Exemple #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);
        }
        public static void scanCurrentFileSystem(bool physicalDelete)
        {
            DateTime startTime = DateTime.Now;

            try
            {
                startTime = DateTime.Now;


                //initialise file system component
                FileSystem fileSystem = new FileSystem();

                //run the scan and pass application setting values.
                ApplicationSettings settings = new ApplicationSettings();
                fileSystem.DatabaseType   = settings.DatabaseType;
                fileSystem.SaveToCSVFile  = settings.FileDeleteCSVFile;
                fileSystem.PhysicalDelete = physicalDelete;
                ScannedFiles files = fileSystem.RunScan(settings.FileAgeLimit, FileDateProperty.DateModified, settings.DirectoryToScan);
                File.AppendAllText(_FileName, "\r\n" + DateTime.Now.ToString() + ": " + files.Count.ToString() + " files were scanned on current file system -scanCurrentFileSystem()");
            }
            catch (Exception ex)
            {
                //logFFCBatch.WriteEntry(DateTime.Now.ToString() + ": Error Occured: " + ex.Message + "-scanCurrentFileSystem()");
                File.AppendAllText(_FileName, "\r\n" + DateTime.Now.ToString() + ": Error Occured: " + ex.Message + "-scanCurrentFileSystem()");
            }
            finally
            {
                //logFFCBatch.WriteEntry(DateTime.Now.ToString() + ": Finished scanning current file system job @ " + System.DateTime.Now.ToString() + " and took " + DateTime.Now.Subtract(startTime).Minutes + " min. -scanCurrentFileSystem()");
                File.AppendAllText(_FileName, "\r\n" + DateTime.Now.ToString() + ": Finished scanning current file system job @ " + System.DateTime.Now.ToString() + " and took " + DateTime.Now.Subtract(startTime).Seconds + " sec. -scanCurrentFileSystem()");
            }
        }
 /// <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 SaveFileList(ScannedFiles files)
 {
     foreach (ScannedFile file in files)
     {
         this.SaveFile(file);
     }
     return(true);
 }
Exemple #4
0
        private void Report_Load(object sender, EventArgs e)
        {
            try
            {
                //ApplicationSettings appSettings = new ApplicationSettings();
                FilesDeleted fileDeletedInstance = FilesDeleted.GetInstance();
                deletedfiles = fileDeletedInstance.GetFiles();

                FilesFailedToDelete filesFailedToDeleteInstance = FilesFailedToDelete.GetInstance();
                filesFailedToDelete = filesFailedToDeleteInstance.GetFiles();

                FilesForNextIteration filesForNextIterationInstance = FilesForNextIteration.GetInstance();
                filesForNextIteration = filesForNextIterationInstance.GetFiles();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }
Exemple #5
0
        private void updateGrid()
        {
            ScannedFiles scannedFiles = new ScannedFiles();

            if (chkFilesDeleted.Checked)
            {
                scannedFiles.AddRange(deletedfiles);
            }
            if (chkFilesFailedToDelete.Checked)
            {
                scannedFiles.AddRange(filesFailedToDelete);
            }
            if (chkFilesForNextIteration.Checked)
            {
                scannedFiles.AddRange(filesForNextIteration);
            }

            grdFiles.DataSource = scannedFiles;
        }
        public static void scanPreviousData(bool physicalDelete)
        {
            DateTime startTime = DateTime.Now;

            try
            {
                startTime = DateTime.Now;
                ScannedFiles scannedFiles = new ScannedFiles();
                //run the scan and pass application setting values.
                ApplicationSettings settings = new ApplicationSettings();
                //initialise file system component
                FileSystem fileSystem = new FileSystem();

                FilesFailedToDelete   filesFailedToDeleteInstance   = FilesFailedToDelete.GetInstance();
                FilesForNextIteration filesForNextIterationInstance = FilesForNextIteration.GetInstance();

                filesFailedToDeleteInstance.DatabaseType = settings.DatabaseType;

                ScannedFiles filesFailedToDelete   = filesFailedToDeleteInstance.GetFiles();
                ScannedFiles filesForNextIteration = filesForNextIterationInstance.GetFiles();

                scannedFiles.AddRange(filesFailedToDelete);
                scannedFiles.AddRange(filesForNextIteration);

                fileSystem.DatabaseType   = settings.DatabaseType;
                fileSystem.SaveToCSVFile  = settings.FileDeleteCSVFile;
                fileSystem.PhysicalDelete = physicalDelete;
                ScannedFiles files = fileSystem.RunScan(settings.FileAgeLimit, FileDateProperty.DateModified, scannedFiles);
                File.AppendAllText(_FileName, "\r\n" + DateTime.Now.ToString() + ": " + files.Count.ToString() + " files were scanned for previous files -scanPreviousData()");
            }
            catch (Exception ex)
            {
                //logFFCBatch.WriteEntry( DateTime.Now.ToString() + ": Error Occured: " + ex.Message + "-scanPreviousData()");
                File.AppendAllText(_FileName, "\r\n" + DateTime.Now.ToString() + ": Error Occured: " + ex.Message + "-scanPreviousData()");
            }
            finally
            {
                //logFFCBatch.WriteEntry( DateTime.Now.ToString() + ": Finished previous scanning job @ " + System.DateTime.Now.ToString() + " and took " + DateTime.Now.Subtract(startTime).Minutes + " min. -scanPreviousData()");
                File.AppendAllText(_FileName, "\r\n" + DateTime.Now.ToString() + ": Finished previous scanning job @ " + System.DateTime.Now.ToString() + " and took " + DateTime.Now.Subtract(startTime).Seconds + " sec(s). -scanPreviousData()");
            }
        }
Exemple #7
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);
        }
Exemple #8
0
        private void btnRunScan_Click(object sender, EventArgs e)
        {
            try
            {
                ScannedFiles        files    = null;
                ApplicationSettings settings = new ApplicationSettings();

                //initialise file system component
                FileSystem fileSystem = new FileSystem();


                FilesFailedToDelete   filesFailedToDeleteInstance   = FilesFailedToDelete.GetInstance();
                FilesForNextIteration filesForNextIterationInstance = FilesForNextIteration.GetInstance();


                ScannedFiles filesFailedToDelete   = filesFailedToDeleteInstance.GetFiles();
                ScannedFiles filesForNextIteration = filesForNextIterationInstance.GetFiles();

                ScannedFiles scannedFiles = new ScannedFiles();
                scannedFiles.AddRange(filesFailedToDelete);
                scannedFiles.AddRange(filesForNextIteration);

                //run the scan passing the previous scan files data from database.
                //get new set of scanned files, and do some processing, if required.
                files = fileSystem.RunScan(settings.FileAgeLimit, FileDateProperty.DateModified, scannedFiles);


                /*
                 * //initialise file system component
                 * fileSystem = new FileSystem();
                 *
                 * //run the scan and pass application setting values.
                 * files = fileSystem.RunScan(settings.FileAgeLimit, FileDateProperty.DateModified, settings.DirectoryToScan);
                 */
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }
        public ScannedFiles Get(ActionToPerform action)
        {
            FileSystemCleanup objBaseScannedFile = null;
            ScannedFiles      files = null;

            switch (action)
            {
            case ActionToPerform.FileFailedToDelete:
                objBaseScannedFile = FilesFailedToDelete.GetInstance();
                break;

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

            case ActionToPerform.FileDeleted:
                objBaseScannedFile = FilesDeleted.GetInstance();
                break;
            }
            objBaseScannedFile.DatabaseType  = DatabaseType;
            objBaseScannedFile.SaveToCSVFile = SaveToCSVFile;
            files = objBaseScannedFile.GetFiles();
            return(files);
        }
Exemple #10
0
    public IEnumerator CreateScannedFile()
    {
        ScannedFiles _data = new ScannedFiles()
        {
            GoodSongs = MakeScannedData(),
            BadSongs  = badFiles
        };

        var jsonSerializerSettings = new JsonSerializerSettings
        {
            ReferenceLoopHandling = ReferenceLoopHandling.Ignore
        };

        string json = JsonConvert.SerializeObject(_data, Formatting.Indented, jsonSerializerSettings);

        if (!File.Exists(@Application.dataPath + "/Scanned.JSON"))
        {
            using (StreamWriter w = File.AppendText(@Application.dataPath + "/Scanned.JSON"))
            {
                w.WriteLine(json);
            }
        }
        else
        {
            File.Delete(@Application.dataPath + "/Scanned.JSON");

            using (StreamWriter w = File.AppendText(@Application.dataPath + "/Scanned.JSON"))
            {
                w.WriteLine(json);
            }
        }

        Instance().Enqueue(LoadSongs());

        yield return(null);
    }
        public ScannedFiles Get()
        {
            ScannedFiles objAllFiles = new ScannedFiles();

            FileSystemCleanup objBaseScannedFile = null;

            objBaseScannedFile = FilesFailedToDelete.GetInstance();
            objBaseScannedFile.DatabaseType = DatabaseType;
            ScannedFiles objFilesFailedToDelete = objBaseScannedFile.GetFiles();

            objBaseScannedFile = FilesForNextIteration.GetInstance();
            objBaseScannedFile.DatabaseType = DatabaseType;
            ScannedFiles objFilesForNextIteration = objBaseScannedFile.GetFiles();

            objBaseScannedFile = FilesDeleted.GetInstance();
            objBaseScannedFile.DatabaseType = DatabaseType;
            ScannedFiles objFilesToDelete = objBaseScannedFile.GetFiles();

            objAllFiles.AddRange(objFilesFailedToDelete);
            objAllFiles.AddRange(objFilesForNextIteration);
            objAllFiles.AddRange(objFilesToDelete);

            return(objAllFiles);
        }
Exemple #12
0
 public abstract bool SaveFileList(ScannedFiles files);
Exemple #13
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="filesToScan"></param>
        public ScannedFiles ScanFiles(ScannedFiles filesToScan)
        {

            return null;
        }
Exemple #14
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="fileAgeLimit"></param>
        /// <param name="cOfFiles"></param>
        public ScannedFiles ProcessScannedFiles(int fileAgeLimit, FileDateProperty enumFileProperty, ScannedFiles cOfFiles)
        {
            processedFile.DatabaseType = DatabaseType;
            processedFile.SaveToCSVFile = SaveToCSVFile;

            DateTime fileAuditDate = DateTime.Today;
            foreach (ScannedFile currentFile in cOfFiles)
            {
                string fullFilePath = currentFile.Filepath + currentFile.Filename;
                if (IsFileExists(fullFilePath))
                {
                    if (enumFileProperty == FileDateProperty.DateAdded)
                    { fileAuditDate = currentFile.LastAccessTime; }
                    else if (enumFileProperty == FileDateProperty.DateModified)
                    { fileAuditDate = currentFile.LastWriteTime; }                    

                    //compulsory check on file accessed and file created date.
                    //IsFilePassedAgeLimit(fileAuditDate, fileAgeLimit) is depreceted
                    if (IsFilePassedAgeLimit(currentFile.LastWriteTime, currentFile.LastAccessTime, fileAgeLimit))
                    {
                        if (IsFileReadyForDelete(fullFilePath))
                        {
                            if (DeleteFile(fullFilePath))
                            {
                                currentFile.performedAction = ActionToPerform.FileDeleted;
                                processedFile.AddFile(ActionToPerform.FileDeleted, currentFile);
                                
                            }
                            else
                            {
                                currentFile.performedAction = ActionToPerform.FileFailedToDelete;
                                processedFile.AddFile(ActionToPerform.FileFailedToDelete, currentFile);
                            }
                        }
                        else
                        {
                            currentFile.performedAction = ActionToPerform.FileFailedToDelete;
                            processedFile.AddFile(ActionToPerform.FileFailedToDelete, currentFile);
                        }

                    }
                    else
                    {
                        currentFile.performedAction = ActionToPerform.FileForNextIteration;
                        processedFile.AddFile(ActionToPerform.FileForNextIteration, currentFile);
                    }

                }
                else
                {
                    currentFile.performedAction = ActionToPerform.FileFailedToDelete;
                    processedFile.AddFile(ActionToPerform.FileFailedToDelete, currentFile);
                }
            }
            return processedFile.Get();
        }
Exemple #15
0
 /// <summary>
 /// <b>Description:</b>
 /// With pass in allowed age limit on specified date access property on specific
 /// location, scan through the files and prepare for files to delete, and add it to
 /// collection of scanned files.
 /// </summary>
 /// <param name="allowedAgeLimit">allowed age limit, in days, to check.</param>
 /// <param name="fileDateProperty">allowed age limit, in days, to check on
 /// specified file date property. date created, accessed, modified.</param>
 /// <param name="directoryLocation">directory location to access.</param>
 public ScannedFiles RunScan(int allowedAgeLimit, FileDateProperty fileProperty, string directoryLocation)
 {
     ScannedFiles cOfScannedFiles = ScanFiles(directoryLocation, fileProperty, allowedAgeLimit);
     ScannedFiles cOfProcessedFiles = ProcessScannedFiles(allowedAgeLimit, fileProperty, cOfScannedFiles);
     return cOfProcessedFiles;
 }
Exemple #16
0
 /// <summary>
 /// <b>Description:</b>
 /// With already scanned files to check, iterate through and validate each file.
 /// </summary>
 /// <param name="allowedAgeLimit">allowed age limit, in days, to check.</param>
 /// <param name="filesToCheck"></param>
 public ScannedFiles RunScan(int allowedAgeLimit, FileDateProperty fileProperty, ScannedFiles filesToCheck)
 {
     ScannedFiles cOfProcessedFiles = this.ProcessScannedFiles(allowedAgeLimit, fileProperty, filesToCheck);
     return cOfProcessedFiles;
 }
Exemple #17
0
    public IEnumerator LoadSongs()
    {
        string[]     JSONFiles  = Directory.GetFiles(dir, "info.JSON", SearchOption.AllDirectories);
        ScannedFiles _preLoaded = LoadsongData(Application.dataPath + "/Scanned.JSON");

        SongList = _preLoaded.GoodSongs;

        if (JSONFiles.Length != _preLoaded.GoodSongs.Count + _preLoaded.BadSongs.Count)
        {
            Instance().Enqueue(CreateScannedFile());
            yield break;
        }

        yield return(null);

        foreach (GoodFile indi in _preLoaded.GoodSongs)
        {
            GameObject Song = Instantiate(SongObject);
            Song.transform.SetParent(songList.transform);
            Song.transform.localScale    = new Vector3(1, 1, 1);
            Song.transform.localPosition = new Vector3(Song.transform.localPosition.x, Song.transform.localPosition.y, 0);
            Song.name = indi.ID.ToString();
            Song.GetComponent <SelectSong>().arrayID = (int)indi.ID;

            Transform[] ts = Song.transform.GetComponentsInChildren <Transform>(true);
            foreach (Transform t in ts)
            {
                if (t.gameObject.name == "Artist")
                {
                    t.gameObject.GetComponent <Text>().text = indi.initialData.Artist;
                }
                if (t.gameObject.name == "SongName")
                {
                    t.gameObject.GetComponent <Text>().text = indi.initialData.SongName;
                }
                if (t.gameObject.name == "noteCount")
                {
                    t.gameObject.GetComponent <Text>().text = "5";
                }
                if (t.gameObject.name == "Cover")
                {
                    string   path     = Path.GetDirectoryName(indi._chartLocation);
                    string[] pngFiles = Directory.GetFiles(path, "*.png", SearchOption.AllDirectories);

                    if (pngFiles.Length == 0)
                    {
                        continue;
                    }

                    StartCoroutine(GetImage(t.gameObject, pngFiles[0]));
                }

                yield return(null);
            }

            yield return(null);
        }

        LoadedText.text = JSONFiles.Length.ToString() + " total songs. " + _preLoaded.GoodSongs.Count.ToString() + " JSONs read successfully. Song folder contains " + _preLoaded.BadSongs.Count.ToString() + " unplayable song(s).";

        chartsLoaded  = true;
        hasLoadedOnce = true;
        yield return(null);
    }