Exemple #1
0
        /// <summary>
        /// Start the process.
        /// </summary>
        public void Start()
        {
            try
            {
                string xmlValidationMessage = string.Empty;

                // Get the xml file location and
                // the xsd file schema.
                string xml = Nequeo.Maintenance.Properties.Settings.Default.LogFileListXmlPath;
                string xsd = Nequeo.Maintenance.Properties.Resources.LogFileList;

                // Validate the filter xml file.
                if (!Validation.IsXmlValidEx(xsd, xml, out xmlValidationMessage))
                {
                    throw new Exception("Xml validation. " + xmlValidationMessage);
                }

                // Deserialise the xml file into
                // the log directory list object
                GeneralSerialisation serial        = new GeneralSerialisation();
                LogDirectoryList     directoryList = ((LogDirectoryList)serial.Deserialise(typeof(LogDirectoryList), xml));

                // Start the deletion process.
                _timer = new IntervalControl(directoryList.Interval);
                _timer.Start(u => DeleteLogFiles(u), directoryList);
            }
            catch (Exception e)
            {
                // Detect a thread abort exception.
                if (e is ThreadAbortException)
                {
                    Thread.ResetAbort();
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Delete the files within the directory.
        /// </summary>
        /// <param name="state">The state data</param>
        private void DeleteLogFiles(Object state)
        {
            LogDirectoryList directoryList = (LogDirectoryList)state;

            try
            {
                // For each directory found
                foreach (LogDirectoryListDirectory item in directoryList.Directories)
                {
                    try
                    {
                        // Create a new retension deletion file object.
                        // Find all the files in each directory that need
                        // to be deleted. Start the deletion of the files.
                        Retention retention = new Retention(item.fileRetension, item.Value, item.filePattern);
                        retention.StartDelete();
                    }
                    catch (Exception e)
                    {
                        // Detect a thread abort exception.
                        if (e is ThreadAbortException)
                        {
                            Thread.ResetAbort();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // Detect a thread abort exception.
                if (e is ThreadAbortException)
                {
                    Thread.ResetAbort();
                }
            }
        }