示例#1
0
        private void Initialize(string filename, byte maxkeysize, bool AllowDuplicateKeys)
        {
            filename    = RaptorFileUtil.FileSystemPath(filename);
            _MaxKeySize = RDBDataType <T> .GetByteSize(maxkeysize);

            _Path = Path.GetDirectoryName(filename);
            Directory.CreateDirectory(_Path);
            string dirSep = "" + Path.DirectorySeparatorChar; // "\\";

            _FileName = Path.GetFileNameWithoutExtension(filename);
            string db  = _Path + dirSep + _FileName + _datExtension;
            string idx = _Path + dirSep + _FileName + _idxExtension;

            LogManager.Configure(_Path + dirSep + _FileName + ".txt", 500, false);

            lock (_indexlock) _index = new MGIndex <T>(_Path, _FileName + _idxExtension, _MaxKeySize, Global.PageItemCount, AllowDuplicateKeys);

            lock (_archivelock) _archive = new StorageFile <T>(db);

            lock (_archivelock) _archive.SkipDateTime = true;

            log.Debug("Current Count = " + RecordCount().ToString("#,0"));

            CheckIndexState();

            log.Debug("Starting save timer");
            _savetimer           = new System.Timers.Timer();
            _savetimer.Elapsed  += new System.Timers.ElapsedEventHandler(_savetimer_Elapsed);
            _savetimer.Interval  = Global.SaveIndexToDiskTimerSeconds * 1000;
            _savetimer.AutoReset = true;
            _savetimer.Start();
        }
示例#2
0
        public void Init(string filename, int sizelimitKB, bool showmethodnames)
        {
            filename        = RaptorFileUtil.FileSystemPath(filename);
            _que            = new Queue();
            _showMethodName = showmethodnames;
            _sizeLimit      = sizelimitKB;
            _filename       = filename;
            // handle folder names as well -> create dir etc.
            _FilePath = Path.GetDirectoryName(filename);
            if (_FilePath != "")
            {
                _FilePath = Directory.CreateDirectory(_FilePath).FullName;
                string dirSep = "" + Path.DirectorySeparatorChar;
                if (_FilePath.EndsWith(dirSep) == false)
                {
                    _FilePath += dirSep;
                }
            }
            filename = RaptorFileUtil.FileSystemPath(filename);

            if (!File.Exists(filename))
            {
                File.WriteAllText(filename, "");
            }
            while (_output == null)
            {
                try
                {
                    _output = new StreamWriter(filename, true);
                }
                catch
                {
                    Thread.Sleep(10);
                }
            }
            FileInfo fi = new FileInfo(filename);

            while (!fi.Exists)
            {
                Thread.Sleep(10);
                fi = new FileInfo(filename);
            }
            _lastSize     = fi.Length;
            _lastFileDate = fi.LastWriteTime;

            _saveTimer           = new System.Timers.Timer(500);
            _saveTimer.Elapsed  += new System.Timers.ElapsedEventHandler(_saveTimer_Elapsed);
            _saveTimer.Enabled   = true;
            _saveTimer.AutoReset = true;
        }
示例#3
0
 public static bool FileExists(string file)
 {
     return(File.Exists(RaptorFileUtil.FileSystemPath(file)));
 }
示例#4
0
 public static void FileMove(string from, string to)
 {
     File.Move(RaptorFileUtil.FileSystemPath(from), RaptorFileUtil.FileSystemPath(to));
 }
示例#5
0
        private void WriteData0()
        {
            if (_output == null)
            {
                return;
            }
            lock (_writelock)
            {
                while (_que.Count > 0)
                {
                    try
                    {
                        object o = _que.Dequeue();
                        if (_output != null && o != null)
                        {
                            if (_sizeLimit > 0)
                            {
                                // implement size limited logs
                                // implement rolling logs
                                #region [  rolling size limit ]
                                _lastSize += ("" + o).Length;
                                if (_lastSize > _sizeLimit * 1000)
                                {
                                    _output.Flush();
                                    _output.Close();
                                    int count = 1;
                                    while (RaptorFileUtil.FileExists(_FilePath + Path.GetFileNameWithoutExtension(_filename) + "." + count.ToString("0000")))
                                    {
                                        count++;
                                    }

                                    RaptorFileUtil.FileMove(_filename,
                                                            _FilePath +
                                                            Path.GetFileNameWithoutExtension(_filename) +
                                                            "." + count.ToString("0000"));
                                    _output   = new StreamWriter(_filename, true);
                                    _lastSize = 0;
                                }
                                #endregion
                            }
                            if (DateTime.Now.Subtract(_lastFileDate).Days > 0)
                            {
                                // implement date logs
                                #region [  rolling dates  ]
                                _output.Flush();
                                _output.Close();
                                int count = 1;
                                while (RaptorFileUtil.FileExists(_FilePath + Path.GetFileNameWithoutExtension(_filename) + "." + count.ToString("0000")))
                                {
                                    RaptorFileUtil.FileMove(_FilePath + Path.GetFileNameWithoutExtension(_filename) + "." + count.ToString("0000"),
                                                            _FilePath +
                                                            Path.GetFileNameWithoutExtension(_filename) +
                                                            "." + count.ToString("0000") +
                                                            "." + _lastFileDate.ToString("yyyy-MM-dd"));
                                    count++;
                                }
                                RaptorFileUtil.FileMove(_filename,
                                                        _FilePath +
                                                        Path.GetFileNameWithoutExtension(_filename) +
                                                        "." + count.ToString("0000") +
                                                        "." + _lastFileDate.ToString("yyyy-MM-dd"));

                                _output       = new StreamWriter(_filename, true);
                                _lastFileDate = DateTime.Now;
                                _lastSize     = 0;
                                #endregion
                            }
                            _output.Write(o);
                        }
                    }
                    catch { }
                }
                if (_output != null)
                {
                    try
                    {
                        _output.Flush();
                    }
                    catch { }
                }
            }
        }