Example #1
0
        public void CopyToVM(string localFilePathGlob, string remoteFilePath, bool recursive, bool force)
        {
            CheckProfileCanResolveSlave();

            Log(string.Format("Copying from local path '{0}' to remote path '{1}'{2}{3}.", localFilePathGlob, remoteFilePath,
                              recursive ? " recursively" : "",
                              force ? " force overwrite" : ""));

            var client = GetSlaveClient();

            bool foundFile = FileUtil.TraverseFiles(localFilePathGlob, recursive,
                                                    (file, relativePath) =>
            {
                Log(string.Format("Copying '{0}'.", relativePath));

                byte[] contents = File.ReadAllBytes(file.FullName);

                WriteFileRequest request = new WriteFileRequest()
                {
                    Contents  = contents,
                    Path      = Path.Combine(remoteFilePath, relativePath),
                    Overwrite = force
                };
                client.WriteFile(request);
            },
                                                    (directory, relativePath) =>
            {
                Log(string.Format("Creating directory '{0}'.", relativePath));

                CreateDirectoryRequest request = new CreateDirectoryRequest()
                {
                    Path = Path.Combine(remoteFilePath, relativePath)
                };
                client.CreateDirectory(request);
            });

            if (!foundFile && !FileUtil.HasWildcard(localFilePathGlob))
            {
                throw new OperationFailedException()
                      {
                          Why = string.Format("Local file{0} not found '{1}'.", recursive ? " or directory" : "", localFilePathGlob)
                      }
            }
            ;
        }
Example #2
0
        public override WriteFileResponse WriteFile(WriteFileRequest request)
        {
            log.InfoFormat("WriteFile:\n  Path: {0}\n  Overwrite: {1}", request.Path, request.Overwrite);

            try
            {
                if (! request.Overwrite && File.Exists(request.Path))
                    throw OperationFailed(string.Format("File already exists and did not request to overwrite '{0}'.", request.Path), null);

                File.WriteAllBytes(request.Path, request.Contents);
            }
            catch (OperationFailedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw OperationFailed(string.Format("Could not read file '{0}'.", request.Path), ex.Message);
            }

            return new WriteFileResponse();
        }
Example #3
0
        public override WriteFileResponse WriteFile(WriteFileRequest request)
        {
            log.InfoFormat("WriteFile:\n  Path: {0}\n  Overwrite: {1}", request.Path, request.Overwrite);

            try
            {
                if (!request.Overwrite && File.Exists(request.Path))
                {
                    throw OperationFailed(string.Format("File already exists and did not request to overwrite '{0}'.", request.Path), null);
                }

                File.WriteAllBytes(request.Path, request.Contents);
            }
            catch (OperationFailedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw OperationFailed(string.Format("Could not read file '{0}'.", request.Path), ex.Message);
            }

            return(new WriteFileResponse());
        }
Example #4
0
 public abstract WriteFileResponse WriteFile(WriteFileRequest request);
Example #5
0
        public void CopyToVM(string localFilePathGlob, string remoteFilePath, bool recursive, bool force)
        {
            CheckProfileCanResolveSlave();

            Log(string.Format("Copying from local path '{0}' to remote path '{1}'{2}{3}.", localFilePathGlob, remoteFilePath,
                recursive ? " recursively" : "",
                force ? " force overwrite" : ""));

            var client = GetSlaveClient();

            bool foundFile = FileUtil.TraverseFiles(localFilePathGlob, recursive,
                (file, relativePath) =>
                {
                    Log(string.Format("Copying '{0}'.", relativePath));

                    byte[] contents = File.ReadAllBytes(file.FullName);

                    WriteFileRequest request = new WriteFileRequest()
                    {
                        Contents = contents,
                        Path = Path.Combine(remoteFilePath, relativePath),
                        Overwrite = force
                    };
                    client.WriteFile(request);
                },
                (directory, relativePath) =>
                {
                    Log(string.Format("Creating directory '{0}'.", relativePath));

                    CreateDirectoryRequest request = new CreateDirectoryRequest()
                    {
                        Path = Path.Combine(remoteFilePath, relativePath)                        
                    };
                    client.CreateDirectory(request);
                });

            if (!foundFile && ! FileUtil.HasWildcard(localFilePathGlob))
                throw new OperationFailedException() {
                    Why = string.Format("Local file{0} not found '{1}'.", recursive ? " or directory" : "", localFilePathGlob) };
        }
Example #6
0
 public abstract WriteFileResponse WriteFile(WriteFileRequest request);