public async Task <IEnumerable <string> > ReadFileRequest(string filepath, int lines = 5, bool useSudo = true) { var interfaceRequest = new ReadFileRequest(filepath, lines, useSudo); var interfaces = await ExecuteTaskAsync <IEnumerable <string> >(interfaceRequest).ConfigureAwait(false); return(interfaces.Data); }
public void CopyFromVM(string remoteFilePathGlob, string localFilePath, bool recursive, bool force) { CheckProfileCanResolveSlave(); Log(string.Format("Copying from remote path '{0}' to local path '{1}'{2}{3}.", localFilePath, remoteFilePathGlob, recursive ? " recursively" : "", force ? " force overwrite" : "")); var client = GetSlaveClient(); EnumerateRequest enumerateRequest = new EnumerateRequest() { PathGlob = remoteFilePathGlob, Recursive = recursive }; EnumerateResponse enumerateResponse = client.Enumerate(enumerateRequest); if (enumerateResponse.Items.Count == 0 && !FileUtil.HasWildcard(remoteFilePathGlob)) { throw new OperationFailedException() { Why = string.Format("Remote file{0} not found '{1}'.", recursive ? " or directory" : "", remoteFilePathGlob) } } ; foreach (EnumerateItem item in enumerateResponse.Items) { string path = Path.Combine(localFilePath, item.RelativePath); if (item.Kind == EnumerateItemKind.DIRECTORY) { if (!Directory.Exists(path)) { Log(string.Format("Creating directory '{0}'.", item.RelativePath)); Directory.CreateDirectory(path); } } else { Log(string.Format("Copying '{0}'.", item.RelativePath)); ReadFileRequest request = new ReadFileRequest() { Path = item.FullPath }; ReadFileResponse response = client.ReadFile(request); if (!force && File.Exists(path)) { throw new OperationFailedException() { Why = string.Format("Local file already exists '{0}'.", path) } } ; File.WriteAllBytes(path, response.Contents); } } }
public override ReadFileResponse ReadFile(ReadFileRequest request) { log.InfoFormat("ReadFile:\n Path: {0}", request.Path); byte[] contents; try { contents = File.ReadAllBytes(request.Path); } catch (Exception ex) { throw OperationFailed(string.Format("Could not read file '{0}'.", request.Path), ex.Message); } return new ReadFileResponse() { Contents = contents }; }
public override ReadFileResponse ReadFile(ReadFileRequest request) { log.InfoFormat("ReadFile:\n Path: {0}", request.Path); byte[] contents; try { contents = File.ReadAllBytes(request.Path); } catch (Exception ex) { throw OperationFailed(string.Format("Could not read file '{0}'.", request.Path), ex.Message); } return(new ReadFileResponse() { Contents = contents }); }
public DataTable LoadFromServer(string fileName) { ErroMessage = string.Empty; ReadFileRequest request = new ReadFileRequest() { NameFile = fileName }; DataTable table = new DataTable(); try { var response = proxy.ReadFile(request); return(response.Result); } catch (Exception e) { ErroMessage = e.Message; return(null); } }
public ReadFileResponse ReadFile(ReadFileRequest request) { if (request.NameFile == null) { return(null); } ReadFileResponse dataTable = new ReadFileResponse(); string path = DirectoryPath + request.NameFile; try { dataTable.Result = Helpers.LoadData(path); return(dataTable); } catch (Exception) { Helpers.ReturnRequest(); return(null); } }
public abstract ReadFileResponse ReadFile(ReadFileRequest request);
public void CopyFromVM(string remoteFilePathGlob, string localFilePath, bool recursive, bool force) { CheckProfileCanResolveSlave(); Log(string.Format("Copying from remote path '{0}' to local path '{1}'{2}{3}.", localFilePath, remoteFilePathGlob, recursive ? " recursively" : "", force ? " force overwrite" : "")); var client = GetSlaveClient(); EnumerateRequest enumerateRequest = new EnumerateRequest() { PathGlob = remoteFilePathGlob, Recursive = recursive }; EnumerateResponse enumerateResponse = client.Enumerate(enumerateRequest); if (enumerateResponse.Items.Count == 0 && !FileUtil.HasWildcard(remoteFilePathGlob)) throw new OperationFailedException() { Why = string.Format("Remote file{0} not found '{1}'.", recursive ? " or directory" : "", remoteFilePathGlob) }; foreach (EnumerateItem item in enumerateResponse.Items) { string path = Path.Combine(localFilePath, item.RelativePath); if (item.Kind == EnumerateItemKind.DIRECTORY) { if (!Directory.Exists(path)) { Log(string.Format("Creating directory '{0}'.", item.RelativePath)); Directory.CreateDirectory(path); } } else { Log(string.Format("Copying '{0}'.", item.RelativePath)); ReadFileRequest request = new ReadFileRequest() { Path = item.FullPath }; ReadFileResponse response = client.ReadFile(request); if (! force && File.Exists(path)) throw new OperationFailedException() { Why = string.Format("Local file already exists '{0}'.", path) }; File.WriteAllBytes(path, response.Contents); } } }
/// <summary> /// 上传文件,返回文件内容 /// </summary> /// <param name="request">请求参数信息</param> /// <returns>请求结果信息</returns> public async Task <ReadFileResponse> ReadFile(ReadFileRequest request) { return(await new ReadFileExecutor().Client(this).Execute <ReadFileResponse, ReadFileResult, ReadFileRequest>(request).ConfigureAwait(false)); }
/// <summary> /// 上传文件,返回文件内容 /// </summary> /// <param name="request">请求参数信息</param> /// <returns>请求结果信息</returns> public ReadFileResponse ReadFile(ReadFileRequest request) { return(new ReadFileExecutor().Client(this).Execute <ReadFileResponse, ReadFileResult, ReadFileRequest>(request)); }