Beispiel #1
0
        public void Import(string pipscsv, StringHandler msgCallback)
        {
            if ((pipscsv != null) && (pipscsv != string.Empty))
            {
                try
                {
                    available = false;
                    CSV csv = new CSV(PIPS.Utilities.FileEncrypter.IsEncrypted(pipscsv) ? PIPS.Utilities.FileEncrypter.GetStreamReader(pipscsv) : new StreamReader(pipscsv));
                    try
                    {
                        //PIPS.Logger.WriteLine("HotList.Import({0})", pipscsv);
                        string[]        fields;
                        int             count  = 0;
                        HotListDataFile hlfile = this.GetLastDataFile();
                        hlfile.BeginTransaction();
                        DateTime start = DateTime.Now;
                        while ((fields = csv.ReadLine()) != null)
                        {
                            if ((count % 10000) == 0)
                            {
                                //PIPS.Logger.WriteLine("HotList.Import({0}, {1})", count, (DateTime.Now - start).TotalMilliseconds);

                                if ((msgCallback != null) && ((count % 1000) == 0))
                                {
                                    msgCallback(string.Format("Importing '{0}' at line {1}...", Path.GetFileNameWithoutExtension(pipscsv), count));
                                }
                            }

                            count++;

                            Int64 bossId;

                            if (fields.Length < 9 || !Int64.TryParse(fields[8], out bossId))
                            {
                                bossId = -1;
                            }
                            this.Save(fields[0], fields[1], fields[2], fields[3], fields[4], fields[5], fields[6], fields[7], bossId);
                        }
                        hlfile.CommitTransaction();
                    }
                    finally
                    {
                        csv.Close();
                    }
                }
                finally
                {
                    available = true;
                    GC.WaitForPendingFinalizers();
                    GC.Collect(0, GCCollectionMode.Forced);
                    GC.Collect(1, GCCollectionMode.Forced);
                    GC.Collect(2, GCCollectionMode.Forced);
                }
            }
        }
Beispiel #2
0
        public HotListDataFile AddNewDataFile()
        {
            if (!Directory.Exists(this.directory))
            {
                Directory.CreateDirectory(this.directory);
            }
            HotListDataFile hl = new HotListDataFile(this.directory, this.dataFiles.Count);

            this.dataFiles.Add(hl);
            hl.Initialize();
            return(hl);
        }
Beispiel #3
0
        private void ImportDeltaInserts(string pipscsv, string filename, StringHandler msgCallback)
        {
            CSV csv = new CSV(PIPS.Utilities.FileEncrypter.IsEncrypted(filename) ? PIPS.Utilities.FileEncrypter.GetStreamReader(filename) : new StreamReader(filename));

            try {
                //PIPS.Logger.WriteLine("HotList.DeltaInserts({0})", filename);
                string[]        fields;
                int             count         = 1;
                int             dataFileIndex = 0;
                Int64           bossId;
                HotListDataFile df = ((HotListDataFile)this.dataFiles[dataFileIndex]);
                df.BeginTransaction();
                while ((fields = csv.ReadLine()) != null)
                {
                    if ((++count % 1000) == 0)
                    {
                        if (null != msgCallback)
                        {
                            msgCallback(string.Format("Inserting '{0}' at line {1}...", Path.GetFileNameWithoutExtension(filename), count));
                        }
                        df.CommitTransaction();
                        dataFileIndex = (dataFileIndex + 1) % this.dataFiles.Count;
                        df.BeginTransaction();
                    }
                    HotListDataEvent de = df.HotList.CreateDataEvent() as HotListDataEvent;
                    de.ID          = -1;
                    de.VRM         = fields[0];
                    de.Field1      = fields[1];
                    de.Field2      = fields[2];
                    de.Field3      = fields[3];
                    de.Field4      = fields[4];
                    de.Field5      = fields[5];
                    de.PNCID       = fields[6];
                    de.Information = fields[7];

                    //  Only BOSS provides a valid BOSS id
                    if (fields.Length < 9 || !Int64.TryParse(fields[8], out bossId))
                    {
                        bossId = -1;
                    }
                    de.BossID = bossId;
                    de.Save();
                }
                df.CommitTransaction();
            } finally {
                csv.Close();
            }
            GC.WaitForPendingFinalizers();
            GC.Collect(0, GCCollectionMode.Forced);
            GC.Collect(1, GCCollectionMode.Forced);
            GC.Collect(2, GCCollectionMode.Forced);
        }
Beispiel #4
0
 private void SaveInternal(HotListDataFile hlfile, string vrm, string field1, string field2, string field3, string field4, string field5, string pncid, string information, long bossID)
 {
     if ((vrm != null) && (vrm != string.Empty))
     {
         this.insertEvent.ID          = -1;
         this.insertEvent.VRM         = vrm;
         this.insertEvent.Field1      = field1;
         this.insertEvent.Field2      = field2;
         this.insertEvent.Field3      = field3;
         this.insertEvent.Field4      = field4;
         this.insertEvent.Field5      = field5;
         this.insertEvent.PNCID       = pncid;
         this.insertEvent.Information = information;
         this.insertEvent.BossID      = bossID;
         hlfile.Insert(this.insertEvent);
     }
 }