/// <summary> /// 是否完成。 /// </summary> /// <returns>true表示完成;false表示未完成。</returns> protected override bool IsDone() { if (!File.Exists(this.filePath)) { this.completed = true; } else if (null == this.stream) { try { this.stream = new FileStream(this.filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); this.bytes = new byte[this.stream.Length]; this.stream.BeginRead(this.bytes, 0, this.bytes.Length, new AsyncCallback(_OnReadComplete), null); } catch (Exception e) { AnyLogger.X(e); this.stream = null; } } return(this.completed); }
/// <summary> /// 是否完成。 /// </summary> /// <returns>true表示完成;false表示未完成。</returns> protected override bool IsDone() { if (null == this.stream) { try { var info = new FileInfo(this.filePath); if (!Directory.Exists(info.DirectoryName)) { Directory.CreateDirectory(info.DirectoryName); } this.stream = new FileStream(this.filePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite); this.stream.Seek(0, (SeekOrigin)this.mode); this.stream.BeginWrite(this.bytes, 0, this.bytes.Length, new AsyncCallback(_OnWriteComplete), null); } catch (Exception e) { AnyLogger.X(e); this.stream = null; } } return(this.completed); }