示例#1
0
        private void Row_Select(object sender, MouseButtonEventArgs e)
        {
            DataGridRow            row  = sender as DataGridRow;
            FailedRequestTraceFile item = (FailedRequestTraceFile)row.Item;
            string sTempFile            = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".xml";

            File.WriteAllText(sTempFile, item.sFileContents);
            try
            {
                File.Copy(System.IO.Path.GetDirectoryName(item.sFilePath) + "\\freb.xsl", System.IO.Path.GetTempPath() + "\\freb.xsl");
            }
            catch (Exception eeek)
            {
                // ignore all exceptions -- whether source file doesn't exist, or target file already exists.
            }
            wbSample.Navigate(sTempFile);
        }
示例#2
0
        private void Row_DoubleClick(object sender, MouseButtonEventArgs e)
        {
            DataGridRow            row  = sender as DataGridRow;
            FailedRequestTraceFile item = (FailedRequestTraceFile)row.Item;

            string sTempFile = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".xml";

            File.WriteAllText(sTempFile, item.sFileContents);
            try
            {
                File.Copy(System.IO.Path.GetDirectoryName(item.sFilePath) + "\\freb.xsl", System.IO.Path.GetTempPath() + "\\freb.xsl");
            }
            catch (Exception eeek)
            {
                // ignore all exceptions -- whether source file doesn't exist, or target file already exists.
            }
            System.Diagnostics.Process.Start(sTempFile);
            // Some operations with this row
        }
示例#3
0
        public bool GenerateFRTObjectFromFile(string sPathToInputFile, out FailedRequestTraceFile outputFRTObject)
        {
            // if fails, set the out object to null.
            outputFRTObject = null;

            // although some information could be missing that causes an exception,
            // when it appears to be a failedrequesttracefile, put a log entry
            bool fFailedRequestFile = false;

            outputFRTObject = new FailedRequestTraceFile();
            try
            {
                outputFRTObject.sFilePath     = sPathToInputFile;
                outputFRTObject.sFileContents = RetryReadingInputFile(sPathToInputFile);
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(outputFRTObject.sFileContents);
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
                nsmgr.AddNamespace("a", "http://schemas.microsoft.com/win/2004/08/events/event");

                XmlNode nxml = doc.SelectSingleNode("/failedRequest");
                if (nxml == null)
                {
                    return(false);
                }
                // matching node is found
                fFailedRequestFile = true; // in case a try/catch occurs, we know it reached this point
                XmlNode sTC = doc.SelectSingleNode("/failedRequest/a:Event/a:System/a:TimeCreated", nsmgr);
                outputFRTObject.sTime = DateTime.Parse(sTC.Attributes["SystemTime"].Value);
                Uri frturl = new Uri(nxml.Attributes["url"].Value);
                outputFRTObject.sHost     = frturl.Host;
                outputFRTObject.sProtocol = frturl.Scheme;
                outputFRTObject.sURL      = frturl.PathAndQuery;
                //frtFile.
                //frtFile.sURL = nxml.Attributes["url"].Value;
                outputFRTObject.sID     = "";
                outputFRTObject.sMethod = nxml.Attributes["verb"].Value;
                //outputFRTObject.sResult = nxml.Attributes["statusCode"].Value;
                outputFRTObject.sAppPool   = nxml.Attributes["appPoolId"].Value;
                outputFRTObject.sTimeTaken = nxml.Attributes["timeTaken"].Value;
                outputFRTObject.sProcessID = nxml.Attributes["processId"].Value;
                outputFRTObject.sSite      = nxml.Attributes["siteId"].Value;
                if (nxml.Attributes["triggerStatus"] != null)
                {
                    outputFRTObject.sTrigger = nxml.Attributes["triggerStatus"].Value;
                }
                //frtFile.sTime = "";
                outputFRTObject.sUser = "";
                // Add the namespace.
                XmlNodeList bytessent = nxml.SelectNodes("//a:Data[@Name='BytesSent']", nsmgr);
                if (bytessent.Count > 0)
                {
                    outputFRTObject.sBody = bytessent[bytessent.Count - 1].FirstChild.Value.ToString();
                }
                else
                {
                    outputFRTObject.sBody = "";
                }

                XmlNodeList httpstatus = nxml.SelectNodes("//a:Data[@Name='HttpStatus']", nsmgr);
                if (httpstatus.Count > 1)
                {
                    outputFRTObject.sResult = httpstatus[httpstatus.Count - 2].FirstChild.Value.ToString();
                }
                else if (httpstatus.Count > 0)
                {
                    outputFRTObject.sResult = httpstatus[httpstatus.Count - 1].FirstChild.Value.ToString();
                }
                else
                {
                    outputFRTObject.sResult = "";
                }

                XmlNodeList contenttypes = doc.SelectNodes("//a:Data[@Name='HeaderName']", nsmgr);
                for (var i = 0; i < contenttypes.Count; i++)
                {
                    if (contenttypes[contenttypes.Count - 1 - i].FirstChild.Value == "Content-Type")
                    {
                        outputFRTObject.sContentType = contenttypes[contenttypes.Count - 1 - i].NextSibling.FirstChild.Value;
                        break;
                    }
                }
                //                frtFile.

                // now handle authentication
                string sAuthType = nxml.Attributes["authenticationType"].Value;
                if ((sAuthType == "Negotiate") || (sAuthType == "Basic"))
                {
                    outputFRTObject.sUser = nxml.Attributes["userName"].Value;
                }
                else if (sAuthType == "anonymous")
                {
                }
                else if (sAuthType == "NOT_AVAILABLE")
                {
                }

                // STRIP CONTENT
                if (frtStripUniqueIds)
                {
                    //  <TimeCreated SystemTime="2020-05-26T16:56:18.549Z"/>
                    //< Correlation ActivityID = "{800001DD-0002-FF00-B63F-84710C7967BB}" />
                    //< Execution ProcessID = "48256" ThreadID = "30264" />
                    //< Computer > BC - 427269616E43 </ Computer >
                    // computer name can just do search and replace.

                    XmlNodeList sCNs = doc.SelectNodes("/failedRequest/a:Event/a:System/a:Computer", nsmgr);
                    foreach (XmlNode ynot in sCNs)
                    {
                        ynot.FirstChild.Value = "COMPUTER";
                        //ynot.ParentNode.RemoveChild(ynot);
                    }

                    XmlNodeList sTCs = doc.SelectNodes("/failedRequest/a:Event/a:System/a:TimeCreated", nsmgr);
                    foreach (XmlNode ynot in sTCs)
                    {
                        ynot.Attributes["SystemTime"].Value = "1970-01-01T00:00:00.000Z";
                        //ynot.ParentNode.RemoveChild(ynot);
                    }
                    XmlNodeList sCOs = doc.SelectNodes("/failedRequest/a:Event/a:System/a:Correlation", nsmgr);
                    foreach (XmlNode ynot in sCOs)
                    {
                        ynot.Attributes["ActivityID"].Value = "{00000000-0000-0000-0000-000000000000}";
                        //ynot.ParentNode.RemoveChild(ynot);
                    }
                    XmlNodeList sEXs = doc.SelectNodes("/failedRequest/a:Event/a:System/a:Execution", nsmgr);
                    foreach (XmlNode ynot in sEXs)
                    {
                        ynot.Attributes["ProcessID"].Value = "0";
                        ynot.Attributes["ThreadID"].Value  = "0";
                        //ynot.ParentNode.RemoveChild(ynot);
                    }
                    XmlNodeList sCIDs = doc.SelectNodes("/failedRequest/a:Event/a:EventData/a:Data[@Name='ContextId']", nsmgr);
                    foreach (XmlNode ynot in sCIDs)
                    {
                        ynot.FirstChild.Value = "{00000000-0000-0000-0000-000000000000}";
                        //ynot.ParentNode.RemoveChild(ynot);
                    }
                    XmlNodeList sCID2s = doc.SelectNodes("/failedRequest/a:Event/a:EventData/a:Data[@Name='Context ID']", nsmgr);
                    foreach (XmlNode ynot in sCID2s)
                    {
                        ynot.FirstChild.Value = "{00000000-0000-0000-0000-000000000000}";
                        //ynot.ParentNode.RemoveChild(ynot);
                    }
                    // write it back out to contents.. pretty print it
                    // Format the XML text.
                    StringWriter  string_writer   = new StringWriter();
                    XmlTextWriter xml_text_writer = new XmlTextWriter(string_writer);
                    xml_text_writer.Formatting = Formatting.Indented;
                    doc.WriteTo(xml_text_writer);

                    // Display the result.
                    outputFRTObject.sFileContents = string_writer.ToString();

                    //outputFRTObject.sFileContents = doc.OuterXml;
                }
                return(true);
            }
            catch (Exception eeek) // any exception just invalidates the file
            {
                if (fFailedRequestFile)
                {
                    outputFRTObject.sURL = "PARSE ERROR! " + outputFRTObject.sURL;
                    return(true);
                }
                else
                {
                    outputFRTObject = null;
                    return(false);
                }
            }

            // logic error (?) if it reaches here.
            outputFRTObject = null;
            return(false);
        }