Exemple #1
0
        /// <summary>
        /// 保存断点信息到文件
        /// </summary>
        /// <param name="resumeInfo">断点信息</param>
        /// <param name="recordFile">断点记录文件</param>
        public static async Task SaveAsync(ResumeInfo resumeInfo, StorageFile recordFile)
        {
            string jsonStr = string.Format("{{\"fileSize\":{0}, \"blockIndex\":{1}, \"blockCount\":{2}, \"contexts\":[{3}]}}",
                                           resumeInfo.FileSize, resumeInfo.BlockIndex, resumeInfo.BlockCount, StringHelper.JsonJoin(resumeInfo.Contexts));

            await FileIO.WriteTextAsync(recordFile, jsonStr);
        }
Exemple #2
0
        /// <summary>
        /// 保存断点信息到文件
        /// </summary>
        /// <param name="resumeInfo">断点信息</param>
        /// <param name="recordFile">断点记录文件</param>
        public static void Save(ResumeInfo resumeInfo, string recordFile)
        {
            string jsonStr = string.Format("{{\"fileSize\":{0}, \"blockIndex\":{1}, \"blockCount\":{2}, \"contexts\":[{3}]}}",
                                           resumeInfo.FileSize, resumeInfo.BlockIndex, resumeInfo.BlockCount, StringHelper.JsonJoin(resumeInfo.Contexts));

            using (FileStream fs = new FileStream(recordFile, FileMode.Create))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    sw.Write(jsonStr);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// 尝试从从文件载入断点信息
        /// </summary>
        /// <param name="recordFile">断点记录文件</param>
        /// <returns>断点信息</returns>
        public static async Task <ResumeInfo> LoadAsync(StorageFile recordFile)
        {
            ResumeInfo resumeInfo = null;

            try
            {
                JsonHelper.Deserialize(await FileIO.ReadTextAsync(recordFile), out resumeInfo);
            }
            catch (Exception)
            {
                resumeInfo = null;
            }

            return(resumeInfo);
        }
Exemple #4
0
        /// <summary>
        /// 尝试从从文件载入断点信息
        /// </summary>
        /// <param name="recordFile">断点记录文件</param>
        /// <returns>断点信息</returns>
        public static async Task <ResumeInfo> LoadAsync(StorageFile recordFile)
        {
            ResumeInfo resumeInfo = null;

            try
            {
                JsonConvert.DeserializeObject <ResumeInfo>(await FileIO.ReadTextAsync(recordFile));
            }
            catch (Exception)
            {
                resumeInfo = null;
            }

            return(resumeInfo);
        }
Exemple #5
0
        /// <summary>
        /// 尝试从从文件载入断点信息
        /// </summary>
        /// <param name="recordFile">断点记录文件</param>
        /// <returns>断点信息</returns>
        public static ResumeInfo Load(string recordFile)
        {
            ResumeInfo resumeInfo = null;

            try
            {
                using (FileStream fs = new FileStream(recordFile, FileMode.Open))
                {
                    using (StreamReader sr = new StreamReader(fs))
                    {
                        string jsonStr = sr.ReadToEnd();
                        JsonHelper.Deserialize(jsonStr, out resumeInfo);
                    }
                }
            }
            catch (Exception)
            {
                resumeInfo = null;
            }

            return(resumeInfo);
        }
Exemple #6
0
        /// <summary>
        /// 尝试从从文件载入断点信息
        /// </summary>
        /// <param name="recordFile">断点记录文件</param>
        /// <returns>断点信息</returns>
        public static async Task <ResumeInfo> LoadAsync(string recordFile)
        {
            ResumeInfo resumeInfo = null;

            try
            {
                using (FileStream fs = new FileStream(recordFile, FileMode.Open))
                {
                    using (StreamReader sr = new StreamReader(fs))
                    {
                        string jsonStr = await sr.ReadToEndAsync();

                        resumeInfo = JsonConvert.DeserializeObject <ResumeInfo>(jsonStr);
                    }
                }
            }
            catch (Exception)
            {
                resumeInfo = null;
            }

            return(resumeInfo);
        }