Esempio n. 1
0
        //! register a log message receiver
        public static Boolean UnregisterLogReceiver(String strID, LogMessage Handler)
        {
            if (null == Handler)
            {
                return(false);
            }

            if ((null == strID) || ("" == strID) || ("ALL" == strID.ToUpper().Trim()))
            {
                //! register a broadcast receiver
                LogMessageEvent     -= new LogMessage(Handler);
                LogMessageSyncEvent -= new LogMessage(Handler);
                return(true);
            }

            LogReceiver Result = new LogReceiver();

            if (FindReceiver(strID, ref Result))
            {
                //! find the receiver
                Result.LogMessageEvent     -= new LogMessage(Handler);
                Result.LogMessageSyncEvent -= new LogMessage(Handler);
                return(true);
            }

            return(true);
        }
Esempio n. 2
0
        //! register a log message receiver
        public static Boolean RegisterLogReceiver(String strID, LogMessage Handler, Boolean bIsAsync)
        {
            if (null == Handler)
            {
                return(false);
            }

            if ((null == strID) || ("" == strID) || ("ALL" == strID.ToUpper().Trim()))
            {
                //! register a broadcast receiver
                if (bIsAsync)
                {
                    LogMessageEvent += new LogMessage(Handler);
                }
                else
                {
                    LogMessageSyncEvent += new LogMessage(Handler);
                }
                return(true);
            }

            LogReceiver Result = new LogReceiver();

            if (FindReceiver(strID, ref Result))
            {
                //! find the receiver
                if (bIsAsync)
                {
                    Result.LogMessageEvent += new LogMessage(Handler);
                }
                else
                {
                    Result.LogMessageSyncEvent += new LogMessage(Handler);
                }
                return(true);
            }
            else
            {
                //! a new receiver
                Result.m_ID = strID;
                if (bIsAsync)
                {
                    Result.LogMessageEvent += new LogMessage(Handler);
                }
                else
                {
                    Result.LogMessageSyncEvent += new LogMessage(Handler);
                }

                m_LogReceiverList.Add(Result);
                return(true);
            }
        }
Esempio n. 3
0
        //! \brief a method for write a log line
        public static void WriteLine(String strReceiverID, String strLogMessage)
        {
            if (null == strLogMessage)
            {
                return;
            }

            if ((null == strReceiverID) || ("" == strReceiverID) || ("ALL" == strReceiverID.ToUpper().Trim()))
            {
                strLogMessage += "\r\n";

                if (null != LogMessageEvent)
                {
                    try
                    {
                        m_RootParentForm.Dispatcher.BeginInvoke(DispatcherPriority.Normal, LogMessageEvent, strLogMessage);
                    }
                    catch (Exception) { }
                }

                if (null != LogMessageSyncEvent)
                {
                    try
                    {
                        LogMessageEvent(strLogMessage);
                    }
                    catch (Exception) { }
                }
            }

            LogReceiver Result = new LogReceiver();

            if (FindReceiver(strReceiverID, ref Result))
            {
                //! find the receiver
                strLogMessage += "\r\n";

                try
                {
                    if (null != Result.LogMessageEvent)
                    {
                        m_RootParentForm.Dispatcher.BeginInvoke(DispatcherPriority.Normal, Result.LogMessageEvent, strLogMessage);
                    }
                }
                catch (Exception) { }

                Result.OnLogMessageArrival(strLogMessage);
            }
        }
Esempio n. 4
0
        private static Boolean FindReceiver(String strID, ref LogReceiver Result)
        {
            List <LogReceiver> .Enumerator tempListEnum = m_LogReceiverList.GetEnumerator();

            if (null == strID)
            {
                return(false);
            }

            while (tempListEnum.MoveNext())
            {
                if (tempListEnum.Current.m_ID == strID)
                {
                    Result = tempListEnum.Current;
                    return(true);
                }
            }

            return(false);
        }