/// <summary> /// 更新百度云所有文件 /// </summary> /// <param name="bosObjectSummarys"></param> public void UpdateBaiduAll() { List <BosObjectSummary> bosObjectSummarys = BaiduBOSAPI.ListObjects(); if (bosObjectSummarys == null) { bosObjectSummarys = new List <BosObjectSummary>(); } //获取数据库中所有的文件 List <CloudFile> dbCloudFiles = CommonCloudFileService.Select(" isDeleted =0 and Type=0"); List <BosObjectSummary> addFiles = new List <BosObjectSummary>(); for (int sub = 0, size = bosObjectSummarys.Count; sub < size; sub++) { BosObjectSummary tempBosObjectSummary = bosObjectSummarys[sub]; CloudFile cloudFileResult = null; Boolean isFind = false; for (int innerSub = 0, innerSize = dbCloudFiles.Count; innerSub < innerSize; innerSub++) { CloudFile tempCloudFile = dbCloudFiles[innerSub]; if (string.Equals(tempCloudFile.Key, tempBosObjectSummary.Key)) { isFind = true; cloudFileResult = tempCloudFile; break; } } //如果发现 则删除 避免重复匹配,以及筛选已删除的文件 if (isFind) { dbCloudFiles.Remove(cloudFileResult); } else { //如果未匹配到 则表示为新增的文件 addFiles.Add(tempBosObjectSummary); } } if (dbCloudFiles != null && dbCloudFiles.Count > 0) { CommonCloudFileService.RemoveByKeys(dbCloudFiles, 0); } if (addFiles.Count > 0) { InsertBaiduAll(addFiles); } }
public void Breakpointdownload() { string key = Thread.CurrentThread.Name; DownloadRecord downloadInfo = (DownloadRecord)DownloadRecordMap[key]; double excuteTime = 0; while (CheckState(key)) { DateTime startDateTime = DateTime.Now; long start = downloadInfo.DownloadSize; long end = start + DownloadSize; if (start != 0) { start += 1; } DownloadResult result = BaiduBOSAPI.DownloadObject(downloadInfo, downloadInfo.TargetFolder, start, end); TimeSpan ts = DateTime.Now - startDateTime; excuteTime = Convert.ToDouble(ts.TotalMilliseconds.ToString()) / 1000; if (excuteTime == 0) { excuteTime = 0.01; } downloadInfo.DownloadSize = end; downloadInfo.Time = downloadInfo.Time + excuteTime; DownloadRecordService.UpdateDownloadSizeAndTime(downloadInfo); Constant.Win.ExecuteJavascript("changeDownloadPercent('" + JsonConvert.SerializeObject(downloadInfo) + "')"); if (result.isDone()) { FinishDownload(key); //调用js通知下载完成 Constant.Win.ExecuteJavascript("downloadDone('" + JsonConvert.SerializeObject(downloadInfo) + "')"); break; } else if (result.isCloudMiss()) { Constant.Win.ExecuteJavascript("downloadMiss('" + JsonConvert.SerializeObject(downloadInfo) + "')"); DownloadRecordService.UpdateDowloadState(downloadInfo.Id, 3); break; } } }
private void LoadHandler_OnLoadStart(object sender, Chromium.Event.CfxOnLoadStartEventArgs e) { //初始化数据库 Db.InitDB(); //初始化表 BosConfigService.CreateBOSConfigTable(); CommonCloudFileService.CreateCloudFileTable(); DownloadRecordService.CreateDownloadRecordTable(); //初始化配置信息 BaiduBOSAPI.SetBosConfig(BosConfigService.Get(" Type=0")); TencentBOSAPI.BosConfig = BosConfigService.Get(" Type=1"); //继续下载未下载完成的文件 DownloadRecordService.StartBaiduDownloading(); DownloadRecordService.StartTencentDownloading(); }
public void addFunction(JSObject myObject) { //修改配置 var editBosConfigFunc = myObject.AddFunction("editBosConfig"); editBosConfigFunc.Execute += (func, args) => { var jsparams = args.Arguments.FirstOrDefault(p => p.IsArray); var jsArray = CfrV8Value.CreateArray(1); BosConfig bosConfig = new BosConfig(); bosConfig.AccessKeyId = jsparams.GetValue(0).StringValue; bosConfig.AccessKey = jsparams.GetValue(1).StringValue; bosConfig.BucketName = jsparams.GetValue(2).StringValue; bosConfig.Endpoint = jsparams.GetValue(3).StringValue; bosConfig.Id = jsparams.GetValue(4).IntValue; bosConfig.AppId = jsparams.GetValue(5).StringValue; Result result = new Result(); BosConfig beforeBosConfig = Constant.CloudType == 0 ? BaiduBOSAPI.BosConfig : TencentBOSAPI.BosConfig; try { BaiduBOSAPI.SetBosConfig(bosConfig); if (Constant.CloudType == 0) { BaiduBOSAPI.BosConfig = bosConfig; BaiduCloudFileService.UpdateBaiduAll(); } else { TencentBOSAPI.BosConfig = bosConfig; TencentCloudFileService.UpdateTencentAll(); } BosConfigService.Update(bosConfig); } catch (Exception exception) { Console.WriteLine("Exception caught: {0}", exception); result.State = 4; result.Msg = "配置信息错误,请检查后再次提交"; if (Constant.CloudType == 0) { BaiduBOSAPI.SetBosConfig(beforeBosConfig); } else { TencentBOSAPI.BosConfig = beforeBosConfig; } } jsArray.SetValue(0, CfrV8Value.CreateString(JsonConvert.SerializeObject(result))); args.SetReturnValue(jsArray); }; //获取配置信息 var getBosConfigFunc = myObject.AddFunction("getBosConfig"); getBosConfigFunc.Execute += (func, args) => { var jsArray = CfrV8Value.CreateArray(1); Result result = new Result(); BosConfig config = BosConfigService.Get(" Type=" + Constant.CloudType); if (config == null) { config = new BosConfig(); } config.Type = Constant.CloudType; result.Data = config; jsArray.SetValue(0, CfrV8Value.CreateString(JsonConvert.SerializeObject(result))); args.SetReturnValue(jsArray); }; }