Versionr.Network.Client.Push C# (CSharp) Method

Push() public method

public Push ( string branchName = null ) : bool
branchName string
return bool
        public bool Push(string branchName = null)
        {
            if (Workspace == null)
                return false;
            try
            {
                if (string.IsNullOrEmpty(RemoteDomain))
                {
                    Printer.PrintError("#b#Initializing bare remote...##");
                    ProtoBuf.Serializer.SerializeWithLengthPrefix<NetCommand>(SharedInfo.Stream, new NetCommand() { Type = NetCommandType.PushInitialVersion }, ProtoBuf.PrefixStyle.Fixed32);
                    Objects.Version initialRevision = Workspace.GetVersion(Workspace.Domain);
                    Objects.Branch initialBranch = Workspace.GetBranch(initialRevision.Branch);
                    Utilities.SendEncrypted<ClonePayload>(SharedInfo, new ClonePayload() { InitialBranch = initialBranch, RootVersion = initialRevision });
                }
                Stack<Objects.Branch> branchesToSend = new Stack<Branch>();
                Stack<Objects.Version> versionsToSend = new Stack<Objects.Version>();
                Printer.PrintMessage("Determining data to send...");
                if (!SharedNetwork.SendBranchJournal(SharedInfo))
                    return false;
                Objects.Version version = Workspace.Version;
                if (branchName != null)
                {
                    bool multiple;
                    var branch = Workspace.GetBranchByPartialName(branchName, out multiple);
                    if (branch == null)
                    {
                        Printer.PrintError("#e#Can't identify branch with name \"{0}\" to send!##", branchName);
                        return false;
                    }
                    if (multiple)
                    {
                        Printer.PrintError("#e#Can't identify object to send - multiple branches with partial name \"{0}\"!##", branchName);
                        return false;
                    }
                    var head = Workspace.GetBranchHead(branch);
                    version = Workspace.GetVersion(head.Version);
                    Printer.PrintMessage("Sending branch #c#{0}## (#b#\"{1}\"##).", branch.ID, branch.Name);
                }
                if (!SharedNetwork.GetVersionList(SharedInfo, version, out branchesToSend, out versionsToSend))
                    return false;
                Printer.PrintDiagnostics("Need to send {0} versions and {1} branches.", versionsToSend.Count, branchesToSend.Count);
                if (!SharedNetwork.SendBranches(SharedInfo, branchesToSend))
                    return false;
                if (!SharedNetwork.SendVersions(SharedInfo, versionsToSend))
                    return false;

                Printer.PrintDiagnostics("Committing changes remotely.");
                ProtoBuf.Serializer.SerializeWithLengthPrefix<NetCommand>(SharedInfo.Stream, new NetCommand() { Type = NetCommandType.PushHead }, ProtoBuf.PrefixStyle.Fixed32);
                NetCommand response = ProtoBuf.Serializer.DeserializeWithLengthPrefix<NetCommand>(SharedInfo.Stream, ProtoBuf.PrefixStyle.Fixed32);
                if (response.Type == NetCommandType.RejectPush)
                {
                    Printer.PrintError("Server rejected push, return code: {0}", response.AdditionalPayload);
                    return false;
                }
                else if (response.Type != NetCommandType.AcceptPush)
                {
                    Printer.PrintError("Unknown error pushing branch head.");
                    return false;
                }
                return true;
            }
            catch (Exception e)
            {
                Printer.PrintError("Error: {0}", e);
                Close();
                return false;
            }
        }

Usage Example

Exemplo n.º 1
0
 protected override bool RunInternal(Client client, RemoteCommandVerbOptions options)
 {
     PushVerbOptions localOptions = options as PushVerbOptions;
     return client.Push(localOptions.Branch);
 }