Beispiel #1
0
        public static StackHashCabCollection GetCabInfoApi(ref Login login, Event theEvent)
        {
            CabCollection cabs = theEvent.GetCabs(ref login);

            StackHashCabCollection apiStackHashCabs = new StackHashCabCollection();

            foreach (Cab cab in cabs)
            {
                StackHashCab stackHashCab = ObjectConversion.ConvertCab(cab);
                apiStackHashCabs.Add(stackHashCab);
            }
            return(apiStackHashCabs);
        }
Beispiel #2
0
        public static StackHashCabCollection GetCabInfoAtom(AtomFeed feed, AtomEvent theEvent)
        {
            // Get the list of events.
            AtomCabCollection atomCabs = feed.GetCabs(theEvent);

            // Convert to a StackHashCabCollection.
            StackHashCabCollection atomStackHashCabss = new StackHashCabCollection();

            foreach (AtomCab atomCab in atomCabs)
            {
                atomStackHashCabss.Add(atomCab.Cab);
            }

            return(atomStackHashCabss);
        }
Beispiel #3
0
        /// <summary>
        /// Parses the database looking for cabs to unwrap.
        /// </summary>
        private void analyzeAllCabs()
        {
            IErrorIndex index = m_TaskParameters.ErrorIndex;

            // Get a list of products.
            StackHashProductCollection products = index.LoadProductList();

            foreach (StackHashProduct product in products)
            {
                if (CurrentTaskState.AbortRequested)
                {
                    throw new OperationCanceledException("Task aborted");
                }

                if (!shouldProcessProduct(product))
                {
                    continue;
                }

                // Get the file list.
                StackHashFileCollection files = index.LoadFileList(product);

                foreach (StackHashFile file in files)
                {
                    if (CurrentTaskState.AbortRequested)
                    {
                        throw new OperationCanceledException("Task aborted");
                    }

                    if (!shouldProcessFile(product, file))
                    {
                        continue;
                    }

                    // Get the event data.
                    StackHashEventCollection events = index.LoadEventList(product, file);

                    foreach (StackHashEvent theEvent in events)
                    {
                        if (CurrentTaskState.AbortRequested)
                        {
                            throw new OperationCanceledException("Task aborted");
                        }

                        if (!shouldProcessEvent(product, file, theEvent))
                        {
                            continue;
                        }

                        StackHashCabCollection cabs = index.LoadCabList(product, file, theEvent);

                        // Process each cab.
                        foreach (StackHashCab cab in cabs)
                        {
                            if (CurrentTaskState.AbortRequested)
                            {
                                throw new OperationCanceledException("Task aborted");
                            }

                            if (!shouldProcessCab(product, file, theEvent, cab))
                            {
                                continue;
                            }

                            processCab(product, file, theEvent, cab);
                        }
                    }
                }
            }
        }
Beispiel #4
0
        public void AutoScriptOnOneCabAlreadyRunButNewerVersion()
        {
            // If the auto task sees the AutoScript.log file exists and has the same
            // version as the current AutoScript.xml then it shouldn't run it again.
            // Determine this by checking the file time after a second run.

            // Create an index with 1 cab file.
            XmlErrorIndex errorIndex = new XmlErrorIndex(m_TempPath, "ErrorIndex");

            errorIndex.Activate();

            StackHashTestIndexData testData = new StackHashTestIndexData();

            testData.NumberOfProducts   = 1;
            testData.NumberOfFiles      = 1;
            testData.NumberOfEvents     = 1;
            testData.NumberOfEventInfos = 1;
            testData.NumberOfCabs       = 1;
            testData.UseLargeCab        = false;
            TestManager.CreateTestIndex(errorIndex, testData);



            ScriptManager scriptManager = new ScriptManager(m_TempPath + "Scripts");

            Assert.AreEqual(scriptManager.NumberOfAutoScripts, scriptManager.ScriptNames.Count);

            ScriptResultsManager scriptResultsManager = new ScriptResultsManager(errorIndex, scriptManager, m_Debugger, m_DebuggerSettings);

            // Set up parameters for the task.
            AnalyzeTaskParameters analyzeParams = new AnalyzeTaskParameters();

            // Standard task parameters.
            analyzeParams.IsBackgroundTask            = true;
            analyzeParams.Name                        = "TestRunOneTask";
            analyzeParams.RunInParallel               = false;
            analyzeParams.UseSeparateThread           = true;
            analyzeParams.AnalysisSettings            = new StackHashAnalysisSettings();
            analyzeParams.AnalysisSettings.ForceRerun = true;
            analyzeParams.ContextId                   = 0;
            analyzeParams.ClientData                  = new StackHashClientData(Guid.NewGuid(), "MarkJ", 1);
            analyzeParams.Debugger                    = m_Debugger;
            analyzeParams.DebuggerSettings            = m_DebuggerSettings;
            analyzeParams.TheScriptManager            = scriptManager;
            analyzeParams.TheScriptResultsManager     = scriptResultsManager;
            int productId = 1;

            analyzeParams.ProductsToSynchronize = new StackHashProductSyncDataCollection();
            analyzeParams.ProductsToSynchronize.Add(new StackHashProductSyncData(productId));

            analyzeParams.ErrorIndex = errorIndex;

            // Create the task and run it.
            AnalyzeTask analyzeTask = new AnalyzeTask(analyzeParams);
            TaskManager taskManager = new TaskManager("Test");

            taskManager.Enqueue(analyzeTask);
            taskManager.WaitForTaskCompletion(analyzeTask, s_TaskTimeout);


            StackHashProductCollection products = errorIndex.LoadProductList();
            StackHashFileCollection    files    = errorIndex.LoadFileList(products[0]);
            StackHashEventCollection   events   = errorIndex.LoadEventList(products[0], files[0]);
            StackHashCabCollection     cabs     = errorIndex.LoadCabList(products[0], files[0], events[0]);

            StackHashScriptResult script1 = scriptResultsManager.GetResultFileData(products[0], files[0], events[0], cabs[0], "AutoScript");

            // Wait for 1 second - so file time granularity exceeded.
            Thread.Sleep(1000);

            // Change the version on the autoscript.
            StackHashScriptSettings settings = scriptManager.LoadScript("AutoScript");

            settings.LastModifiedDate = DateTime.Now;
            scriptManager.AddScript(settings, true, true);

            // Now run the task again.
            analyzeTask = new AnalyzeTask(analyzeParams);
            taskManager.Enqueue(analyzeTask);
            taskManager.WaitForTaskCompletion(analyzeTask, s_TaskTimeout);


            Assert.AreEqual(true, analyzeTask.CurrentTaskState.TaskCompleted);

            // Refresh the cab list data.
            cabs = errorIndex.LoadCabList(products[0], files[0], events[0]);

            StackHashDumpAnalysis analysis = cabs[0].DumpAnalysis;

            Assert.AreEqual("not available", analysis.SystemUpTime);
            Assert.AreEqual("0 days 0:00:15.000", analysis.ProcessUpTime);
            Assert.AreEqual("2.0.50727.3603", analysis.DotNetVersion);


            StackHashScriptResult script2 = scriptResultsManager.GetResultFileData(products[0], files[0], events[0], cabs[0], "AutoScript");

            Assert.AreEqual(true, script2.RunDate > script1.RunDate);
        }
Beispiel #5
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

        /// <summary>
        /// Add n event notes
        /// </summary>
        public void getPackages(int numProducts, int numFiles, int numEvents, int numEventInfos, int numCabs, bool useSameLocale, bool incrementingEventId, bool randomEventIds)
        {
            int    cabId     = 1000;
            int    eventId   = 1320080390;
            int    fileId    = 0x12345678;
            int    productId = 122;
            Random rand      = new Random(100);


            m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder);
            m_Index.DeleteIndex();

            m_Index.Activate();

            Dictionary <int, StackHashEventPackageCollection> expectedProductEvents = new Dictionary <int, StackHashEventPackageCollection>();
            StackHashProductCollection allProducts = new StackHashProductCollection();

            for (int productCount = 0; productCount < numProducts; productCount++)
            {
                DateTime         creationDateTime = new DateTime(2010, 04, 04, 22, 9, 0, DateTimeKind.Utc);
                DateTime         modifiedDateTime = new DateTime(2010, 05, 05, 23, 10, 0, DateTimeKind.Utc);
                StackHashProduct product1         =
                    new StackHashProduct(creationDateTime, modifiedDateTime, null, productId++, "TestProduct1", 20, 30, "2.10.02123.1293");

                m_Index.AddProduct(product1);
                allProducts.Add(product1);
                StackHashEventPackageCollection allAddedEvents = new StackHashEventPackageCollection();

                for (int fileCount = 0; fileCount < numFiles; fileCount++)
                {
                    StackHashFile file1 =
                        new StackHashFile(creationDateTime, modifiedDateTime, fileId++, creationDateTime, "File1.dll", "2.3.4.5");

                    StackHashEventSignature eventSignature = new StackHashEventSignature();
                    eventSignature.Parameters = new StackHashParameterCollection();
                    eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamApplicationName, "AppName"));
                    eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamApplicationVersion, "1.2.3.4"));
                    eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamApplicationTimeStamp, creationDateTime.ToString()));
                    eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamModuleName, "ModuleName"));
                    eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamModuleVersion, "2.3.4.5"));
                    eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamModuleTimeStamp, creationDateTime.ToString()));
                    eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamExceptionCode, "1234"));
                    eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamOffset, "0x1234"));
                    eventSignature.InterpretParameters();

                    m_Index.AddFile(product1, file1);

                    for (int eventCount = 0; eventCount < numEvents; eventCount++)
                    {
                        StackHashEvent event1 =
                            new StackHashEvent(creationDateTime, modifiedDateTime, "EventTypeName1", eventId, eventSignature, eventCount, file1.Id, "bug" + eventCount.ToString());


                        if (randomEventIds)
                        {
                            eventId = rand.Next(100, 1320080390);
                        }
                        else
                        {
                            if (incrementingEventId)
                            {
                                eventId++;
                            }
                            else
                            {
                                eventId--;
                            }
                        }
                        m_Index.AddEvent(product1, file1, event1);

                        StackHashEventInfoCollection eventInfos = new StackHashEventInfoCollection();

                        int hitCount  = 1;
                        int totalHits = 0;
                        for (int i = 0; i < numEventInfos; i++)
                        {
                            DateTime nowTime = DateTime.Now;
                            DateTime date    = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, nowTime.Hour, nowTime.Minute, 0);

                            int localeId = 10;
                            if (!useSameLocale)
                            {
                                localeId += i;
                            }

                            totalHits += hitCount;
                            StackHashEventInfo eventInfo = new StackHashEventInfo(date.AddDays(i * 1), date.AddDays(i * 2), date.AddDays(i * 3), "US", localeId, "English", "Windows Vista" + i.ToString(), "1.2.3.4 build 7", hitCount++);

                            eventInfos.Add(eventInfo);
                        }
                        event1.TotalHits = totalHits;
                        m_Index.AddEventInfoCollection(product1, file1, event1, eventInfos);

                        StackHashCabCollection cabs = new StackHashCabCollection();

                        for (int i = 0; i < numCabs; i++)
                        {
                            DateTime nowTime = DateTime.Now;
                            DateTime date    = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, nowTime.Hour, nowTime.Minute, 0);

                            StackHashCab cab = new StackHashCab(date.AddDays(i * 1), date.AddDays(i * 2), event1.Id, event1.EventTypeName, "cab12345_23232.cab", cabId++, i * 2000);
                            cab.DumpAnalysis = new StackHashDumpAnalysis("2 days, 5 hours, 2 mins", "1 hour, 2 mins", "2.120.222.1121212", "Microsoft Windows Vista X64 6.0.212121212 (Build 2500)", "64 bit windows");

                            cab.CabDownloaded = false;
                            cabs.Add(cab);
                            m_Index.AddCab(product1, file1, event1, cab, true);
                        }

                        allAddedEvents.Add(new StackHashEventPackage(eventInfos, new StackHashCabPackageCollection(cabs), event1, product1.Id));
                    }
                }

                expectedProductEvents[product1.Id] = allAddedEvents;
            }


            foreach (StackHashProduct product in allProducts)
            {
                StackHashEventPackageCollection allEvents = m_Index.GetProductEvents(product);

                StackHashEventPackageCollection expectedEvents = expectedProductEvents[product.Id];

                Assert.AreNotEqual(null, allEvents);
                Assert.AreEqual(expectedEvents.Count, allEvents.Count);

                foreach (StackHashEventPackage package in allEvents)
                {
                    StackHashEventPackage matchedEvent = expectedEvents.FindEventPackage(package.EventData.Id, package.EventData.EventTypeName);

                    Assert.AreNotEqual(null, matchedEvent);

                    Assert.AreEqual(0, package.EventInfoList.CompareTo(matchedEvent.EventInfoList));
                    Assert.AreEqual(0, package.Cabs.CompareTo(matchedEvent.Cabs));
                }
            }
        }
Beispiel #6
0
        public void AutoScriptOnOneCabProductNotEnabled()
        {
            // Create an index with 1 cab file.
            XmlErrorIndex errorIndex = new XmlErrorIndex(m_TempPath, "ErrorIndex");

            errorIndex.Activate();

            StackHashTestIndexData testData = new StackHashTestIndexData();

            testData.NumberOfProducts   = 1;
            testData.NumberOfFiles      = 1;
            testData.NumberOfEvents     = 1;
            testData.NumberOfEventInfos = 1;
            testData.NumberOfCabs       = 1;
            testData.UseLargeCab        = false;
            TestManager.CreateTestIndex(errorIndex, testData);


            ScriptManager scriptManager = new ScriptManager(m_TempPath + "Scripts");

            Assert.AreEqual(scriptManager.NumberOfAutoScripts, scriptManager.ScriptNames.Count);

            ScriptResultsManager scriptResultsManager = new ScriptResultsManager(errorIndex, scriptManager, m_Debugger, m_DebuggerSettings);

            // Set up parameters for the task.
            AnalyzeTaskParameters analyzeParams = new AnalyzeTaskParameters();

            // Standard task parameters.
            analyzeParams.IsBackgroundTask            = true;
            analyzeParams.Name                        = "TestRunOneTask";
            analyzeParams.RunInParallel               = false;
            analyzeParams.UseSeparateThread           = true;
            analyzeParams.AnalysisSettings            = new StackHashAnalysisSettings();
            analyzeParams.AnalysisSettings.ForceRerun = true;
            analyzeParams.ContextId                   = 0;
            analyzeParams.ClientData                  = new StackHashClientData(Guid.NewGuid(), "MarkJ", 1);
            analyzeParams.Debugger                    = m_Debugger;
            analyzeParams.DebuggerSettings            = m_DebuggerSettings;
            analyzeParams.TheScriptManager            = scriptManager;
            analyzeParams.TheScriptResultsManager     = scriptResultsManager;
            analyzeParams.ProductsToSynchronize       = new StackHashProductSyncDataCollection();

            analyzeParams.ErrorIndex = errorIndex;

            // Create the task and run it.
            AnalyzeTask analyzeTask = new AnalyzeTask(analyzeParams);
            TaskManager taskManager = new TaskManager("Test");

            taskManager.Enqueue(analyzeTask);

            taskManager.WaitForTaskCompletion(analyzeTask, s_TaskTimeout);

            Assert.AreEqual(true, analyzeTask.CurrentTaskState.TaskCompleted);

            StackHashProductCollection products = errorIndex.LoadProductList();
            StackHashFileCollection    files    = errorIndex.LoadFileList(products[0]);
            StackHashEventCollection   events   = errorIndex.LoadEventList(products[0], files[0]);
            StackHashCabCollection     cabs     = errorIndex.LoadCabList(products[0], files[0], events[0]);

            StackHashDumpAnalysis analysis = cabs[0].DumpAnalysis;

            Assert.AreEqual(null, analysis.DotNetVersion);
            Assert.AreEqual(null, analysis.MachineArchitecture);
            Assert.AreEqual(null, analysis.OSVersion);
            Assert.AreEqual(null, analysis.ProcessUpTime);
            Assert.AreEqual(null, analysis.SystemUpTime);
        }
Beispiel #7
0
        private void purgeEvent(StackHashProduct product, StackHashFile file, StackHashEvent theEvent, StackHashPurgeOptions purgeOptions)
        {
            IErrorIndex errorIndex = m_TaskParameters.ErrorIndex;

            // Get a list of all cabs for the event.
            StackHashCabCollection cabs = errorIndex.LoadCabList(product, file, theEvent);
            bool error = false;

            foreach (StackHashCab cab in cabs)
            {
                String cabFileFolder = errorIndex.GetCabFolder(product, file, theEvent, cab);

                // Check if anything to purge.
                if (!Directory.Exists(cabFileFolder))
                {
                    continue;
                }

                // Don't purge if files not that old.
                int daysOld = (DateTime.Now.ToUniversalTime() - cab.DateCreatedLocal).Days;

                if (daysOld < purgeOptions.AgeToPurge)
                {
                    continue;
                }

                if (purgeOptions.PurgeDumpFiles)
                {
                    String[] dumpFiles = Directory.GetFiles(cabFileFolder, "*.*dmp*");

                    foreach (String dumpFile in dumpFiles)
                    {
                        try
                        {
                            // Update the statistics.
                            FileInfo fileInfo = new FileInfo(dumpFile);
                            m_Statistics.NumberOfDumpFiles++;
                            m_Statistics.DumpFilesTotalSize += fileInfo.Length;

                            DiagnosticsHelper.LogMessage(DiagSeverity.Information,
                                                         String.Format(CultureInfo.InvariantCulture, "Purged File {0}, {1}, {2}, {3}, {4}", dumpFile, product.Id, file.Id, theEvent.Id, cab.Id));
                            File.Delete(dumpFile);
                        }
                        catch (System.Exception ex)
                        {
                            error = true;
                            DiagnosticsHelper.LogException(DiagSeverity.Warning, "Failed to purge dump file " + dumpFile, ex);
                        }
                    }
                }
                if (purgeOptions.PurgeCabFiles)
                {
                    String cabFileName = errorIndex.GetCabFileName(product, file, theEvent, cab);

                    if (File.Exists(cabFileName))
                    {
                        try
                        {
                            // Update the statistics.
                            FileInfo fileInfo = new FileInfo(cabFileName);
                            m_Statistics.NumberOfCabs++;
                            m_Statistics.CabsTotalSize += fileInfo.Length;

                            DiagnosticsHelper.LogMessage(DiagSeverity.Information,
                                                         String.Format(CultureInfo.InvariantCulture, "Purged Cab File {0}, {1}, {2}, {3}, {4}", cabFileName, product.Id, file.Id, theEvent.Id, cab.Id));
                            File.Delete(cabFileName);
                        }
                        catch (System.Exception ex)
                        {
                            error = true;
                            DiagnosticsHelper.LogException(DiagSeverity.Warning, "Failed to purge cab file " + cabFileName, ex);
                        }
                    }
                }

                if (!error)
                {
                    // Mark the cab as purged and no longer downloaded.
                    cab.Purged        = true;
                    cab.CabDownloaded = false;
                    errorIndex.AddCab(product, file, theEvent, cab, false);
                }
            }
        }
Beispiel #8
0
        public void RunScriptOnCorruptCab()
        {
            // Create an index with 1 cab file.
            XmlErrorIndex errorIndex = new XmlErrorIndex(m_TempPath, "ErrorIndex");

            errorIndex.Activate();

            StackHashTestIndexData testData = new StackHashTestIndexData();

            testData.NumberOfProducts   = 1;
            testData.NumberOfFiles      = 1;
            testData.NumberOfEvents     = 1;
            testData.NumberOfEventInfos = 1;
            testData.NumberOfCabs       = 1;
            testData.UseLargeCab        = false;
            TestManager.CreateTestIndex(errorIndex, testData);

            // Delete the cab file.
            StackHashProduct product = errorIndex.GetProduct(1);
            StackHashFile    file    = errorIndex.GetFile(product, 1);
            StackHashEventPackageCollection events = errorIndex.GetProductEvents(product);

            String cabFileName = errorIndex.GetCabFileName(product, file, events[0].EventData, events[0].Cabs[0].Cab);

            if (File.Exists(cabFileName))
            {
                FileStream fileStream = File.Open(cabFileName, FileMode.Open, FileAccess.ReadWrite);

                try
                {
                    fileStream.SetLength(100);
                }
                finally
                {
                    fileStream.Close();
                }
            }


            ScriptManager scriptManager = new ScriptManager(m_TempPath + "Scripts");

            Assert.AreEqual(scriptManager.NumberOfAutoScripts, scriptManager.ScriptNames.Count);

            ScriptResultsManager scriptResultsManager = new ScriptResultsManager(errorIndex, scriptManager, m_Debugger, m_DebuggerSettings);

            // Set up parameters for the task.
            DebugScriptTaskParameters runScriptParams = new DebugScriptTaskParameters();

            // Standard task parameters.
            runScriptParams.IsBackgroundTask        = true;
            runScriptParams.Name                    = "TestRunOneTask";
            runScriptParams.RunInParallel           = false;
            runScriptParams.UseSeparateThread       = true;
            runScriptParams.ContextId               = 0;
            runScriptParams.ClientData              = new StackHashClientData(Guid.NewGuid(), "MarkJ", 1);
            runScriptParams.Debugger                = m_Debugger;
            runScriptParams.TheScriptManager        = scriptManager;
            runScriptParams.TheScriptResultsManager = scriptResultsManager;
            runScriptParams.Product                 = product;
            runScriptParams.File                    = file;
            runScriptParams.TheEvent                = events[0].EventData;
            runScriptParams.Cab        = events[0].Cabs[0].Cab;
            runScriptParams.ErrorIndex = errorIndex;

            // Create the task and run it.
            DebugScriptTask debugScriptTask = new DebugScriptTask(runScriptParams);
            TaskManager     taskManager     = new TaskManager("Test");

            taskManager.Enqueue(debugScriptTask);

            taskManager.WaitForTaskCompletion(debugScriptTask, s_TaskTimeout);

            Assert.AreEqual(true, debugScriptTask.CurrentTaskState.TaskCompleted);

            Assert.AreNotEqual(null, debugScriptTask.LastException);
            Assert.AreEqual(true, debugScriptTask.LastException is StackHashException);

            StackHashException ex = debugScriptTask.LastException as StackHashException;

            Assert.AreEqual(StackHashServiceErrorCode.CabIsCorrupt, ex.ServiceErrorCode);

            StackHashCabCollection cabs     = errorIndex.LoadCabList(product, file, events[0].EventData);
            StackHashDumpAnalysis  analysis = cabs[0].DumpAnalysis;
        }
Beispiel #9
0
        static void Go(ProgramArguments programArguments)
        {
            LogManager logger = new LogManager();

            logger.StartLogging();
            bool noCabs = false;

            try
            {
                StackHashUtilities.SystemInformation.DisableSleep();

                AtomFeed atomFeed = new AtomFeed(programArguments.ProxySettings, 5, 300000, programArguments.LogXml, true, programArguments.IPAddress, 11);

                if (!atomFeed.Login(programArguments.UserName, programArguments.Password))
                {
                    DiagnosticsHelper.LogMessage(DiagSeverity.Information, "Failed to logon - check your username and password");
                    return;
                }
                else
                {
                    DiagnosticsHelper.LogMessage(DiagSeverity.Information, "Logged on successfully.");
                }

                // ATOM GetProducts.
                AtomProductCollection atomProducts = atomFeed.GetProducts();

                foreach (AtomProduct atomProduct in atomProducts)
                {
                }

                foreach (AtomProduct atomProduct in atomProducts)
                {
                    DiagnosticsHelper.LogMessage(DiagSeverity.Information, atomProduct.Product.ToString());

                    // ATOM GetFiles.
                    AtomFileCollection atomFiles = atomFeed.GetFiles(atomProduct);
                    int totalEvents = 0;

                    foreach (AtomFile atomFile in atomFiles)
                    {
                        //                       String eventsLink = @"https://winqual.microsoft.com/Services/wer/user/events.aspx?fileid=" + fileId.ToString();
                        //                       AtomFile atomFile = new AtomFile(new StackHashFile(), eventsLink);

                        DiagnosticsHelper.LogMessage(DiagSeverity.Information, atomFile.File.ToString());

                        // ATOM GetEvents.
                        AtomEventCollection atomEvents = atomFeed.GetEvents(atomFile);

                        foreach (AtomEvent atomEvent in atomEvents)
                        {
                            totalEvents++;
                            DiagnosticsHelper.LogMessage(DiagSeverity.Information, atomEvent.Event.ToString());

                            // ATOM events.
                            StackHashEventInfoCollection eventInfos = GetEventInfoAtom(atomFeed, atomEvent, 90);

                            StackHashEventInfoCollection normalizedEventInfos = new StackHashEventInfoCollection();

                            bool stop = false;
                            foreach (StackHashEventInfo eventInfo in eventInfos)
                            {
                                DiagnosticsHelper.LogMessage(DiagSeverity.Information, eventInfo.ToString());
                                if (eventInfos.GetEventInfoMatchCount(eventInfo) != 1)
                                {
                                    DiagnosticsHelper.LogMessage(DiagSeverity.Information, "*** DUPLICATE HIT");
                                    DiagnosticsHelper.LogMessage(DiagSeverity.Information, eventInfo.ToString());
                                    stop = true;
                                }
                                StackHashEventInfo normalizedEventInfo = eventInfo.Normalize();
                                DiagnosticsHelper.LogMessage(DiagSeverity.Information, "N: " + normalizedEventInfo.ToString());
                                normalizedEventInfos.Add(normalizedEventInfo);
                                if (normalizedEventInfos.GetEventInfoMatchCount(normalizedEventInfo) != 1)
                                {
                                    DiagnosticsHelper.LogMessage(DiagSeverity.Information, "*** NORMALIZATION ERROR");
                                    DiagnosticsHelper.LogMessage(DiagSeverity.Information, normalizedEventInfo.ToString());
                                    stop = true;
                                }
                            }

                            if (stop)
                            {
                                return;
                            }


                            if (!noCabs)
                            {
                                // ATOM GetCabs.
                                StackHashCabCollection atomCabs = GetCabInfoAtom(atomFeed, atomEvent);

                                foreach (StackHashCab cab in atomCabs)
                                {
                                    DiagnosticsHelper.LogMessage(DiagSeverity.Information, cab.ToString());
                                }
                            }
                        }
                    }

                    DiagnosticsHelper.LogMessage(DiagSeverity.Information, String.Format("TOTAL EVENTS: {0}", totalEvents));
                }
            }
            catch (System.Exception ex)
            {
                DiagnosticsHelper.LogMessage(DiagSeverity.Information, "Error: " + ex.ToString());
            }
            finally
            {
                StackHashUtilities.SystemInformation.EnableSleep();
                logger.StopLogging();
            }
        }
Beispiel #10
0
        public void DownloadCabAllOkDummy()
        {
            String errorIndexFolder = Path.GetTempPath() + "StackHashCabDownloadTests";
            String errorIndexName   = "CabDownloads";
            String scriptFolder     = errorIndexFolder + "\\Scripts";

            if (Directory.Exists(errorIndexFolder))
            {
                PathUtils.SetFilesWritable(errorIndexFolder, true);
                PathUtils.DeleteDirectory(errorIndexFolder, true);
            }

            Directory.CreateDirectory(errorIndexFolder);
            Directory.CreateDirectory(scriptFolder);

            try
            {
                // Create a settings manager and a new context.
                SettingsManager          settingsManager = new SettingsManager(errorIndexFolder + "\\ServiceSettings.XML");
                StackHashContextSettings contextSettings = settingsManager.CreateNewContextSettings();

                contextSettings.WinQualSettings = new WinQualSettings("UserName", "Password", "Company", 10,
                                                                      new StackHashProductSyncDataCollection(), false, 0, 1, WinQualSettings.DefaultSyncsBeforeResync, false);

                contextSettings.ErrorIndexSettings        = new ErrorIndexSettings();
                contextSettings.ErrorIndexSettings.Folder = errorIndexFolder;
                contextSettings.ErrorIndexSettings.Name   = errorIndexName;

                ScriptManager scriptManager = new ScriptManager(scriptFolder);

                string         licenseFileName = string.Format("{0}\\License.bin", errorIndexFolder);
                LicenseManager licenseManager  = new LicenseManager(licenseFileName, s_TestServiceGuid);
                licenseManager.SetLicense(s_LicenseId);

                ControllerContext controllerContext = new ControllerContext(contextSettings, scriptManager, new Windbg(),
                                                                            settingsManager, true, StackHashTestData.Default, licenseManager);

                // Activate the context and the associated index.
                controllerContext.Activate();

                // Hook up to receive admin reports.
                controllerContext.AdminReports += new EventHandler <AdminReportEventArgs>(this.OnAdminReport);

                // Run the download task.
                Guid guid = new Guid();

                StackHashClientData clientData = new StackHashClientData(guid, "GuidName", 1);


                StackHashProduct product  = new StackHashProduct(DateTime.Now, DateTime.Now, "www.files.com", 12345678, "CuckuBackup", 10, 1, "1.2.3.4");
                StackHashFile    file     = new StackHashFile(DateTime.Now, DateTime.Now, 23, DateTime.Now, "FileName", "2.3.4.5");
                StackHashEvent   theEvent = new StackHashEvent(DateTime.Now, DateTime.Now, "EventTypeName", 10, new StackHashEventSignature(), 1, 23);
                StackHashCab     cab      = new StackHashCab(DateTime.Now, DateTime.Now, 10, "EventTypeName", "this.cab", 100, 10000);

                controllerContext.ErrorIndex.AddProduct(product);
                controllerContext.ErrorIndex.AddFile(product, file);
                controllerContext.ErrorIndex.AddEvent(product, file, theEvent);

                cab.DumpAnalysis = new StackHashDumpAnalysis();
                cab.DumpAnalysis.DotNetVersion = "xxx";
                controllerContext.ErrorIndex.AddCab(product, file, theEvent, cab, false);


                controllerContext.RunDownloadCabTask(clientData, product, file, theEvent, cab, false);

                // Wait for the download task to complete.
                waitForDownloadCompleted(30000);

                Assert.AreEqual(2, m_AdminReports.Count);

                Assert.AreEqual(null, m_AdminReports[0].Report.LastException);
                Assert.AreEqual(0, m_AdminReports[0].Report.ContextId);
                Assert.AreEqual(StackHashAdminOperation.DownloadCabStarted, m_AdminReports[0].Report.Operation);
                Assert.AreEqual(clientData.ApplicationGuid, m_AdminReports[0].Report.ClientData.ApplicationGuid);
                Assert.AreEqual(clientData.ClientId, m_AdminReports[0].Report.ClientData.ClientId);
                Assert.AreEqual(clientData.ClientName, m_AdminReports[0].Report.ClientData.ClientName);
                Assert.AreEqual(clientData.ClientRequestId, m_AdminReports[0].Report.ClientData.ClientRequestId);

                Assert.AreEqual(null, m_AdminReports[1].Report.LastException);
                Assert.AreEqual(0, m_AdminReports[1].Report.ContextId);
                Assert.AreEqual(StackHashAdminOperation.DownloadCabCompleted, m_AdminReports[1].Report.Operation);
                Assert.AreEqual(clientData.ApplicationGuid, m_AdminReports[1].Report.ClientData.ApplicationGuid);
                Assert.AreEqual(clientData.ClientId, m_AdminReports[1].Report.ClientData.ClientId);
                Assert.AreEqual(clientData.ClientName, m_AdminReports[1].Report.ClientData.ClientName);
                Assert.AreEqual(clientData.ClientRequestId, m_AdminReports[1].Report.ClientData.ClientRequestId);

                // Get the cab data to ensure that it is set to downloaded.
                StackHashCabCollection cabs = controllerContext.ErrorIndex.LoadCabList(product, file, theEvent);
                Assert.AreEqual(true, cabs[0].CabDownloaded);

                Assert.AreEqual("xxx", cabs[0].DumpAnalysis.DotNetVersion);

                controllerContext.Deactivate();
                controllerContext.AdminReports -= new EventHandler <AdminReportEventArgs>(this.OnAdminReport);
            }
            finally
            {
                if (Directory.Exists(errorIndexFolder))
                {
                    PathUtils.SetFilesWritable(errorIndexFolder, true);
                    PathUtils.DeleteDirectory(errorIndexFolder, true);
                }
            }
        }