SparkleLib.SparkleRepoBase.OnFileActivity C# (CSharp) Méthode

OnFileActivity() public méthode

public OnFileActivity ( FileSystemEventArgs args ) : void
args System.IO.FileSystemEventArgs
Résultat void
        public void OnFileActivity (FileSystemEventArgs args)
        {
            if (IsBuffering || this.is_syncing)
                return;

            if (args != null) {
                foreach (string exclude_path in ExcludePaths) {
                    if (args.FullPath.Contains (Path.DirectorySeparatorChar + exclude_path))
                        return;
                }
            }

            lock (this.buffer_lock) {
                if (IsBuffering || this.is_syncing || !HasLocalChanges)
                    return;

                IsBuffering = true;
            }

            ChangesDetected ();

            if (!UseCustomWatcher)
                this.watcher.Disable ();

            SparkleLogger.LogInfo ("Local", Name + " | Activity detected, waiting for it to settle...");

            List<double> size_buffer = new List<double> ();
            DirectoryInfo info = new DirectoryInfo (LocalPath);

            do {
                if (size_buffer.Count >= 4)
                    size_buffer.RemoveAt (0);

                size_buffer.Add (CalculateSize (info));

                if (size_buffer.Count >= 4 &&
                    size_buffer [0].Equals (size_buffer [1]) &&
                    size_buffer [1].Equals (size_buffer [2]) &&
                    size_buffer [2].Equals (size_buffer [3])) {

                    SparkleLogger.LogInfo ("Local", Name + " | Activity has settled");
                    IsBuffering = false;

                    if (HasLocalChanges) {
                        do {
                            SyncUpBase ();

                        } while (HasLocalChanges);

                    } else {
                        SyncStatusChanged (SyncStatus.Idle);
                    }

                } else {
                    Thread.Sleep (500);
                }

            } while (IsBuffering);

            if (!UseCustomWatcher)
                this.watcher.Enable ();
        }

Usage Example

 private FileActivityTask MacActivityTask(SparkleRepoBase repo, FileSystemEventArgs fse_args)
 {
     return delegate { new Thread (() => { repo.OnFileActivity (fse_args); }).Start (); };
 }