コード例 #1
0
        /// <summary>
        /// Executes a version control operation with the specified arguments.
        /// </summary>
        /// <param name="arguments">The arguments.</param>
        /// <returns>Execution results.</returns>
        public IServiceResult Execute(VersionControlArguments arguments)
        {
            if (arguments == null) throw new ArgumentNullException("arguments");

            ValidateArguments(arguments);
            return ExecuteOperation(arguments);
        }
コード例 #2
0
        /// <summary>
        /// Takes the arguments in the form of a <see cref="Uri"/> and
        /// converts them to a <see cref="VersionControlArguments"/>.
        /// </summary>
        /// <param name="uri">The URI specifying the arguments.</param>
        /// <returns></returns>
        public static VersionControlArguments FromUri(Uri uri)
        {
            if (uri == null) throw new ArgumentNullException("uri");

            var args = new VersionControlArguments
            {
                Provider = uri.Scheme,
                Server = uri.GetComponents(UriComponents.HostAndPort, UriFormat.UriEscaped)
            };

            if (!uri.UserInfo.IsNullOrEmpty())
            {
                var parts = uri.UserInfo.Split(new[] { ':' });
                var userName = parts[0];
                var password = parts[1];

                args.Credentials = new NetworkCredential(userName, password);
            }

            // The project name is the first part of the path
            args.Project = Uri.UnescapeDataString(uri.Segments[1]).Trim('/', '\\');

            // Query string arguments
            var queryStringArgs = ParseQueryStringArgs(uri);

            if( queryStringArgs.ContainsKey("label")) args.Label = Uri.UnescapeDataString(queryStringArgs["label"]);
            if (queryStringArgs.ContainsKey("destinationpath")) args.DestinationPath = Uri.UnescapeDataString(queryStringArgs["destinationpath"]);

            return args;
        }
コード例 #3
0
        public void GetVariableBlock()
        {
            var provider = new Mock<BaseCommandLineVersionControlProvider>();
            provider.Setup(controlProvider =>
                controlProvider.BuildCommandLineArguments(It.IsAny<VersionControlArguments>()))
                .Returns("args");
            provider.SetupGet(vcp => vcp.FileName).Returns("VcsExecutable.exe");

            var args = new VersionControlArguments
            {
                Credentials = new NetworkCredential("username", "password"),
                DestinationPath = "D:\\WorkingFolder\\MyProject",
                Label = "My Label",
                Operation = VersionControlOperation.Get,
                Project = "MyProject",
                Provider = "Vault",
                Server = "server:port",
                SourcePath = "$/MyProject"
            };
            var indexer = new SourceIndexer(provider.Object, args);

            var block = indexer.GetVariableBlock();

            Assert.AreEqual(@"SRCSRV: variables ------------------------------------------
            VCS_EXECUTABLE=VcsExecutable.exe
            VCS_USERNAME=username
            VCS_PASSWORD=password
            VCS_SERVER=server:port
            VCS_PROJECT=MyProject
            SRCSRVTRG=%VCS_EXTRACT_TARGET%
            VCS_EXTRACT_CMD=""%VCS_EXECUTABLE%"" args
            SRCSRVCMD=%VCS_EXTRACT_CMD%
            VCS_EXTRACT_TARGET=" + SourceIndexer.VcsDestinationPath + "\r\n", block, ignoreCase: true);
        }
コード例 #4
0
        public void GetIniBlock()
        {
            var provider = new Mock<BaseCommandLineVersionControlProvider>();
            provider.Setup(controlProvider =>
                controlProvider.BuildCommandLineArguments(It.IsAny<VersionControlArguments>()))
                .Returns("args");

            var args = new VersionControlArguments
            {
                Credentials = new NetworkCredential("username", "password"),
                DestinationPath = "D:\\WorkingFolder\\MyProject",
                Label = "My Label",
                Operation = VersionControlOperation.Get,
                Project = "MyProject",
                Provider = "Provider",
                Server = "server:port",
                SourcePath = "$/MyProject"
            };
            var indexer = new SourceIndexer(provider.Object, args);

            var block = indexer.GetIniBlock();

            var now = DateTime.Now.ToUniversalTime().ToString("u");

            Assert.AreEqual(@"SRCSRV: ini ------------------------------------------------
            VERSION=1
            VERCTRL=Provider
            DATETIME=" + now, block.Trim(), ignoreCase: true);
        }
コード例 #5
0
        /// <summary>
        /// Validates the arguments.
        /// </summary>
        /// <param name="arguments">The arguments.</param>
        protected internal virtual void ValidateArguments(VersionControlArguments arguments)
        {
            if (arguments.Server.IsNullOrEmpty()) throw new ArgumentException("You must specify a Server", "arguments");

            if (arguments.Operation == VersionControlOperation.None)
            {
                throw new ArgumentException("You must specify a valid source control operation for the VersionControlArguments (the Operation property is set to None)", "arguments");
            }
        }
コード例 #6
0
        public void Server_is_required()
        {
            var provider = new StubBaseVersionControlProvider();
            var args = new VersionControlArguments();

            AssertException.Throws<ArgumentException>(
                "You must specify a Server\r\nParameter name: arguments",
                () => provider.ValidateArguments(args));
        }
コード例 #7
0
        public void Execute_throws_ArgumentException_if_Operation_is_None()
        {
            var provider = new StubBaseVersionControlProvider();
            var args = new VersionControlArguments
            {
                Server = "Server",
                Operation = VersionControlOperation.None
            };

            AssertException.Throws<ArgumentException>(
                "You must specify a valid source control operation for the VersionControlArguments (the Operation property is set to None)\r\nParameter name: arguments",
                () => provider.Execute(args));
        }
コード例 #8
0
        public void GetLocalVersionCommandLine()
        {
            var provider = new VaultVersionControlProvider(@"C:\Program Files\SourceGear\Vault Client\vault.exe");

            var args = new VersionControlArguments
            {
                Credentials = new NetworkCredential("Username", "Password"),
                Operation = VersionControlOperation.GetLocalVersion,
                Project = "ProjectName",
                Provider = "Vault",
                Server = "Server:Port",
                SourcePath = "SourcePath\\FileName.ext"
            };

            var result = provider.BuildCommandLineArguments(args);

            Assert.AreEqual("listfolder -host \"Server:Port\" -user \"Username\" -password \"Password\" -repository \"ProjectName\" \"$SourcePath\"", result);
        }
コード例 #9
0
        public void GetSourceIndexForFile()
        {
            var provider = new VaultVersionControlProvider("%VCS_EXECUTABLE%");

            var args = new VersionControlArguments
            {
                Credentials = new NetworkCredential("Username", "Password"),
                DestinationPath = @"D:\Source\",
                Project = "ProjectName",
                Provider = "Vault",
                Server = "Server:Port",
                SourcePath = "$/ProjectName/SourcePath",
                Label = "My Label"
            };
            var indexer = new SourceIndexer(provider, args);

            Assert.AreEqual(@"D:\Source\ProjectName\SourcePath\File.ext*/ProjectName/SourcePath*My Label", indexer.GetVersionIndexForFile(@"d:\Source\ProjectName\SourcePath\File.ext"), ignoreCase: true);
            Assert.AreEqual(@"D:\Source\ProjectName\SourcePath\File.ext*/ProjectName/SourcePath*My Label", indexer.GetVersionIndexForFile(@"D:\Source\ProjectName\SourcePath\File.ext"), ignoreCase: true);
        }
コード例 #10
0
        /// <summary>
        /// Executes the VCS command line, building up the arguments using <see cref="BuildCommandLineArguments"/>
        /// and then parsing the result of the executable in <see cref="ParseResult"/>.
        /// </summary>
        /// <param name="arguments">The arguments.</param>
        /// <returns></returns>
        public IServiceResult CommandLineExecute(VersionControlArguments arguments)
        {
            var commandLineArgs = BuildCommandLineArguments(arguments);
            var processStartInfo = new ProcessStartInfo(FileName, commandLineArgs);

            using (var process = new Process())
            {
                process.StartInfo = processStartInfo;

                // UseShellExecute must be false so we can do
                // redirection of standard input and output.
                processStartInfo.UseShellExecute = false;

                process.Start();
                process.WaitForExit((int) Timeout.TotalMilliseconds);

                return ParseResult(arguments, new ProcessResult(process) );
            }
        }
コード例 #11
0
        public void GetVersionCommandForFile()
        {
            var provider = new VaultVersionControlProvider("%VCS_EXECUTABLE%");

            var args = new VersionControlArguments
            {
                Credentials = new NetworkCredential("Username", "Password"),
                DestinationPath = @"D:\Source",
                Project = "ProjectName",
                Provider = "Vault",
                Server = "Server:Port",
                SourcePath = "$/SourcePath",
                Label = "My Label"
            };
            var indexer = new SourceIndexer(provider, args);

            var command = indexer.GetVersionCommand();

            Assert.AreEqual("\"%VCS_EXECUTABLE%\" getlabel -host \"%VCS_SERVER%\" -user \"%VCS_USERNAME%\" -password \"%VCS_PASSWORD%\" -repository \"%VCS_PROJECT%\" -destpath \"%TARG%\\%VAR3%%fnbksl%(%VAR2%)\" \"$%VAR2%/%fnfile%(%VAR1%)\" \"%VAR3%\"", command, ignoreCase: true);
        }
コード例 #12
0
        public void BuildCommandLineArguments_for_get_specific_version()
        {
            var provider = new VaultVersionControlProvider(@"C:\Program Files\SourceGear\Vault Client\vault.exe");

            var args = new VersionControlArguments
            {
                Credentials = new NetworkCredential("Username", "Password"),
                DestinationPath = "DestinationPath",
                Operation = VersionControlOperation.Get,
                Project = "ProjectName",
                Provider = "Vault",
                Server = "Server:Port",
                SourcePath = "SourcePath",
                Version = "50"
            };

            var result = provider.BuildCommandLineArguments(args);

            Assert.AreEqual("getversion -host \"Server:Port\" -user \"Username\" -password \"Password\" -repository \"ProjectName\" 50 \"$SourcePath\" \"DestinationPath\"", result);
        }
コード例 #13
0
        public void ToString_converts_arguments_to_uri_string()
        {
            var args = new VersionControlArguments
            {
                Credentials = new NetworkCredential("username", "password"),
                DestinationPath = "destination",
                Operation = VersionControlOperation.Get,
                Project = "ProjectName",
                Server = "ServerName",
                SourcePath = "Source/Path/",
                Version = "50",
                Provider = "Vault",
                Label = "Label"
            };

            Assert.AreEqual("vault://*****:*****@ServerName/ProjectName/Source/Path/?operation=Get&destination=destination&Label=Label#50", args.ToString());

            args.Label = null;

            Assert.AreEqual("vault://*****:*****@ServerName/ProjectName/Source/Path/?operation=Get&destination=destination#50", args.ToString());
        }
コード例 #14
0
        public void GetLocalVersion()
        {
            var provider = new VaultVersionControlProvider(@"C:\Program Files\SourceGear\Vault Client\vault.exe");

            var args = new VersionControlArguments
            {
                Credentials = new NetworkCredential("Username", "Password"),
                Operation = VersionControlOperation.GetLocalVersion,
                Project = "ProjectName",
                Provider = "Vault",
                Server = "Server:Port",
                SourcePath = "SourcePath\\UnchangedFile.cs"
            };

            var process = new Mock<IProcessResult>();
            process.Setup(process1 => process1.StandardOutput).Returns(VaultTestResponses.ListFolderResponse);

            var result = provider.ParseResult(args, process.Object);

            Assert.AreEqual(ServiceResultCode.Success, result.ResultCode);
            Assert.AreEqual(6, result.ResultValue);
        }
コード例 #15
0
        public void Get_for_label()
        {
            var provider = new VaultVersionControlProvider(@"C:\Program Files\SourceGear\Vault Client\vault.exe");

            var args = new VersionControlArguments
            {
                Credentials = new NetworkCredential("Username", "Password"),
                DestinationPath = @"C:\DestinationPath\",
                Operation = VersionControlOperation.Get,
                Project = "ProjectName",
                Provider = "Vault",
                Server = "Server:Port",
                SourcePath = "/SourcePath/FileName.ext",
                Label = "My Label"
            };

            var result = provider.BuildCommandLineArguments(args);

            Assert.AreEqual("getlabel -host \"Server:Port\" -user \"Username\" -password \"Password\" -repository \"ProjectName\" -destpath \"C:\\DestinationPath\" \"$SourcePath/FileName.ext\" \"My Label\"", result);
        }
コード例 #16
0
 public SourceIndexer(BaseCommandLineVersionControlProvider versionControlProvider, VersionControlArguments args)
 {
     this.versionControlProvider = versionControlProvider;
     this.args = args;
 }
コード例 #17
0
        public string GetVersionCommand()
        {
            var getArgs = new VersionControlArguments
            {
                Credentials = new NetworkCredential(VcsUsername, VcsPassword),
                DestinationPath = VcsDestinationPath,
                Label = VcsLabel,
                Operation = VersionControlOperation.Get,
                Project = VcsProject,
                Provider = VcsProvider,
                Server = VcsServer,
                SourcePath = VcsSourceFullPath
            };

            var commandLine = versionControlProvider.BuildCommandLineArguments(getArgs);

            return "\"{0}\" {1}".StringFormat(VcsExecutable, commandLine);
        }
コード例 #18
0
 /// <summary>
 /// Builds the command line arguments.
 /// </summary>
 /// <param name="arguments">The arguments.</param>
 /// <returns></returns>
 public abstract string BuildCommandLineArguments(VersionControlArguments arguments);
コード例 #19
0
 protected override IServiceResult ExecuteOperation(VersionControlArguments arguments)
 {
     return CommandLineExecute(arguments);
 }
コード例 #20
0
 /// <summary>
 /// Parses the result of executing the VCS executable.
 /// </summary>
 /// <param name="args"></param>
 /// <param name="processResult"></param>
 /// <returns></returns>
 public abstract IServiceResult ParseResult(VersionControlArguments args, IProcessResult processResult);
コード例 #21
0
 protected override IServiceResult ExecuteOperation(VersionControlArguments arguments)
 {
     return null;
 }
コード例 #22
0
        public void GetVersionIndexForFile()
        {
            var provider = new Mock<BaseCommandLineVersionControlProvider>();
            provider.Setup(controlProvider =>
                controlProvider.BuildCommandLineArguments(It.IsAny<VersionControlArguments>()))
                .Returns("args");

            provider.Setup(versionControlProvider => versionControlProvider
                .MapVersionControlSourcePath(It.IsAny<string>(), It.IsAny<VersionControlArguments>()))
                .Returns("/MyProject/SubFolder");

            var args = new VersionControlArguments
            {
                Credentials = new NetworkCredential("username", "password"),
                DestinationPath = "D:\\WorkingFolder\\MyProject",
                Label = "My Label",
                Operation = VersionControlOperation.Get,
                Project = "MyProject",
                Provider = "Vault",
                Server = "server:port",
                SourcePath = "$/MyProject"
            };

            var indexer = new SourceIndexer(provider.Object, args);

            var line = indexer.GetVersionIndexForFile("D:\\WorkingFolder\\MyProject\\SubFolder\\FileName.ext");

            Assert.AreEqual("D:\\WorkingFolder\\MyProject\\SubFolder\\FileName.ext*/MyProject/SubFolder*My Label", line, ignoreCase: true);
        }
コード例 #23
0
        public void MapVersionControlSourcePath()
        {
            var provider = new VaultVersionControlProvider(@"C:\Program Files\SourceGear\Vault Client\vault.exe");

            var args = new VersionControlArguments
            {
                Credentials = new NetworkCredential("Username", "Password"),
                DestinationPath = "C:\\WorkingFolder",
                Operation = VersionControlOperation.Get,
                Project = "ProjectName",
                Provider = "Vault",
                Server = "Server:Port",
                SourcePath = "SourcePath\\FileName.ext",
                Label = "My Label"
            };

            Assert.IsNull(provider.MapVersionControlSourcePath("D:\\WorkingFolder", args));
            Assert.AreEqual("/Folder", provider.MapVersionControlSourcePath(@"C:\WorkingFolder\Folder\File.ext", args));
            Assert.AreEqual("/Folder", provider.MapVersionControlSourcePath(@"C:\workingFolder/Folder\File.ext", args));
        }
コード例 #24
0
 protected abstract IServiceResult ExecuteOperation(VersionControlArguments arguments);
コード例 #25
0
 /// <summary>
 /// Maps the version control source path from a local working path.
 /// </summary>
 /// <param name="localPath">The local path.</param>
 /// <param name="args">The args.</param>
 /// <returns></returns>
 public abstract string MapVersionControlSourcePath(string localPath, VersionControlArguments args);