Beispiel #1
0
 IEnumerator CycleSaveFile(string filePath, GetDataCycleHandle handler)
 {
     using (FileStream file = File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
     {
         while (true)
         {
             if (handler != null)
             {
                 byte[] data = handler();
                 if (data != null)
                 {
                     file.Write(data, 0, data.Length);
                     file.Flush();
                     yield return(1);
                 }
                 else
                 {
                     break;
                 }
             }
             else
             {
                 break;
             }
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// 循环写入本地文件
        /// </summary>
        /// <param name="filePath">文件路径</param>
        /// <param name="handler">获取流资源方法</param>
        public virtual void WriteCycle(string filePath, GetDataCycleHandle handler)
        {
            //循环创建好文件夹
            string tmpFilePath = RecursiveCheckDir(filePath);

            if (string.IsNullOrEmpty(tmpFilePath))
            {
                throw new FileNotFoundException("文件路径有误---->" + filePath);
            }
            if (File.Exists(tmpFilePath))
            {
                File.Delete(tmpFilePath);
            }

            IEnumerator ienum = CycleSaveFile(filePath, handler);

            while (ienum.MoveNext())
            {
                ;
            }
        }
Beispiel #3
0
        /// <summary>
        /// 循环写入文件
        /// </summary>
        /// <param name="filePath">文件写入路径</param>
        /// <param name="handler">可以持续获取字节流的委托</param>
        public void WriteFileCycle(string filePath, GetDataCycleHandle handler)
        {
            FileHelper fileHelper = new FileHelper();

            lock (dic)
            {
GET_ID:
                fileHelper.Id = Guid.NewGuid().ToString();
                if (dic.ContainsKey(fileHelper.Id))
                {
                    goto GET_ID;
                }
                dic.Add(fileHelper.Id, fileHelper);
            }
            fileHelper.WriteCycle(filePath, handler);
            lock (dic)
            {
                if (dic.ContainsKey(fileHelper.Id))
                {
                    dic.Remove(fileHelper.Id);
                }
            }
        }
 public static void WriteFileCycle(string filePath, GetDataCycleHandle handler)
 {
     fileMgr.WriteFileCycle(filePath, handler);
 }