protected override bool RunInternal(Client client, RemoteCommandVerbOptions options) { SyncRecordsOptions localOptions = options as SyncRecordsOptions; if (localOptions.Current) return client.SyncCurrentRecords(); else return client.SyncRecords(); }
public AreaVM(string path, string name, AreaInitMode areaInitMode, string host = null, int port = 0) { RefreshCommand = new DelegateCommand(Refresh); PullCommand = new DelegateCommand(Pull); PushCommand = new DelegateCommand(Push); _name = name; DirectoryInfo dir = new DirectoryInfo(path); switch (areaInitMode) { case AreaInitMode.Clone: // Spawn another dialog for the source (or put it in the Clone New button) Client client = new Client(dir); if (client.Connect(host, port, null, true)) { bool result = client.Clone(true); if (!result) result = client.Clone(false); if (result) { string remoteName = "default"; client.Workspace.SetRemote(client.Host, client.Port, client.Module, remoteName); client.Pull(false, client.Workspace.CurrentBranch.ID.ToString()); _area = Area.Load(client.Workspace.Root); _area.Checkout(null, false, false); client.SyncRecords(); } } else { MessageBox.Show(string.Format("Couldn't connect to {0}:{1}", host, port), "Clone Failed", MessageBoxButton.OK, MessageBoxImage.Error); } client.Close(); break; case AreaInitMode.InitNew: // Tell versionr to initialize at path try { dir.Create(); } catch { MessageBox.Show("Error - couldn't create subdirectory \"{0}\"", dir.FullName); break; } _area = Area.Init(dir, name); break; case AreaInitMode.UseExisting: // Add it to settings and refresh UI, get status etc. _area = Area.Load(dir); break; } }
protected override bool RunInternal(Client client, RemoteCommandVerbOptions options) { CloneVerbOptions localOptions = options as CloneVerbOptions; if (localOptions.QuietFail && new System.IO.DirectoryInfo(System.IO.Path.Combine(TargetDirectory.FullName, ".versionr")).Exists) return true; bool result = false; try { TargetDirectory.Create(); } catch { Printer.PrintError("#e#Error - couldn't create subdirectory \"{0}\"##", TargetDirectory); return false; } if (localOptions.Full.HasValue) result = client.Clone(localOptions.Full.Value); else { result = client.Clone(true); if (!result) result = client.Clone(false); } if (result) { Printer.PrintMessage("Successfully cloned from remote vault. Initializing default remote."); string remoteName = "default"; if (client.Workspace.SetRemote(client.Host, client.Port, client.Module, remoteName)) Printer.PrintMessage("Configured remote \"#b#{0}##\" as: #b#{1}##", remoteName, client.VersionrURL); if (localOptions.Partial != null) client.Workspace.SetPartialPath(localOptions.Partial); if (localOptions.Update) { client.Pull(false, string.IsNullOrEmpty(localOptions.Branch) ? client.Workspace.CurrentBranch.ID.ToString() : localOptions.Branch); Area area = Area.Load(client.Workspace.Root); area.Checkout(localOptions.Branch, false, false); } if (localOptions.Synchronize) return client.SyncRecords(); } return result; }
public void Run() { AutomatrLog.Log("Loaded area " + Config.Path + "... ", false); m_Area = Area.Load(new DirectoryInfo(Config.Path)); AutomatrLog.Log("Done"); AutomatrLog.Log("Creating Client... ", false); m_Client = new Client(m_Area); AutomatrLog.Log("Done."); if (!Connect()) { AutomatrLog.Log("Connection Failed!", AutomatrLog.LogLevel.Error); Environment.Exit(1); } AutomatrLog.Log("Connection successful."); BranchStatus status = GetStatus(); AutomatrLog.Log("Branch status: " + status); if (status == BranchStatus.Behind || Program.Options.Force) RunTasks(); }
public void ExecuteClientCommand(Action<Client> action, string command, bool requiresWriteAccess = false) { if (SelectedRemote != null) { Client client = new Client(_area); if (client.Connect(SelectedRemote.Host, SelectedRemote.Port, SelectedRemote.Module, requiresWriteAccess)) action.Invoke(client); else MessageBox.Show(string.Format("Couldn't connect to remote {0} while processing {1} command!", SelectedRemote.Host, command), "Command Failed", MessageBoxButton.OK, MessageBoxImage.Error); client.Close(); } }
protected override bool RunInternal(Client client, RemoteCommandVerbOptions options) { PullVerbOptions localOptions = options as PullVerbOptions; bool objects = true; if (localOptions.PullAll) objects = false; if (localOptions.List) { var branches = client.ListBranches(); if (branches == null) return false; Printer.PrintMessage("Displaying remote branches:"); foreach (var x in branches.Item1) { if (!localOptions.Deleted && x.Terminus.HasValue) continue; string tipmarker = ""; if (x.ID == client.Workspace.CurrentBranch.ID) tipmarker = " #w#*<current>##"; Printer.PrintMessage("#b#{1}## - #c#{0}##{2}", x.ID, x.Name, tipmarker); string heading = string.Empty; var localBranch = client.Workspace.GetBranch(x.ID); if (x.Terminus.HasValue) { var terminus = branches.Item3[x.Terminus.Value]; bool present = client.Workspace.GetVersion(x.Terminus.Value) != null; string presentMarker = present ? "" : " #w#(behind)##"; if (present && localBranch != null) { if (localBranch.Terminus.Value != x.Terminus.Value) presentMarker += " #w#(ahead)##"; } if (localBranch != null && !localBranch.Terminus.HasValue) presentMarker += " #w#(not locally deleted)##"; if (localBranch == null) presentMarker += " #w#(not synchronized)##"; Printer.PrintMessage(" #e#(deleted)## - Last version: #b#{0}##{3}, #q#{2} {1}##", terminus.ShortName, terminus.Timestamp.ToLocalTime(), terminus.Author, presentMarker); } foreach (var z in branches.Item2.Where(y => y.Key == x.ID)) { bool present = client.Workspace.GetVersion(z.Value) != null; string presentMarker = present ? "" : " #w#(behind)##"; if (present && localBranch != null) { var localHeads = client.Workspace.GetBranchHeads(localBranch); if (localHeads.Count == 1 && localHeads[0].Version != z.Value) presentMarker += " #w#(ahead)##"; } if (localBranch != null && localBranch.Terminus.HasValue) presentMarker += " #e#(locally deleted)##"; if (localBranch == null) presentMarker += " #w#(not synchronized)##"; var head = branches.Item3[z.Value]; Printer.PrintMessage(" #s#(head)## - Version: #b#{0}##{3}, #q#{2} {1}##", head.ShortName, head.Timestamp.ToLocalTime(), head.Author, presentMarker); } } return true; } if (!client.Pull(localOptions.PullObjects.HasValue ? localOptions.PullObjects.Value : objects, localOptions.RemoteBranch, localOptions.PullAll)) return false; if (localOptions.Update) { client.Workspace.Update(); } return true; }
public bool Run(System.IO.DirectoryInfo workingDirectory, object options) { RemoteCommandVerbOptions localOptions = options as RemoteCommandVerbOptions; Printer.EnableDiagnostics = localOptions.Verbose; Network.Client client = null; Area ws = null; Tuple<bool, string, int, string> parsedRemoteName = null; if (!string.IsNullOrEmpty(localOptions.Remote)) { if (parsedRemoteName == null) parsedRemoteName = TryParseRemoteName(localOptions.Remote); localOptions.Host = parsedRemoteName.Item2; if (parsedRemoteName.Item3 != -1) localOptions.Port = parsedRemoteName.Item3; localOptions.Module = parsedRemoteName.Item4; } if (NeedsWorkspace) { ws = Area.Load(workingDirectory, Headless); if (ws == null) { Printer.Write(Printer.MessageType.Error, string.Format("#x#Error:##\n The current directory #b#`{0}`## is not part of a vault.\n", workingDirectory.FullName)); return false; } client = new Network.Client(ws); } else { if (NeedsNoWorkspace) { string subdir = localOptions.Name; if (string.IsNullOrEmpty(subdir) && !string.IsNullOrEmpty(localOptions.Module)) subdir = localOptions.Module; if (!string.IsNullOrEmpty(subdir)) { System.IO.DirectoryInfo info; try { info = new System.IO.DirectoryInfo(System.IO.Path.Combine(workingDirectory.FullName, subdir)); } catch { Printer.PrintError("#e#Error - invalid subdirectory \"{0}\"##", subdir); return false; } Printer.PrintMessage("Target directory: #b#{0}##.", info); workingDirectory = info; } try { ws = Area.Load(workingDirectory, Headless); if (ws != null) { CloneVerbOptions cloneOptions = options as CloneVerbOptions; if (cloneOptions != null && cloneOptions.QuietFail) { Printer.PrintMessage("Directory already contains a vault. Skipping."); return false; } Printer.PrintError("This command cannot function with an active Versionr vault."); return false; } } catch { } } client = new Client(workingDirectory); } TargetDirectory = workingDirectory; bool requireRemoteName = false; if (string.IsNullOrEmpty(localOptions.Host) || localOptions.Port == -1) requireRemoteName = true; LocalState.RemoteConfig config = null; if (ws != null) { if (requireRemoteName) config = ws.GetRemote(string.IsNullOrEmpty(localOptions.Name) ? "default" : localOptions.Name); if (UpdateRemoteTimestamp && config != null) ws.UpdateRemoteTimestamp(config); } if (config == null && requireRemoteName) { if (parsedRemoteName != null && parsedRemoteName.Item1 == false) { Printer.PrintError("You must specify either a host and port or a remote name."); return false; } } if (config == null) config = new LocalState.RemoteConfig() { Host = localOptions.Host, Port = localOptions.Port, Module = localOptions.Module }; if (!client.Connect(config.Host, config.Port, config.Module, RequiresWriteAccess)) { Printer.PrintError("Couldn't connect to server!"); return false; } bool result = RunInternal(client, localOptions); client.Close(); return result; }
protected abstract bool RunInternal(Client client, RemoteCommandVerbOptions options);
protected override bool RunInternal(Client client, RemoteCommandVerbOptions options) { PushVerbOptions localOptions = options as PushVerbOptions; return client.Push(localOptions.Branch); }