Example #1
0
        public ServiceMain()
        {
            InitializeComponent();
            _logFile             = new Logging();
            _logFile.logFileName = "EventLog";
            _logFile.WriteToLog("EventLog has been created.");

            string minuteDisplay;
            int    timerIntervalMinutes = Properties.Settings.Default.TimerIntervalMinutes;

            minuteDisplay = timerIntervalMinutes == 1 ? " minute." : " minutes.";

            _timerIntervalMilliseconds = 1000 * 60 * timerIntervalMinutes;
            _logFile.WriteToLog("Timer interval set to " + timerIntervalMinutes.ToString() + minuteDisplay);

            System.Collections.Specialized.StringCollection sc = new System.Collections.Specialized.StringCollection();
            sc = Properties.Settings.Default.ScanDirectories;
            string[] scanDir = new string[sc.Count];

            //Copies all rows from string collection
            sc.CopyTo(scanDir, 0);

            string dirDisplay;

            dirDisplay = sc.Count == 1 ? "directory" : "directories";
            _logFile.WriteToLog("The following source " + dirDisplay + " will be scanned:");
            foreach (string dirName in scanDir)
            {
                _logFile.WriteToLog("--> " + dirName);
            }

            //jvc
            string failedDir = Properties.Settings.Default.FailedDirectory;

            _logFile.WriteToLog("FailedDirectory=" + failedDir);

            string outputDir         = Properties.Settings.Default.OutputDirectory;
            string processedDir      = Properties.Settings.Default.ProcessedDirectory;
            string validFileExt      = Properties.Settings.Default.ValidFileExt;
            bool   isDebugLogEnabled = Properties.Settings.Default.DebugLogEnabled;

            //_logFile.WriteToLog("OutputDirectory=" + outputDir);
            _logFile.WriteToLog("ProcessedDirectory=" + processedDir);
            _logFile.WriteToLog("ValidFileExt=" + validFileExt);
            _logFile.WriteToLog("DebugLogEnabled=" + isDebugLogEnabled);

            _logFile.WriteToLog("Creating DirectoryPoller...");
            _dirProcessor = new DirectoryProcessor(scanDir, validFileExt, outputDir, processedDir, failedDir, _logFile);
            _dirProcessor._isDebugLogEnabled = isDebugLogEnabled;
            _dirProcessor._EventLog          = _logFile;
            _logFile.WriteToLog("DirectoryPoller was successfully created.");

            this.timerMain.Interval = _timerIntervalMilliseconds;
            //this.timerMain.Elapsed += new System.Timers.ElapsedEventHandler(timerMain_Elapsed);

            // If the timer is declared in a long-running method, use
            // KeepAlive to prevent garbage collection from occurring
            // before the method ends.
            GC.KeepAlive(timerMain);
        }
Example #2
0
        public ServiceMain()
        {
            InitializeComponent();
            _logFile = new Logging();
            _logFile.logFileName = "EventLog";
            _logFile.WriteToLog("EventLog has been created.");

            string minuteDisplay;
            int timerIntervalMinutes = Properties.Settings.Default.TimerIntervalMinutes;
            minuteDisplay = timerIntervalMinutes == 1 ? " minute." : " minutes.";

            _timerIntervalMilliseconds = 1000 * 60 * timerIntervalMinutes;
            _logFile.WriteToLog("Timer interval set to " + timerIntervalMinutes.ToString() + minuteDisplay);

            System.Collections.Specialized.StringCollection sc = new System.Collections.Specialized.StringCollection();
            sc = Properties.Settings.Default.ScanDirectories;
            string[] scanDir = new string[sc.Count];

            //Copies all rows from string collection
            sc.CopyTo(scanDir, 0);

            string dirDisplay;
            dirDisplay = sc.Count == 1 ? "directory" : "directories";
            _logFile.WriteToLog("The following source " + dirDisplay + " will be scanned:");
            foreach (string dirName in scanDir)
            {
                _logFile.WriteToLog("--> " + dirName);
            }

            //jvc
            string failedDir = Properties.Settings.Default.FailedDirectory;
            _logFile.WriteToLog("FailedDirectory=" + failedDir);

            string outputDir = Properties.Settings.Default.OutputDirectory;
            string processedDir = Properties.Settings.Default.ProcessedDirectory;
            string validFileExt = Properties.Settings.Default.ValidFileExt;
            bool isDebugLogEnabled = Properties.Settings.Default.DebugLogEnabled;

            //_logFile.WriteToLog("OutputDirectory=" + outputDir);
            _logFile.WriteToLog("ProcessedDirectory=" + processedDir);
            _logFile.WriteToLog("ValidFileExt=" + validFileExt);
            _logFile.WriteToLog("DebugLogEnabled=" + isDebugLogEnabled);

            _logFile.WriteToLog("Creating DirectoryPoller...");
            _dirProcessor = new DirectoryProcessor(scanDir, validFileExt, outputDir, processedDir, failedDir, _logFile);
            _dirProcessor._isDebugLogEnabled = isDebugLogEnabled;
            _dirProcessor._EventLog = _logFile;
            _logFile.WriteToLog("DirectoryPoller was successfully created.");

            this.timerMain.Interval = _timerIntervalMilliseconds;
            //this.timerMain.Elapsed += new System.Timers.ElapsedEventHandler(timerMain_Elapsed);

            // If the timer is declared in a long-running method, use
            // KeepAlive to prevent garbage collection from occurring
            // before the method ends.
            GC.KeepAlive(timerMain);
        }
Example #3
0
        private void btnProcessDirs_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            tssLabelStatus.Text = "Processing...";
            this.Refresh();
            try
            {
                string validFileExt = Properties.Settings.Default.ValidFileExt;

                _scanDirs[0] = initTestDirectory(this.tbRootDir.Text, "");
                _outputDir = initTestDirectory(tbOuputDir.Text, "");
                _failedDir = initTestDirectory(tbFailedDir.Text, "");
                _processedDir = initTestDirectory(tbProcessedDir.Text, "");
                DirectoryProcessor dirProcessor = new DirectoryProcessor(_scanDirs, validFileExt, _outputDir, _processedDir, _failedDir, null);
                dirProcessor._isDebugLogEnabled = true;
                dirProcessor._EventLog = _EventLog;
                dirProcessor.ProcessDirectories();
            }
            finally
            {
                this.Cursor = Cursors.Default;
                tssLabelStatus.Text = "Done.";
            }
        }