Пример #1
0
        public void aSynchronizeDirectory(string oDirectory)
        {
            JobsBO bo = (JobsBO)SingletonManager.GetSingleton(typeof(JobsBO));
            List <JobContainer> selected = bo.JContainer.Jobs.FindAll(delegate(JobContainer j){
                return(Path.GetDirectoryName(j.SourceDirectory).ToLower().CompareTo(oDirectory) == 0);
            });

            foreach (JobContainer container in selected)
            {
                this.aSynchronizeDirectory(oDirectory, oDirectory, container.DestinationDirectory, container.WatchSubDirectories, false);
            }
            this.OnFinishedSynch(EventArgs.Empty);
        }
Пример #2
0
        public void aSynchronizeFile(string oFile)
        {
            JobsBO bo = (JobsBO)SingletonManager.GetSingleton(typeof(JobsBO));
            List <JobContainer> selected = bo.JContainer.Jobs.FindAll(delegate(JobContainer j) {
                return(Path.GetDirectoryName(j.SourceDirectory).ToLower().CompareTo(Path.GetDirectoryName(oFile)) == 0);
            });

            foreach (JobContainer container in selected)
            {
                this.aSynchronizeFile(oFile, Path.Combine(Path.GetDirectoryName(container.DestinationDirectory), Path.GetFileName(oFile)));
            }
            this.OnFinishedSynch(EventArgs.Empty);
        }
Пример #3
0
        public void StartListeners()
        {
            if (this.Started)
            {
                return;
            }

            JobsBO jbo = (JobsBO)SingletonManager.GetSingleton(typeof(JobsBO));

            foreach (JobContainer container in jbo.JContainer.Jobs)
            {
                if (container.SourceDirectory.Length > 0 && container.DestinationDirectory.Length > 0)
                {
                    if (Directory.Exists(container.SourceDirectory) && Directory.Exists(container.DestinationDirectory))
                    {
                        try {
                            FileSystemWatcher watcher = new FileSystemWatcher(container.SourceDirectory);
                            watcher.NotifyFilter          = NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Size | NotifyFilters.DirectoryName | NotifyFilters.CreationTime;
                            watcher.IncludeSubdirectories = container.WatchSubDirectories;
                            watcher.Created += new FileSystemEventHandler(Watcher_Event);
                            //watcher.Deleted += new FileSystemEventHandler(Watcher_Event);
                            watcher.Renamed            += new RenamedEventHandler(Watcher_Renamed);
                            watcher.Changed            += new FileSystemEventHandler(Watcher_Event);
                            watcher.EnableRaisingEvents = true;
                            lock (this.Watchers) { Watchers.Add(container, watcher); }
                            lock (this.WatcherContainers) { this.WatcherContainers.Add(container.SourceDirectory, container); }
                        }
                        catch (Exception ex) {
                            IReporter reporter = ReporterManager.GetReporter();
                            reporter.AddReport(new ActionReportContainer(ActionType.Notify, ActionReportResult.Noted, ex.ToString()));
                        }
                    }
                    else
                    {
                        IReporter reporter = ReporterManager.GetReporter();
                        reporter.AddReport(new ActionReportContainer(ActionType.Notify, ActionReportResult.Noted,
                                                                     "There was an error finding one or more of the two following directories:\n" +
                                                                     container.SourceDirectory + "\n" + container.DestinationDirectory));
                    }
                }
            }
            this.Started = true;
            OnStatusChanged(EventArgs.Empty);
        }
Пример #4
0
        public void SynchronizeAll()
        {
            JobsBO bo = (JobsBO)SingletonManager.GetSingleton(typeof(JobsBO));

            SynchProgressCount = 0;
            foreach (JobContainer container in bo.JContainer.Jobs)
            {
                SynchTotalFileCount += countFiles(container.SourceDirectory, container.WatchSubDirectories);
            }
            foreach (JobContainer container in bo.JContainer.Jobs)
            {
                SynchronizeDirectory(
                    container.SourceDirectory,
                    container.SourceDirectory,
                    container.DestinationDirectory,
                    container.WatchSubDirectories,
                    false);
            }
            this.OnFinishedSynch(EventArgs.Empty);
        }