/[ThermoControl]/trunk/libThermoControl/Configuration.cs
ViewVC logotype

Diff of /trunk/libThermoControl/Configuration.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/libThermoControl/Configuration.cs	2013/11/13 01:51:18	17
+++ trunk/libThermoControl/Configuration.cs	2013/11/13 02:22:43	20
@@ -12,6 +12,10 @@
     public static class Configuration
     {
         private const string config_file = "config.xml";
+        private const string temp_file = "current_temp.bin";
+        
+        
+        public static int CurrentTemp { get { return ReadTemp(); } set { WriteTemp(value); } }
 
         public static readonly string THERMISTAT_DEVICE = ""; // 60
         public static readonly int MIN_TEMP = 0; // 60
@@ -56,6 +60,49 @@
                     field.SetValue(null, Convert.ChangeType(t,field.FieldType));
                 }
             }
+
+            // get the current temp from file
+            //ReadTemp();
+        }
+
+        static void WriteTemp(int temp)
+        {
+            using (FileStream fs = new FileStream(temp_file, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
+            {
+                using (BinaryWriter bw = new BinaryWriter(fs))
+                {
+                    bw.Write(temp);
+                    bw.Flush();
+                    bw.Close();
+                }
+            }
+        }
+        static int ReadTemp()
+        {
+            int temp = 0;
+            if (!File.Exists(temp_file))
+            {
+                WriteTemp(Configuration.DEFAULT_TEMP);
+            }
+            else
+            {
+                FileInfo fi = new FileInfo(temp_file);
+                if (fi.Length == 0)
+                {
+                    WriteTemp(Configuration.DEFAULT_TEMP);
+                }
+            }
+
+
+            using (FileStream fs = new FileStream(temp_file, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read))
+            {
+                using (BinaryReader br = new BinaryReader(fs))
+                {
+                    temp = br.ReadInt32();
+                    br.Close();
+                }
+            }
+            return temp;
         }
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22