コード例 #1
0
 public void FileNameCanBeSetAndRetrieved()
 {
     var request = new FileTransferRequest();
     var projectName = "projectName";
     request.FileName = projectName;
     Assert.AreEqual(projectName, request.FileName);
 }
コード例 #2
0
 public void FullConstructorInitialisesTheValues()
 {
     var sessionId = "MyNewSession";
     var projectName = "projectName";
     var fileName = "fileName";
     var request = new FileTransferRequest(sessionId, projectName, fileName);
     Assert.AreEqual(sessionId, request.SessionToken);
     Assert.AreEqual(projectName, request.ProjectName);
     Assert.AreEqual(fileName, request.FileName);
 }
コード例 #3
0
        /// <summary>
        /// Retrieves a file transfer instance.
        /// </summary>
        /// <param name="projectName">The name of the project.</param>
        /// <param name="fileName">The name of the file.</param>
        /// <returns>The file transfer instance.</returns>
        public override IFileTransfer RetrieveFileTransfer(string projectName, string fileName)
        {
            if (string.IsNullOrEmpty(projectName)) throw new ArgumentNullException("projectName");

            var request = new FileTransferRequest(SessionToken, projectName, fileName);
            request.ServerName = TargetServer;
            var response = connection.SendMessage("RetrieveFileTransfer", request);
            ValidateResponse(response);
            return (response as FileTransferResponse).FileTransfer;
        }
コード例 #4
0
 /// <summary>
 /// Retrieve a file transfer object.
 /// </summary>
 public FileTransferResponse RetrieveFileTransfer(FileTransferRequest request)
 {
     return cruiseServer.RetrieveFileTransfer(request);
 }
コード例 #5
0
 /// <summary>
 /// Retrieve a file transfer object.
 /// </summary>
 /// <param name="project">The project to retrieve the file for.</param>
 /// <param name="fileName">The name of the file.</param>
 public virtual RemotingFileTransfer RetrieveFileTransfer(string project, string fileName)
 {
     var request = new FileTransferRequest();
     request.ProjectName = project;
     request.FileName = fileName;
     var response = cruiseServer.RetrieveFileTransfer(request);
     ValidateResponse(response);
     return response.FileTransfer as RemotingFileTransfer;
 }
コード例 #6
0
        /// <summary>
        /// Retrieve a file transfer object.
        /// </summary>
        /// <param name="request"></param>
        public virtual FileTransferResponse RetrieveFileTransfer(FileTransferRequest request)
        {
            var response = new FileTransferResponse(request);
            try
            {
                // Validate that the path is valid
                var sourceProject = GetIntegrator(request.ProjectName).Project;
                var filePath = Path.Combine(sourceProject.ArtifactDirectory, request.FileName);
                var fileInfo = new FileInfo(filePath);
                if (!fileInfo.FullName.StartsWith(sourceProject.ArtifactDirectory, StringComparison.OrdinalIgnoreCase))
                {
                    var message = string.Format(CultureInfo.CurrentCulture, "Files can only be retrieved from the artefact folder - unable to retrieve {0}", request.FileName);
                    Log.Warning(message);
                    throw new CruiseControlException(message);
                }
                else if (fileInfo.FullName.StartsWith(Path.Combine(sourceProject.ArtifactDirectory, "buildlogs"), StringComparison.OrdinalIgnoreCase))
                {
                    var message = string.Format(CultureInfo.CurrentCulture, "Unable to retrieve files from the build logs folder - unable to retrieve {0}", request.FileName);
                    Log.Warning(message);
                    throw new CruiseControlException(message);
                }

                RemotingFileTransfer fileTransfer = null;
                if (fileInfo.Exists)
                {
                    Log.Debug(string.Format(CultureInfo.CurrentCulture, "Retrieving file '{0}' from '{1}'", request.FileName, request.ProjectName));
                    fileTransfer = new RemotingFileTransfer(File.OpenRead(filePath));
                }
                else
                {
                    Log.Warning(string.Format(CultureInfo.CurrentCulture, "Unable to find file '{0}' in '{1}'", request.FileName, request.ProjectName));
                }
                response.FileTransfer = fileTransfer;
                response.Result = ResponseResult.Success;
            }
            catch (Exception error)
            {
                response.Result = ResponseResult.Failure;
                response.ErrorMessages.Add(
                    new ErrorMessage(error.Message));
            }
            return response;
        }
コード例 #7
0
 public void SessionConstructorInitialisesTheValues()
 {
     var sessionId = "MyNewSession";
     var request = new FileTransferRequest(sessionId);
     Assert.AreEqual(sessionId, request.SessionToken);
 }
コード例 #8
0
 /// <summary>
 /// Retrieve a file transfer object.
 /// </summary>
 public virtual FileTransferResponse RetrieveFileTransfer(FileTransferRequest request)
 {
     return server.RetrieveFileTransfer(request);
 }