Watches the local filesystem for changes.
Inheritance: System.IO.FileSystemWatcher
Beispiel #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public RepoBase(RepoInfo repoInfo, IActivityListener activityListener)
        {
            EventManager = new SyncEventManager();
            EventManager.AddEventHandler(new DebugLoggingHandler());
            EventManager.AddEventHandler(new GenericSyncEventHandler <RepoConfigChangedEvent>(0, RepoInfoChanged));
            Queue     = new SyncEventQueue(EventManager);
            RepoInfo  = repoInfo;
            LocalPath = repoInfo.TargetDirectory;
            Name      = repoInfo.Name;
            RemoteUrl = repoInfo.Address;

            this.activityListener = activityListener;

            if (repoInfo.IsSuspended)
            {
                Status = SyncStatus.Suspend;
            }

            // Folder lock.
            // Disabled for now. Can be an interesting feature, but should be made opt-in, as
            // most users would be surprised to see this file appear.
            // folderLock = new FolderLock(LocalPath);

            Watcher = new Watcher(LocalPath);
            Watcher.EnableRaisingEvents = true;


            // Main loop syncing every X seconds.
            remote_timer.Elapsed += delegate
            {
                // Synchronize.
                SyncInBackground();
            };
            remote_timer.AutoReset = true;
            Logger.Info("Repo " + repoInfo.Name + " - Set poll interval to " + repoInfo.PollInterval + "ms");
            remote_timer.Interval = repoInfo.PollInterval;

            //Partial sync interval..
            local_timer.Elapsed += delegate
            {
                // Run partial sync.
                SyncInBackground(false);
            };
            local_timer.AutoReset = false;
            local_timer.Interval  = delay_interval;
        }
Beispiel #2
0
        /// <summary>
        /// Constructor.
        /// <param name="perpetual">Whether to perpetually sync again and again at regular intervals. False means syncing just once then stopping.</param>
        /// </summary>
        public RepoBase(RepoInfo repoInfo, IActivityListener activityListener, bool enableWatcher, bool perpetual)
        {
            RepoInfo  = repoInfo;
            LocalPath = repoInfo.TargetDirectory;
            Name      = repoInfo.Name;
            RemoteUrl = repoInfo.Address;

            this.activityListener = activityListener;

            Enabled = !repoInfo.IsSuspended;

            // Folder lock.
            // Disabled for now. Can be an interesting feature, but should be made opt-in, as
            // most users would be surprised to see this file appear.
            // folderLock = new FolderLock(LocalPath);

            if (enableWatcher)
            {
                Watcher = new Watcher(LocalPath);
                Watcher.EnableRaisingEvents = true;
            }

            if (perpetual)
            {
                // Main loop syncing every X seconds.
                periodicSynchronizationTimer.Elapsed += delegate
                {
                    // Synchronize.
                    SyncInBackground();
                };
                periodicSynchronizationTimer.AutoReset = true;
                Logger.Info("Repo " + repoInfo.Name + " - Set poll interval to " + repoInfo.PollInterval + "ms");
                periodicSynchronizationTimer.Interval = repoInfo.PollInterval;
                periodicSynchronizationTimer.Enabled  = true;

                // Partial sync interval.
                watcherDelayTimer.Elapsed += delegate
                {
                    // Run partial sync.
                    SyncInBackground();
                };
                watcherDelayTimer.AutoReset = false;
                watcherDelayTimer.Interval  = delayAfterLocalChange;
            }
        }