Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
TemporaryProgressStream.cs
1using System.Threading;
2using System.Threading.Tasks;
3using Waher.Events;
4
6{
12 {
13 private long nrReadTotal = 0;
14 private long nrWrittenTotal = 0;
15
21 : base()
22 {
23 }
24
30 public TemporaryProgressStream(int BufferSize)
31 : base(BufferSize)
32 {
33 }
34
38 public event EventHandlerAsync<IoBytesEventArgs> OnRead;
39
43 public event EventHandlerAsync<IoBytesEventArgs> OnWrite;
44
46 public override void Write(byte[] array, int offset, int count)
47 {
48 base.Write(array, offset, count);
49
50 this.nrWrittenTotal += count;
51 this.OnWrite.Raise(this, new IoBytesEventArgs(count, this.nrWrittenTotal));
52 }
53
55 public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
56 {
57 await base.WriteAsync(buffer, offset, count, cancellationToken);
58
59 this.nrWrittenTotal += count;
60 await this.OnWrite.Raise(this, new IoBytesEventArgs(count, this.nrWrittenTotal));
61 }
62
64 public override void WriteByte(byte value)
65 {
66 base.WriteByte(value);
67
68 this.nrWrittenTotal++;
69 this.OnWrite.Raise(this, new IoBytesEventArgs(1, this.nrWrittenTotal));
70 }
71
73 public override int Read(byte[] array, int offset, int count)
74 {
75 int i = base.Read(array, offset, count);
76
77 if (i > 0)
78 {
79 this.nrReadTotal += i;
80 this.OnRead.Raise(this, new IoBytesEventArgs(i, this.nrReadTotal));
81 }
82
83 return i;
84 }
85
87 public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
88 {
89 int i = await base.ReadAsync(buffer, offset, count, cancellationToken);
90
91 if (i > 0)
92 {
93 this.nrReadTotal += i;
94 await this.OnRead.Raise(this, new IoBytesEventArgs(i, this.nrReadTotal));
95 }
96
97 return i;
98 }
99
101 public override int ReadByte()
102 {
103 int i = base.ReadByte();
104 if (i < 0)
105 return i;
106
107 this.nrReadTotal++;
108 this.OnRead.Raise(this, new IoBytesEventArgs(i, this.nrReadTotal));
109
110 return i;
111 }
112
113 }
114}
Event arguments for an I/O bytes event.
Class managing the contents of a temporary stream. When the class is disposed, any temporary file is ...
TemporaryProgressStream(int BufferSize)
Class managing the contents of a temporary stream. When the class is disposed, any temporary file is ...
TemporaryProgressStream()
Class managing the contents of a temporary stream. When the class is disposed, any temporary file is ...
override int Read(byte[] array, int offset, int count)
EventHandlerAsync< IoBytesEventArgs > OnRead
Event raised when data has been read from the file.
EventHandlerAsync< IoBytesEventArgs > OnWrite
Event raised when data has been written to the file.
override async Task< int > ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
override void Write(byte[] array, int offset, int count)
override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Manages a temporary stream. Contents is kept in-memory, if below a memory threshold,...