示例#1
0
        public static void UpdateListViewItem(ListViewItem listViewItem, TraceElement traceElement)
        {
            traceElement.Analyze();
            if (traceElement.HighlightColour != null)
            {
                listViewItem.BackColor = (Color)traceElement.HighlightColour;
            }

            listViewItem.SubItems[1].Text = traceElement.TraceTag;
            listViewItem.SubItems[3].Text = traceElement.SOAPMethod;
            listViewItem.SubItems[4].Text = traceElement.Data.Length.ToString();
            listViewItem.SubItems[5].Text = traceElement.Mailbox;
            listViewItem.SubItems[6].Text = traceElement.Impersonating;
        }
示例#2
0
        public static TraceElement CreateFromDataTableRow(DataRow dataRow)
        {
            // We create a TraceElement from the passed DataRow.  We do not perform any analysis at this stage

            TraceElement traceElement = new TraceElement();

            traceElement._traceTagAttributes = new Dictionary <string, string>();
            traceElement._xmlElements        = new Dictionary <string, string>();

            foreach (DataColumn dataColumn in dataRow.Table.Columns)
            {
                switch (dataColumn.ColumnName)
                {
                case "Data":
                    traceElement.Data = (string)dataRow["Data"];
                    break;

                case "SOAPMethod":
                case "Mailbox":
                case "ExchangeImpersonation":
                    traceElement._xmlElements.Add(dataColumn.ColumnName.ToLower(), dataRow[dataColumn.ColumnName].ToString());
                    break;

                default:
                    traceElement._traceTagAttributes.Add(dataColumn.ColumnName.ToLower(), dataRow[dataColumn.ColumnName].ToString());
                    break;
                }
            }

            /*
             * row["Tag"] = Tag;
             * row["Tid"] = ThreadId;
             * row["Time"] = LogTime;
             * row["Version"] = LogVersion;
             * row["Application"] = LogApplication;
             * row["SOAPMethod"] = ReadMethodFromRequest(Data);
             * row["Data"] = Data;
             * row["Size"] = Data.Length;
             * row["Mailbox"] = Mailbox;
             * row["ExchangeImpersonation"] = Impersonating;
             * row["ClientRequestId"] = ClientRequestId;
             */

            return(traceElement);
        }
示例#3
0
        private void CheckForErrors(object o)
        {
            // Go through the listbox items and check content for errors
            // This method is intended to run on a background thread, as the checking can take a significant length of time

            if (this._checkingForErrors)
            {
                return;
            }

            this._checkingForErrors = true;

            int i = 0;

            if (listViewLogIndex.InvokeRequired)
            {
                listViewLogIndex.Invoke(new MethodInvoker(delegate() {
                    while (i < listViewLogIndex.Items.Count)
                    {
                        TraceElement trace = new TraceElement((string)listViewLogIndex.Items[i].Tag, listViewLogIndex.Items[i].SubItems[1].Text);
                        if (trace.IsErrorResponse)
                        {
                            listViewLogIndex.Items[i].BackColor = Color.Red;
                        }
                        i++;
                    }
                }));
            }
            else
            {
                while (i < listViewLogIndex.Items.Count)
                {
                    TraceElement trace = new TraceElement((string)listViewLogIndex.Items[i].Tag, listViewLogIndex.Items[i].SubItems[1].Text);
                    if (trace.IsErrorResponse)
                    {
                        listViewLogIndex.Items[i].BackColor = Color.Red;
                    }
                    i++;
                }
            }
            this._checkingForErrors = false;
        }
示例#4
0
 public LogAddedEventArgs(TraceElement traceElement)
 {
     _trace = traceElement;
 }
示例#5
0
        public static void AnalyseErrors(TraceElement traceElement)
        {
            if (traceElement.TraceType == EWSTraceType.Response)
            {
                // Check for errors

                // Check if we have response headers...
                if (traceElement.TraceTag.StartsWith("EwsResponseHttpHeaders") || traceElement.TraceTag.StartsWith("Response Headers"))
                {
                    // Check for server error
                    try
                    {
                        string sHTTPResponse = traceElement.Data.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)[0];
                        if (!(sHTTPResponse.StartsWith("200")))
                        {
                            if (!(sHTTPResponse.Contains(" 200 ")))
                            {
                                traceElement._isError = true;
                            }
                        }
                    }
                    catch { }
                }
                else if (traceElement.TraceTag.Contains("EwsResponse"))
                {
                    // Check EWS response for errors
                    if (traceElement.Data.Contains("ResponseClass=\"Error\""))
                    {
                        traceElement._isError = true;
                    }
                    else if (traceElement.Data.Contains("Fault>"))
                    {
                        if (traceElement.Data.Contains("<faultcode"))
                        {
                            traceElement._isError = true;
                        }
                    }
                }
                else if (traceElement.TraceTag.Contains("AutodiscoverResponse"))
                {
                    // Check autodiscover response for errors
                    if (traceElement.Data.Contains("<ErrorCode>"))
                    {
                        traceElement._isError = true;
                    }
                }

                if (traceElement._isError)
                {
                    if (!String.IsNullOrEmpty(traceElement.ClientRequestId))
                    {
                        _clientRequestIdsWithError.Add(traceElement.ClientRequestId);
                    }
                }

                // Check for throttling
                // Check for server busy response
                if (traceElement.TraceTag.Contains("EwsResponse"))
                {
                    if (traceElement.Data.Contains("ResponseCode>ErrorServerBusy"))
                    {
                        traceElement._isThrottled = true;
                    }
                    if (traceElement.Data.Contains("Too many concurrent connections opened."))
                    {
                        traceElement._isThrottled = true;
                    }
                }
                if (traceElement._isThrottled)
                {
                    if (!String.IsNullOrEmpty(traceElement.ClientRequestId))
                    {
                        _clientRequestIdsThrottled.Add(traceElement.ClientRequestId);
                    }
                }
            }
            else if (traceElement.TraceType == EWSTraceType.Autodiscover)
            {
                if (traceElement.Data.Contains("<ErrorCode>"))
                {
                    traceElement._isError = true;
                }

                if (traceElement._isError)
                {
                    if (!String.IsNullOrEmpty(traceElement.ClientRequestId))
                    {
                        _clientRequestIdsWithError.Add(traceElement.ClientRequestId);
                    }
                }
            }
            else
            {
                if (!String.IsNullOrEmpty(traceElement.ClientRequestId))
                {
                    traceElement._isThrottled = _clientRequestIdsThrottled.Contains(traceElement.ClientRequestId);
                    traceElement._isError     = _clientRequestIdsWithError.Contains(traceElement.ClientRequestId);
                }
            }

            if (traceElement.TraceTag.EndsWith("HttpHeaders"))
            {
                // For HTTP headers, check if we have X-AnchorMailbox, and if we do, add it as an interesting Xml element
                using (System.IO.StringReader reader = new System.IO.StringReader(traceElement.Data))
                {
                    string headerLine;
                    while ((headerLine = reader.ReadLine()) != null)
                    {
                        if (headerLine.StartsWith("X-AnchorMailbox"))
                        {
                            string mailbox = headerLine.Substring(16).Trim();
                            if (!String.IsNullOrEmpty(mailbox))
                            {
                                traceElement._xmlElements.Add("Mailbox", mailbox);
                            }
                        }
                    }
                }
            }
        }
示例#6
0
        public void Log(string Details, string Description, bool SuppressLogToFile, DateTime LogTime, int ThreadId, string LogApplication, string LogVersion, bool SuppressEvent, string clientRequestId = "")
        {
            DateTime logTime = DateTime.Now;

            if (LogTime != null)
            {
                logTime = (DateTime)LogTime;
            }

            // Build the trace (we use the same format as EWSEditor)
            if (String.IsNullOrEmpty(LogVersion) && LogApplication.Equals("SOAPe"))
            {
                LogVersion = Application.ProductVersion;
            }
            StringBuilder sTrace = new StringBuilder();

            sTrace.Append($"<Trace Tag=\"{TraceTag(Description)}\" Tid=\"{ThreadId}\" Time=\"{logTime}\" Application=\"{LogApplication}\" Version=\"{LogVersion}\"");
            if (!String.IsNullOrEmpty(clientRequestId))
            {
                sTrace.Append($" ClientRequestId=\"{clientRequestId}\"");
            }
            sTrace.Append(" >");
            sTrace.Append(Environment.NewLine);
            sTrace.Append(Details);
            sTrace.Append(Environment.NewLine);
            sTrace.Append("</Trace>");

            lock (_lockObject)
            {
                if (!SuppressLogToFile)
                {
                    if (!(_logFileStream == null))
                    {
                        if (!_logFileStream.CanWrite)
                        {
                            try
                            {
                                _logFileStream.Close();
                            }
                            catch { }
                            _logFileStream = null;
                        }
                    }
                    if (_logFileStream == null)
                    {
                        try
                        {
                            _logFileStream = new FileStream(_logPath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
                        }
                        catch { }
                    }
                    using (StreamWriter logStreamWriter = new StreamWriter(_logFileStream))
                    {
                        logStreamWriter.WriteLine("");
                        logStreamWriter.WriteLine(sTrace.ToString());
                    }
                }
            }

            TraceElement traceElement = new TraceElement(sTrace.ToString());

            LogToDatabase(Details, TraceTag(Description), logTime, ThreadId, LogApplication, LogVersion, traceElement.Mailbox, traceElement.Impersonating, traceElement.ClientRequestId);
            if (!SuppressEvent)
            {
                OnLogAdded(new LogAddedEventArgs(traceElement));
            }
        }
示例#7
0
        private void ShowLogIndex()
        {
            // Read the logs and update the UI

            if (_logger.LogDataTable == null)
            {
                return;
            }

            int iTraceCount = _logger.LogDataTable.Rows.Count;

            if (iTraceCount == 0)
            {
                return;
            }

            string sOrderBy = (String)listViewLogIndex.Tag;

            if (String.IsNullOrEmpty(sOrderBy))
            {
                sOrderBy = "Time ASC,Tid ASC";
            }
            DataRow[] logRows = null;
            string    sFilter = GetLogFilter();

            try
            {
                logRows = _logger.LogDataTable.Select(sFilter, sOrderBy);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(String.Format("Error querying logs, please check filter{0}Error: {1}", Environment.NewLine, ex.Message),
                                                     "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                _logger.DebugLog(String.Format("Error retrieving logs rows, filter: {0}", sFilter));
                _logger.DebugLogError(ex);
                return;
            }

            xmlEditor1.Text = "No data found for this session.";

            int i = -1;

            if (listViewLogIndex.InvokeRequired)
            {
                listViewLogIndex.Invoke(new MethodInvoker(delegate()
                {
                    listViewLogIndex.BeginUpdate();
                    listViewLogIndex.Items.Clear();
                }));
            }
            else
            {
                listViewLogIndex.BeginUpdate();
                listViewLogIndex.Items.Clear();
            }

            iTraceCount = logRows.Length;

            while (i < iTraceCount - 1)
            {
                ShowStatus($"Analysing {i++} of {iTraceCount}", ((double)i / (double)iTraceCount) * 100);
                ListViewItem item = new ListViewItem(logRows[i]["Time"].ToString());
                item.Tag = TraceElement.CreateFromDataTableRow(logRows[i]);
                StringBuilder sDescription = new StringBuilder(logRows[i]["Tag"].ToString());
                item.SubItems.Add(sDescription.ToString());
                item.SubItems.Add(logRows[i]["Tid"].ToString());
                item.SubItems.Add(logRows[i]["SOAPMethod"].ToString());
                item.SubItems.Add(((Int64)logRows[i]["Size"]).ToString("0,0"));
                item.SubItems.Add(logRows[i]["Mailbox"].ToString());
                item.SubItems.Add(logRows[i]["ExchangeImpersonation"].ToString());
                if (listViewLogIndex.InvokeRequired)
                {
                    listViewLogIndex.Invoke(new MethodInvoker(delegate()
                    {
                        listViewLogIndex.Items.Add(item);
                    }));
                }
                else
                {
                    listViewLogIndex.Items.Add(item);
                }
            }
            if (listViewLogIndex.InvokeRequired)
            {
                listViewLogIndex.Invoke(new MethodInvoker(delegate()
                {
                    listViewLogIndex.EndUpdate();
                }));
            }
            else
            {
                listViewLogIndex.EndUpdate();
            }

            if (String.IsNullOrEmpty(sFilter))
            {
                ShowStatus(null);
            }
            else
            {
                ShowStatus("Filter Active", 100, Color.MintCream);
            }
            Task.Run(new Action(() => { AnalyzeTrace(); }));
        }