Exemplo n.º 1
0
        /// <summary>
        /// 更新腾讯云的文件
        /// </summary>
        /// <param name="allCloudFiles"></param>
        public void UpdateTencentAll()
        {
            List <CloudFile> allCloudFiles = TencentBOSAPI.ListObjects();

            if (allCloudFiles == null)
            {
                allCloudFiles = new List <CloudFile>();
            }
            //获取数据库中所有的文件
            List <CloudFile> dbCloudFiles = CommonCloudFileService.Select(" isDeleted =0 and Type=1");

            List <CloudFile> addFiles = new List <CloudFile>();

            for (int sub = 0, size = allCloudFiles.Count; sub < size; sub++)
            {
                CloudFile tempBosObjectSummary = allCloudFiles[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, 1);
            }

            if (addFiles.Count > 0)
            {
                InsertTencentAll(addFiles);
            }
        }
Exemplo n.º 2
0
    public void Breakpointdownload()
    {
        string         key          = Thread.CurrentThread.Name;
        DownloadRecord downloadInfo = (DownloadRecord)DownloadRecordMap[key];



        while (CheckState(key))
        {
            DateTime startDateTime = DateTime.Now;
            double   excuteTime    = 0;
            long     start         = downloadInfo.DownloadSize;
            long     end           = start + DownloadSize;
            if (start != 0)
            {
                start += 1;
            }

            DownloadResult result = TencentBOSAPI.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;
            }
        }
    }