/[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

--- trunk/gr2lib/core/coretypes/implementation/granny_log_callback_builder.cs	2010/07/22 07:39:03	157
+++ trunk/gr2lib/core/coretypes/implementation/granny_log_callback_builder.cs	2010/07/22 09:06:12	158
@@ -6,18 +6,65 @@
 using gr2lib.core.coretypes.native;
 using gr2lib.core.interfaces;
 using System.Runtime.InteropServices;
+using gr2lib.core.helpers;
 
 namespace gr2lib.core.coretypes.implementation
 {
+    #region  public class grannylog_messageType : igrannylog_messageType
+    public interface igrannylog_messageType
+    {
+        DateTime LogTimeStamp { get; }
+        string LogTimeStampAsString { get; } 
+
+        NameValuePair<string, granny_log_message_type> Type { get; }
+        NameValuePair<string, granny_log_message_origin> Origin { get; }
+        string Message { get; }
+    }
+    public class grannylog_messageType : igrannylog_messageType
+    {
+
+        public grannylog_messageType()
+        {
+            _LogTimeStamp = DateTime.Now;
+            _Type = new NameValuePair<string, granny_log_message_type>("default_message", 0);
+            _Origin = new NameValuePair<string, granny_log_message_origin>("default_origin", 0);
+            _Message = "{no message}";
+        }
+
+        public grannylog_messageType(NameValuePair<string, granny_log_message_type> Type, NameValuePair<string, granny_log_message_origin> Origin, string Message)
+        {
+            _LogTimeStamp = DateTime.Now;
+            this._Type = Type;
+            this._Origin = Origin;
+            this._Message = Message;            
+        }
+
+        #region igrannylog_messageType Members
+
+        private NameValuePair<string, granny_log_message_type> _Type;
+        private NameValuePair<string, granny_log_message_origin> _Origin;
+        private string _Message;
+
+        private DateTime _LogTimeStamp;
+        public DateTime LogTimeStamp { get { return _LogTimeStamp; } }
+        public string LogTimeStampAsString { get { return this.LogTimeStamp.ToString("MM/dd/yyyy hh:mm:ss.fff tt"); } } 
+        public NameValuePair<string, granny_log_message_type> Type { get { return _Type; } }
+        public NameValuePair<string, granny_log_message_origin> Origin { get { return _Origin; } }
+        public string Message { get { return _Message; } }
+        #endregion
+    }
+    #endregion
+
+    #region public class granny_log_eventargs : EventArgs
     public class granny_log_eventargs : EventArgs
     {
         private string message;
-        private int type;
-        private int origin;
+        private granny_log_message_type type;
+        private granny_log_message_origin origin;
         private string _type_string;
         private string _origin_string;
 
-        public granny_log_eventargs(int type, int origin, string message)
+        public granny_log_eventargs(granny_log_message_type type, granny_log_message_origin origin, string message)
         {
             this.type = type;
             this.origin = origin;
@@ -25,7 +72,7 @@
             this._type_string = coreapi.GrannyGetLogMessageTypeString(type);
             this._origin_string = coreapi.GrannyGetLogMessageOriginString(origin);
         }
-        public granny_log_eventargs(int type, int origin, [MarshalAs(UnmanagedType.LPStr)] string message, string type_string, string origin_string)
+        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)
         {
             this.type = type;
             this.origin = origin;
@@ -34,14 +81,16 @@
             this._origin_string = origin_string;
         }
 
-        public int Type { get { return type; } }
-        public int Origin { get { return origin; } }
+        public granny_log_message_type Type { get { return type; } }
+        public granny_log_message_origin Origin { get { return origin; } }
 
         public string TypeString { get { return _type_string; } }
         public string OriginString { get { return _origin_string; } }
         public string Message { get { return message; } }
     }
+    #endregion
 
+    #region public class granny_log_callback_builder : igranny_log_callback_builder
     public class granny_log_callback_builder : igranny_log_callback_builder
     {
 
@@ -51,47 +100,78 @@
         internal granny_log_callback _log_call_back;
         private coreapi.granny_log_callback_method _callback = null;
 
-        private void LogCallback(int Type, int Origin, [MarshalAs(UnmanagedType.LPStr)] string Message, IntPtr UserData)
+        private void LogCallback(granny_log_message_type Type, granny_log_message_origin Origin, [MarshalAs(UnmanagedType.LPStr)] string Message, IntPtr UserData)
         {
             string TypeString = coreapi.GrannyGetLogMessageTypeString(Type);
             string OriginString = coreapi.GrannyGetLogMessageOriginString(Origin);
 
-            Console.WriteLine();
-            Console.WriteLine("Granny2 API Logger: Logging Message -> ");
-            Console.WriteLine();
-            Console.WriteLine("\tMessage Log Type: {0}\n\tMessage Log Origin: {1}\n\tMessage: {2}", TypeString, OriginString, Message);
-            Console.WriteLine();
+            switch (Type)
+            {
+                case granny_log_message_type.GrannyErrorLogMessage:
+                    grannylog_messageType _msg_error = new grannylog_messageType(
+                        new NameValuePair<string, granny_log_message_type>(TypeString, Type),
+                        new NameValuePair<string, granny_log_message_origin>(OriginString, Origin), 
+                        Message);
+                    this.Error.Add(_msg_error);
+                    break;
+                case granny_log_message_type.GrannyIgnoredLogMessage:
+                    grannylog_messageType _msg_ignored = new grannylog_messageType(
+                        new NameValuePair<string, granny_log_message_type>(TypeString, Type),
+                        new NameValuePair<string, granny_log_message_origin>(OriginString, Origin),
+                        Message);
+                    this.Ingored.Add(_msg_ignored);
+                    break;
+                case granny_log_message_type.GrannyNoteLogMessage:
+                    grannylog_messageType _msg_note = new grannylog_messageType(
+                        new NameValuePair<string, granny_log_message_type>(TypeString, Type),
+                        new NameValuePair<string, granny_log_message_origin>(OriginString, Origin),
+                        Message);
+                    this.Note.Add(_msg_note);
+                    break;
+                case granny_log_message_type.GrannyOnePastLastMessageType:
+                    grannylog_messageType _msg_onepast = new grannylog_messageType(
+                        new NameValuePair<string, granny_log_message_type>(TypeString, Type),
+                        new NameValuePair<string, granny_log_message_origin>(OriginString, Origin),
+                        Message);
+                    this.OnePastLastMessage.Add(_msg_onepast);
+                    break;
+                case granny_log_message_type.GrannyWarningLogMessage:
+                    grannylog_messageType _msg_warning = new grannylog_messageType(
+                        new NameValuePair<string, granny_log_message_type>(TypeString, Type),
+                        new NameValuePair<string, granny_log_message_origin>(OriginString, Origin),
+                        Message);
+                    this.Warning.Add(_msg_warning);
+                    break;
+                default: break;
+            }
 
-            if (OnMessageLoggedEventHandler != null)
+            if (OnMessageLoggedEventHandler == null)
             {
+                Console.WriteLine();
+                Console.WriteLine("Granny2 API Logger: Logging Message -> ");
+                Console.WriteLine();
+                Console.WriteLine("\tMessage Log Type: {0}\n\tMessage Log Origin: {1}\n\tMessage: {2}", TypeString, OriginString, Message);
+                Console.WriteLine();
+            }
+            else
+            {          
                 OnMessageLoggedEventHandler(this, new granny_log_eventargs(Type, Origin, Message));
             }
-            //GC.KeepAlive(this);
         }
 
         public granny_log_callback_builder() { _callback = new coreapi.granny_log_callback_method(this.LogCallback); }
         //public granny_log_callback_builder(coreapi.granny_log_callback_method LogCallBack) { this._callback = LogCallBack; }
         public granny_log_callback_builder(OnMessageLogged OnMessageLoggedEventHandler) { this.OnMessageLoggedEventHandler = OnMessageLoggedEventHandler; }
+
+        #region Start Logger
         public void StartLogging()
         {
             try
             {
                 _log_call_back = new granny_log_callback();
-                unsafe
-                {
-                    coreapi.granny_log_callback_method _granny_log_callback_method = new coreapi.granny_log_callback_method(this.LogCallback);
-
-                    //IntPtr _granny_log_callback_methodPtr = Marshal.GetFunctionPointerForDelegate(_granny_log_callback_method);
-                    //_log_call_back.Function = _granny_log_callback_methodPtr;
-                    _log_call_back.Function = _granny_log_callback_method;
-
-                    _log_call_back.UserData = IntPtr.Zero;
-                }
-
-                //int _log_call_back_size = Marshal.SizeOf(_log_call_back);
-                //IntPtr _log_call_backPtr = Marshal.AllocHGlobal(_log_call_back_size);
-                //Marshal.StructureToPtr(_log_call_back_size, _log_call_backPtr, true);
-
+                coreapi.granny_log_callback_method _granny_log_callback_method = new coreapi.granny_log_callback_method(this.LogCallback);
+                _log_call_back.Function = _granny_log_callback_method;
+                _log_call_back.UserData = IntPtr.Zero;
                 coreapi.GrannySetLogCallback(ref _log_call_back);
                 Console.WriteLine("Granny2 API Logger: {0}", "Activated");
             }
@@ -101,27 +181,19 @@
             }
 
         }
+        #endregion
+
+        #region Stop Logger
         public void StopLogging()
         {
             try
             {
                 _log_call_back = new granny_log_callback();
-                unsafe
-                {
-                    coreapi.granny_log_callback_method _granny_log_callback_method = new coreapi.granny_log_callback_method(this.LogCallback);
-
-                    //IntPtr _granny_log_callback_methodPtr = Marshal.GetFunctionPointerForDelegate(_granny_log_callback_method);
-                    //_log_call_back.Function = _granny_log_callback_methodPtr;
-                    _log_call_back.Function = _granny_log_callback_method;
-
-                    _log_call_back.UserData = IntPtr.Zero; 
-                }
-
-
-                //int _log_call_back_size = Marshal.SizeOf(_log_call_back);
-                //IntPtr _log_call_backPtr = Marshal.AllocHGlobal(_log_call_back_size);
-                //Marshal.StructureToPtr(_log_call_back_size, _log_call_backPtr, true);
-
+                _log_call_back = new granny_log_callback();
+                coreapi.granny_log_callback_method _granny_log_callback_method = null;
+                _log_call_back.Function = _granny_log_callback_method;
+                _log_call_back.UserData = IntPtr.Zero;
+                coreapi.GrannySetLogCallback(ref _log_call_back);
                 coreapi.GrannySetLogCallback(ref _log_call_back);
                 Console.WriteLine("Granny2 API Logger: {0}", "Deactivated");
             }
@@ -130,7 +202,24 @@
                 Console.WriteLine("Granny2 API Logger: {0}", "Not Deactivated");
             }
         }
+        #endregion
+
 
+        #region igranny_log_callback_builder Members
+        private List<grannylog_messageType> _Ingored = new List<grannylog_messageType>();
+        private List<grannylog_messageType> _Note = new List<grannylog_messageType>();
+        private List<grannylog_messageType> _Warning = new List<grannylog_messageType>();
+        private List<grannylog_messageType> _Error = new List<grannylog_messageType>();
+        private List<grannylog_messageType> _OnePastLastMessage = new List<grannylog_messageType>();
+
+        public List<grannylog_messageType> Ingored { get { return _Ingored; } }
+        public List<grannylog_messageType> Note { get { return _Note; } }
+        public List<grannylog_messageType> Warning { get { return _Warning; } }
+        public List<grannylog_messageType> Error { get { return _Error; } }
+        public List<grannylog_messageType> OnePastLastMessage { get { return _OnePastLastMessage; } }
+        #endregion
     }
+    #endregion
 }
 
+

 

  ViewVC Help
Powered by ViewVC 1.1.22