Ejemplo n.º 1
0
        /*
         * public static CMSLogEvent GetNewLogEvent(Type logEventType)
         * {
         *  if (!CanCreateLogEvent(logEventType))
         *      return null;
         *
         *  return Activator.CreateInstance(logEventType)as CMSLogEvent;
         * }
         */

        public static void SendLogEvent(CMSLogEvent logEvent)
        {
            if (logger != null && logger.IsRunning)
            {
                logger.SendLog(logEvent);
            }
        }
Ejemplo n.º 2
0
        public bool WriteLogEvents(LinkedList <object> logEvents, out bool finished)
        {
            lock (mutex)
            {
                finished = false;
                try
                {
                    if (!isOpen)
                    {
                        return(false);
                    }

                    foreach (object o in logEvents)
                    {
                        if (o is CMSLogEvent)
                        {
                            string MStart      = ("<M>");
                            byte[] MStartBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(MStart);
                            fileStream.Write(MStartBytes, 0, MStartBytes.Length);

                            CMSLogEvent logEvent = (CMSLogEvent)o;
                            byte[]      toWrite  = logEvent.ToXmlBytes();
                            fileStream.Write(toWrite, 0, toWrite.Length);
                            curCharacterCount += toWrite.Length;

                            string MEnd      = ("</M>");
                            byte[] MEndBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(MEnd);
                            fileStream.Write(MEndBytes, 0, MEndBytes.Length);
                        }
                    }
                    fileStream.Flush();

                    if (curCharacterCount < characterCount)
                    {
                        return(true);
                    }

                    finished = true;

                    return(Close());
                }
                catch (Exception e)
                {
                    try
                    {
                        Close();
                    }
                    catch
                    {
                    }

                    return(false);
                }
            }
        }
Ejemplo n.º 3
0
 public void SendLog(CMSLogEvent logEvent)
 {
     lock (logMutex)
     {
         long tickCount = Environment.TickCount;
         if (tickCount - lastDateTimeStampSendTime > dateTimeStampWaitPeriodMillis)
         {
             lastDateTimeStampSendTime = tickCount;
             logEvent.SetDateTime(DateTime.Now);
         }
         logEvent.SessionNum   = logConfig.SessionNum;
         logEvent.TimeInMillis = tickCount - startTimeInMillis;
         logEvent.Uid          = logConfig.Uid;
         logEvent.LogId        = ++logUid;
         logEvents.AddLast(logEvent);
     }
 }
Ejemplo n.º 4
0
        public CMSLogEvent GetNewLog(Type logEventType)
        {
            lock (logMutex)
            {
                long        curTime = Environment.TickCount;
                Attribute[] attrs   = System.Attribute.GetCustomAttributes(logEventType);

                CMSLogAtt attr = null;
                foreach (Attribute curAttr in attrs)
                {
                    if (curAttr is CMSLogAtt)
                    {
                        attr = curAttr as CMSLogAtt;
                        break;
                    }
                }

                if (!timingProfile.Send(attr, logEventType.ToString(), curTime, IsConnected || neverConnect))
                {
                    return(null);
                }

                CMSLogEvent logEvent = Activator.CreateInstance(logEventType) as CMSLogEvent;

                /*
                 * if (includeDateTimeStamps)
                 *  logEvent.SetDateTime(DateTime.Now);
                 * logEvent.SessionNum = logConfig.SessionNum;
                 * logEvent.TimeInMillis = curTime - startTimeInMillis;
                 * logEvent.Uid = logConfig.Uid;
                 * logEvent.LogId = ++logUid;
                 */

                return(logEvent);
            }
        }
        /*
         * private Queue<CMSLogEvent> logEvents = new Queue<CMSLogEvent>();
         *
         * public void AddLogEvent(CMSLogEvent logEvent)
         * {
         *  lock (mutex)
         *  {
         *      if (logEvents.Count >= maxNumLogEvents)
         *          logEvents.Dequeue();
         *      logEvents.Enqueue(logEvent);
         *  }
         * }
         */

        public bool SendLogEvents(LinkedList <object> logEvents)
        {
            if (!isConnected)
            {
                return(false);
            }

            if (uid == 0)
            {
                return(true);
            }

            CMSLogMessage message = new CMSLogMessage();

            message.Uid = uid;


            object [] les = null;
            lock (mutex)
            {
                les = logEvents.ToArray();
                logEvents.Clear();
            }
            message.Messages = new System.Xml.XmlElement[les.Length];
            for (int i = 0; i < les.Length; i++)
            {
                if (les[i] is CMSLogEvent)
                {
                    CMSLogEvent curLogEvent = les[i] as CMSLogEvent;
                    if (curLogEvent.Uid == 0)
                    {
                        curLogEvent.Uid = uid;
                    }
                    message.Messages[i] = curLogEvent.ToXml();
                }
                else if (les[i] is XmlElement)
                {
                    message.Messages[i] = (XmlElement)les[i];
                }
            }

            try
            {
                CMSAckMessage ackMessage = restClient.SendRequest(endPoint, message, typeof(CMSAckMessage), proxyServer) as CMSAckMessage;
                if (ackMessage == null)
                {
                    exception   = new Exception("No Response from server");
                    isConnected = false;
                    return(false);
                }
                if (ackMessage.Uid != uid)
                {
                    exception   = new Exception("Server responded with different user id");
                    isConnected = false;
                    return(false);
                }
                return(true);
            }
            catch (Exception e)
            {
                exception   = e;
                isConnected = false;
                return(false);
            }
        }