locked
looking advice on re-architecting this simple filewatcher app RRS feed

  • Question

  • //any suggestions on how to make this better - architecture-wise appreciated!!!!!!!! 

    public class Watcher : FileSystemWatcher { private IFileProcessor processor; public Watcher() { processor = new FileProcessorBase(); } public Watcher(IFileProcessor p) { processor = p; } public void watcher_Created(object sender, FileSystemEventArgs e) { processor.QueueInput(e.FullPath); } } public partial class AidMatrixFileFixerNotifier : ServiceBase, IFileWatcher { public AidMatrixFileFixerNotifier() { InitializeComponent(); } #region IFileWatcher Members public string InputDirectory { get; set; } public string Filter { get; set; } public string OutputDirectory { get; set; } public string ErrorDirectory { get; set; } public void SetUpDiagnostics(string diagnosticName) { if (!System.Diagnostics.EventLog.SourceExists("diagnosticName")) { System.Diagnostics.EventLog.CreateEventSource( diagnosticName, diagnosticName + "log"); } eventLog1.Source = diagnosticName; eventLog1.Log = diagnosticName + "log"; eventLog1.WriteEntry("In SetUpDiagnostics."); } public void GetWatcherParameters(XElement elem) { InputDirectory = elem.Attributes().Where(s => s.Name == "InputDirectory").FirstOrDefault().Value; Filter = elem.Attributes().Where(s => s.Name == "Filter").FirstOrDefault().Value; OutputDirectory = elem.Attributes().Where(s => s.Name == "OutputDirectory").FirstOrDefault().Value; ErrorDirectory = elem.Attributes().Where(s => s.Name == "ErrorDirectory").FirstOrDefault().Value; } public void StartWatcher(IFileWatcher w) { Watcher watcher = new Watcher(new FileProcessorNotifier()); watcher.Path = w.InputDirectory; watcher.NotifyFilter = NotifyFilters.FileName ; watcher.Filter = w.Filter; watcher.Created += new FileSystemEventHandler(watcher.watcher_Created); watcher.EnableRaisingEvents = true; } #endregion protected override void OnStart(string[] args) { SetUpDiagnostics(this.ToString()); //read the directories for input, output and error XDocument doc = XDocument.Load("FileDirectories.xml"); foreach (XElement elem in doc.Elements()) { GetWatcherParameters(elem); StartWatcher((IFileWatcher)this); } } protected override void OnStop() { eventLog1.WriteEntry("In onStop."); } }


    Tuesday, November 27, 2012 12:22 AM