Пример #1
0
        public void ParseJournalFiles(Func <bool> cancelRequested, Action <int, string> updateProgress, bool forceReload = false)
        {
            List <EDCommander> listCommanders = EDCommander.GetList();

            if (frontierfolder != null && frontierfolder.Length != 0 && Directory.Exists(frontierfolder))
            {
                if (watchers.FindIndex(x => x.m_watcherfolder.Equals(frontierfolder)) < 0)
                {
                    System.Diagnostics.Trace.WriteLine(string.Format("New watch on {0}", frontierfolder));
                    MonitorWatcher mw = new MonitorWatcher(frontierfolder);
                    watchers.Add(mw);
                }
            }

            for (int i = 0; i < listCommanders.Count; i++)             // see if new watchers are needed
            {
                string datapath = GetWatchFolder(listCommanders[i].JournalDir);

                if (datapath == null || datapath.Length == 0 || !Directory.Exists(datapath))
                {
                    continue;
                }

                if (watchers.FindIndex(x => x.m_watcherfolder.Equals(datapath)) >= 0) // if we already have a watch on this folder..
                {
                    continue;                                                         // already done
                }
                System.Diagnostics.Trace.WriteLine(string.Format("New watch on {0}", datapath));
                MonitorWatcher mw = new MonitorWatcher(datapath);
                watchers.Add(mw);
            }

            List <int> tobedeleted = new List <int>();

            for (int i = 0; i < watchers.Count; i++)
            {
                bool found = false;
                for (int j = 0; j < listCommanders.Count; j++)          // all commanders, see if this watch folder is present
                {
                    found |= watchers[i].m_watcherfolder.Equals(GetWatchFolder(listCommanders[j].JournalDir));
                }

                if (!found)
                {
                    tobedeleted.Add(i);
                }
            }

            foreach (int i in tobedeleted)
            {
                System.Diagnostics.Trace.WriteLine(string.Format("Delete watch on {0}", watchers[i].m_watcherfolder));
                MonitorWatcher mw = watchers[i];
                mw.StopMonitor();          // just in case
                watchers.Remove(mw);
            }

            for (int i = 0; i < watchers.Count; i++)                                         // parse files of all folders being watched
            {
                watchers[i].ParseJournalFiles(cancelRequested, updateProgress, forceReload); // may create new commanders at the end, but won't need any new watchers, because they will obv be in the same folder
            }
        }
Пример #2
0
        public void ParseJournalFiles(Func <bool> cancelRequested, Action <int, string> updateProgress, bool forceReload = false)
        {
            List <EDCommander> listCommanders = EDCommander.GetList();

            // add the default frontier folder in

            if (!string.IsNullOrEmpty(frontierfolder) && Directory.Exists(frontierfolder)) // if it exists..
            {
                if (watchers.FindIndex(x => x.WatcherFolder.Equals(frontierfolder)) < 0)   // and we are not watching it..
                {
                    System.Diagnostics.Trace.WriteLine(string.Format("New watch on {0}", frontierfolder));
                    JournalMonitorWatcher mw = new JournalMonitorWatcher(frontierfolder);
                    watchers.Add(mw);

                    StatusMonitorWatcher sw = new StatusMonitorWatcher(frontierfolder, ScanTick);
                    sw.UIEventCallBack += UIEvent;
                    statuswatchers.Add(sw);
                }
            }

            for (int i = 0; i < listCommanders.Count; i++)             // see if new watchers are needed
            {
                string datapath = GetWatchFolder(listCommanders[i].JournalDir);

                if (string.IsNullOrEmpty(datapath) || !Directory.Exists(datapath))  // not exist, ignore
                {
                    continue;
                }

                if (watchers.FindIndex(x => x.WatcherFolder.Equals(datapath)) >= 0) // if we already have a watch on this folder..
                {
                    continue;                                                       // already done
                }
                System.Diagnostics.Trace.WriteLine(string.Format("New watch on {0}", datapath));
                JournalMonitorWatcher mw = new JournalMonitorWatcher(datapath);
                watchers.Add(mw);

                StatusMonitorWatcher sw = new StatusMonitorWatcher(datapath, ScanTick);
                sw.UIEventCallBack += UIEvent;
                statuswatchers.Add(sw);
            }

            // clean up monitors on journals
            {
                List <int> tobedeleted = new List <int>();
                for (int i = 0; i < watchers.Count; i++)
                {
                    bool found = false;
                    for (int j = 0; j < listCommanders.Count; j++)          // all commanders, see if this watch folder is present
                    {
                        found |= watchers[i].WatcherFolder.Equals(GetWatchFolder(listCommanders[j].JournalDir));
                    }

                    if (!found)
                    {
                        tobedeleted.Add(i);
                    }
                }

                foreach (int i in tobedeleted)
                {
                    System.Diagnostics.Trace.WriteLine(string.Format("Delete watch on {0}", watchers[i].WatcherFolder));
                    JournalMonitorWatcher mw = watchers[i];
                    mw.StopMonitor();          // just in case
                    watchers.Remove(mw);
                }
            }

            // and on status files
            {
                List <int> statustobedeleted = new List <int>();
                for (int i = 0; i < statuswatchers.Count; i++)
                {
                    bool found = false;
                    for (int j = 0; j < listCommanders.Count; j++)          // all commanders, see if this watch folder is present
                    {
                        found |= statuswatchers[i].WatcherFolder.Equals(GetWatchFolder(listCommanders[j].JournalDir));
                    }

                    if (!found)
                    {
                        statustobedeleted.Add(i);
                    }
                }

                foreach (int i in statustobedeleted)
                {
                    System.Diagnostics.Trace.WriteLine(string.Format("Delete status watch on {0}", statuswatchers[i].WatcherFolder));
                    StatusMonitorWatcher mw = statuswatchers[i];
                    mw.StopMonitor();          // just in case
                    statuswatchers.Remove(mw);
                }
            }

            for (int i = 0; i < watchers.Count; i++)                                         // parse files of all folders being watched
            {
                watchers[i].ParseJournalFiles(cancelRequested, updateProgress, forceReload); // may create new commanders at the end, but won't need any new watchers, because they will obv be in the same folder
            }
        }