Esempio n. 1
0
        public void TestSchedule()
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(TestResource.FileMateTestConfig_scheduleSpecificTime);

            // build a schedule in the future
            DateTime testSchedule = DateTime.Now;

            testSchedule = testSchedule.AddMinutes(2);
            int           hr  = testSchedule.Hour;
            int           min = testSchedule.Minute;
            StringBuilder b   = new StringBuilder(hr.ToString());

            b.Append(":");
            b.Append(min.ToString());

            XmlNode scheduleNode = doc.SelectSingleNode("//schedule");

            scheduleNode.InnerText = b.ToString();

            CopyGroup cg = new CopyGroup(doc);

            string[] files = cg.CopyOperations[0].SourceFileRepository.GetFileList();

            // wait
            Thread.Sleep(new TimeSpan(0, 3, 0));

            Assert.AreEqual <int>(files.Length, cg.CopyOperations[0].Targets[0].GetFileList().Length);
        }
Esempio n. 2
0
        public void TestInterval()
        {
            XmlDocument doc = new XmlDocument();

            // delete source is false
            doc.LoadXml(TestResource.FileMateConfig_FilesToFolderWithSchedule);
            CopyGroup cg = new CopyGroup(doc);

            string[] files = cg.CopyOperations[0].SourceFileRepository.GetFileList();
            Thread.Sleep(70000);
            Assert.AreEqual <int>(files.Length, cg.CopyOperations[0].Targets[0].GetFileList().Length);
        }
Esempio n. 3
0
        public void BasicFtpToFolderTest()
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(TestResource.FileMateConfig_FtpToFolder);
            CopyGroup cg = new CopyGroup(doc);

            string[] files = cg.CopyOperations[0].SourceFileRepository.GetFileList();

            cg.ExecuteCopyOperations();

            Assert.AreEqual <int>(files.Length, cg.CopyOperations[0].Targets[0].GetFileList().Length);
        }
Esempio n. 4
0
        void _flushAll()
        {
            this.Stop();

            foreach (CopyOperation co in _cg.CopyOperations)
            {
                co.Cleanup();
            }

            _tcpListener = null;
            _cg          = null;

            GC.Collect();
        }
Esempio n. 5
0
        public void TestHeadOfficeUploadBasic()
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(TestResource.FileMateConfig_HeadOfficeUpload);
            CopyGroup cg = new CopyGroup(doc);

            string[] files = cg.CopyOperations[0].SourceFileRepository.GetFileList();

            cg.ExecuteCopyOperations();

            Assert.AreEqual <int>(1, cg.CopyOperations[0].Targets[0].GetFileList().Length);
            Assert.AreEqual <int>(1, cg.CopyOperations[0].Targets[1].GetFileList().Length);
            Assert.AreEqual <int>(1, cg.CopyOperations[1].Targets[0].GetFileList().Length);
        }
Esempio n. 6
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);
            }
        }
Esempio n. 7
0
        private void _initCopyGroups()
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(_singletonConfigFile.ConfigPath);

            //doc.Load(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase), @"FileMateConfig.xml"));

            _cg = new CopyGroup(doc);

            // set up schedule event
            if (!_doorAccessFlag)
            {
                _cg.CopyOperations[0].ExecuteEvent += new CopyOperation.ExecuteEventDelegate(Server_ScheduleEvent);
                _singletonLogger.Log(string.Format(@"{0} loaded", @"Summa Upload Proccess"));
            }
            else
            {
                _cg.CopyOperations[0].ExecuteEvent += new CopyOperation.ExecuteEventDelegate(Local_ScheduleEvent);
                _singletonLogger.Log(string.Format(@"{0} loaded", @"Door Access Upload Proccess"));
            }
        }
Esempio n. 8
0
        public void BasicFileCopyTest()
        {
            string pf = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);

            XmlDocument doc = new XmlDocument();

            // delete source is false
            doc.LoadXml(TestResource.TestConfig_FileToFolder);

            CopyGroup cg = new CopyGroup(doc);

            string[] files = cg.CopyOperations[0].SourceFileRepository.GetFileList();
            cg.ExecuteCopyOperations();
            Assert.AreEqual <int>(files.Length, cg.CopyOperations[0].Targets[0].GetFileList().Length);

            Thread.Sleep(1000); // wait for a bit

            // do it again should get another target folder based on date, i.e., two folders
            cg.ExecuteCopyOperations();
            Assert.AreEqual <int>(files.Length, cg.CopyOperations[0].Targets[0].GetFileList().Length);
            Assert.AreEqual <int>(2, Directory.GetDirectories(Path.Combine(cg.CopyOperations[0].Targets[0].Url, ".."),
                                                              "*.*").Length);
        }
Esempio n. 9
0
 protected override void OnShutdown()
 {
     _cg = null;
     this.EventLog.WriteEntry("FileMate stopped because of shutdown", EventLogEntryType.Information);
 }
Esempio n. 10
0
 protected override void OnStop()
 {
     _cg = null;
     this.EventLog.WriteEntry("FileMate stopped", EventLogEntryType.Information);
 }