12 |
public static class Configuration |
public static class Configuration |
13 |
{ |
{ |
14 |
private const string config_file = "config.xml"; |
private const string config_file = "config.xml"; |
15 |
|
private const string temp_file = "current_temp.bin"; |
16 |
|
|
17 |
|
|
18 |
|
public static int CurrentTemp { get { return ReadTemp(); } set { WriteTemp(value); } } |
19 |
|
|
20 |
public static readonly string THERMISTAT_DEVICE = ""; // 60 |
public static readonly string THERMISTAT_DEVICE = ""; // 60 |
21 |
public static readonly int MIN_TEMP = 0; // 60 |
public static readonly int MIN_TEMP = 0; // 60 |
60 |
field.SetValue(null, Convert.ChangeType(t,field.FieldType)); |
field.SetValue(null, Convert.ChangeType(t,field.FieldType)); |
61 |
} |
} |
62 |
} |
} |
63 |
|
|
64 |
|
// get the current temp from file |
65 |
|
//ReadTemp(); |
66 |
|
} |
67 |
|
|
68 |
|
static void WriteTemp(int temp) |
69 |
|
{ |
70 |
|
using (FileStream fs = new FileStream(temp_file, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read)) |
71 |
|
{ |
72 |
|
using (BinaryWriter bw = new BinaryWriter(fs)) |
73 |
|
{ |
74 |
|
bw.Write(temp); |
75 |
|
bw.Flush(); |
76 |
|
bw.Close(); |
77 |
|
} |
78 |
|
} |
79 |
|
} |
80 |
|
static int ReadTemp() |
81 |
|
{ |
82 |
|
int temp = 0; |
83 |
|
if (!File.Exists(temp_file)) |
84 |
|
{ |
85 |
|
WriteTemp(Configuration.DEFAULT_TEMP); |
86 |
|
} |
87 |
|
else |
88 |
|
{ |
89 |
|
FileInfo fi = new FileInfo(temp_file); |
90 |
|
if (fi.Length == 0) |
91 |
|
{ |
92 |
|
WriteTemp(Configuration.DEFAULT_TEMP); |
93 |
|
} |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
|
using (FileStream fs = new FileStream(temp_file, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read)) |
98 |
|
{ |
99 |
|
using (BinaryReader br = new BinaryReader(fs)) |
100 |
|
{ |
101 |
|
temp = br.ReadInt32(); |
102 |
|
br.Close(); |
103 |
|
} |
104 |
|
} |
105 |
|
return temp; |
106 |
} |
} |
107 |
} |
} |
108 |
} |
} |