public void Reconnect() { SparkleLogger.LogInfo("Listener", "Trying to reconnect to " + Server); Connect(); }
public void OnDisconnected(string message) { SparkleLogger.LogInfo("Listener", "Disconnected from " + Server + ": " + message); Disconnected(); }
private void ListenerDisconnectedDelegate() { this.poll_interval = PollInterval.Short; SparkleLogger.LogInfo(Name, "Falling back to regular polling"); }
private void SyncDownBase() { if (!UseCustomWatcher) { this.watcher.Disable(); } SparkleLogger.LogInfo("SyncDown", Name + " | Initiated"); Status = SyncStatus.SyncDown; SyncStatusChanged(Status); string pre_sync_revision = CurrentRevision; if (SyncDown()) { Error = ErrorStatus.None; string identifier_file_path = Path.Combine(LocalPath, ".sparkleshare"); File.SetAttributes(identifier_file_path, FileAttributes.Hidden); ChangeSets = GetChangeSets(); if (!pre_sync_revision.Equals(CurrentRevision) && ChangeSets != null && ChangeSets.Count > 0 && !ChangeSets [0].User.Name.Equals(this.local_config.User.Name)) { bool emit_change_event = true; foreach (SparkleChange change in ChangeSets[0].Changes) { if (change.Path.EndsWith(".sparkleshare")) { emit_change_event = false; break; } } if (emit_change_event) { NewChangeSet(ChangeSets [0]); } } SparkleLogger.LogInfo("SyncDown", Name + " | Done"); // There could be changes from a resolved // conflict. Tries only once, then lets // the timer try again periodically if (HasUnsyncedChanges) { Status = SyncStatus.SyncUp; SyncStatusChanged(Status); if (SyncUp()) { HasUnsyncedChanges = false; } } Status = SyncStatus.Idle; SyncStatusChanged(Status); } else { SparkleLogger.LogInfo("SyncDown", Name + " | Error"); ChangeSets = GetChangeSets(); Status = SyncStatus.Error; SyncStatusChanged(Status); } ProgressPercentage = 0.0; ProgressSpeed = 0.0; Status = SyncStatus.Idle; SyncStatusChanged(Status); if (!UseCustomWatcher) { this.watcher.Enable(); } }
private void SyncUpBase() { if (!UseCustomWatcher) { this.watcher.Disable(); } SparkleLogger.LogInfo("SyncUp", Name + " | Initiated"); HasUnsyncedChanges = true; Status = SyncStatus.SyncUp; SyncStatusChanged(Status); if (SyncUp()) { SparkleLogger.LogInfo("SyncUp", Name + " | Done"); ChangeSets = GetChangeSets(); HasUnsyncedChanges = false; this.poll_interval = PollInterval.Long; this.listener.Announce(new SparkleAnnouncement(Identifier, CurrentRevision)); Status = SyncStatus.Idle; SyncStatusChanged(Status); } else { SparkleLogger.LogInfo("SyncUp", Name + " | Error"); SyncDownBase(); if (!UseCustomWatcher) { this.watcher.Disable(); } if (Error == ErrorStatus.None && SyncUp()) { HasUnsyncedChanges = false; this.listener.Announce(new SparkleAnnouncement(Identifier, CurrentRevision)); Status = SyncStatus.Idle; SyncStatusChanged(Status); } else { this.poll_interval = PollInterval.Short; Status = SyncStatus.Error; SyncStatusChanged(Status); } } ProgressPercentage = 0.0; ProgressSpeed = 0.0; if (!UseCustomWatcher) { this.watcher.Enable(); } }
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; bool first_sync = true; if (HasLocalChanges && Status == SyncStatus.Idle) { do { if (!first_sync) { SparkleLogger.LogInfo("Local", Name + " | More changes found"); } SyncUpBase(); if (Error == ErrorStatus.UnreadableFiles) { return; } first_sync = false; } while (HasLocalChanges); } if (Status != SyncStatus.Idle && Status != SyncStatus.Error) { Status = SyncStatus.Idle; SyncStatusChanged(Status); } } else { Thread.Sleep(500); } } while (IsBuffering); if (!UseCustomWatcher) { this.watcher.Enable(); } }
public SparkleRepoBase(string path, SparkleConfig config) { SparkleLogger.LogInfo(path, "Initializing..."); Status = SyncStatus.Idle; Error = ErrorStatus.None; this.local_config = config; LocalPath = path; Name = Path.GetFileName(LocalPath); RemoteUrl = new Uri(this.local_config.GetUrlForFolder(Name)); IsBuffering = false; this.identifier = Identifier; ChangeSets = GetChangeSets(); string identifier_file_path = Path.Combine(LocalPath, ".sparkleshare"); File.SetAttributes(identifier_file_path, FileAttributes.Hidden); if (!UseCustomWatcher) { this.watcher = new SparkleWatcher(LocalPath); } new Thread(() => CreateListener()).Start(); this.remote_timer.Elapsed += delegate { if (this.is_syncing || IsBuffering) { return; } int time_comparison = DateTime.Compare(this.last_poll, DateTime.Now.Subtract(this.poll_interval)); if (time_comparison < 0) { if (HasUnsyncedChanges && !this.is_syncing) { SyncUpBase(); } this.last_poll = DateTime.Now; if (HasRemoteChanges && !this.is_syncing) { SyncDownBase(); } if (this.listener.IsConnected) { this.poll_interval = PollInterval.Long; } } // In the unlikely case that we haven't synced up our // changes or the server was down, sync up again if (HasUnsyncedChanges && !this.is_syncing && Error == ErrorStatus.None) { SyncUpBase(); } if (Status != SyncStatus.Idle && Status != SyncStatus.Error) { Status = SyncStatus.Idle; SyncStatusChanged(Status); } }; }