コード例 #1
0
        private static async Task UploadWork(FileQueue file)
        {
            file.Status = "上传中";
            if (file.SendListLock == null)
            {
                file.SendListLock = new object();
            }
            bool isComplete = true;

            Program.Log($"文件{file.FileName}上传中...");
            for (int i = 0; i < file.SendList.Count; i++)
            {
                SendQueue itm = file.SendList[i];
                if (itm.IsSendOver)
                {
                    continue;
                }
                itm.Status       = "上传中";
                file.SendList[i] = itm;
                FileQueue.Save();
                Program.Log($"-->Part {i + 1} 正在上传");
                bool flag = await UploadBlock(itm);

                itm.IsSendOver = flag;
                if (itm.IsSendOver)
                {
                    Program.Log($"   -->[ok]Part {i + 1} 上传成功,总计 {file.SendList.Count}");
                    itm.Status = "已上传";
                }
                else
                {
                    isComplete = false;
                    Program.Log($"   -->[fail]Part {i+1} 上传失败,等待下次重传");
                }
                file.SendList[i]  = itm;
                file.CurrentIndex = i + 1;
                FileQueue.Save();
            }
            if (isComplete)
            {
                Program.Log($"文件{file.FileName}上传成功!");
                FileQueue.RemoveFirst();
                FileQueue.Save();
            }
            else
            {
                Program.Log($"文件{file.FileName}部分块上传失败,等待重传");
            }
        }
コード例 #2
0
        static void Run(string path = "")
        {
            if (!string.IsNullOrEmpty(path))
            {
                if (Directory.Exists(path))
                {
                    Log("检测到文件夹,读取文件中...");
                    DirectoryInfo dinfo = new DirectoryInfo(path);
                    foreach (var f in dinfo.GetFiles())
                    {
                        FileQueue.Add(f.FullName);
                    }
                    FileQueue.Save();
                }
                else
                {
                    if (!File.Exists(path))
                    {
                        Log("文件不存在");
                    }
                    else
                    {
                        Log("新增文件...");
                        FileQueue.Add(path);
                        FileQueue.Save();
                    }
                }
            }

            try
            {
                LoopUploader.StartWork();
            }
            catch (Exception e)
            {
                Log(e.ToString());
            }
        }