コード例 #1
0
        private void AddNoteToParagraph(StackHashNoteEntry note, ref Paragraph para)
        {
            // create header
            Span noteHeaderSpan = new Span();

            noteHeaderSpan.FontWeight = FontWeights.Bold;
            noteHeaderSpan.Inlines.Add(new Run(string.Format(CultureInfo.CurrentCulture,
                                                             Properties.Resources.NotesControl_HeaderName,
                                                             note.User)));

            Span noteInfoSpan = new Span();

            noteInfoSpan.Foreground = Brushes.Gray;
            noteInfoSpan.Inlines.Add(new Run(string.Format(CultureInfo.CurrentCulture,
                                                           Properties.Resources.NotesControl_HeaderDetails,
                                                           (string)_dateTimeDisplayConverter.Convert(note.TimeOfEntry, typeof(string), null, CultureInfo.CurrentCulture),
                                                           note.Source)));

            // create note
            Run noteRun = new Run(note.Note);

            Hyperlink linkEditNote = new Hyperlink(new Run("Edit"));

            linkEditNote.Tag              = note;
            linkEditNote.NavigateUri      = new Uri("http://www.stackhash.com/");
            linkEditNote.RequestNavigate += new RequestNavigateEventHandler(linkEditNote_RequestNavigate);

            para.Inlines.Add(noteHeaderSpan);
            para.Inlines.Add(new Run(" "));
            para.Inlines.Add(noteInfoSpan);
            para.Inlines.Add(new Run(" ("));
            para.Inlines.Add(linkEditNote);
            para.Inlines.Add(new Run(")"));
            para.Inlines.Add(new LineBreak());
            para.Inlines.Add(noteRun);
            para.Inlines.Add(new LineBreak());
            para.Inlines.Add(new LineBreak());

            // add hyperlinks to note run
            try
            {
                while (ProcessInlines(para.Inlines.FirstInline))
                {
                }
                ;
            }
            catch (Exception ex)
            {
                DiagnosticsHelper.LogException(DiagSeverity.Warning, "AddNoteToParagraph failed", ex);
            }
        }
コード例 #2
0
        /// <summary>
        /// Process a cab note table update. This may indicate a new item or the change to an existing item.
        /// </summary>
        private bool processCabNoteUpdate(StackHashBugTrackerUpdate update)
        {
            // Get the associated product and file information.
            StackHashProduct   product  = m_Index.GetProduct((int)update.ProductId);
            StackHashFile      file     = m_Index.GetFile(product, (int)update.FileId);
            StackHashEvent     theEvent = m_Index.GetEvent(product, file, new StackHashEvent((int)update.EventId, update.EventTypeName));
            StackHashCab       cab      = m_Index.GetCab(product, file, theEvent, (int)update.CabId);
            StackHashNoteEntry note     = m_Index.GetCabNote((int)update.ChangedObjectId);

            if ((product == null) || (file == null) || (theEvent == null) || (cab == null) || (note == null))
            {
                DiagnosticsHelper.LogMessage(DiagSeverity.Warning, "Processing Cab Note: Inconsistent Update Table Entry");
                return(false);
            }

            BugTrackerProduct   btProduct      = new BugTrackerProduct(product.Name, product.Version, product.Id);
            BugTrackerFile      btFile         = new BugTrackerFile(file.Name, file.Version, file.Id);
            NameValueCollection eventSignature = new NameValueCollection();

            foreach (StackHashParameter param in theEvent.EventSignature.Parameters)
            {
                eventSignature.Add(param.Name, param.Value);
            }

            BugTrackerEvent btEvent = new BugTrackerEvent(theEvent.BugId, theEvent.PlugInBugId, theEvent.Id, theEvent.EventTypeName,
                                                          theEvent.TotalHits, eventSignature);

            NameValueCollection analysis = new NameValueCollection();

            analysis.Add("DotNetVersion", cab.DumpAnalysis.DotNetVersion);
            analysis.Add("MachineArchitecture", cab.DumpAnalysis.MachineArchitecture);
            analysis.Add("OSVersion", cab.DumpAnalysis.OSVersion);
            analysis.Add("ProcessUpTime", cab.DumpAnalysis.ProcessUpTime);
            analysis.Add("SystemUpTime", cab.DumpAnalysis.SystemUpTime);

            String        cabFileName = m_Index.GetCabFileName(product, file, theEvent, cab);
            BugTrackerCab btCab       = new BugTrackerCab(cab.Id, cab.SizeInBytes, cab.CabDownloaded, cab.Purged, analysis, cabFileName);

            BugTrackerNote btCabNote = new BugTrackerNote(note.TimeOfEntry, note.Source, note.User, note.Note);

            String newBugId = null;

            if (update.TypeOfChange == StackHashChangeType.NewEntry)
            {
                newBugId = m_TaskParameters.PlugInContext.CabNoteAdded(null, BugTrackerReportType.Automatic, btProduct, btFile, btEvent, btCab, btCabNote);
            }

            setPlugInBugReference(product, file, theEvent, newBugId);

            return(true);
        }
コード例 #3
0
        private void ConfigureEditMode(StackHashNoteEntry editNote)
        {
            _currentEditNote = editNote;
            if (_currentEditNote == null)
            {
                textBoxNote.Text = string.Empty;
            }
            else
            {
                textBoxNote.Text = _currentEditNote.Note;
            }

            textAddNote.Visibility  = Visibility.Collapsed;
            textBoxNote.Visibility  = Visibility.Visible;
            panelButtons.Visibility = Visibility.Visible;

            Keyboard.Focus(textBoxNote);
        }
コード例 #4
0
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        //================================================================================================================================
        // GET CAB FOLDER TESTS.
        //================================================================================================================================
        #region AddCabNoteTests

        private void testAddCabNoteNullProduct(IErrorIndex index)
        {
            try
            {
                index.Activate();

                StackHashFile      file     = new StackHashFile();
                StackHashEvent     theEvent = new StackHashEvent();
                StackHashCab       cab      = new StackHashCab();
                StackHashNoteEntry note     = new StackHashNoteEntry();

                index.AddCabNote(null, file, theEvent, cab, note);
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("product", ex.ParamName);
                throw;
            }
        }
コード例 #5
0
        private void testAddCabNoteProductDoesntExist(IErrorIndex index)
        {
            try
            {
                index.Activate();
                StackHashProduct product = new StackHashProduct(DateTime.Now, DateTime.Now, "fileslink", 1, "Name", 10, 11, "version");

                StackHashFile      file     = new StackHashFile();
                StackHashEvent     theEvent = new StackHashEvent();
                StackHashCab       cab      = new StackHashCab();
                StackHashNoteEntry note     = new StackHashNoteEntry();

                index.AddCabNote(product, file, theEvent, cab, note);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("product", ex.ParamName);
                throw;
            }
        }
コード例 #6
0
        private void testAddCabNoteNullEvent(IErrorIndex index)
        {
            try
            {
                index.Activate();
                StackHashProduct   product = new StackHashProduct(DateTime.Now, DateTime.Now, "fileslink", 1, "Name", 10, 11, "version");
                StackHashFile      file    = new StackHashFile(DateTime.Now, DateTime.Now, 6, DateTime.Now, "FileName", "FileVersion");
                StackHashCab       cab     = new StackHashCab();
                StackHashNoteEntry note    = new StackHashNoteEntry();

                index.AddProduct(product);
                index.AddFile(product, file);

                index.AddCabNote(product, file, null, cab, note);
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("theEvent", ex.ParamName);
                throw;
            }
        }
コード例 #7
0
        /// <summary>
        /// Process an event note table update. This may indicate a new item or the change to an existing item.
        /// </summary>
        private bool processEventNoteUpdate(StackHashBugTrackerUpdate update)
        {
            // Get the associated product and file information.
            StackHashProduct   product  = m_Index.GetProduct((int)update.ProductId);
            StackHashFile      file     = m_Index.GetFile(product, (int)update.FileId);
            StackHashEvent     theEvent = m_Index.GetEvent(product, file, new StackHashEvent((int)update.EventId, update.EventTypeName));
            StackHashNoteEntry note     = m_Index.GetEventNote((int)update.ChangedObjectId);

            if ((product == null) || (file == null) || (theEvent == null) || (note == null))
            {
                DiagnosticsHelper.LogMessage(DiagSeverity.Warning, "Processing Event Note: Inconsistent Update Table Entry");
                return(false);
            }

            BugTrackerProduct   btProduct      = new BugTrackerProduct(product.Name, product.Version, product.Id);
            BugTrackerFile      btFile         = new BugTrackerFile(file.Name, file.Version, file.Id);
            NameValueCollection eventSignature = new NameValueCollection();

            foreach (StackHashParameter param in theEvent.EventSignature.Parameters)
            {
                eventSignature.Add(param.Name, param.Value);
            }

            BugTrackerEvent btEvent = new BugTrackerEvent(theEvent.BugId, theEvent.PlugInBugId, theEvent.Id, theEvent.EventTypeName,
                                                          theEvent.TotalHits, eventSignature);


            BugTrackerNote btEventNote = new BugTrackerNote(note.TimeOfEntry, note.Source, note.User, note.Note);

            String newBugId = null;

            if (update.TypeOfChange == StackHashChangeType.NewEntry)
            {
                newBugId = m_TaskParameters.PlugInContext.EventNoteAdded(null, BugTrackerReportType.Automatic, btProduct, btFile, btEvent, btEventNote);
            }

            setPlugInBugReference(product, file, theEvent, newBugId);

            return(true);
        }
コード例 #8
0
        private void testAddCabNNotes(IErrorIndex index, int numNotes)
        {
            index.Activate();
            StackHashProduct product  = new StackHashProduct(DateTime.Now, DateTime.Now, "fileslink", 1, "Name", 10, 11, "version");
            StackHashFile    file     = new StackHashFile(DateTime.Now, DateTime.Now, 6, DateTime.Now, "FileName", "FileVersion");
            StackHashEvent   theEvent = new StackHashEvent(DateTime.Now, DateTime.Now, "TypeName", 10, new StackHashEventSignature(), 10, 2);
            StackHashCab     cab      = new StackHashCab(DateTime.Now, DateTime.Now, 10, "Type", "EventFileName", 10, 100);

            index.AddProduct(product);
            index.AddFile(product, file);
            index.AddEvent(product, file, theEvent);
            index.AddCab(product, file, theEvent, cab, false);

            StackHashNotes allNotes = new StackHashNotes();

            for (int i = 0; i < numNotes; i++)
            {
                StackHashNoteEntry note = new StackHashNoteEntry(new DateTime(i), "Source" + i.ToString(), "User" + i.ToString(), "Notes...." + i.ToString());
                allNotes.Add(note);
                index.AddCabNote(product, file, theEvent, cab, note);
            }


            // Get the list back.
            StackHashNotes notes = index.GetCabNotes(product, file, theEvent, cab);

            Assert.AreEqual(numNotes, notes.Count);

            for (int i = 0; i < numNotes; i++)
            {
                Assert.AreEqual(allNotes[i].TimeOfEntry, notes[i].TimeOfEntry);
                Assert.AreEqual(allNotes[i].Source, notes[i].Source);
                Assert.AreEqual(allNotes[i].User, notes[i].User);
                Assert.AreEqual(allNotes[i].Note, notes[i].Note);
            }
        }
コード例 #9
0
        public StackHashScriptResult RunScript(StackHashProduct product, StackHashFile file, StackHashEvent theEvent, StackHashCab cab,
                                               String dumpFileName, String scriptName, bool extractCab, StackHashClientData clientData, bool forceRun)
        {
            if (product == null)
            {
                throw new ArgumentNullException("product");
            }
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }
            if (theEvent == null)
            {
                throw new ArgumentNullException("theEvent");
            }
            if (cab == null)
            {
                throw new ArgumentNullException("cab");
            }
            if (scriptName == null)
            {
                throw new ArgumentNullException("scriptName");
            }


            String machineArchitecture = "x86"; // Default to 32 bit.

            if ((cab.DumpAnalysis != null) && !String.IsNullOrEmpty(cab.DumpAnalysis.MachineArchitecture))
            {
                machineArchitecture = cab.DumpAnalysis.MachineArchitecture;
            }


            StackHashScriptResult result = null;
            bool use32BitDebugger        = true;

            if (machineArchitecture != null)
            {
                if ((String.Compare(machineArchitecture, "x64", StringComparison.OrdinalIgnoreCase) == 0) ||
                    (String.Compare(machineArchitecture, "X64", StringComparison.OrdinalIgnoreCase) == 0))
                {
                    use32BitDebugger = false;
                }
            }


            // Unwrap the cab if necessary.
            String cabFileName   = m_ErrorIndex.GetCabFileName(product, file, theEvent, cab);
            String cabFileFolder = Path.GetDirectoryName(cabFileName);

            if (!File.Exists(cabFileName))
            {
                throw new StackHashException("Cab file does not exist: " + cabFileName, StackHashServiceErrorCode.CabDoesNotExist);
            }

            if (extractCab)
            {
                try
                {
                    Cabs.ExtractCab(cabFileName, cabFileFolder);
                }
                catch (System.Exception ex)
                {
                    if (ex.Message.Contains("The file is not a cabinet") || ex.Message.Contains("corrupt") || ex.Message.Contains("Corrupt"))
                    {
                        // Set the downloaded flag appropriately if different.
                        StackHashCab loadedCab = m_ErrorIndex.GetCab(product, file, theEvent, cab.Id);

                        if (loadedCab != null)
                        {
                            if (loadedCab.CabDownloaded)
                            {
                                loadedCab.CabDownloaded = false;
                                m_ErrorIndex.AddCab(product, file, theEvent, loadedCab, false);
                            }
                        }
                    }

                    throw new StackHashException("Cab file cannot be unpackaged. Try downloading the file from again.", ex, StackHashServiceErrorCode.CabIsCorrupt);
                }
            }

            // Now get the dump filename - mdmp and dmp files should be returned.
            String[] allDumpFiles = Directory.GetFiles(cabFileFolder, "*.*dmp");

            if (allDumpFiles.Length == 0)
            {
                return(null);
            }

            // Choose the largest dump file to process.
            String fullDumpFilePath = null;

            long largestFileSize = 0;

            foreach (String fileName in allDumpFiles)
            {
                FileInfo fileInfo = new FileInfo(fileName);
                if (fileInfo.Length > largestFileSize)
                {
                    largestFileSize  = fileInfo.Length;
                    fullDumpFilePath = fileName;
                }
            }

            if (!String.IsNullOrEmpty(dumpFileName))
            {
                fullDumpFilePath = cabFileFolder + "\\" + dumpFileName;
            }

            // Find the script that the user wants to run.
            StackHashScriptSettings scriptSettings = m_ScriptManager.LoadScript(scriptName);

            // Auto generate the script file.
            String dumpAnalysisFolder = cabFileFolder + "\\Analysis";

            if (!Directory.Exists(dumpAnalysisFolder))
            {
                Directory.CreateDirectory(dumpAnalysisFolder);
            }

            // Check if the file has already been run.
            bool   runScript       = true;
            String resultsFileName = String.Format(CultureInfo.InvariantCulture, "{0}\\{1}.log", dumpAnalysisFolder, scriptSettings.Name);

            if (File.Exists(resultsFileName))
            {
                DateTime lastWriteTime = File.GetLastWriteTimeUtc(resultsFileName);

                if (scriptSettings.LastModifiedDate <= lastWriteTime)
                {
                    runScript = false;
                }
            }

            String installFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            if (runScript || forceRun)
            {
                String overrideSymbolPath = null;
                String overrideBinaryPath = null;
                String overrideSourcePath = null;

                if (m_Debugger.Use32BitDebugger(use32BitDebugger, m_DebuggerSettings))
                {
                    overrideSymbolPath = m_DebuggerSettings.SymbolPath.FullPath;
                    overrideBinaryPath = m_DebuggerSettings.BinaryPath.FullPath;
                    overrideSourcePath = null;

                    // Check the script for PSSCOR loading.
                    String clrVersion = String.Empty;
                    if ((cab.DumpAnalysis != null) && (!String.IsNullOrEmpty(cab.DumpAnalysis.DotNetVersion)))
                    {
                        clrVersion = cab.DumpAnalysis.DotNetVersion;
                    }
                    scriptSettings.FixUp(StackHashScriptDumpArchitecture.X86, clrVersion, installFolder);
                }
                else
                {
                    overrideSymbolPath = m_DebuggerSettings.SymbolPath64Bit.FullPath;
                    overrideBinaryPath = m_DebuggerSettings.BinaryPath64Bit.FullPath;
                    overrideSourcePath = null;

                    // Check the script for PSSCOR loading.
                    String clrVersion = String.Empty;
                    if ((cab.DumpAnalysis != null) && (!String.IsNullOrEmpty(cab.DumpAnalysis.DotNetVersion)))
                    {
                        clrVersion = cab.DumpAnalysis.DotNetVersion;
                    }
                    scriptSettings.FixUp(StackHashScriptDumpArchitecture.Amd64, clrVersion, installFolder);
                }

                String scriptFileName = Path.GetTempFileName();
                scriptSettings.GenerateScriptFile(scriptFileName, resultsFileName, ref overrideSymbolPath, ref overrideBinaryPath, ref overrideSourcePath);

                DateTime timeOfRun = DateTime.Now.ToUniversalTime();
                try
                {
                    m_Debugger.RunScript(m_DebuggerSettings, use32BitDebugger, scriptFileName, fullDumpFilePath, resultsFileName, overrideSymbolPath, overrideBinaryPath, overrideSourcePath);

                    // Check if the results were generated. If not there must be a command line error so get the output from the
                    // debugger and throw an exception.
                    if (!File.Exists(resultsFileName))
                    {
                        throw new StackHashException("Debugger Error: " + m_Debugger.StandardError, StackHashServiceErrorCode.DebuggerError);
                    }


                    // Load in the results.
                    result = StackHashScriptResult.MergeAnalysisDumpFiles(resultsFileName);

                    // Add a script run note to the error index.
                    StackHashNoteEntry note = new StackHashNoteEntry();

                    // MUST KEEP THIS TEXT THE SAME - because it is used as a search string by the BugTrackerTask.
                    note.Note = String.Format(CultureInfo.CurrentCulture, "Script {0} executed", scriptName);
                    if ((clientData == null) || (clientData.ClientName == null))
                    {
                        note.Source = "Service";
                        note.User   = "******";
                    }
                    else
                    {
                        note.Source = "StackHash Client";
                        note.User   = clientData.ClientName;
                    }

                    note.TimeOfEntry = timeOfRun;
                    int cabNoteId = m_ErrorIndex.AddCabNote(product, file, theEvent, cab, note);

                    // Report the event to bug tracking plug-ins.
                    m_ErrorIndex.AddUpdate(new StackHashBugTrackerUpdate(
                                               StackHashDataChanged.DebugScript, StackHashChangeType.NewEntry, product.Id, file.Id, theEvent.Id, theEvent.EventTypeName, cab.Id, cabNoteId));
                }
                catch (System.Exception ex)
                {
                    // Add a script run note to the error index.
                    StackHashNoteEntry note = new StackHashNoteEntry();
                    note.Note   = String.Format(CultureInfo.CurrentCulture, "Script {0} execution failed: {1}", scriptName, ex.Message);
                    note.Source = "Service";
                    if ((clientData == null) || (clientData.ClientName == null))
                    {
                        note.User = "******";
                    }
                    else
                    {
                        note.User = clientData.ClientName;
                    }
                    note.TimeOfEntry = timeOfRun;
                    m_ErrorIndex.AddCabNote(product, file, theEvent, cab, note);
                    throw;
                }
                finally
                {
                    if (File.Exists(scriptFileName))
                    {
                        File.Delete(scriptFileName);
                    }
                }
            }

            return(result);
        }
コード例 #10
0
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        public void addRemoveEventNotes(int numberOfNotes)
        {
            StackHashTestIndexData testIndexData = new StackHashTestIndexData();

            testIndexData.NumberOfProducts   = 1;
            testIndexData.NumberOfFiles      = 1;
            testIndexData.NumberOfEvents     = 1;
            testIndexData.NumberOfEventInfos = 0;
            testIndexData.NumberOfCabs       = 0;

            // Add a context.
            CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(ErrorIndexType.SqlExpress);

            String testPath = "c:\\stackhashunittests\\testindex\\";

            resp.Settings.ErrorIndexSettings.Folder = testPath;
            resp.Settings.ErrorIndexSettings.Name   = "TestIndex";
            resp.Settings.ErrorIndexSettings.Type   = ErrorIndexType.SqlExpress;
            m_Utils.SetContextSettings(resp.Settings);
            m_Utils.DeleteIndex(0);
            m_Utils.ActivateContext(0);

            m_Utils.CreateTestIndex(0, testIndexData);

            try
            {
                // Enable all products so that they appear in searchs.
                StackHashProductInfoCollection products = m_Utils.GetProducts(0).Products;
                StackHashProduct         product        = products[0].Product;
                StackHashFileCollection  files          = m_Utils.GetFiles(0, product).Files;
                StackHashEventCollection events         = m_Utils.GetEvents(0, product, files[0]).Events;


                // Add the specified number of event notes.
                for (int eventCount = 0; eventCount < numberOfNotes; eventCount++)
                {
                    StackHashNoteEntry note = new StackHashNoteEntry();
                    note.Note        = "Note" + (eventCount + 1).ToString();
                    note.Source      = "USER";
                    note.User        = "******";
                    note.TimeOfEntry = DateTime.Now.AddDays(-1);

                    m_Utils.AddEventNote(0, product, files[0], events[0], note);

                    StackHashNotes notes = m_Utils.GetEventNotes(0, product, files[0], events[0]).Notes;

                    Assert.AreEqual(eventCount + 1, notes.Count);
                    bool found = false;
                    foreach (StackHashNoteEntry noteEntry in notes)
                    {
                        if (noteEntry.NoteId == eventCount + 1)
                        {
                            Assert.AreEqual(note.Note, noteEntry.Note);
                            Assert.AreEqual(note.Source, noteEntry.Source);
                            Assert.AreEqual(note.User, noteEntry.User);
                            Assert.AreEqual(DateTime.UtcNow.Date, noteEntry.TimeOfEntry.Date);
                            found = true;
                            break;
                        }
                    }

                    Assert.AreEqual(true, found);
                }

                // Now delete the event notes.
                int expectedEventNotes = numberOfNotes;

                for (int eventCount = 0; eventCount < numberOfNotes; eventCount++)
                {
                    m_Utils.DeleteEventNote(0, product, files[0], events[0], eventCount + 1);

                    expectedEventNotes--;

                    StackHashNotes notes = m_Utils.GetEventNotes(0, product, files[0], events[0]).Notes;

                    Assert.AreEqual(expectedEventNotes, notes.Count);

                    bool found = false;
                    foreach (StackHashNoteEntry noteEntry in notes)
                    {
                        if (noteEntry.NoteId == eventCount + 1)
                        {
                            found = true;
                            break;
                        }
                    }

                    Assert.AreEqual(false, found);
                }
            }
            finally
            {
                m_Utils.DeactivateContext(0);
                m_Utils.DeleteIndex(0);
            }
        }
コード例 #11
0
        /// <summary>
        /// Process a debug script change.
        /// </summary>
        private bool processDebugScriptUpdate(StackHashBugTrackerUpdate update)
        {
            // Get the associated product and file information.
            StackHashProduct product  = m_Index.GetProduct((int)update.ProductId);
            StackHashFile    file     = m_Index.GetFile(product, (int)update.FileId);
            StackHashEvent   theEvent = m_Index.GetEvent(product, file, new StackHashEvent((int)update.EventId, update.EventTypeName));

            DiagnosticsHelper.LogMessage(DiagSeverity.Warning, "Processing Debug Script: getting cab data1");
            StackHashCab cab = m_Index.GetCab(product, file, theEvent, (int)update.CabId);

            DiagnosticsHelper.LogMessage(DiagSeverity.Warning, "Processing Debug Script: getting cab data2");
            StackHashNoteEntry note = m_Index.GetCabNote((int)update.ChangedObjectId);

            if ((product == null) || (file == null) || (theEvent == null) || (cab == null) || (note == null))
            {
                if (product == null)
                {
                    DiagnosticsHelper.LogMessage(DiagSeverity.Warning, "Processing Debug Script: Inconsistent Update Table Entry : product");
                }
                if (file == null)
                {
                    DiagnosticsHelper.LogMessage(DiagSeverity.Warning, "Processing Debug Script: Inconsistent Update Table Entry : file");
                }
                if (theEvent == null)
                {
                    DiagnosticsHelper.LogMessage(DiagSeverity.Warning, "Processing Debug Script: Inconsistent Update Table Entry : the Event");
                }
                if (cab == null)
                {
                    DiagnosticsHelper.LogMessage(DiagSeverity.Warning, "Processing Debug Script: Inconsistent Update Table Entry : cab: " + update.CabId.ToString(CultureInfo.InvariantCulture));
                }
                if (note == null)
                {
                    DiagnosticsHelper.LogMessage(DiagSeverity.Warning, "Processing Debug Script: Inconsistent Update Table Entry : note");
                }
                return(false);
            }

            BugTrackerProduct   btProduct      = new BugTrackerProduct(product.Name, product.Version, product.Id);
            BugTrackerFile      btFile         = new BugTrackerFile(file.Name, file.Version, file.Id);
            NameValueCollection eventSignature = new NameValueCollection();

            foreach (StackHashParameter param in theEvent.EventSignature.Parameters)
            {
                eventSignature.Add(param.Name, param.Value);
            }

            BugTrackerEvent btEvent = new BugTrackerEvent(theEvent.BugId, theEvent.PlugInBugId, theEvent.Id, theEvent.EventTypeName,
                                                          theEvent.TotalHits, eventSignature);

            NameValueCollection analysis = new NameValueCollection();

            analysis.Add("DotNetVersion", cab.DumpAnalysis.DotNetVersion);
            analysis.Add("MachineArchitecture", cab.DumpAnalysis.MachineArchitecture);
            analysis.Add("OSVersion", cab.DumpAnalysis.OSVersion);
            analysis.Add("ProcessUpTime", cab.DumpAnalysis.ProcessUpTime);
            analysis.Add("SystemUpTime", cab.DumpAnalysis.SystemUpTime);

            String        cabFileName = m_Index.GetCabFileName(product, file, theEvent, cab);
            BugTrackerCab btCab       = new BugTrackerCab(cab.Id, cab.SizeInBytes, cab.CabDownloaded, cab.Purged, analysis, cabFileName);

            BugTrackerNote btCabNote = new BugTrackerNote(note.TimeOfEntry, note.Source, note.User, note.Note);

            // A note entry will be written when a script is run. Pick out the name of the script.
            // Format is "Script {0} executed".
            int    startIndex = btCabNote.Note.IndexOf("Script ", StringComparison.OrdinalIgnoreCase) + "Script ".Length;
            int    endIndex   = btCabNote.Note.IndexOf("executed", StringComparison.OrdinalIgnoreCase) - 2;
            int    length     = endIndex - startIndex + 1;
            String scriptName = btCabNote.Note.Substring(startIndex, length);

            StackHashScriptResult stackHashScriptResult = m_TaskParameters.TheScriptResultsManager.GetResultFileData(product, file, theEvent, cab, scriptName);

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

            BugTrackerScriptResult btScriptResult = new BugTrackerScriptResult(stackHashScriptResult.Name, stackHashScriptResult.ScriptVersion,
                                                                               stackHashScriptResult.LastModifiedDate, stackHashScriptResult.RunDate, stackHashScriptResult.ToString());

            String newBugId = null;

            if (update.TypeOfChange == StackHashChangeType.NewEntry)
            {
                newBugId = m_TaskParameters.PlugInContext.DebugScriptExecuted(null, BugTrackerReportType.Automatic, btProduct, btFile, btEvent, btCab, btScriptResult);
            }
            setPlugInBugReference(product, file, theEvent, newBugId);

            return(true);
        }
コード例 #12
0
        public static void CreateTestIndex(IErrorIndex index, StackHashTestIndexData testData, bool includeDuplicates)
        {
            if (testData.EventsToAssignCabs == 0)
            {
                testData.EventsToAssignCabs = 1;
            }

            Random rand       = new Random(1);
            Random scriptRand = new Random(1);

            if (index == null)
            {
                throw new ArgumentNullException("index");
            }
            if (testData == null)
            {
                throw new ArgumentNullException("testData");
            }

            DateTime now = DateTime.Now;


            int fileId    = 1;
            int eventId   = 1;
            int cabId     = 1;
            int productId = 1;
            int offset    = 10000;

            if (!s_IsTestMode)
            {
                productId = 26214;
                fileId    = 1035620;
                eventId   = 1099309964;
                cabId     = 939529168;
            }

            int initialFileId  = fileId;
            int initialEventId = eventId;
            int initialCabId   = cabId;
            int initialOffset  = offset;

            int totalEventsPerProduct = testData.NumberOfFiles * testData.NumberOfEvents;

            index.SetLastSyncTimeLocal(-2, DateTime.Now.AddDays(-14));

            for (int i = 0; i < testData.NumberOfProducts; i++)
            {
                StackHashProduct product = new StackHashProduct();
                product.DateCreatedLocal  = now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180)).RoundToPreviousMinute();
                product.DateModifiedLocal = product.DateCreatedLocal.AddDays(rand.Next(-10, 10)).RoundToPreviousMinute();
                product.FilesLink         = "http://www.cucku.com";
                product.Id             = productId;
                product.Name           = "StackHash" + productId.ToString(CultureInfo.InvariantCulture);
                product.TotalEvents    = totalEventsPerProduct;
                product.TotalResponses = 1;
                product.Version        = "1.2.3." + productId.ToString(CultureInfo.InvariantCulture);

                index.AddProduct(product);
                productId++;

                if (includeDuplicates)
                {
                    fileId  = initialFileId;
                    eventId = initialEventId;
                    cabId   = initialCabId;
                    offset  = initialOffset;
                    rand    = new Random(1);
                }

                for (int j = 0; j < testData.NumberOfFiles; j++)
                {
                    StackHashFile file = new StackHashFile();

                    file.DateCreatedLocal  = now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180)).RoundToPreviousMinute();
                    file.DateModifiedLocal = file.DateCreatedLocal.AddDays(rand.Next(-10, 10)).RoundToPreviousMinute();
                    file.Id            = fileId++;
                    file.LinkDateLocal = file.DateCreatedLocal.AddDays(rand.Next(-10, 10)).RoundToPreviousMinute();

                    int fileIndex = rand.Next() % s_FileNames.Length;

                    file.Name    = String.Format(CultureInfo.InvariantCulture, "{0}.{1}", s_FileNames[fileIndex], "dll");
                    file.Version = String.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}{3}.{4}",
                                                 fileId, rand.Next() % 99, rand.Next() % 366, rand.Next() % 5 + 2005, (j + 1) * 1237);

                    index.AddFile(product, file);

                    for (int k = 0; k < testData.NumberOfEvents; k++)
                    {
                        int totalHits = 0;

                        Random hitsRand = new Random(k);
                        for (int l = 0; l < testData.NumberOfEventInfos; l++)
                        {
                            if (s_IsTestMode)
                            {
                                totalHits += (l + k);
                            }
                            else
                            {
                                totalHits += hitsRand.Next(0, 50);
                            }
                        }

                        StackHashEvent theEvent = new StackHashEvent();

                        theEvent.DateCreatedLocal  = now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180)).RoundToPreviousMinute();
                        theEvent.DateModifiedLocal = theEvent.DateCreatedLocal.AddDays(rand.Next(-10, 10)).RoundToPreviousMinute();

                        theEvent.EventTypeName = s_EventTypes[rand.Next(0, s_EventTypes.Length)];
                        theEvent.FileId        = file.Id;
                        theEvent.Id            = eventId;
                        theEvent.BugId         = "Bug" + eventId.ToString(CultureInfo.InvariantCulture);
                        theEvent.TotalHits     = totalHits;

                        theEvent.EventSignature = new StackHashEventSignature();
                        theEvent.EventSignature.ApplicationName      = "StackHash.exe";
                        theEvent.EventSignature.ApplicationTimeStamp = now.ToUniversalTime().AddDays(rand.Next(-180, 0));
                        theEvent.EventSignature.ApplicationVersion   = String.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}{3}.{4}",
                                                                                     eventId, rand.Next() % 99, rand.Next() % 366, rand.Next() % 5 + 2005, (Math.Abs(eventId) + 1) * 1234);
                        theEvent.EventSignature.ExceptionCode = 0xc0000000 + rand.Next(0, 16);

                        theEvent.EventSignature.ModuleName      = "Module" + k.ToString(CultureInfo.InvariantCulture);
                        theEvent.EventSignature.ModuleTimeStamp = now.ToUniversalTime().AddDays(-1 * ((rand.Next() % 200)));
                        theEvent.EventSignature.ModuleVersion   = String.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}{3}.{4}",
                                                                                eventId, rand.Next() % 99, rand.Next() % 366, rand.Next() % 5 + 2005, (Math.Abs(eventId) + 1) * 1234);

                        if (s_IsTestMode)
                        {
                            theEvent.EventSignature.Offset = offset--;   // Make these go backwards.
                        }
                        else
                        {
                            theEvent.EventSignature.Offset = rand.Next(0, 0xfffff);
                        }

                        theEvent.EventSignature.Parameters = new StackHashParameterCollection();
                        theEvent.EventSignature.Parameters.Add(new StackHashParameter("applicationName", theEvent.EventSignature.ApplicationName));
                        theEvent.EventSignature.Parameters.Add(new StackHashParameter("applicationTimeStamp", theEvent.EventSignature.ApplicationTimeStamp.ToString(CultureInfo.InvariantCulture)));
                        theEvent.EventSignature.Parameters.Add(new StackHashParameter("applicationVersion", theEvent.EventSignature.ApplicationVersion));
                        theEvent.EventSignature.Parameters.Add(new StackHashParameter("exceptionCode", String.Format(CultureInfo.InvariantCulture, "{0:X}", theEvent.EventSignature.ExceptionCode)));
                        theEvent.EventSignature.Parameters.Add(new StackHashParameter("moduleName", theEvent.EventSignature.ModuleName));
                        theEvent.EventSignature.Parameters.Add(new StackHashParameter("moduleTimeStamp", theEvent.EventSignature.ModuleTimeStamp.ToString(CultureInfo.InvariantCulture)));
                        theEvent.EventSignature.Parameters.Add(new StackHashParameter("moduleVersion", theEvent.EventSignature.ModuleVersion.ToString()));
                        theEvent.EventSignature.Parameters.Add(new StackHashParameter("offset", String.Format(CultureInfo.InvariantCulture, "{0:X}", theEvent.EventSignature.Offset)));
                        theEvent.EventSignature.InterpretParameters();
                        index.AddEvent(product, file, theEvent);

                        // Allow for some duplicate event ids.
                        if (!s_IsTestMode)
                        {
                            eventId++;
                            //if (rand.Next(0, 100) > 5)
                            //    eventId++;

                            //if (rand.Next(0, 100) > 50)
                            //    eventId = -1 * eventId;
                        }
                        else
                        {
                            eventId++;
                        }

                        hitsRand = new Random(k);
                        StackHashEventInfoCollection eventInfoCollection = new StackHashEventInfoCollection();
                        for (int l = 0; l < testData.NumberOfEventInfos; l++)
                        {
                            int languageIndex = rand.Next() % s_Languages.Length;

                            if (s_IsTestMode)
                            {
                                languageIndex = l % s_Languages.Length;
                            }

                            StackHashEventInfo eventInfo = new StackHashEventInfo();
                            eventInfo.DateCreatedLocal  = now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180)).RoundToPreviousMinute();
                            eventInfo.DateModifiedLocal = eventInfo.DateCreatedLocal.AddDays(l).RoundToPreviousMinute();

                            if (s_IsTestMode)
                            {
                                eventInfo.HitDateLocal = now.ToUniversalTime().AddDays(-1 * l).RoundToPreviousMinute();
                            }
                            else
                            {
                                eventInfo.HitDateLocal = now.ToUniversalTime().AddDays(rand.Next(-180, 0)).RoundToPreviousMinute();
                            }

                            eventInfo.Language = s_Languages[languageIndex].Name;
                            eventInfo.Lcid     = s_Languages[languageIndex].Lcid;
                            eventInfo.Locale   = s_Languages[languageIndex].LocaleCode;


                            int osIndex = rand.Next(0, s_OperatingSystems.Length);
                            if (s_IsTestMode)
                            {
                                osIndex = l % s_OperatingSystems.Length;
                            }
                            eventInfo.OperatingSystemName = s_OperatingSystems[osIndex];

                            if (s_IsTestMode)
                            {
                                eventInfo.OperatingSystemVersion = s_OperatingSystemVersions[osIndex] + l.ToString(CultureInfo.InvariantCulture);
                            }
                            else
                            {
                                eventInfo.OperatingSystemVersion = s_OperatingSystemVersions[osIndex];
                            }

                            if (s_IsTestMode)
                            {
                                eventInfo.TotalHits = l + k;
                            }
                            else
                            {
                                eventInfo.TotalHits = hitsRand.Next(0, 50);
                            }

                            if (eventInfoCollection.FindEventInfo(eventInfo) == null)
                            {
                                eventInfoCollection.Add(eventInfo);
                            }
                        }

                        index.MergeEventInfoCollection(product, file, theEvent, eventInfoCollection);

                        for (int m = 0; m < testData.NumberOfCabs; m++)
                        {
                            if ((k % testData.EventsToAssignCabs) != 0)
                            {
                                break;
                            }

                            StackHashCab cab = new StackHashCab();

                            if (IsTestMode)
                            {
                                cab.DateCreatedLocal  = now.ToUniversalTime().AddDays(-1 * m).RoundToPreviousMinute();
                                cab.DateModifiedLocal = cab.DateCreatedLocal.AddDays(m).RoundToPreviousMinute();
                            }
                            else
                            {
                                cab.DateCreatedLocal  = now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180)).RoundToPreviousMinute();
                                cab.DateModifiedLocal = cab.DateCreatedLocal.AddDays(m).RoundToPreviousMinute();
                            }
                            cab.EventId       = theEvent.Id;
                            cab.EventTypeName = theEvent.EventTypeName;
                            cab.FileName      = String.Format(CultureInfo.InvariantCulture, "{0}-{1}-{2}.cab", cab.EventId, cab.EventTypeName, cab.Id);
                            cab.Id            = cabId++;
                            cab.SizeInBytes   = 64123 + rand.Next(-4000, 4000); // Some random value - corrected later if a real file exists.
                            cab.CabDownloaded = true;

                            // Get the size of the cab file.
                            String sourceCabFile;
                            if (testData.CabFileName != null)
                            {
                                sourceCabFile = Path.Combine(TestSettings.TestDataFolder + @"Cabs\", testData.CabFileName);
                            }
                            else if (testData.UseLargeCab)
                            {
                                sourceCabFile = TestSettings.TestDataFolder + @"Cabs\1630796338-Crash32bit-0760025228.cab";
                            }
                            else
                            {
                                sourceCabFile = TestSettings.TestDataFolder + @"Cabs\1641909485-Crash32bit-0773522646.cab";
                            }

                            if (File.Exists(sourceCabFile))
                            {
                                FileInfo sourceCabFileInfo = new FileInfo(sourceCabFile);
                                cab.SizeInBytes = sourceCabFileInfo.Length;
                            }

                            index.AddCab(product, file, theEvent, cab, false);


                            // Copy in a test cab file.

                            String cabFolder = index.GetCabFolder(product, file, theEvent, cab);
                            if (!Directory.Exists(cabFolder))
                            {
                                Directory.CreateDirectory(cabFolder);
                            }
                            String cabFileName = index.GetCabFileName(product, file, theEvent, cab);

                            if (!File.Exists(cabFileName))
                            {
                                if (testData.CabFileName != null)
                                {
                                    File.Copy(Path.Combine(TestSettings.TestDataFolder + @"Cabs\", testData.CabFileName), cabFileName);
                                }
                                else if (testData.UseLargeCab)
                                {
                                    File.Copy(TestSettings.TestDataFolder + @"Cabs\1630796338-Crash32bit-0760025228.cab", cabFileName);
                                }
                                else
                                {
                                    File.Copy(TestSettings.TestDataFolder + @"Cabs\1641909485-Crash32bit-0773522646.cab", cabFileName);
                                }
                            }


                            // Make sure the file is not read only.
                            FileAttributes attributes = File.GetAttributes(cabFileName);
                            attributes &= ~FileAttributes.ReadOnly;
                            File.SetAttributes(cabFileName, attributes);


                            // Unwrap the cab.
                            if (testData.UnwrapCabs)
                            {
                                Cabs.ExtractCab(cabFileName, cabFolder);
                            }

                            if (testData.NumberOfScriptResults > 0)
                            {
                                String analysisFolder = index.GetCabFolder(product, file, theEvent, cab) + "\\analysis";

                                if (!Directory.Exists(analysisFolder))
                                {
                                    Directory.CreateDirectory(analysisFolder);
                                }

                                for (int scriptCount = 0; scriptCount < testData.NumberOfScriptResults; scriptCount++)
                                {
                                    CreateScriptFile(scriptCount, cab.Id, analysisFolder, scriptRand.Next(5), CultureInfo.InvariantCulture, 2, testData.ScriptFileSize);
                                }
                            }


                            StackHashNotes cabNotes = index.GetCabNotes(product, file, theEvent, cab);
                            for (int q = 0; q < testData.NumberOfCabNotes; q++)
                            {
                                StackHashNoteEntry note = new StackHashNoteEntry(now.ToUniversalTime().RoundToPreviousSecond(), "User", "MarkJ", "This is a cab note" + q.ToString(CultureInfo.InvariantCulture));

                                // Don't add duplicate cab notes in the SQL index. The XML index may contain duplicates.
                                if (index.IndexType == ErrorIndexType.Xml || !cabNotes.ContainsNote(note))
                                {
                                    index.AddCabNote(product, file, theEvent, cab, note);
                                }
                            }
                        }

                        StackHashNotes eventNotes = index.GetEventNotes(product, file, theEvent);
                        for (int p = 0; p < testData.NumberOfEventNotes; p++)
                        {
                            StackHashNoteEntry note = new StackHashNoteEntry(now.ToUniversalTime().RoundToPreviousSecond(), "User", "MarkJ", "This is an event note" + p.ToString(CultureInfo.InvariantCulture));

                            // Don't add duplicate event notes in the SQL index. The XML index may contain duplicates.
                            if (index.IndexType == ErrorIndexType.Xml || !eventNotes.ContainsNote(note))
                            {
                                index.AddEventNote(product, file, theEvent, note);
                            }
                        }
                    }
                }
                index.UpdateProductStatistics(product);
            }
        }
コード例 #13
0
 public int AddCabNote(StackHashProduct product, StackHashFile file, StackHashEvent theEvent, StackHashCab cab, StackHashNoteEntry note)
 {
     return(0);
 }