/[gr2lib]/trunk/gr2lib/core/coretypes/implementation/granny_log_callback_builder.cs
ViewVC logotype

Diff of /trunk/gr2lib/core/coretypes/implementation/granny_log_callback_builder.cs

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

revision 166 by william, Thu Jul 22 14:24:07 2010 UTC revision 187 by william, Sat Jul 24 04:16:43 2010 UTC
# Line 11  using gr2lib.core.helpers; Line 11  using gr2lib.core.helpers;
11  namespace gr2lib.core.coretypes.implementation  namespace gr2lib.core.coretypes.implementation
12  {  {
13      #region  public class grannylog_messageType : igrannylog_messageType      #region  public class grannylog_messageType : igrannylog_messageType
14        /// <summary>
15        /// igrannylog_messageType interface
16        /// </summary>
17      public interface igrannylog_messageType      public interface igrannylog_messageType
18      {      {
19            /// <summary>
20            /// Gets LogTimeStamp
21            /// </summary>
22          DateTime LogTimeStamp { get; }          DateTime LogTimeStamp { get; }
23            /// <summary>
24            /// Gets LogTimeStamp as string
25            /// </summary>
26          string LogTimeStampAsString { get; }          string LogTimeStampAsString { get; }
27    
28            /// <summary>
29            /// Message Type as NameValuePair
30            /// </summary>
31          NameValuePair<string, granny_log_message_type> Type { get; }          NameValuePair<string, granny_log_message_type> Type { get; }
32            /// <summary>
33            /// Message Origin as NameValuePair
34            /// </summary>
35          NameValuePair<string, granny_log_message_origin> Origin { get; }          NameValuePair<string, granny_log_message_origin> Origin { get; }
36            /// <summary>
37            /// get the message
38            /// </summary>
39          string Message { get; }          string Message { get; }
40      }      }
41        /// <summary>
42        /// grannylog_messageType class
43        /// </summary>
44      public class grannylog_messageType : igrannylog_messageType      public class grannylog_messageType : igrannylog_messageType
45      {      {
46            /// <summary>
47            /// default constructor
48            /// </summary>
49          public grannylog_messageType()          public grannylog_messageType()
50          {          {
51              _LogTimeStamp = DateTime.Now;              _LogTimeStamp = DateTime.Now;
# Line 30  namespace gr2lib.core.coretypes.implemen Line 53  namespace gr2lib.core.coretypes.implemen
53              _Origin = new NameValuePair<string, granny_log_message_origin>("default_origin", 0);              _Origin = new NameValuePair<string, granny_log_message_origin>("default_origin", 0);
54              _Message = "{no message}";              _Message = "{no message}";
55          }          }
56            /// <summary>
57            /// default constructor - specify: Type, Origin, Message)
58            /// </summary>
59          public grannylog_messageType(NameValuePair<string, granny_log_message_type> Type, NameValuePair<string, granny_log_message_origin> Origin, string Message)          public grannylog_messageType(NameValuePair<string, granny_log_message_type> Type, NameValuePair<string, granny_log_message_origin> Origin, string Message)
60          {          {
61              _LogTimeStamp = DateTime.Now;              _LogTimeStamp = DateTime.Now;
# Line 46  namespace gr2lib.core.coretypes.implemen Line 71  namespace gr2lib.core.coretypes.implemen
71          private string _Message;          private string _Message;
72    
73          private DateTime _LogTimeStamp;          private DateTime _LogTimeStamp;
74    
75            /// <summary>
76            /// Gets LogTimeStamp
77            /// </summary>
78          public DateTime LogTimeStamp { get { return _LogTimeStamp; } }          public DateTime LogTimeStamp { get { return _LogTimeStamp; } }
79          public string LogTimeStampAsString { get { return this.LogTimeStamp.ToString("MM/dd/yyyy hh:mm:ss.fff tt"); } }          /// <summary>
80            /// Gets LogTimeStamp as string
81            /// </summary>
82            public string LogTimeStampAsString { get { return this.LogTimeStamp.ToString("MM/dd/yyyy hh:mm:ss.fff tt"); } }
83            /// <summary>
84            /// Message Type as NameValuePair
85            /// </summary>
86          public NameValuePair<string, granny_log_message_type> Type { get { return _Type; } }          public NameValuePair<string, granny_log_message_type> Type { get { return _Type; } }
87            /// <summary>
88            /// Message Origin as NameValuePair
89            /// </summary>
90          public NameValuePair<string, granny_log_message_origin> Origin { get { return _Origin; } }          public NameValuePair<string, granny_log_message_origin> Origin { get { return _Origin; } }
91            /// <summary>
92            /// get the message
93            /// </summary>
94          public string Message { get { return _Message; } }          public string Message { get { return _Message; } }
95          #endregion          #endregion
96      }      }
97      #endregion      #endregion
98    
99      #region public class granny_log_eventargs : EventArgs      #region public class granny_log_eventargs : EventArgs
100        /// <summary>
101        /// granny_log_eventargs class
102        /// </summary>
103      public class granny_log_eventargs : EventArgs      public class granny_log_eventargs : EventArgs
104      {      {
105          private string message;          private string message;
106          private granny_log_message_type type;          private granny_log_message_type type;
107          private granny_log_message_origin origin;          private granny_log_message_origin origin;
108          private string _type_string;          /// <summary>
109          private string _origin_string;          /// default constructor - specify: type, origin, message
110            /// </summary>
111          public granny_log_eventargs(granny_log_message_type type, granny_log_message_origin origin, string message)          /// <param name="type"></param>
112          {          /// <param name="origin"></param>
113              this.type = type;          /// <param name="message"></param>
114              this.origin = origin;          public granny_log_eventargs(granny_log_message_type type, granny_log_message_origin origin, [MarshalAs(UnmanagedType.LPStr)] string message)
             this.message = message;  
             this._type_string = coreapi.GrannyGetLogMessageTypeString(type);  
             this._origin_string = coreapi.GrannyGetLogMessageOriginString(origin);  
         }  
         public granny_log_eventargs(granny_log_message_type type, granny_log_message_origin origin, [MarshalAs(UnmanagedType.LPStr)] string message, string type_string, string origin_string)  
115          {          {
116              this.type = type;              this.type = type;
117              this.origin = origin;              this.origin = origin;
118              this.message = message;              this.message = message;
             this._type_string = type_string;  
             this._origin_string = origin_string;  
119          }          }
120    
121            /// <summary>
122            /// Get Message Log Type value
123            /// </summary>
124          public granny_log_message_type Type { get { return type; } }          public granny_log_message_type Type { get { return type; } }
125    
126            /// <summary>
127            /// Get Message Log Origin value
128            /// </summary>
129          public granny_log_message_origin Origin { get { return origin; } }          public granny_log_message_origin Origin { get { return origin; } }
130    
131          public string TypeString { get { return _type_string; } }          /// <summary>
132          public string OriginString { get { return _origin_string; } }          /// Get Message Log Type name
133            /// </summary>
134            public string TypeString { get { return coreapi.GrannyGetLogMessageTypeString(type); } }
135            /// <summary>
136            /// Get Message Log Origin name
137            /// </summary>
138            public string OriginString { get { return coreapi.GrannyGetLogMessageOriginString(origin); } }
139            /// <summary>
140            /// Get the Message
141            /// </summary>
142          public string Message { get { return message; } }          public string Message { get { return message; } }
143      }      }
144      #endregion      #endregion
145    
146      #region public class granny_log_callback_builder : igranny_log_callback_builder      #region public class granny_log_callback_builder : igranny_log_callback_builder
147        /// <summary>
148        /// granny_log_callback_builder class
149        /// </summary>
150      public class granny_log_callback_builder : igranny_log_callback_builder      public class granny_log_callback_builder : igranny_log_callback_builder
151      {      {
152            /// <summary>
153            /// granny_log_callback_method delegate
154            /// </summary>
155            /// <param name="Type">granny_log_message_type</param>
156            /// <param name="Origin">granny_log_message_origin</param>
157            /// <param name="Message">The log message</param>
158            /// <param name="UserData">Pointer to UserData, in this implementation is always: IntPtr.Zero</param>
159          [UnmanagedFunctionPointer(CallingConvention.Cdecl)]          [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
160          public delegate void granny_log_callback_method(granny_log_message_type Type, granny_log_message_origin Origin, [MarshalAs(UnmanagedType.LPStr)] string Message, IntPtr UserData);          public delegate void granny_log_callback_method(granny_log_message_type Type, granny_log_message_origin Origin, [MarshalAs(UnmanagedType.LPStr)] string Message, IntPtr UserData);
161    
162            /// <summary>
163            /// OnMessageLogged delegate
164            /// </summary>
165            /// <param name="sender">object</param>
166            /// <param name="e">granny_log_eventargs</param>
167          public delegate void OnMessageLogged(object sender, granny_log_eventargs e);          public delegate void OnMessageLogged(object sender, granny_log_eventargs e);
168            /// <summary>
169            /// Handler for OnMessageLogged delegate, use this if you wish to handle Granny2 Log Events in your own code
170            /// </summary>
171          public event OnMessageLogged OnMessageLoggedEventHandler;          public event OnMessageLogged OnMessageLoggedEventHandler;
172    
173          internal granny_log_callback _log_call_back;          internal granny_log_callback _log_call_back;
174          internal granny_log_callback_method _callback = null;          internal granny_log_callback_method _callback = null;
175    
176            /// <summary>
177            /// granny_log_callback
178            /// </summary>
179          [StructLayout(LayoutKind.Sequential, Pack = 4), Size(Size = 8)]          [StructLayout(LayoutKind.Sequential, Pack = 4), Size(Size = 8)]
180          public struct granny_log_callback          public struct granny_log_callback
181          {          {
182                /// <summary>
183                /// the fucntion to call when something is logged
184                /// </summary>
185              [MarshalAs(UnmanagedType.FunctionPtr)]              [MarshalAs(UnmanagedType.FunctionPtr)]
186              public granny_log_callback_method Function;              public granny_log_callback_method Function;
187                /// <summary>
188                /// pointer to UserData, in this implementation is always: IntPtr.Zero
189                /// </summary>
190              public IntPtr UserData;              public IntPtr UserData;
191          }          }
192    
# Line 130  namespace gr2lib.core.coretypes.implemen Line 210  namespace gr2lib.core.coretypes.implemen
210                          new NameValuePair<string, granny_log_message_type>(TypeString, Type),                          new NameValuePair<string, granny_log_message_type>(TypeString, Type),
211                          new NameValuePair<string, granny_log_message_origin>(OriginString, Origin),                          new NameValuePair<string, granny_log_message_origin>(OriginString, Origin),
212                          Message);                          Message);
213                      this.Ingored.Add(_msg_ignored);                      this.Ignored.Add(_msg_ignored);
214                      break;                      break;
215                  case granny_log_message_type.GrannyNoteLogMessage:                  case granny_log_message_type.GrannyNoteLogMessage:
216                      grannylog_messageType _msg_note = new grannylog_messageType(                      grannylog_messageType _msg_note = new grannylog_messageType(
# Line 173  namespace gr2lib.core.coretypes.implemen Line 253  namespace gr2lib.core.coretypes.implemen
253          }          }
254          #endregion          #endregion
255    
256            /// <summary>
257            /// default constructor
258            /// </summary>
259          public granny_log_callback_builder() { _callback = new granny_log_callback_method(this.LogCallback); }          public granny_log_callback_builder() { _callback = new granny_log_callback_method(this.LogCallback); }
260          //public granny_log_callback_builder(coreapi.granny_log_callback_method LogCallBack) { this._callback = LogCallBack; }          //public granny_log_callback_builder(coreapi.granny_log_callback_method LogCallBack) { this._callback = LogCallBack; }
261            /// <summary>
262            /// default constructor - specify: OnMessageLoggedEvntHandler
263            /// </summary>
264            /// <param name="OnMessageLoggedEvntHandler">delegate that will be called when ever something is logged (use this if you wish to handle Granny2 Log Events in your own code)</param>
265          public granny_log_callback_builder(OnMessageLogged OnMessageLoggedEvntHandler) { OnMessageLoggedEventHandler = OnMessageLoggedEvntHandler; _callback = new granny_log_callback_method(this.LogCallback); }          public granny_log_callback_builder(OnMessageLogged OnMessageLoggedEvntHandler) { OnMessageLoggedEventHandler = OnMessageLoggedEvntHandler; _callback = new granny_log_callback_method(this.LogCallback); }
266    
267          #region Start Logger          #region Start Logger
268            /// <summary>
269            /// When called will initialize the logger
270            /// </summary>
271          public void StartLogging()          public void StartLogging()
272          {          {
273              try              try
# Line 199  namespace gr2lib.core.coretypes.implemen Line 289  namespace gr2lib.core.coretypes.implemen
289          #endregion          #endregion
290    
291          #region Stop Logger          #region Stop Logger
292            /// <summary>
293            /// When called will destroy the logger
294            /// </summary>
295          public void StopLogging()          public void StopLogging()
296          {          {
297              try              try
# Line 226  namespace gr2lib.core.coretypes.implemen Line 319  namespace gr2lib.core.coretypes.implemen
319          private List<grannylog_messageType> _Error = new List<grannylog_messageType>();          private List<grannylog_messageType> _Error = new List<grannylog_messageType>();
320          private List<grannylog_messageType> _OnePastLastMessage = new List<grannylog_messageType>();          private List<grannylog_messageType> _OnePastLastMessage = new List<grannylog_messageType>();
321    
322          public List<grannylog_messageType> Ingored { get { return _Ingored; } }          /// <summary>
323            /// Get the Ignored Log
324            /// </summary>
325            public List<grannylog_messageType> Ignored { get { return _Ingored; } }
326            /// <summary>
327            /// Get the Note Log
328            /// </summary>
329          public List<grannylog_messageType> Note { get { return _Note; } }          public List<grannylog_messageType> Note { get { return _Note; } }
330            /// <summary>
331            /// Get the Warning Log
332            /// </summary>
333          public List<grannylog_messageType> Warning { get { return _Warning; } }          public List<grannylog_messageType> Warning { get { return _Warning; } }
334            /// <summary>
335            /// Get the Error Log
336            /// </summary>
337          public List<grannylog_messageType> Error { get { return _Error; } }          public List<grannylog_messageType> Error { get { return _Error; } }
338            /// <summary>
339            /// Get the OnePastLastMessage Log
340            /// </summary>
341          public List<grannylog_messageType> OnePastLastMessage { get { return _OnePastLastMessage; } }          public List<grannylog_messageType> OnePastLastMessage { get { return _OnePastLastMessage; } }
342          #endregion          #endregion
343      }      }

Legend:
Removed from v.166  
changed lines
  Added in v.187

  ViewVC Help
Powered by ViewVC 1.1.22