Exemple #1
0
        //Not to use anymore, Use function scanNewFile().
        public static void verifyFileAttributes(string fpath, List <string> tagsToGet = null, string watchID = null)
        {
            if (tagsToGet == null)
            {
                tagsToGet = attributeTagsToGet;
            }
            var flInfo = SQLiteDatabase.getFileLocationInfo(SQLiteDatabase.RowCheckTypes.filePath, filepath: fpath);
            List <SQLiteDatabase.AttributeInfo> faInfo;
            string hashFromDB = null;

            if (flInfo != null)
            {
                faInfo     = SQLiteDatabase.getAttributeInfo(SQLiteDatabase.RowCheckTypes.attributeID, id: flInfo[0].AttributeID);
                hashFromDB = faInfo[0].Hash;
            }
            var hash = fileHash.getFileHash(fpath);

            if (hash != hashFromDB && hashFromDB != null)
            {
                FileInfo finfo    = new FileInfo(fpath);
                var      fileSize = finfo.Length;
                if (!SQLiteDatabase.checkDBHashAndSize(hash, fileSize))//checks if a file with the same hash and size is listed in the db
                {
                    var tagAttributesFromFile = DICOMTagReader.scanDICOM(fpath, tagsToGet);
                    SQLiteDatabase.addRowToDICOM_file_attributes(tagAttributesFromFile, fpath, hash, fileSize, watchedID: watchID);
                }
                else
                {
                    //SQLiteDatabase.removeFileLocation(fpath, flInfo[0].AttributeID);
                    //SQLiteDatabase.addFileLocation(fpath, fileSize, hash, watchedID: watchID);
                    var AttrInfo = SQLiteDatabase.getAttributeInfo(SQLiteDatabase.RowCheckTypes.hash, hash: hash);
                    SQLiteDatabase.setFileAttributeIDForLocation(fpath, AttrInfo[0].AttributeSetID);
                }
            }
        }
Exemple #2
0
        //public static void scanNewFile(string fpath, List<string> tagsToGet, string fromWatched = null)//Needs changes, first IF should only check filepath, then branch to options like an updated or modifed file or a new copy or complete new DICOM
        //{
        //    FileInfo finfo = new FileInfo(fpath);
        //    var fileSize = finfo.Length;
        //    if (!SQLiteDatabase.checkDBFilePathAndSize(fpath, fileSize))//checks if a file matching the path and file size is already in the db
        //    {
        //        var hash = fileHash.getFileHash(fpath);
        //        if (!SQLiteDatabase.checkDBHashAndSize(hash, fileSize))//checks if a file with the same hash and size is listed in the db
        //        {
        //            var tagAttributesFromFile = DICOMTagReader.scanDICOM(fpath, tagsToGet);
        //            SQLiteDatabase.addRowToDICOM_file_attributes(tagAttributesFromFile, fpath, hash, fileSize, watchedID: fromWatched);
        //        }
        //        else
        //        {
        //            SQLiteDatabase.addFileLocation(fpath, fileSize, hash, watchedID: fromWatched);
        //        }
        //    }
        //}

        //Scans files on detection of new instance or change. First IF should only check filepath, then branch to options like an updated or modifed file or a new copy or complete new DICOM
        public static void scanNewFile(string fpath, List <string> tagsToGet, string fromWatched = null)
        {
            FileInfo finfo    = new FileInfo(fpath);
            var      fileSize = finfo.Length;
            string   fullPath = finfo.FullName;
            var      hash     = fileHash.getFileHash(fullPath);

            if (!SQLiteDatabase.checkIfFilePathInDB(fullPath))          //checks if a file matching the path is already in the db
            {
                if (!SQLiteDatabase.checkDBHashAndSize(hash, fileSize)) //checks if a file with the same hash and size is listed in the db
                {
                    var tagAttributesFromFile = DICOMTagReader.scanDICOM(fullPath, tagsToGet);
                    SQLiteDatabase.addRowToDICOM_file_attributes(tagAttributesFromFile, fullPath, hash, fileSize, watchedID: fromWatched);
                }
                else
                {
                    SQLiteDatabase.addFileLocation(fullPath, fileSize, hash, watchedID: fromWatched);
                }
            }
            else
            {
                var LocInfo  = SQLiteDatabase.getFileLocationInfo(addChecks: SQLiteDatabase.RowCheckTypes.filePath, filepath: fullPath);
                var AttrInfo = SQLiteDatabase.getAttributeInfo(addChecks: SQLiteDatabase.RowCheckTypes.attributeID, id: LocInfo[0].AttributeID);
                if (hash != AttrInfo[0].Hash)
                {
                    if (!SQLiteDatabase.checkDBHashAndSize(hash, fileSize))
                    {
                        var tagAttributesFromFile = DICOMTagReader.scanDICOM(fullPath, tagsToGet);
                        SQLiteDatabase.addRowToDICOM_file_attributes(tagAttributesFromFile, fullPath, hash, fileSize, watchedID: fromWatched, newFileLocation: false);
                        //to do: 1-get the new row, 2-use compareAttr class method, 3-write the differences to DB table of file changes (parameters=change type,effectedfile1,effectedfile2,note)
                        var    NewAttrInfo = SQLiteDatabase.getAttributeInfo(addChecks: SQLiteDatabase.RowCheckTypes.hash, hash: hash);
                        string fileChanges = NewAttrInfo[0].compareAttr(AttrInfo[0]);
                        SQLiteDatabase.addToChangeLog("Modified", LocInfo[0].FilePath, null, "Old Hash: " + AttrInfo[0].Hash + " New Hash: " + hash + " No match for new hash and file size in DB, " + fileChanges);
                    }
                    else
                    {
                        //change file_loc table so attributeID column points to new hash
                        var NewAttrInfo = SQLiteDatabase.getAttributeInfo(addChecks: SQLiteDatabase.RowCheckTypes.hash, hash: hash);
                        SQLiteDatabase.setFileAttributeIDForLocation(LocInfo[0].FilePath, NewAttrInfo[0].AttributeSetID);
                        //write to DB table that file was renamed to an already existing file path
                        SQLiteDatabase.addToChangeLog("Modified/Renamed", LocInfo[0].FilePath, null, "File at indexed location changed to a new attribute set that already is recorded, Old Attribute Set ID: " + AttrInfo[0].AttributeSetID + " New Attribute Set ID: " + NewAttrInfo[0].AttributeSetID);
                    }
                }
            }
        }
        public static bool consoleSingleFileParse()
        {
            OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog();;
            DialogResult   result          = openFileDialog1.ShowDialog();
            string         openFileName    = "";

            // OK button was pressed.
            if (result == DialogResult.OK)
            {
                openFileName = openFileDialog1.FileName;
                try
                {
                    DICOMTagReader.scanDICOM(openFileName, null, true);
                }
                catch (Exception e)
                {
                    Console.WriteLine("An error occurred while attempting to load the file. The error is:\n"
                                      + e.ToString());
                }
                Console.WriteLine();
            }

            return(true);
        }