示例#1
0
        /// <summary>
        /// GetMaxCorpId
        /// </summary>
        /// <returns></returns>
        public static int GetMaxDestMolId()
        {
            int            molId, maxMolId = 0;
            FingerprintDao fpd = new FingerprintDao(Database, FingerprintType);
            List <string>  ids = new List <string>();

            if (!fpd.DataFilesExist())
            {
                return(maxMolId);
            }

            fpd.OpenReaders();

            while (true)
            {
                FingerprintRec rec = fpd.ReadFingerprintRec();
                if (rec == null)
                {
                    break;
                }

                //CorpIds.Add(rec.Cid); // debug

                if (CorpDatabase)
                {
                    int.TryParse(rec.Cid, out molId);
                }
                else
                {
                    molId = rec.molId;
                }

                if (molId > maxMolId)
                {
                    maxMolId = molId;
                }
            }

            fpd.CloseReaders();

            return(maxMolId);
        }
示例#2
0
        /// <summary>
        /// Merge existing .bin files with new records
        /// 1. Copy .bin files to .mrg files filtering out cids that have been updated
        /// 2. Append new records to .mrg files
        /// 3. Rename .bin files to .bak files and .mrg files to new .bin files
        /// </summary>

        static void MergeRecordsIntoFiles(
            List <FingerprintRec> fpRecList)
        {
            string date1, date2;

            Progress.Show("Merging existing and new files...");

            // Copy existing bin file entries filtering out cids that were updated

            FpDao.OpenReaders("bin");                            // open existing .bin files for input
            FpDao.OpenWriters("mrg", FileMode.Create);           // open new merge files for output

            HashSet <string> fpRecHash = new HashSet <string>(); // build a hash of cids that shouldn't be copied

            foreach (FingerprintRec fpr in fpRecList)
            {
                fpRecHash.Add(fpr.Cid);
            }

            int replacementCnt = 0;

            for (int fi = 0; fi < FingerprintDao.FingerprintFileCount; fi++)             // copy each file
            {
                BinaryWriter bw = FpDao.BinaryWriters[fi];

                while (true)
                {
                    FingerprintRec fpr = FpDao.ReadFingerprintRec(fi);
                    if (fpr == null)
                    {
                        break;
                    }

                    if (fpRecHash.Contains(fpr.Cid))
                    {
                        //Log("Removing " + fpr.Cid); // debug
                        replacementCnt++;
                        continue;                         // skip if this cid is was updated in the incoming list
                    }

                    FpDao.WriteFingerprintRec(bw, fpr);
                }
            }

            FpDao.CloseReaders();

            // Append the new records to the merge files

            foreach (FingerprintRec fpr in fpRecList)             // write out buffered recs
            {
                FpDao.WriteFingerprintRec(fpr);
            }

            FpDao.CloseWriters();

            // Backup old files and activate new files

            for (int fi = 0; fi < FingerprintDao.FingerprintFileCount; fi++)             // check that we can backup all bin files
            {
                string fileName = FpDao.GetFpFileName(fi) + ".bin";
                bool   backupOk = FileUtil.CanRename(fileName);
                if (!backupOk)
                {
                    throw new Exception("Unable to rename file: " + fileName + ", aborting update");
                }
            }

            for (int fi = 0; fi < FingerprintDao.FingerprintFileCount; fi++)
            {
                string fileName = FpDao.GetFpFileName(fi);
                bool   backupOk = FileUtil.BackupAndReplaceFile(fileName + ".bin", fileName + ".bak", fileName + ".mrg");
                if (!backupOk)
                {
                    throw new Exception("Error replacing file: " + fileName + ".bin");
                }
            }

            if (ByCheckpoint)
            {
                string checkPointDate = String.Format("{0:dd-MMM-yyyy HHmmss}", MoleculeDateTime);   // format last new/updated date time in a format that works with Oracle
                FpDao.WriteFingerPrintSimMxDataUpdateCheckpointDate(checkPointDate);                 // update checkpoint
            }

            Progress.Show("Merging complete...");

            int    cnt  = fpRecList.Count;
            string cid1 = fpRecList[0].Cid;
            string cid2 = fpRecList[cnt - 1].Cid;

            if (CidUpdateDateDict.ContainsKey(cid1))
            {
                date1 = CidUpdateDateDict[cid1].ToString();
            }
            else
            {
                date1 = "Missing";
            }

            if (CidUpdateDateDict.ContainsKey(cid2))
            {
                date2 = CidUpdateDateDict[cid1].ToString();
            }
            else
            {
                date2 = "Missing";
            }

            Log("Records stored: " + cnt + ", Adds: " + (cnt - replacementCnt) + ", Replacements: " + replacementCnt +
                ", Date range: " + date1 + " - " + date2 + ", CIDs: First = " + cid1 + ", Last = " + cid2);

            return;
        }