示例#1
0
        public static StackHashScriptResult MergeAnalysisDumpFiles(string fileName)
        {
            // Load the script results from the specified file.
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            if (!File.Exists(fileName))
            {
                throw new ArgumentException("File not found", "fileName");
            }

            // String[] allLines = File.ReadAllLines(fileName, Encoding.Unicode);
            String[] allLines = FileUtils.ReadAllLinesWithTypeCheck(fileName);

            StackHashScriptLineResult thisCommand = null;

            String[]      separators           = new String[] { "---" };
            List <String> outLines             = new List <String>();
            bool          foundAnalysisCommand = false;
            bool          foundCommandStart    = false;

            for (int i = 0; i < allLines.Length; i++)
            {
                if (allLines[i].StartsWith("Command---", StringComparison.OrdinalIgnoreCase))
                {
                    // Get the command and comment.
                    String[] components = allLines[i].Split(separators, StringSplitOptions.RemoveEmptyEntries);
                    thisCommand = new StackHashScriptLineResult();


                    if (components.Length == 1)
                    {
                        thisCommand.ScriptLine = new StackHashScriptLine();
                    }
                    else if (components.Length == 2)
                    {
                        thisCommand.ScriptLine = new StackHashScriptLine(components[1], null);
                    }
                    else if (components.Length == 3)
                    {
                        thisCommand.ScriptLine = new StackHashScriptLine(components[1], components[2]);
                    }
                    thisCommand.ScriptLineOutput = new StackHashScriptLineOutput();

                    // Check for the !analysis command.
                    if ((thisCommand.ScriptLine != null) && (thisCommand.ScriptLine.Command != null) && (thisCommand.ScriptLine.Command.IndexOf("!Analysis", StringComparison.OrdinalIgnoreCase) != -1))
                    {
                        foundCommandStart = true;
                    }
                }
                else if (allLines[i].StartsWith("CommandEnd---", StringComparison.OrdinalIgnoreCase))
                {
                    if (foundCommandStart)
                    {
                        // If the analysis command end has been found then get the results.
                        foundAnalysisCommand = true;
                        addAnalysisFiles(Path.GetDirectoryName(fileName), outLines);
                        foundCommandStart = false;
                    }
                }
                outLines.Add(allLines[i]);
            }


            if (foundCommandStart)
            {
                foundAnalysisCommand = true;
                // The command end seems to be missing for this !analysis.
                addAnalysisFiles(Path.GetDirectoryName(fileName), outLines);
            }

            if (foundAnalysisCommand)
            {
                File.WriteAllLines(fileName, outLines.ToArray());
            }

            return(new StackHashScriptResult(fileName));
        }
示例#2
0
        public StackHashScriptResult(string fileName)
        {
            // Load the script results from the specified file.
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            if (!File.Exists(fileName))
            {
                throw new ArgumentException("File not found", "fileName");
            }

            // String[] allLines = File.ReadAllLines(fileName, Encoding.Unicode);
            String[] allLines = FileUtils.ReadAllLinesWithTypeCheck(fileName);

            StackHashScriptLineResults allResults  = new StackHashScriptLineResults();
            StackHashScriptLineResult  thisCommand = null;

            bool isDebuggerVersion  = false;
            bool awaitingCommandEnd = false;
            bool standardLogOutput  = false;

            for (int i = 0; i < allLines.Length; i++)
            {
                String[] separators = new String[] { "---" };
                if (allLines[i].StartsWith("Script---", StringComparison.OrdinalIgnoreCase) ||
                    allLines[i].StartsWith("Script2---", StringComparison.OrdinalIgnoreCase))
                {
                    int scriptVersion = 1;

                    if (allLines[i].StartsWith("Script2---", StringComparison.OrdinalIgnoreCase))
                    {
                        scriptVersion = 2;
                    }

                    standardLogOutput = true;

                    // Get the name and LastModified date of the script.
                    String[] components = allLines[i].Split(separators, StringSplitOptions.RemoveEmptyEntries);

                    m_Name = components[1];

                    // Note these dates are stored with current culture so they look good when presented to user.
                    if (scriptVersion == 1)
                    {
                        m_LastModifiedDate = getDateTimeFromText(components[3], CultureInfo.CurrentCulture);
                        m_RunDate          = getDateTimeFromText(components[5], CultureInfo.CurrentCulture);
                    }
                    else
                    {
                        m_LastModifiedDate = getDateTimeFromText(components[3], CultureInfo.InvariantCulture);
                        m_RunDate          = getDateTimeFromText(components[5], CultureInfo.InvariantCulture);
                    }
                    m_LastModifiedDate = new DateTime(m_LastModifiedDate.Ticks, DateTimeKind.Utc);
                    m_RunDate          = new DateTime(m_RunDate.Ticks, DateTimeKind.Utc);

                    if (components.Length >= 8)
                    {
                        m_ScriptVersion = int.Parse(components[7], CultureInfo.InvariantCulture);
                    }
                }
                else if (allLines[i].StartsWith("Command---", StringComparison.OrdinalIgnoreCase))
                {
                    // Get the command and comment.
                    String[] components = allLines[i].Split(separators, StringSplitOptions.RemoveEmptyEntries);
                    thisCommand = new StackHashScriptLineResult();


                    if (components.Length == 1)
                    {
                        thisCommand.ScriptLine = new StackHashScriptLine();
                    }
                    else if (components.Length == 2)
                    {
                        thisCommand.ScriptLine = new StackHashScriptLine(components[1], null);
                    }
                    else if (components.Length == 3)
                    {
                        thisCommand.ScriptLine = new StackHashScriptLine(components[1], components[2]);
                    }
                    thisCommand.ScriptLineOutput = new StackHashScriptLineOutput();

                    awaitingCommandEnd = true;

                    // It is possible for the command to be an empty line.
                    if ((thisCommand.ScriptLine != null) && (thisCommand.ScriptLine.Command != null))
                    {
                        isDebuggerVersion = (thisCommand.ScriptLine.Command == "version");
                    }
                    else
                    {
                        isDebuggerVersion = false;
                    }
                }
                else if (allLines[i].StartsWith("CommandEnd---", StringComparison.OrdinalIgnoreCase))
                {
                    awaitingCommandEnd = false;
                    if (thisCommand != null)
                    {
                        allResults.Add(thisCommand);
                        thisCommand       = null;
                        isDebuggerVersion = false;
                    }
                }
                else
                {
                    if (thisCommand != null)
                    {
                        if (isDebuggerVersion)
                        {
                            // Only store the first line of the debugger version.
                            if (allLines[i].Contains("Microsoft (R) Windows Debugger Version"))
                            {
                                thisCommand.ScriptLineOutput.Add(allLines[i]);
                            }
                        }
                        else
                        {
                            thisCommand.ScriptLineOutput.Add(allLines[i]);
                        }
                    }
                }
            }

            // If an error occurred in the script then it may be incomplete.
            // In this case return the error back to the user.
            if (awaitingCommandEnd)
            {
                if (thisCommand != null)
                {
                    allResults.Add(thisCommand);
                }
            }

            // The !Analysis command produces a load of log files in the script output folder. Just load these as standard text files.
            if (!standardLogOutput)
            {
                thisCommand                  = new StackHashScriptLineResult();
                thisCommand.ScriptLine       = new StackHashScriptLine("Script command", "Special script");
                thisCommand.ScriptLineOutput = new StackHashScriptLineOutput();

                m_Name = Path.GetFileNameWithoutExtension(fileName);

                m_LastModifiedDate = File.GetLastWriteTimeUtc(fileName);
                m_RunDate          = File.GetLastWriteTimeUtc(fileName);

                foreach (String line in allLines)
                {
                    thisCommand.ScriptLineOutput.Add(line);
                }
                allResults.Add(thisCommand);
            }

            m_ScriptResults = allResults;
        }