public static XElement CreateSingleDownloadXElement(BiliDashDownload viewModel)//单个视频创建XElement
        {
            var model = new DownloadXmlModel()
            {
                DownloadName    = viewModel.DownloadName,
                Title           = viewModel.Title,
                Bv              = viewModel.Bv,
                Cid             = viewModel.Cid,
                Quality         = viewModel.Quality,
                CacheFolderPath = viewModel.CacheFolder.Path,
                PartList        = new DownloadPartXmlModel[]
                {
                    new DownloadPartXmlModel()
                    {
                        TaskGuid         = viewModel.PartList[0].TaskGuid,
                        RestoreModelJson = viewModel.PartList[0].TaskRestoreModelJson
                    },
                    new DownloadPartXmlModel()
                    {
                        TaskGuid         = viewModel.PartList[1].TaskGuid,
                        RestoreModelJson = viewModel.PartList[1].TaskRestoreModelJson
                    }
                }
            };//建立xml模型,用于储存

            return(DownloadXmlModelToXElement(model));
        }
        public static async Task <IBiliDownload> RecreateAsync(DownloadXmlModel xml, string sessdata)
        {
            var video = await BiliVideoHelper.GetSingleVideoAsync(xml.Bv, xml.Cid, xml.Quality, sessdata);

            var partList = new List <IBiliDownloadPart>();

            var t1 = JsonConvert.DeserializeObject <DownloadTaskRestoreModel>(xml.PartList[0].RestoreModelJson);
            var t2 = JsonConvert.DeserializeObject <DownloadTaskRestoreModel>(xml.PartList[1].RestoreModelJson);

            t1.Url = video.VideoUrl;
            t2.Url = video.AudioUrl;

            var part1 = new BiliDashDownloadPart()//使用构造函数来创建实例,灵活
            {
                Task      = DownloadTask.Restore(t1),
                CacheFile = await StorageFile.GetFileFromPathAsync(t1.Path)
            };
            var part2 = new BiliDashDownloadPart()
            {
                Task      = DownloadTask.Restore(t2),
                CacheFile = await StorageFile.GetFileFromPathAsync(t2.Path)
            };

            partList.Add(part1);
            partList.Add(part2);

            var download = new BiliDashDownload()
            {
                DownloadName = xml.DownloadName,
                Bv           = xml.Bv,
                Cid          = xml.Cid,
                Quality      = xml.Quality,
                VideoUrl     = video.VideoUrl,
                AudioUrl     = video.AudioUrl,
                CacheFolder  = await StorageFolder.GetFolderFromPathAsync(xml.CacheFolderPath),
                PartList     = partList,
                Title        = xml.Title
            };

            download.ChineseStatus = "已暂停";
            ulong currentProgress = 0;
            ulong fullProgress    = 0;

            foreach (var part in partList)
            {
                currentProgress += part.Task.DownloadedBytes;
                fullProgress    += part.Task.TotalBytes;
            }
            download.CurrentProgress = currentProgress;
            download.FullProgress    = fullProgress;
            download.currentSpeed    = 0;
            download.IsPaused        = true;

            return(download);
        }
        private static XElement DownloadXmlModelToXElement(DownloadXmlModel model)
        {
            var downloadXElement = new XElement("Download",
                                                new XElement("Name", model.DownloadName),
                                                new XElement("Title", model.Title),
                                                new XElement("Bv", model.Bv),
                                                new XElement("Cid", model.Cid),
                                                new XElement("Quality", model.Quality),
                                                new XElement("CacheFolderPath", model.CacheFolderPath),
                                                new XElement("Parts",
                                                             new XElement("Part",
                                                                          new XElement("TaskGuid", model.PartList[0].TaskGuid.ToString()),
                                                                          new XElement("RestoreModelJson", model.PartList[0].RestoreModelJson)),
                                                             new XElement("Part",
                                                                          new XElement("TaskGuid", model.PartList[1].TaskGuid.ToString()),
                                                                          new XElement("RestoreModelJson", model.PartList[1].RestoreModelJson))));

            return(downloadXElement);
        }