C++客户端开发接口库 V5.1.8.15
连接信创集成中间件服务程序的二次开发接口
载入中...
搜索中...
未找到
FileTransferHelper.h
1#pragma once
2#include "MidLinkBase.h"
3#include "MidLinkComm.h"
4#include "RDMS_MFNDefine.h"
5#include "MidLinkDLL.h"
6#include <string>
7#include <vector>
8#include <memory>
9#include <functional>
10#include <algorithm>
11#include "mdwclient_global.h"
12
13namespace mdwc
14{
17 {
19 int64_t i8FileID;
21 std::string FileName;
23 std::string RootPath;
25 std::string FileAttributes;
27 int64_t FileSize;
29 std::string FileType;
31 std::string VersionInfo;
33 std::string CreateTime;
35 std::string AccessTime;
37 std::string UpdateTime;
39 std::string FileMD5Hash;
41 std::string LoaclFileName;
45 std::string LocalFileMD5Hash;
46
48 void Clear()
49 {
50 i8FileID = 0;
51 FileName = "";
52 RootPath = "";
53 FileAttributes = "";
54 FileSize = 0;
55 FileType = "";
56 VersionInfo = "";
57 CreateTime = "";
58 AccessTime = "";
59 UpdateTime = "";
60 FileMD5Hash = "";
61 LoaclFileName = "";
62 LocalFileSize = 0;
64 }
65
67 {
68 Clear();
69 }
70 };
71
73 enum class REMOTE_STORE_TYPE : int
74 {
76 DAS = 0,
78 DASMF = 1,
80 OBS = 2,
82 OBSMF = 3,
84 FTP = 4,
86 FTPMF = 5,
88 QR = 6,
90 QFMF = 7
91 };
92
95 {
97 int64_t i8FileID;
99 std::string sLocalFileName;
101 int64_t i8FileSize;
103 std::string sFileMD5Value;
105 std::string sServerFileName;
107 std::string sCreateTime;
109 std::string sModifyTime;
111 {
112 i8FileID = 0;
113 i8FileSize = 0;
114 sLocalFileName = "";
115 sFileMD5Value = "";
116 sServerFileName = "";
117 };
118
119 bool IsEmpty()
120 {
121 return i8FileID == 0 && i8FileSize == 0 && sLocalFileName.empty();
122 }
123 };
124
135 typedef bool (PPROGRESSCALLBACK)(const int Prcent, const int Speed, const int64_t FinshedFileID, const int64_t i8DataSize, const int64_t i8Duration);
136
140 class MDWC_COMPLILE CFileTransferHelper
141 {
142 private:
144 CMidLinkComm* m_MidComm;
146 bool m_bAutoFreeMidComm;
148 unsigned char m_uRouteNode;
150 int m_iLassErrorCode;
152 std::string m_sLastErrorMsg;
154 int m_iProgressPercent;
156 int64_t m_i64LastFileID;
158 int m_iSpeed;
160 std::string m_sProgressFileName;
162 std::string m_sCurrentLocalFile;
164 int64_t m_i8StartTick;
166 int64_t m_i8FileStartTick;
168 std::function<PPROGRESSCALLBACK> m_pProgressCallback;
169 private:
170 // 禁止拷贝构造函数
171 CFileTransferHelper(const CFileTransferHelper&) = delete;
172 // 禁止拷贝赋值运算符
173 CFileTransferHelper& operator=(const CFileTransferHelper&) = delete;
174
183 bool ProcessProgress(const int64_t i8ProcessData, const int64_t i8AllData, const int64_t i64FileID = 0);
184
191 std::string StoreTypeName(mdwc::REMOTE_STORE_TYPE storetype);
192
194 void ReleaseMidLinkComm();
195
201 bool CheckMidLinkComm();
202
209 std::string ReadMTPFileLine(std::fstream& fs);
210 public:
216 CFileTransferHelper(unsigned char uRouteNode = 0);
217
223 CFileTransferHelper(CMidLinkComm* MidComm);
224
228 ~CFileTransferHelper();
229
231 void SetProgressCallback(std::function<PPROGRESSCALLBACK> pCallback) { m_pProgressCallback = pCallback; }
232
238 std::string GetLastErrorMessage();
239
245 int GetLastErrorCode();
246
258 int64_t DownLoadFile(const std::string& sLocalFileName, const std::string& sRemoteFileName, bool ResumeBreak,
259 int64_t iFileSize = 0, const std::string& sVerifyMD5 = "", int iDownReqNo = RDMS_DOWNLOADFILE);
260
270 int64_t DownLoadFile(const std::string& sRemoteFileName, std::streambuf& sRcvStream, int64_t iFileSize = 0, int iDownReqNo = RDMS_DOWNLOADFILE);
271
281 std::vector<REMOTE_FILE_INFO> GetServerDirectoryFileInfo(const std::string& sPathName,
282 bool bSearchSubDir = true, bool bCalculateMD5 = false, int iDownReqNo = RDMS_GETDIR_FILEINFO);
283
293 bool DownloadDirectoryFiles(const std::string& sPathName, const std::string& sSavePathTo,
294 bool bIncludeSubDir = true, int iDownReqNo = RDMS_DOWNLOAD_FLODER);
295
307 bool BatchDownLoadFiles(const std::vector<REMOTE_FILE_INFO>& lstFiles,
308 const std::string& sSavePathTo, REMOTE_STORE_TYPE store_type = REMOTE_STORE_TYPE::DAS,
309 bool ResumeBreak = true, const std::string& sSotrePara = "", int iDownReqNo = RDMS_BATCHGET_FILES);
310
320 int UpLoadFile(const std::string& sLocalFileName, const std::string& sServerSaveFileName, bool ResumeBreak = true, int iUploadReqNo = RDMS_UPLOAD_FILE);
321
330 bool UpLoadFileToMidCache(const std::string& sLocalFileName, std::string& sFileMD5, int iUploadReqNo = RDMS_SAVEFILE_CACHE);
331
340 int BatchUpLoadFiles(const std::vector<SEND_FILE_INFO>& lstFiles, int iUploadReqNo = RDMS_UPLOAD_FILE, const std::string& sAddToMidFileCache = "Auto");
341
352 int UpLoadDirectoryFile(const std::string& sLocalPathName, const std::string& sSavePathTo,
353 bool bIncludeSubDir = true, bool ResumeBreak = true, int iUploadReqNo = RDMS_UPLOAD_FILE);
354
366 int UpLoadFrontServerFileToRemote(unsigned char uRemoteNode, const std::string& sFSPathName, const std::string& sRSPathName,
367 bool bIncludeSubDir = true, const std::string& sAddToCache = "AUTO", int iUploadReqNo = RDMS_UPLOAD_FSFILE);
368
377 bool DeleteServerFile(const std::string& sServerFileName, const std::string& sFloderDelteMode = "", int iReqNo = RDMS_DELET_FILE);
378
385 std::vector<std::string> ReadMTPFile(const std::string& sFileName);
386
394 static int64_t GetFileMD5(const std::string& sFileName, std::string& sMD5Value);
395
404 static bool GetFileMD5(const std::string& sFileName, int64_t& iFileSize, std::string& sMD5Value);
405
410 static std::string SpeedFormat(int speed);
411
417 static std::string TimeFormat(int64_t time, bool bIsMicrosecond = false);
418 };
419}
void SetProgressCallback(std::function< PPROGRESSCALLBACK > pCallback)
定义 FileTransferHelper.h:231
定义 AutoUpdateHelper.h:8
bool PPROGRESSCALLBACK(const int Prcent, const int Speed, const int64_t FinshedFileID, const int64_t i8DataSize, const int64_t i8Duration)
定义 FileTransferHelper.h:135
REMOTE_STORE_TYPE
定义 FileTransferHelper.h:74
@ OBSMF
定义 FileTransferHelper.h:82
@ FTPMF
定义 FileTransferHelper.h:86
@ QFMF
定义 FileTransferHelper.h:90
@ QR
定义 FileTransferHelper.h:88
@ OBS
定义 FileTransferHelper.h:80
@ DASMF
定义 FileTransferHelper.h:78
@ FTP
定义 FileTransferHelper.h:84
@ DAS
定义 FileTransferHelper.h:76
std::string AccessTime
定义 FileTransferHelper.h:35
std::string LocalFileMD5Hash
定义 FileTransferHelper.h:45
int64_t i8FileID
定义 FileTransferHelper.h:19
std::string RootPath
定义 FileTransferHelper.h:23
std::string CreateTime
定义 FileTransferHelper.h:33
std::string FileType
定义 FileTransferHelper.h:29
std::string FileMD5Hash
定义 FileTransferHelper.h:39
int64_t LocalFileSize
定义 FileTransferHelper.h:43
std::string LoaclFileName
定义 FileTransferHelper.h:41
std::string FileName
定义 FileTransferHelper.h:21
std::string VersionInfo
定义 FileTransferHelper.h:31
std::string FileAttributes
定义 FileTransferHelper.h:25
REMOTE_FILE_INFO()
定义 FileTransferHelper.h:66
void Clear()
定义 FileTransferHelper.h:48
int64_t FileSize
定义 FileTransferHelper.h:27
std::string UpdateTime
定义 FileTransferHelper.h:37
std::string sLocalFileName
定义 FileTransferHelper.h:99
std::string sFileMD5Value
定义 FileTransferHelper.h:103
std::string sCreateTime
定义 FileTransferHelper.h:107
SEND_FILE_INFO()
定义 FileTransferHelper.h:110
int64_t i8FileSize
定义 FileTransferHelper.h:101
std::string sServerFileName
定义 FileTransferHelper.h:105
bool IsEmpty()
定义 FileTransferHelper.h:119
std::string sModifyTime
定义 FileTransferHelper.h:109
int64_t i8FileID
定义 FileTransferHelper.h:97