示例#1
0
        private bool CheckCurrentWorkers(WorkerItem workerItem)
        {
            SetStatus("CheckCurrentWorkers:enter:");

            List <WorkerItem> workerItems = GetWorkers(workerItem);

            WorkerItem.State newState = WorkerItem.State.Ready;

            if (workerItems.Count == 0)
            {
                return(false);
            }
            else if (workerItems.Count == 1)
            {
                newState = WorkerItem.State.NotStarted;
            }

            foreach (WorkerItem item in workerItems)
            {
                if (item.WorkerState == WorkerItem.State.Started)
                {
                }
                else if (item.WorkerState != WorkerItem.State.Completed)
                {
                    item.WorkerModification = workerItem.WorkerModification;
                    item.WorkerState        = newState;
                    SetStatus("CheckCurrentWorkers:resetting state:" + item.WorkerState.ToString());
                }
            }

            return(true);
        }
示例#2
0
        public void StartWorker(WorkerItem workerItem)
        {
            // This method runs on the main thread.
            SetStatus(string.Format("StartWorker:enter:WorkerModification:{0} {1}", workerItem.WorkerModification, workerItem.WorkerState));

            switch (workerItem.WorkerModification)
            {
            case WorkerItem.Modification.LogAdded:
                workerItem.BackGroundWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(DoLogWork);
                break;

            case WorkerItem.Modification.FilterAdded:
            case WorkerItem.Modification.FilterModified:
                workerItem.BackGroundWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(DoFilterWork);
                break;

            default:
                SetStatus("StartWorker:not configured WorkerModification:" + workerItem.WorkerModification.ToString());
                return;
            }

            Mouse.OverrideCursor = Cursors.AppStarting;
            CancelAllWorkers();

            workerItem.BackGroundWorker.WorkerSupportsCancellation = true;
            workerItem.BackGroundWorker.DoWork             += new System.ComponentModel.DoWorkEventHandler(DoLogWork);
            workerItem.BackGroundWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(RunLogWorkerCompleted);

            // Start the asynchronous operation.
            workerItem.BackGroundWorker.RunWorkerAsync(workerItem);
            SetStatus("StartWorker:worker started:exit");
            return;
        }
示例#3
0
        private void filterItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            SetStatus("Parser:filterItemsCollectionChanged");
            WorkerItem worker = ModifiedFilterFile();

            _workerManager.ProcessWorker(worker);
        }
示例#4
0
        public void AddWorkersByWorkerItemFilterFile(WorkerItem workerItem)
        {
            //if (workerItem == null || workerItem.LogFile == null | workerItem.FilterFile == null)
            //{
            //    SetStatus("AddWorkersByFilterFile:returning due to incomplete workItem");
            //    return;
            //}

            // add base one with no log used when no log selected
            workerItem.FilterNeed         = workerItem.FilterFile == null ? FilterNeed.ShowAll : FilterNeed.Filter;
            workerItem.WorkerModification = WorkerItem.Modification.FilterAdded;
            workerItem.WorkerState        = WorkerItem.State.NotStarted;
            AddWorker(workerItem);

            List <LogFile> logFiles = GetLogFiles();

            if (logFiles.Count > 0)
            {
                foreach (LogFile logFile in logFiles)
                {
                    if (GetWorkers(workerItem.FilterFile, logFile).Count == 0)
                    {
                        WorkerItem bgItem = new WorkerItem()
                        {
                            FilterFile         = workerItem.FilterFile,
                            LogFile            = logFile,
                            FilterNeed         = workerItem.FilterNeed,
                            WorkerModification = workerItem.WorkerModification,
                            // if current logfile, set to notstarted so it gets processed first
                            WorkerState = logFile == workerItem.LogFile ? WorkerItem.State.NotStarted : WorkerItem.State.Ready
                        };

                        AddWorker(bgItem);
                        SetStatus(string.Format("AddWorkersByWorkerItemFilterFile:Added worker:{0} {1} total workers:{2}",
                                                workerItem.LogFile != null ? workerItem.LogFile.Tag : string.Empty,
                                                workerItem.FilterFile.Tag,
                                                _workerManager.BGWorkers.Count()));
                    }
                }
            }
            else
            {
                WorkerItem bgItem = new WorkerItem()
                {
                    FilterFile         = workerItem.FilterFile,
                    FilterNeed         = workerItem.FilterNeed,
                    WorkerModification = workerItem.WorkerModification,
                    // if current logfile, set to notstarted so it gets processed first
                    WorkerState = WorkerItem.State.NotStarted
                };

                AddWorker(bgItem);
                SetStatus(string.Format("AddWorkersByWorkerItemFilterFile:Added null worker:{0} {1} total workers:{2}",
                                        workerItem.LogFile != null ? workerItem.LogFile.Tag : string.Empty,
                                        workerItem.FilterFile.Tag,
                                        _workerManager.BGWorkers.Count()));
            }
        }
示例#5
0
 private void CancelWorker(WorkerItem bgWorker)
 {
     if (bgWorker.BackGroundWorker != null && bgWorker.BackGroundWorker.IsBusy)
     {
         SetStatus("CancelAllWorkers:cancelling worker");
         bgWorker.BackGroundWorker.CancelAsync();
         bgWorker.WorkerState = WorkerItem.State.Aborted;
     }
 }
示例#6
0
        private void logViewManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            SetStatus("Parser:logViewPropertyChanged:" + e.PropertyName);
            // todo: determine what changed and run parser new log or remove log

            WorkerItem worker = ModifiedLogFile();

            _workerManager.ProcessWorker(worker);
        }
示例#7
0
        public void ReadFile()
        {
            SetStatus("Parser:ReadFile");
            // todo: determine what changed and run parser new log or remove log

            WorkerItem worker = ModifiedLogFile();

            _workerManager.ProcessWorker(worker);
        }
示例#8
0
 public void RemoveWorker(WorkerItem bgWorker)
 {
     // Cancel the asynchronous operation.
     if (BGWorkers.Contains(bgWorker))
     {
         SetStatus("RemoveWorker:removing worker");
         bgWorker.BackGroundWorker.CancelAsync();
         BGWorkers.Remove(bgWorker);
     }
 }
示例#9
0
        private void DoLogWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bgWorker;

            bgWorker = (BackgroundWorker)sender;

            WorkerItem workerItem = (WorkerItem)e.Argument;

            workerItem.WorkerState = WorkerItem.State.Started;

            e.Result = MMFConcurrentRead(workerItem.LogFile, bgWorker);

            SetStatus("WorkerManager:DoWork:exit");
        }
示例#10
0
        private void filterViewManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            SetStatus("Parser:filterViewPropertyChanged:" + e.PropertyName);
            // todo: determine what changed and run parser new filter, modified filter, removed filter
            // see if tab was added or removed

            WorkerItem worker = ModifiedFilterFile();

            _workerManager.ProcessWorker(worker);
            //check worker

            // todo : re parse current log with new selected filter bool ret =
            // ParseFile(_filterViewModel.CurrentFile(), _logViewModel.CurrentFile());
        }
示例#11
0
        private void DoFilterWork(object sender, DoWorkEventArgs e)
        {
            SetStatus("DoFilterWork:enter:notimplementedexception");

            BackgroundWorker bgWorker;

            bgWorker = (BackgroundWorker)sender;

            WorkerItem workerItem = (WorkerItem)e.Argument;

            workerItem.WorkerState = WorkerItem.State.Started;

            //e.Result = MMFConcurrentRead(workerItem.LogFile, bgWorker);

            SetStatus("WorkerManager:DoFilterWork:exit");
        }
示例#12
0
        private void AddWorker(WorkerItem workerItem)
        {
            if (GetWorkers(workerItem).Count == 0)
            {
                if (workerItem.WorkerState == WorkerItem.State.NotStarted)
                {
                    foreach (WorkerItem item in GetWorkers().Where(x => x.WorkerState == WorkerItem.State.NotStarted))
                    {
                        item.WorkerState = WorkerItem.State.Ready;
                    }
                }

                SetStatus("AddWorker:adding worker");

                BGWorkers.Add(workerItem);
            }
            else
            {
                SetStatus("AddWorker:exiting: worker already exists");
            }
        }
示例#13
0
        private bool ResetCurrentWorkersByFilter(WorkerItem workerItem)
        {
            SetStatus("ResetCurrentWorkersbyFilter:enter");
            if (GetWorkers(workerItem.FilterFile).Count == 0)
            {
                return(false);
            }

            foreach (WorkerItem item in GetWorkers(workerItem.FilterFile))
            {
                if (item.WorkerState == WorkerItem.State.Started)
                {
                    CancelWorker(item);
                }

                item.WorkerState = workerItem.LogFile == item.LogFile ? WorkerItem.State.NotStarted : WorkerItem.State.Ready;
                SetStatus("ResetCurrentworkersByfilter:resetting state:" + item.WorkerState.ToString());

                item.WorkerModification = WorkerItem.Modification.FilterModified;
            }

            return(true);
        }
示例#14
0
        private WorkerItem ModifiedFilterFile()
        {
            SetStatus("Parser:ModifiedFilterFile:enter");
            List <IFile <FilterFileItem> > currentFilterFiles = CurrentFilterFiles();
            FilterFile currentFilterFile = CurrentFilterFile();

            //LogFile currentLog = (LogFile)_logViewModel.CurrentFile();

            if (currentFilterFiles == null) // || currentFilterFile == null)
            {
                // SyncFilterFiles();
                return(new WorkerItem());
            }

            if (currentFilterFiles.Count > 0 && _previousFilterFiles.Count == currentFilterFiles.Count)
            {
                SetStatus("Parser:ModifiedFilterFile:same count");
                WorkerItem filterFileWorkerItem = new WorkerItem()
                {
                    WorkerModification = WorkerItem.Modification.Unknown,
                    FilterFile         = currentFilterFile,
                    LogFile            = (LogFile)_logViewModel.CurrentFile()
                };

                FilterNeed filterNeed = FilterNeed.Unknown;
                //if (_previousFilterFiles.Contains(currentFilterFile))
                if (_previousFilterFiles.Exists(x => x.Tag == currentFilterFile.Tag))
                {
                    SetStatus("Parser:ModifiedFilterFile:have previous version");
                    FilterFile previousVersionFilterFile = _previousFilterFiles.First(x => x.Tag == currentFilterFile.Tag);
                    filterNeed = _FilterViewModel.CompareFilterList(previousVersionFilterFile.ContentItems.ToList());
                }
                else
                {
                    filterNeed = FilterNeed.Filter;
                }

                if (currentFilterFile != _filterFilePrevious)
                {
                    SetStatus("Parser:ModifiedFilterFile:current filter file changed");
                    filterFileWorkerItem.WorkerModification = WorkerItem.Modification.FilterIndex;
                    filterNeed          = FilterNeed.Filter;
                    _filterFilePrevious = currentFilterFile;
                }

                switch (filterNeed)
                {
                case FilterNeed.Unknown:
                case FilterNeed.ShowAll:
                case FilterNeed.Filter:
                case FilterNeed.ApplyColor:
                    filterFileWorkerItem.FilterNeed         = filterNeed;
                    filterFileWorkerItem.WorkerModification = WorkerItem.Modification.FilterModified;
                    return(filterFileWorkerItem);

                case FilterNeed.Current:
                    SetStatus("Parser:ModifiedFilterFile:current");
                    filterFileWorkerItem.FilterNeed         = FilterNeed.Current;
                    filterFileWorkerItem.WorkerModification = WorkerItem.Modification.Unknown;
                    return(filterFileWorkerItem);

                default:
                    break;
                }
            }
            else if (_previousFilterFiles.Count < currentFilterFiles.Count)
            {
                SetStatus("Parser:ModifiedFilterFile:filter file added");
                SyncFilterFiles();
                EnableFilterFileMonitoring(true);
                // todo : re parse current log with new filter
                return(new WorkerItem()
                {
                    FilterFile = CurrentFilterFile(),
                    FilterNeed = FilterNeed.Filter,
                    WorkerModification = WorkerItem.Modification.FilterAdded
                });
            }
            else
            {
                SetStatus("Parser:ModifiedFilterFile:filter file removed");
                SyncFilterFiles();
                EnableFilterFileMonitoring(false);
                // todo : re parse current log with new filter
                return(new WorkerItem()
                {
                    FilterFile = CurrentFilterFile(),
                    FilterNeed = FilterNeed.Filter,
                    WorkerModification = WorkerItem.Modification.FilterRemoved
                });
            }

            return(new WorkerItem()
            {
                FilterNeed = FilterNeed.Unknown,
                WorkerModification = WorkerItem.Modification.Unknown
            });
        }
示例#15
0
        private WorkerItem ModifiedLogFile()
        {
            SetStatus("Parser.ModifiedLogFile:enter");
            List <IFile <LogFileItem> > currentLogFiles = CurrentLogFiles();
            LogFile currentLogFile = CurrentLogFile();

            if (currentLogFiles == null) // || currentLogFile == null)
            {
                SetStatus("Parser.ModifiedLogFile:currentLog empty");
                // SyncLogFiles();
                return(new WorkerItem());
            }

            if (_previousLogFiles.Count == currentLogFiles.Count)
            {
                WorkerItem workerItem = new WorkerItem()
                {
                    FilterFile         = (FilterFile)_FilterViewModel.CurrentFile(),
                    LogFile            = currentLogFile,
                    WorkerModification = WorkerItem.Modification.Unknown,
                    FilterNeed         = FilterNeed.Current
                };

                if (currentLogFile != _logFilePrevious)
                {
                    workerItem.WorkerModification = WorkerItem.Modification.LogIndex;
                    workerItem.FilterNeed         = FilterNeed.Filter;
                    _logFilePrevious = currentLogFile;
                }

                SetStatus("Parser.ModifiedLogFile:logfile count same");
                return(workerItem);
            }
            else if (_previousLogFiles.Count < currentLogFiles.Count)
            {
                SetStatus("Parser.ModifiedLogFiles:logfile file added");
                SyncLogFiles();
                return(new WorkerItem()
                {
                    LogFile = CurrentLogFile(),
                    FilterNeed = FilterNeed.Filter,
                    WorkerModification = WorkerItem.Modification.LogAdded
                });
            }
            else
            {
                SetStatus("Parser.ModifiedLogFiles:logfile file removed");
                SyncLogFiles();
                return(new WorkerItem()
                {
                    LogFile = CurrentLogFile(),
                    FilterNeed = FilterNeed.Filter,
                    WorkerModification = WorkerItem.Modification.LogRemoved
                });
            }

            //return new WorkerItem()
            //{
            //    FilterNeed = FilterNeed.Unknown,
            //    WorkerModification = WorkerItem.Modification.Unknown
            //};
        }
示例#16
0
 public List <WorkerItem> GetWorkers(WorkerItem workerItem)
 {
     return(GetWorkers(workerItem.FilterFile, workerItem.LogFile));
 }
示例#17
0
        public bool ProcessWorker(WorkerItem workerItem)
        {
            // todo: remove when switching to mapped file
            return(true);

            if (workerItem == null)
            {
                SetStatus("WorkerManager.ProcessWorker enter worker null. returning");
                return(false);
            }

            SetStatus("WorkerManager.ProcessWorker enter worker.Modification:" + workerItem.WorkerModification.ToString());

            switch (workerItem.WorkerModification)
            {
            case WorkerItem.Modification.LogRemoved:
                RemoveWorkersByLogFile(workerItem.LogFile);
                return(true);

            case WorkerItem.Modification.FilterRemoved:
                RemoveWorkersByFilterFile(workerItem.FilterFile);
                return(true);

            case WorkerItem.Modification.FilterModified:
                ResetCurrentWorkersByFilter(workerItem);
                break;

            case WorkerItem.Modification.FilterIndex:
                CheckCurrentWorkers(workerItem);
                break;

            case WorkerItem.Modification.LogIndex:
                CheckCurrentWorkers(workerItem);
                break;

            case WorkerItem.Modification.FilterAdded:
                AddWorkersByWorkerItemFilterFile(workerItem);
                break;

            case WorkerItem.Modification.LogAdded:
                AddWorkersByWorkerItemLogFile(workerItem);
                break;

            case WorkerItem.Modification.Unknown:
            default:
            {
                SetStatus("Error:WorkerManager.ProcessWorker unknown state exit.");
                return(false);
            }
            }

            SetStatus("WorkerManager.ProcessWorker:workerItem.State:" + workerItem.WorkerState.ToString());

            if (workerItem.WorkerState == WorkerItem.State.Ready | workerItem.WorkerState == WorkerItem.State.NotStarted)
            {
                StartWorker(workerItem);
            }
            else if (GetWorkers().Count(x => x.WorkerState == WorkerItem.State.NotStarted) > 0)
            {
                StartWorker(GetWorkers().First(x => x.WorkerState == WorkerItem.State.NotStarted));
            }
            else if (GetWorkers().Count(x => x.WorkerState == WorkerItem.State.Ready) > 0)
            {
                StartWorker(GetWorkers().First(x => x.WorkerState == WorkerItem.State.Ready));
            }
            else if (GetWorkers().Count(x => x.WorkerState == WorkerItem.State.Aborted) > 0)
            {
                StartWorker(GetWorkers().First(x => x.WorkerState == WorkerItem.State.Aborted));
            }
            else
            {
                SetStatus("WorkerManager.ProcessWorker:workerItem not ready or notstarted. exiting.");
            }

            return(true);
        }