protected override Stream DoGetInputStream(out string encoding, FileMode mode, FileShare sharing) { Stream retval; lock (this) { long? length = 0; bool error = false; DateTime?creationTime = null; DateTime?lastWriteTime = null; this.file.Attributes.Refresh(); this.shadowFile.Attributes.Refresh(); try { if (this.file.Exists) { length = this.file.Length ?? 0; creationTime = this.file.Attributes.CreationTime; lastWriteTime = this.file.Attributes.LastWriteTime; } else { error = true; } } catch (IOException) { error = true; } if (!error && length == this.shadowFile.Length && creationTime == this.shadowFile.Attributes.CreationTime && lastWriteTime == this.shadowFile.Attributes.LastWriteTime && (mode == FileMode.Open || mode == FileMode.OpenOrCreate)) { try { retval = new ShadowInputStream(this.file.GetContent().GetInputStream(out encoding, sharing), this.file); return(retval); } catch (IOException) { } } this.file = this.tempFileSystem.ResolveFile(GenerateName()); switch (mode) { case FileMode.Create: this.file.Create(); break; case FileMode.CreateNew: if (this.shadowFile.Exists) { throw new IOException("File exists"); } this.file.Create(); break; case FileMode.OpenOrCreate: try { this.shadowFile.CopyTo(this.file, true); } catch (FileNotFoundException) { this.file.Create(); } break; case FileMode.Open: default: this.file.ParentDirectory.Create(true); this.shadowFile.CopyTo(this.file, true); break; } this.file.Attributes.CreationTime = this.shadowFile.Attributes.CreationTime; this.file.Attributes.LastWriteTime = this.shadowFile.Attributes.LastWriteTime; retval = new ShadowInputStream(this.file.GetContent().GetInputStream(out encoding, sharing), this.file); return(retval); } }
protected override Stream DoGetInputStream(out string encoding, FileMode mode, FileShare sharing) { Stream retval; lock (this) { long? length = 0; bool error = false; DateTime? creationTime = null; DateTime? lastWriteTime = null; this.file.Attributes.Refresh(); this.shadowFile.Attributes.Refresh(); try { if (this.file.Exists) { length = this.file.Length ?? 0; creationTime = this.file.Attributes.CreationTime; lastWriteTime = this.file.Attributes.LastWriteTime; } else { error = true; } } catch (IOException) { error = true; } if (!error && length == this.shadowFile.Length && creationTime == this.shadowFile.Attributes.CreationTime && lastWriteTime == this.shadowFile.Attributes.LastWriteTime && (mode == FileMode.Open || mode == FileMode.OpenOrCreate)) { try { retval = new ShadowInputStream(this.file.GetContent().GetInputStream(out encoding, sharing), this.file); return retval; } catch (IOException) { } } this.file = this.tempFileSystem.ResolveFile(GenerateName()); switch (mode) { case FileMode.Create: this.file.Create(); break; case FileMode.CreateNew: if (this.shadowFile.Exists) { throw new IOException("File exists"); } this.file.Create(); break; case FileMode.OpenOrCreate: try { this.shadowFile.CopyTo(this.file, true); } catch (FileNotFoundException) { this.file.Create(); } break; case FileMode.Open: default: this.file.ParentDirectory.Create(true); this.shadowFile.CopyTo(this.file, true); break; } this.file.Attributes.CreationTime = this.shadowFile.Attributes.CreationTime; this.file.Attributes.LastWriteTime = this.shadowFile.Attributes.LastWriteTime; retval = new ShadowInputStream(this.file.GetContent().GetInputStream(out encoding, sharing), this.file); return retval; } }