/[ThermoControl]/trunk/UnitTest.libThermoControl/Program.cs
ViewVC logotype

Contents of /trunk/UnitTest.libThermoControl/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 257 - (show annotations) (download)
Thu Jun 25 22:07:09 2015 UTC (5 years ago) by william
File size: 5649 byte(s)


1 #define UNITTEST_ENABLE_PAUSE
2
3 #define DISABLE_RELEASE_MODE_KLOGLEVEL_DEBUG // when defined will turn off kLogLevel_Debug messages, in release mode
4 //#define DISABLE_DEBUG_MODE_KLOGLEVEL_VERBOSE_DEBUG // when defined will turn off kLogLevel_VerboseDebug message, in debug mode
5
6 using Enterprise.Logging;
7 using libThermoControl;
8 using System;
9 using System.Linq;
10 using System.Collections.Generic;
11 using System.Diagnostics;
12 using System.IO;
13 using System.Text;
14 using System.Windows.Forms;
15
16 namespace UnitTest.libThermoControl
17 {
18 class Program
19 {
20 #region logging support
21 const long MAX_LOG_FILESIZE_IN_BYTES = 250000; //250kb max
22 static void TruncateLogFile(FileInfo log_file)
23 {
24 if (!log_file.Exists)
25 {
26 gLog.CreateLog(log_file.FullName, false, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush));
27 }
28 else
29 {
30 if (log_file.Length > MAX_LOG_FILESIZE_IN_BYTES)
31 {
32 string match = string.Format("{0}.*", log_file.Name);
33 var files = Directory.GetFiles(log_file.Directory.FullName, match).ToList();
34 files.RemoveAt(0);
35 files.TrimExcess();
36 int count = files.Count;
37 if (log_file.Exists)
38 {
39 File.Copy(log_file.FullName, string.Format("{0}.{1}", log_file.FullName, count));
40 }
41 gLog.CreateLog(log_file.FullName, true, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush));
42 }
43 else
44 {
45 gLog.CreateLog(log_file.FullName, false, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush));
46 }
47 }
48 }
49 StringBuilder log_flusher = new StringBuilder();
50 static void Log_OnFlush(object sender, LoggerOnFlushEventArgs e) { OnLogFlush(e.Buffer); }
51 static void OnLogFlush(string logmessage)
52 {
53 //if (this.IsDisposed) { return; }
54 ////UpdateStatus(logmessage);
55 ////UpdateLogOutput(logmessage);
56 //Application.DoEvents();
57 }
58 #endregion
59
60 #region Pause
61 [Conditional("UNITTEST_ENABLE_PAUSE")]
62 static void Pause()
63 {
64 Console.WriteLine("Press any key to continue.");
65 Console.ReadKey(true);
66 }
67 #endregion
68
69 static void Main(string[] args)
70 {
71 #region logging support
72 string log_path = Application.StartupPath;
73 string log_filename = string.Format("{0}.log", typeof(Program).Assembly.GetName().Name);
74 FileInfo log_file = new FileInfo(string.Format(@"{0}\{1}", log_path, log_filename));
75 TruncateLogFile(log_file);
76 #if DEBUG
77 LogLevel gLevel = gLog.LogLevel;
78 #if DISABLE_DEBUG_MODE_KLOGLEVEL_VERBOSE_DEBUG
79 gLevel &= ~LogLevel.kLogLevel_VerboseDebug;
80 #else
81 gLevel |= LogLevel.kLogLevel_VerboseDebug;
82 #endif
83 gLevel |= LogLevel.kLogLevel_Debug;
84 gLog.SetLogLevel(gLevel);
85 #else
86 LogLevel gLevel = LogLevel.kLogLevel_Default; // set the default log level: Info, Warn, Error, Debug
87 // it is OK for kLogLevel_Debug to be set in Release mode ... must of the chatty messages are from kLogLevel_VerboseDebug
88 #if DISABLE_RELEASE_MODE_KLOGLEVEL_DEBUG
89 gLevel &= ~LogLevel.kLogLevel_Debug;
90 #else
91 gLevel |= LogLevel.kLogLevel_Debug;
92 #endif
93 gLevel &= ~LogLevel.kLogLevel_VerboseDebug; // ensure this is not set, ever in release mode
94 gLog.SetLogLevel(gLevel);
95 #endif
96 #endregion
97 Controller c = new Controller();
98 //c.Reset();
99 ///* Example controller usage :
100 // c.SetFanOnlySpeed(FanOnlySpeedState.MEDIUM);
101 // c.SetFanMode(FanModeState.COOL);
102 // c.SetFanSpeed(FanSpeedState.AUTO);
103 // c.Reset();
104 // c.SetFanMode(FanModeState.COOL);
105 // c.SetFanMode(FanModeState.FANONLY);
106 // c.SetFanSpeed(FanSpeedState.MEDIUM);
107 // c.SetFanMode(FanModeState.FANONLY);
108 // c.Reset();
109 // */d
110
111
112 //ThermistatControls.SendButton(ACControls.TEMP_UP);
113 //ThermistatControls.SendButton(ACControls.TEMP_UP);
114 //ThermistatControls.SendButton(ACControls.TEMP_UP);
115 //ThermistatControls.SendButton(ACControls.TEMP_UP);
116 //ThermistatControls.SendButton(ACControls.TEMP_UP);
117 //ThermistatControls.SendButton(ACControls.TEMP_UP);
118
119 //ThermistatControls.SendButton(ACControls.TIMER);
120 //ThermistatControls.SendButton(ACControls.TIMER_UP);
121 //ThermistatControls.SendButton(ACControls.TIMER_UP);
122 //ThermistatControls.SendButton(ACControls.TIMER_UP);
123 //ThermistatControls.SendButton(ACControls.TEMP_UP);
124
125 var def = ThermistatControls.GetButtonByName("TEMP_TIMER_UP");
126 ThermistatControls.SendButton(def);
127 //Controller c = new Controller();
128 //c.Reset();
129
130 //ThermistatControls.SendButton(ACControls.POWER);
131 //Controller c = new Controller(@"c:\temp");
132
133 Pause();
134 }
135 }
136 }

  ViewVC Help
Powered by ViewVC 1.1.22