@@ -19,106 +19,106 @@ internal class Sensor : ISensor {
1919 private float ? currentValue ;
2020 private float ? minValue ;
2121 private float ? maxValue ;
22- private readonly RingCollection < SensorValue >
22+ private readonly RingCollection < SensorValue >
2323 values = new RingCollection < SensorValue > ( ) ;
2424 private readonly ISettings settings ;
2525 private IControl control ;
26-
26+
2727 private float sum ;
2828 private int count ;
29-
29+
3030 public Sensor ( string name , int index , SensorType sensorType ,
31- Hardware hardware , ISettings settings ) :
31+ Hardware hardware , ISettings settings ) :
3232 this ( name , index , sensorType , hardware , null , settings ) { }
3333
3434 public Sensor ( string name , int index , SensorType sensorType ,
35- Hardware hardware , ParameterDescription [ ] parameterDescriptions ,
35+ Hardware hardware , ParameterDescription [ ] parameterDescriptions ,
3636 ISettings settings ) :
3737 this ( name , index , false , sensorType , hardware ,
3838 parameterDescriptions , settings ) { }
3939
40- public Sensor ( string name , int index , bool defaultHidden ,
41- SensorType sensorType , Hardware hardware ,
42- ParameterDescription [ ] parameterDescriptions , ISettings settings )
43- {
40+ public Sensor ( string name , int index , bool defaultHidden ,
41+ SensorType sensorType , Hardware hardware ,
42+ ParameterDescription [ ] parameterDescriptions , ISettings settings )
43+ {
4444 this . index = index ;
4545 this . defaultHidden = defaultHidden ;
4646 this . sensorType = sensorType ;
4747 this . hardware = hardware ;
4848 Parameter [ ] parameters = new Parameter [ parameterDescriptions == null ?
4949 0 : parameterDescriptions . Length ] ;
50- for ( int i = 0 ; i < parameters . Length ; i ++ )
50+ for ( int i = 0 ; i < parameters . Length ; i ++ )
5151 parameters [ i ] = new Parameter ( parameterDescriptions [ i ] , this , settings ) ;
5252 this . parameters = parameters ;
5353
5454 this . settings = settings ;
55- this . defaultName = name ;
55+ this . defaultName = name ;
5656 this . name = settings . GetValue (
5757 new Identifier ( Identifier , "name" ) . ToString ( ) , name ) ;
5858
59- GetSensorValuesFromSettings ( ) ;
60-
61- hardware . Closing += delegate ( IHardware h ) {
62- SetSensorValuesToSettings ( ) ;
63- } ;
64- }
65-
66- private void SetSensorValuesToSettings ( ) {
67- using ( MemoryStream m = new MemoryStream ( ) ) {
68- using ( GZipStream c = new GZipStream ( m , CompressionMode . Compress ) )
69- using ( BufferedStream b = new BufferedStream ( c , 65536 ) )
70- using ( BinaryWriter writer = new BinaryWriter ( b ) ) {
71- long t = 0 ;
72- foreach ( SensorValue sensorValue in values ) {
73- long v = sensorValue . Time . ToBinary ( ) ;
74- writer . Write ( v - t ) ;
75- t = v ;
76- writer . Write ( sensorValue . Value ) ;
77- }
78- writer . Flush ( ) ;
79- }
80- settings . SetValue ( new Identifier ( Identifier , "values" ) . ToString ( ) ,
81- Convert . ToBase64String ( m . ToArray ( ) ) ) ;
82- }
83- }
84-
85- private void GetSensorValuesFromSettings ( ) {
86- string name = new Identifier ( Identifier , "values" ) . ToString ( ) ;
87- string s = settings . GetValue ( name , null ) ;
88-
89- try {
90- byte [ ] array = Convert . FromBase64String ( s ) ;
91- s = null ;
92- DateTime now = DateTime . UtcNow ;
93- using ( MemoryStream m = new MemoryStream ( array ) )
94- using ( GZipStream c = new GZipStream ( m , CompressionMode . Decompress ) )
95- using ( BinaryReader reader = new BinaryReader ( c ) ) {
96- try {
97- long t = 0 ;
98- while ( true ) {
99- t += reader . ReadInt64 ( ) ;
100- DateTime time = DateTime . FromBinary ( t ) ;
101- if ( time > now )
102- break ;
103- float value = reader . ReadSingle ( ) ;
104- AppendValue ( value , time ) ;
105- }
106- } catch ( EndOfStreamException ) { }
107- }
108- } catch { }
109- if ( values . Count > 0 )
110- AppendValue ( float . NaN , DateTime . UtcNow ) ;
111-
112- // remove the value string from the settings to reduce memory usage
113- settings . Remove ( name ) ;
114- }
59+ // GetSensorValuesFromSettings();
60+
61+ // hardware.Closing += delegate(IHardware h) {
62+ // SetSensorValuesToSettings();
63+ // };
64+ }
65+
66+ // private void SetSensorValuesToSettings() {
67+ // using (MemoryStream m = new MemoryStream()) {
68+ // using (GZipStream c = new GZipStream(m, CompressionMode.Compress))
69+ // using (BufferedStream b = new BufferedStream(c, 65536))
70+ // using (BinaryWriter writer = new BinaryWriter(b)) {
71+ // long t = 0;
72+ // foreach (SensorValue sensorValue in values) {
73+ // long v = sensorValue.Time.ToBinary();
74+ // writer.Write(v - t);
75+ // t = v;
76+ // writer.Write(sensorValue.Value);
77+ // }
78+ // writer.Flush();
79+ // }
80+ // settings.SetValue(new Identifier(Identifier, "values").ToString(),
81+ // Convert.ToBase64String(m.ToArray()));
82+ // }
83+ // }
84+ //
85+ // private void GetSensorValuesFromSettings() {
86+ // string name = new Identifier(Identifier, "values").ToString();
87+ // string s = settings.GetValue(name, null);
88+ //
89+ // try {
90+ // byte[] array = Convert.FromBase64String(s);
91+ // s = null;
92+ // DateTime now = DateTime.UtcNow;
93+ // using (MemoryStream m = new MemoryStream(array))
94+ // using (GZipStream c = new GZipStream(m, CompressionMode.Decompress))
95+ // using (BinaryReader reader = new BinaryReader(c)) {
96+ // try {
97+ // long t = 0;
98+ // while (true) {
99+ // t += reader.ReadInt64();
100+ // DateTime time = DateTime.FromBinary(t);
101+ // if (time > now)
102+ // break;
103+ // float value = reader.ReadSingle();
104+ // AppendValue(value, time);
105+ // }
106+ // } catch (EndOfStreamException) { }
107+ // }
108+ // } catch { }
109+ // if (values.Count > 0)
110+ // AppendValue(float.NaN, DateTime.UtcNow);
111+ //
112+ // // remove the value string from the settings to reduce memory usage
113+ // settings.Remove(name);
114+ // }
115115
116116 private void AppendValue ( float value , DateTime time ) {
117- if ( values . Count >= 2 && values . Last . Value == value &&
117+ if ( values . Count >= 2 && values . Last . Value == value &&
118118 values [ values . Count - 2 ] . Value == value ) {
119119 values . Last = new SensorValue ( value , time ) ;
120120 return ;
121- }
121+ }
122122
123123 values . Append ( new SensorValue ( value , time ) ) ;
124124 }
@@ -140,13 +140,13 @@ public Identifier Identifier {
140140 }
141141
142142 public string Name {
143- get {
144- return name ;
143+ get {
144+ return name ;
145145 }
146146 set {
147- if ( ! string . IsNullOrEmpty ( value ) )
148- name = value ;
149- else
147+ if ( ! string . IsNullOrEmpty ( value ) )
148+ name = value ;
149+ else
150150 name = defaultName ;
151151 settings . SetValue ( new Identifier ( Identifier , "name" ) . ToString ( ) , name ) ;
152152 }
@@ -165,8 +165,8 @@ public IReadOnlyArray<IParameter> Parameters {
165165 }
166166
167167 public float ? Value {
168- get {
169- return currentValue ;
168+ get {
169+ return currentValue ;
170170 }
171171 set {
172172 DateTime now = DateTime . UtcNow ;
@@ -204,7 +204,7 @@ public void ResetMax() {
204204
205205 public IEnumerable < SensorValue > Values {
206206 get { return values ; }
207- }
207+ }
208208
209209 public void Accept ( IVisitor visitor ) {
210210 if ( visitor == null )
0 commit comments