Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
TemporaryFile.cs
1using System;
2using System.IO;
3using Waher.Events;
4
6{
10 public class TemporaryFile : FileStream
11 {
15 public const int DefaultBufferSize = 16384;
16
17 private string fileName;
18 private bool deleteWhenDisposed = true;
19
24 : this(Path.GetTempFileName(), DefaultBufferSize)
25 {
26 }
27
32 public TemporaryFile(string FileName)
34 {
35 }
36
42 public TemporaryFile(string FileName, int BufferSize)
43 : base(FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read, BufferSize, FileOptions.RandomAccess)
44 {
45 this.fileName = FileName;
46 }
47
51 public string FileName => this.fileName;
52
57 {
58 get => this.deleteWhenDisposed;
59 set => this.deleteWhenDisposed = value;
60 }
61
65 protected override void Dispose(bool disposing)
66 {
67 base.Dispose(disposing);
68
69 if (!(this.fileName is null))
70 {
71 if (this.deleteWhenDisposed)
72 {
73 try
74 {
75 File.Delete(this.fileName);
76 }
77 catch (Exception ex)
78 {
79 Log.Exception(ex);
80 }
81 }
82
83 this.fileName = null;
84 }
85 }
86 }
87}
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:13
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Definition: Log.cs:1647
Class managing the contents of a temporary file. When the class is disposed, the temporary file is de...
override void Dispose(bool disposing)
Disposes of the object, and deletes the temporary file.
bool DeleteWhenDisposed
Delete file when object is disposed.
TemporaryFile(string FileName)
Class managing the contents of a temporary file. When the class is disposed, the temporary file is de...
const int DefaultBufferSize
Default buffer size, in bytes.
TemporaryFile()
Class managing the contents of a temporary file. When the class is disposed, the temporary file is de...
TemporaryFile(string FileName, int BufferSize)
Class managing the contents of a temporary file. When the class is disposed, the temporary file is de...