Beispiel #1
0
        private void loadServerListToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_frmBatchCollector.ShowDialog() == DialogResult.OK)
            {
                if (!string.IsNullOrEmpty(_frmBatchCollector.BehaviorName))
                {
                    var beh = _colBehaviors.Where(b => b.BehaviorName.Equals(_frmBatchCollector.BehaviorName, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
                    if (beh != null)
                        _objChosenBehavior = beh;
                }

                if (_frmBatchCollector.LogDirectories.Count == 0)
                {
                    _objGlobalLineFilter = _frmBatchCollector.CardsLineFilter;
                }

                ProgressBarManager.ShowProgressBar(100);
                foreach (string directory in _frmBatchCollector.LogDirectories)
                    ProcessLogDirectory(_frmBatchCollector.ExcludeList, _frmBatchCollector.IncludeList, _frmBatchCollector.CardsLineFilter, _frmBatchCollector.History, directory);
                ProgressBarManager.CloseProgress();

                //perform a memory collection
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
            }
        }
 private void txtLineContains_TextChanged(object sender, EventArgs e)
 {
     m_cardsLineFilter = new WildCards("*" + txtLineContains.Text.Trim() + "*");
 }
Beispiel #3
0
        //move to engine
        private void ProcessLogDirectory(List<string> colExcludeList, List<string> colIncludeList, WildCards cardsLineFilter, int intHistory, string line)
        {
            Dictionary<string, DateTime> colFileTimes = new Dictionary<string, DateTime>();

            //get all files from server dir
            string dir = line.Trim();
            if (!dir.EndsWith("\\"))
                dir += "\\";

            if (!Directory.Exists(dir))
                return;
            try
            {
                string[] files = Directory.GetFiles(dir);
                List<string> colLogFiles = new List<string>();

                //get all included files into a list
                bool badFile = false;
                foreach (string file1 in files)
                {
                    badFile = false;
                    //include files
                    foreach (string inc in colIncludeList)
                    {
                        if (!file1.ToLower().Contains(inc))
                        {
                            badFile = true;
                            break;
                        }
                    }

                    //excluded files
                    if (!badFile)
                    {
                        foreach (string exc in colExcludeList)
                        {
                            if (file1.ToLower().Contains(exc))
                            {
                                badFile = true;
                                break;
                            }
                        }
                    }

                    //get all good files into a list
                    if (!badFile)
                    {
                        colLogFiles.Add(file1);
                        colFileTimes.Add(file1, new FileInfo(file1).LastWriteTime);
                    }
                }

                //sort the good files by last modified date
                colLogFiles.Sort((Comparison<string>)delegate(string a, string b)
                {
                    DateTime dt1 = colFileTimes[a];//GetFileLastModifiedTime(a);
                    DateTime dt2 = colFileTimes[b];//GetFileLastModifiedTime(b);
                    if (dt1 > dt2)
                        return -1;
                    if (dt1 == dt2)
                        return 0;
                    else return 1;
                });

                List<string> colFilesForCollection = new List<string>();
                long intTotalDirLogBytes = 0;
                for (int i = 0; i < intHistory; ++i)
                {
                    if (colLogFiles.Count > i)
                    {
                        string logFile = colLogFiles[i];
                        if (_colLineFilter.ContainsKey(logFile))
                            _colLineFilter[logFile] = cardsLineFilter;
                        else
                            _colLineFilter.Add(logFile, cardsLineFilter);
                        colFilesForCollection.Add(logFile);
                        intTotalDirLogBytes += (new FileInfo(logFile)).Length;
                    }
                }

                ProgressBarManager.FullProgressBarValue = intTotalDirLogBytes;
                ProgressBarManager.SetLableText("loading: " + dir);
                colFilesForCollection.ForEach(f => AddFile(f));
                Thread.Sleep(200);
                //Thread t = new Thread((ThreadStart)delegate
                //{
                //    Thread.Sleep(700);
                //    ProgressBarManager.ClearProgress();
                //});
                //t.Start();
                ProgressBarManager.ClearProgress();
                //ProgressBarManager.CloseProgress();
            }
            catch (Exception ex)
            {
            }
        }