public Exception DeltaUploadProject(string fileName, string projectId, OnProgressCallback progressCb, OnMessageCallback messageCallback, OnSuccessCallback <CosResult> successCb, OnFailedCallback failedCb) { var filePath = Path.GetFullPath(fileName); if (!File.Exists(filePath)) { failedCb( new CosClientException(COS_STATUS.CLIENT_ERR, string.Format(COS_MSG.ERR_CLIENT_TARGET_NOT_EXIST, fileName)), new CosServerException(COS_STATUS.CLIENT_ERR, COS_MSG.ERR_CLIENT) ); } var fileKey = $"{projectId}/{Path.GetFileName(fileName)}"; if (CheckFileExists(sourceBucket, fileKey)) { successCb(CreateTaskResult(COS_STATUS.SKIP, string.Format(COS_MSG.INFO_TARGET_EXIST_ON_SERVER, fileName))); return(null); } if (CheckFileExists(deltaBucket, $"{projectId}/{BASE_META}")) { _DeltaUpdateProject(filePath, projectId, progressCb, messageCallback, successCb, failedCb); } else { _InitProject(filePath, projectId, progressCb, messageCallback, successCb, failedCb); } return(new Exception()); }
public Handle(float timeLength, bool locked, bool useProgress, OnProgressCallback c) { this.timeStart = Time.realtimeSinceStartup; this.timeLength = timeLength; this.locked = locked; this.useProgress = useProgress; this.callback = c; }
public void AsyncUploadProject(string fileName, string projectId, OnProgressCallback progressCb, OnMessageCallback messageCallback, OnSuccessCallback <CosResult> successCb, OnFailedCallback failedCb) { Func <string, string, OnProgressCallback, OnMessageCallback, OnSuccessCallback <CosResult>, OnFailedCallback, Exception> fun = DeltaUploadProject; fun.BeginInvoke(fileName, projectId, progressCb, messageCallback, successCb, failedCb, ar => { Console.WriteLine(ar.AsyncState); }, fun); }
internal static void Download(string path, OnProgressCallback onProgress, OnCompletedCallback onCompleted) { basePath = path; onProgressCallback = onProgress; onCompletedCallback = onCompleted; webClient.DownloadProgressChanged += DownloadProgressCallback; webClient.DownloadFileCompleted += DownloadCompletedCallback; webClient.DownloadFileAsync(new Uri("https://srec-1251216093.file.myqcloud.com/ffmpeg.zip"), basePath + "/ffmpeg.zip"); }
private void UploadFile(string bucket, string fileKey, string filePath, OnProgressCallback progressCb, OnSuccessCallback <CosResult> successCb, OnFailedCallback failedCb) { COSXMLUploadTask uploadTask = new COSXMLUploadTask(bucket, null, fileKey) { progressCallback = progressCb, successCallback = successCb, failCallback = failedCb }; uploadTask.SetSrcPath(filePath); transferManager.Upload(uploadTask); }
public void AddTencentCos(string path, OnProgressCallback postpath, string name) { CosXmlConfig config = new CosXmlConfig.Builder() .SetConnectionTimeoutMs(SetConnectionTimeoutMs) //设置连接超时时间,单位毫秒,默认45000ms .SetReadWriteTimeoutMs(SetReadWriteTimeoutMs) //设置读写超时时间,单位毫秒,默认45000ms .IsHttps(IsHttps) //设置默认 HTTPS 请求 .SetAppid(SetAppid) //设置腾讯云账户的账户标识 APPID .SetRegion(SetRegion) //设置一个默认的存储桶地域 .Build(); string secretId = SecretId; //云 API 密钥 SecretId string secretKey = SecretKey; //云 API 密钥 SecretKey long durationSecond = 60000; //每次请求签名有效时长,单位为秒 QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, secretKey, durationSecond); CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider); try { string bucket = "yuanguhl"; //存储桶,格式:BucketName-APPID string key = $"{DateTime.Now.ToString("yy")}/Add/" + name; //对象在存储桶中的位置,即称对象键 string srcPath = path; //本地文件绝对路径 if (!File.Exists(srcPath)) { // 如果不存在目标文件,创建一个临时的测试文件 File.WriteAllBytes(srcPath, new byte[1024]); } PostObjectRequest request = new PostObjectRequest(bucket, key, srcPath); request.Region = "ap-beijing"; //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //设置进度回调 request.SetCosProgressCallback(postpath); //执行请求 PostObjectResult result = cosXml.PostObject(request); //请求成功 } catch (COSXML.CosException.CosClientException clientEx) { //请求失败 throw clientEx; } catch (COSXML.CosException.CosServerException serverEx) { //请求失败 throw serverEx; } }
public void GetFileDow(string keyw, string name, OnProgressCallback Dwjindu, string path) { CosXmlConfig config = new CosXmlConfig.Builder() .SetConnectionTimeoutMs(SetConnectionTimeoutMs) //设置连接超时时间,单位毫秒,默认45000ms .SetReadWriteTimeoutMs(SetReadWriteTimeoutMs) //设置读写超时时间,单位毫秒,默认45000ms .IsHttps(IsHttps) //设置默认 HTTPS 请求 .SetAppid(SetAppid) //设置腾讯云账户的账户标识 APPID .SetRegion(SetRegion) //设置一个默认的存储桶地域 .Build(); string secretId = SecretId; //云 API 密钥 SecretId string secretKey = SecretKey; //云 API 密钥 SecretKey long durationSecond = 600; //每次请求签名有效时长,单位为秒 QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, secretKey, durationSecond); CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider); try { string bucket = "yuanguhl"; //存储桶,格式:BucketName-APPID string key = keyw; //对象在存储桶中的位置,即称对象键 string localDir = path; //本地文件夹 string localFileName = name; //指定本地保存的文件名 GetObjectRequest request = new GetObjectRequest(bucket, key, localDir, localFileName); request.Region = "ap-beijing"; //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //设置进度回调 request.SetCosProgressCallback(Dwjindu); //执行请求 GetObjectResult result = cosXml.GetObject(request); //请求成功 } catch (COSXML.CosException.CosClientException clientEx) { //请求失败 throw clientEx; } catch (COSXML.CosException.CosServerException serverEx) { //请求失败 throw serverEx; } }
public void UploadProject(string fileName, string projectId, OnProgressCallback progressCb, OnMessageCallback messageCallback, OnSuccessCallback <CosResult> successCb, OnFailedCallback failedCb) { var filePath = Path.GetFullPath(fileName); var fileKey = $"{projectId}/{Path.GetFileName(fileName)}"; if (CheckFileExists(sourceBucket, fileKey)) { successCb(CreateTaskResult(COS_STATUS.SKIP, string.Format(COS_MSG.INFO_TARGET_EXIST_ON_SERVER, fileName))); return; } _InitProject(filePath, projectId, progressCb, messageCallback, successCb, failedCb); }
private void _InitProject(string filePath, string projectId, OnProgressCallback progressCb, OnMessageCallback messageCallback, OnSuccessCallback <CosResult> successCb, OnFailedCallback failedCb) { var localDir = Path.GetDirectoryName(filePath); var fileKey = $"{projectId}/{Path.GetFileName(filePath)}"; var signatureKey = $"{fileKey}{SIG_SUFFIX}"; var signaturePath = $"{filePath}{SIG_SUFFIX}"; var baseMetaKey = $"{projectId}/{BASE_META}"; var baseMetaPath = $"{localDir}/{BASE_META}"; clearOldFiles(baseMetaPath, signaturePath); AutoResetEvent signatureEvent = new AutoResetEvent(false); AutoResetEvent baseMetaEvent = new AutoResetEvent(false); messageCallback(COS_MSG.TITLE_UPLOADING_PROJECT, string.Format(COS_MSG.INFO_UPLOADING_PROJECT, fileKey)); UploadFile(sourceBucket, fileKey, filePath, progressCb, delegate(CosResult result1) { signatureEvent.WaitOne(); messageCallback(COS_MSG.TITLE_UPLOADING_SIG_FILE, string.Format(COS_MSG.INFO_UPLOADING_SIG_FILE, signatureKey)); UploadFile(deltaBucket, signatureKey, signaturePath, progressCb, delegate(CosResult result) { baseMetaEvent.WaitOne(); messageCallback(COS_MSG.TITLE_UPLOADING_META_FILE, string.Format(COS_MSG.INFO_UPLOADING_META_FILE, baseMetaKey)); UploadFile(deltaBucket, baseMetaKey, baseMetaPath, progressCb, delegate(CosResult cosResult) { clearOldFiles(baseMetaPath, signaturePath); successCb( CreateTaskResult(COS_STATUS.OK, string.Format(COS_MSG.INFO_INIT_SUCCESS, filePath, projectId))); }, failedCb); }, failedCb); }, failedCb); AsyncCreateSignature(filePath, signaturePath, () => { signatureEvent.Set(); }); AsyncCreateBaseMeta(filePath, fileKey, signatureKey, projectId, baseMetaPath, () => { baseMetaEvent.Set(); }); }
private void syncDownloadFile(string bucket, string fileKey, string localDir, string localFileName, OnProgressCallback progressCb, OnSuccessCallback <CosResult> successCb, OnFailedCallback failedCb) { try { GetObjectRequest request = new GetObjectRequest(bucket, fileKey, localDir, localFileName); request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); request.SetCosProgressCallback(progressCb); GetObjectResult result = cosXml.GetObject(request); } catch (CosClientException clientEx) { failedCb(clientEx, null); } catch (CosServerException serverEx) { failedCb(null, serverEx); } }
public static void WeightedProgressCallBack(long completed, long total, int start, int end, OnProgressCallback mProgressCallback) { var weightedCompleted = WEIGHTED_TOTAL * (Math.Max(0, start) + (Math.Min(FULL_WEIGHT, end) - Math.Max(0, start)) * completed / total) / FULL_WEIGHT; mProgressCallback(weightedCompleted, WEIGHTED_TOTAL); }
static Wait.Handle FireActive(float timeLength, bool locked, bool useProgress, OnProgressCallback callback) { var inst = Wait.instance; if (!inst) { return(null); } var data = new Handle(timeLength, locked, useProgress, callback); inst.list.AddLast(data); if (locked) { inst.IncreaseLock(); } Wait.IsActive = true; return(data); }
public static Wait.Handle ActiveWithProgress(float timeLength, bool locked, OnProgressCallback callback) { return(Wait.FireActive(timeLength, locked, true, callback)); }
private void _DeltaUpdateProject(string filePath, string projectId, OnProgressCallback progressCb, OnMessageCallback messageCb, OnSuccessCallback <CosResult> successCb, OnFailedCallback failedCb) { var localDir = Path.GetDirectoryName(filePath); var fileName = Path.GetFileName(filePath); var fileKey = $"{projectId}/{fileName}"; var baseMetaKey = $"{projectId}/{BASE_META}"; var baseMetaPath = $"{localDir}/{BASE_META}"; var deltaKey = $"{projectId}/{fileName}{DELTA_SUFFIX}"; var deltaPath = $"{filePath}{DELTA_SUFFIX}"; var baseSignature = $"{fileName}{SIG_SUFFIX}"; var baseSignaturePath = $"{localDir}/{baseSignature}"; string hashPattern = @"(?<=" + projectId + @"/)(.*)(?=\.zip$)"; string projectHash = new Regex(hashPattern).Match(fileKey).Value; clearOldFiles(baseMetaPath, baseSignaturePath, deltaPath); messageCb(COS_MSG.TITLE_DOWNLOADING_META_FILE, string.Format(COS_MSG.INFO_DOWNLOADING_META_FILE, baseMetaKey, $"{localDir}/{BASE_META}")); syncDownloadFile(deltaBucket, baseMetaKey, localDir, BASE_META, progressCb, DoNothing, failedCb); var metaInfo = JsonConvert.DeserializeObject <MetaInfo>(File.ReadAllText(baseMetaPath)); if ((float)new FileInfo(filePath).Length / metaInfo.baseFileSize > 1 + DELTA_THRESHOLD) { clearOldFiles(baseMetaPath); _InitProject(filePath, projectId, progressCb, messageCb, successCb, failedCb); return; } ucbFacade.InitDeltaUpload(new DeltaInfo { baseFileKey = metaInfo.baseFileName, deltaFileKey = $"{fileKey}{DELTA_SUFFIX}", newFileKey = fileKey, projectId = projectId, fileHash = projectHash }); messageCb(COS_MSG.TITLE_DOWNLOADING_SIG_FILE, string.Format(COS_MSG.INFO_DOWNLOADING_SIG_FILE, metaInfo.signatureKey, $"{localDir}/{baseSignature}")); syncDownloadFile(deltaBucket, metaInfo.signatureKey, localDir, baseSignature, progressCb, DoNothing, failedCb); messageCb(COS_MSG.TITLE_CREATING_DELTA_FILE, string.Format(COS_MSG.INFO_CREATING_DELTA_FILE, deltaPath, filePath, baseSignaturePath)); CreateDelta(filePath, baseSignaturePath, deltaPath); if ((float)new FileInfo(deltaPath).Length / metaInfo.baseFileSize > DELTA_THRESHOLD) { clearOldFiles(baseMetaPath, baseSignaturePath, deltaPath); _InitProject(filePath, projectId, progressCb, messageCb, successCb, failedCb); return; } messageCb(COS_MSG.TITLE_UPLOADING_DELTA_FILE, string.Format(COS_MSG.INFO_UPLOADING_DELTA_FILE, deltaKey)); UploadFile(deltaBucket, deltaKey, deltaPath, progressCb, delegate(CosResult uploadResult) { deltaPatch(metaInfo.baseFileName, fileKey, projectId, projectHash); clearOldFiles(baseMetaPath, baseSignaturePath, deltaPath); messageCb(COS_MSG.TITLE_PATCHING_DELTA_FILE, COS_MSG.INFO_PATCHING_DELTA_FILE); }, failedCb); }