repo: replace multiple events by one SyncStatusChanged event + enum
This commit is contained in:
parent
a858d8e537
commit
032f9dbc55
|
@ -27,6 +27,15 @@ using Mono.Unix;
|
||||||
|
|
||||||
namespace SparkleLib {
|
namespace SparkleLib {
|
||||||
|
|
||||||
|
public enum SyncStatus {
|
||||||
|
SyncUpStarted,
|
||||||
|
SyncUpFinished,
|
||||||
|
SyncUpFailed,
|
||||||
|
SyncDownStarted,
|
||||||
|
SyncDownFinished,
|
||||||
|
SyncDownFailed
|
||||||
|
}
|
||||||
|
|
||||||
public class SparkleRepo {
|
public class SparkleRepo {
|
||||||
|
|
||||||
private Timer remote_timer;
|
private Timer remote_timer;
|
||||||
|
@ -104,23 +113,15 @@ namespace SparkleLib {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public delegate void PushingStartedEventHandler (object o, SparkleEventArgs args);
|
public delegate void SyncStatusChangedEventHandler (SyncStatus status);
|
||||||
public delegate void PushingFinishedEventHandler (object o, SparkleEventArgs args);
|
public event SyncStatusChangedEventHandler SyncStatusChanged;
|
||||||
public delegate void PushingFailedEventHandler (object o, SparkleEventArgs args);
|
|
||||||
public delegate void FetchingStartedEventHandler (object o, SparkleEventArgs args);
|
|
||||||
public delegate void FetchingFinishedEventHandler (object o, SparkleEventArgs args);
|
|
||||||
public delegate void FetchingFailedEventHandler (object o, SparkleEventArgs args);
|
|
||||||
public delegate void NewCommitEventHandler (SparkleCommit commit, string repository_path);
|
public delegate void NewCommitEventHandler (SparkleCommit commit, string repository_path);
|
||||||
public delegate void ConflictDetectedEventHandler (object o, SparkleEventArgs args);
|
public delegate void ConflictDetectedEventHandler (object o, SparkleEventArgs args);
|
||||||
public delegate void ChangesDetectedEventHandler (object o, SparkleEventArgs args);
|
public delegate void ChangesDetectedEventHandler (object o, SparkleEventArgs args);
|
||||||
public delegate void CommitEndedUpEmptyEventHandler (object o, SparkleEventArgs args);
|
public delegate void CommitEndedUpEmptyEventHandler (object o, SparkleEventArgs args);
|
||||||
|
|
||||||
public event PushingStartedEventHandler PushingStarted;
|
|
||||||
public event PushingFinishedEventHandler PushingFinished;
|
|
||||||
public event PushingFailedEventHandler PushingFailed;
|
|
||||||
public event FetchingStartedEventHandler FetchingStarted;
|
|
||||||
public event FetchingFinishedEventHandler FetchingFinished;
|
|
||||||
public event FetchingFailedEventHandler FetchingFailed;
|
|
||||||
public event NewCommitEventHandler NewCommit;
|
public event NewCommitEventHandler NewCommit;
|
||||||
public event ConflictDetectedEventHandler ConflictDetected;
|
public event ConflictDetectedEventHandler ConflictDetected;
|
||||||
public event ChangesDetectedEventHandler ChangesDetected;
|
public event ChangesDetectedEventHandler ChangesDetected;
|
||||||
|
@ -505,10 +506,8 @@ namespace SparkleLib {
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes...");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes...");
|
||||||
SparkleGit git = new SparkleGit (LocalPath, "fetch -v origin master");
|
SparkleGit git = new SparkleGit (LocalPath, "fetch -v origin master");
|
||||||
|
|
||||||
SparkleEventArgs args = new SparkleEventArgs ("FetchingStarted");
|
if (SyncStatusChanged != null)
|
||||||
|
SyncStatusChanged (SyncStatus.SyncDownStarted);
|
||||||
if (FetchingStarted != null)
|
|
||||||
FetchingStarted (this, args);
|
|
||||||
|
|
||||||
git.Exited += delegate {
|
git.Exited += delegate {
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes fetched.");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes fetched.");
|
||||||
|
@ -520,17 +519,13 @@ namespace SparkleLib {
|
||||||
if (git.ExitCode != 0) {
|
if (git.ExitCode != 0) {
|
||||||
this.server_online = false;
|
this.server_online = false;
|
||||||
|
|
||||||
args = new SparkleEventArgs ("FetchingFailed");
|
if (SyncStatusChanged != null)
|
||||||
|
SyncStatusChanged (SyncStatus.SyncDownFailed);
|
||||||
if (FetchingFailed != null)
|
|
||||||
FetchingFailed (this, args);
|
|
||||||
} else {
|
} else {
|
||||||
this.server_online = true;
|
this.server_online = true;
|
||||||
|
|
||||||
args = new SparkleEventArgs ("FetchingFinished");
|
if (SyncStatusChanged != null)
|
||||||
|
SyncStatusChanged (SyncStatus.SyncDownFinished);
|
||||||
if (FetchingFinished != null)
|
|
||||||
FetchingFinished (this, args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.remote_timer.Start ();
|
this.remote_timer.Start ();
|
||||||
|
@ -691,10 +686,8 @@ namespace SparkleLib {
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing changes...");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing changes...");
|
||||||
SparkleGit git = new SparkleGit (LocalPath, "push origin master");
|
SparkleGit git = new SparkleGit (LocalPath, "push origin master");
|
||||||
|
|
||||||
SparkleEventArgs args = new SparkleEventArgs ("PushingStarted");
|
if (SyncStatusChanged != null)
|
||||||
|
SyncStatusChanged (SyncStatus.SyncUpStarted);
|
||||||
if (PushingStarted != null)
|
|
||||||
PushingStarted (this, args);
|
|
||||||
|
|
||||||
git.Exited += delegate {
|
git.Exited += delegate {
|
||||||
this.is_syncing = false;
|
this.is_syncing = false;
|
||||||
|
@ -711,15 +704,12 @@ namespace SparkleLib {
|
||||||
|
|
||||||
this.has_unsynced_changes = true;
|
this.has_unsynced_changes = true;
|
||||||
|
|
||||||
args = new SparkleEventArgs ("PushingFailed");
|
if (SyncStatusChanged != null)
|
||||||
|
SyncStatusChanged (SyncStatus.SyncUpFailed);
|
||||||
if (PushingFailed != null)
|
|
||||||
PushingFailed (this, args);
|
|
||||||
|
|
||||||
FetchRebaseAndPush ();
|
FetchRebaseAndPush ();
|
||||||
} else {
|
} else {
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes pushed.");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes pushed.");
|
||||||
args = new SparkleEventArgs ("PushingFinished");
|
|
||||||
|
|
||||||
string unsynced_file_path = SparkleHelpers.CombineMore (LocalPath ,
|
string unsynced_file_path = SparkleHelpers.CombineMore (LocalPath ,
|
||||||
".git", "has_unsynced_changes");
|
".git", "has_unsynced_changes");
|
||||||
|
@ -729,8 +719,8 @@ namespace SparkleLib {
|
||||||
|
|
||||||
this.has_unsynced_changes = false;
|
this.has_unsynced_changes = false;
|
||||||
|
|
||||||
if (PushingFinished != null)
|
if (SyncStatusChanged != null)
|
||||||
PushingFinished (this, args);
|
SyncStatusChanged (SyncStatus.SyncDownFinished);
|
||||||
|
|
||||||
this.listener.Announce (this.current_hash);
|
this.listener.Announce (this.current_hash);
|
||||||
}
|
}
|
||||||
|
|
|
@ -504,7 +504,7 @@ namespace SparkleShare {
|
||||||
// Adds a repository to the list of repositories
|
// Adds a repository to the list of repositories
|
||||||
private void AddRepository (string folder_path)
|
private void AddRepository (string folder_path)
|
||||||
{
|
{
|
||||||
// TODO: determine the backend type here
|
// TODO: determine the backend type here.
|
||||||
// need to keep track of a table with folder+backendtype
|
// need to keep track of a table with folder+backendtype
|
||||||
// and use GitBackend.IsValidFolder (string path);
|
// and use GitBackend.IsValidFolder (string path);
|
||||||
|
|
||||||
|
@ -512,60 +512,40 @@ namespace SparkleShare {
|
||||||
if (!SparkleRepo.IsRepo (folder_path))
|
if (!SparkleRepo.IsRepo (folder_path))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
SparkleRepo repo = new SparkleRepo (folder_path, SparkleBackend.DefaultBackend);
|
SparkleRepo repo = new SparkleRepo (folder_path, SparkleBackend.DefaultBackend);
|
||||||
|
|
||||||
repo.NewCommit += delegate (SparkleCommit commit, string repository_path) {
|
repo.NewCommit += delegate (SparkleCommit commit, string repository_path) {
|
||||||
string message = FormatMessage (commit);
|
string message = FormatMessage (commit);
|
||||||
|
|
||||||
Console.WriteLine ("===== ARGUMENTS: =====");
|
|
||||||
Console.WriteLine ("[0]" + commit.UserName);
|
|
||||||
Console.WriteLine ("[0]" + commit.UserEmail);
|
|
||||||
Console.WriteLine ("[0]" + message);
|
|
||||||
Console.WriteLine ("[0]" + repository_path);
|
|
||||||
Console.WriteLine ("======================");
|
|
||||||
|
|
||||||
if (NotificationRaised != null)
|
if (NotificationRaised != null)
|
||||||
NotificationRaised (commit.UserName, commit.UserEmail, message, repository_path);
|
NotificationRaised (commit.UserName, commit.UserEmail, message, repository_path);
|
||||||
};
|
};
|
||||||
|
|
||||||
repo.FetchingStarted += delegate {
|
repo.ConflictDetected += delegate {
|
||||||
UpdateState ();
|
if (ConflictNotificationRaised != null)
|
||||||
|
ConflictNotificationRaised ();
|
||||||
};
|
};
|
||||||
|
|
||||||
repo.FetchingFinished += delegate {
|
repo.SyncStatusChanged += delegate (SyncStatus status) {
|
||||||
UpdateState ();
|
if (status == SyncStatus.SyncDownFailed ||
|
||||||
};
|
status == SyncStatus.SyncDownFinished ||
|
||||||
|
status == SyncStatus.SyncDownStarted ||
|
||||||
|
status == SyncStatus.SyncUpFailed ||
|
||||||
|
status == SyncStatus.SyncUpFinished ||
|
||||||
|
status == SyncStatus.SyncUpStarted) {
|
||||||
|
|
||||||
repo.FetchingFailed += delegate {
|
|
||||||
UpdateState ();
|
UpdateState ();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
repo.ChangesDetected += delegate {
|
repo.ChangesDetected += delegate {
|
||||||
UpdateState ();
|
UpdateState ();
|
||||||
};
|
};
|
||||||
|
|
||||||
repo.PushingStarted += delegate {
|
|
||||||
UpdateState ();
|
|
||||||
};
|
|
||||||
|
|
||||||
repo.PushingFinished += delegate {
|
|
||||||
UpdateState ();
|
|
||||||
};
|
|
||||||
|
|
||||||
repo.CommitEndedUpEmpty += delegate {
|
repo.CommitEndedUpEmpty += delegate {
|
||||||
UpdateState ();
|
UpdateState ();
|
||||||
};
|
};
|
||||||
|
|
||||||
repo.PushingFailed += delegate {
|
|
||||||
UpdateState ();
|
|
||||||
};
|
|
||||||
|
|
||||||
repo.ConflictDetected += delegate {
|
|
||||||
if (ConflictNotificationRaised != null)
|
|
||||||
ConflictNotificationRaised ();
|
|
||||||
};
|
|
||||||
|
|
||||||
Repositories.Add (repo);
|
Repositories.Add (repo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue