Ejemplo n.º 1
0
        void checkConfigFileModifications(object sender, ElapsedEventArgs e)
        {
            try
            {
                string programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
                this._configFilePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "FileMateConfig.xml");
                if (File.Exists(this._configFilePath))
                {
                    _configChangedCheckTimer.Stop();
                    try
                    {
                        // config file is available.. if it is modified, re-initiate the copy operations
                        if (configFileModified())
                        {
                            XmlDocument doc = new XmlDocument();
                            doc.Load(_configFilePath);

                            if (_cg == null)
                            {
                                _cg = new CopyGroup(doc);
                            }
                            else
                            {
                                // re-load copy operations from xml document
                                this.EventLog.WriteEntry("Configurations modified..re-initializing transfers", EventLogEntryType.Information);
                                _cg.ReInitiateCopyOperations(doc);
                            }

                            // start file transfer
                            _cg.StartCopyOperationsSchedules();
                        }
                    }
                    catch (Exception ex)
                    {
                        this.EventLog.WriteEntry(string.Format("Failed to load FileMate configuration, invalid or missing settings file : {0}", ex.Message), EventLogEntryType.Error);
                    }
                    _configChangedCheckTimer.Start();
                }
                else
                {
                    this.EventLog.WriteEntry("FileMate configuration file not found", EventLogEntryType.Error);
                }
            }
            catch (Exception ex)
            {
                this.EventLog.WriteEntry(string.Format("An exception occurred : {0}", ex.Message), EventLogEntryType.Error);
            }
        }