示例#1
0
        /// <summary>
        /// Make sure notification only comes back to the one client.
        /// Username and password are incorrect so should just fail to login.
        /// </summary>
        public void adminReportShouldBeSentToIndividualClient(ErrorIndexType indexType)
        {
            m_Utils.RegisterForNotifications(true, Guid.NewGuid());
            m_Utils.RegisterForNotifications(true, m_Utils.ApplicationGuid);
            m_Utils.RegisterForNotifications(true, Guid.NewGuid());
            m_Utils.CreateAndSetNewContext(indexType);
            m_Utils.ActivateContext(0);

            StackHashTestIndexData indexData = new StackHashTestIndexData();

            indexData.NumberOfProducts   = 1;
            indexData.NumberOfFiles      = 1;
            indexData.NumberOfEvents     = 1;
            indexData.NumberOfCabs       = 1;
            indexData.NumberOfEventInfos = 1;

            m_Utils.CreateTestIndex(0, indexData);

            try
            {
                StackHashProductInfoCollection  products = m_Utils.GetProducts(0).Products;
                StackHashFileCollection         files    = m_Utils.GetFiles(0, products[0].Product).Files;
                StackHashEventPackageCollection events   = m_Utils.GetProductEventPackages(0, products[0].Product).EventPackages;
                StackHashCabPackageCollection   cabs     = events[0].Cabs;

                DownloadCabResponse resp = m_Utils.DownloadCab(0, products[0].Product, files[0], events[0].EventData, events[0].Cabs[0].Cab, 30000);

                StackHashAdminReport adminReport = m_Utils.DownloadCabAdminReport;
                Assert.AreNotEqual(null, adminReport);
                Assert.AreEqual(m_Utils.LastClientData.ApplicationGuid, adminReport.ClientData.ApplicationGuid);
                Assert.AreEqual(m_Utils.LastClientData.ClientId, adminReport.ClientData.ClientId);
                Assert.AreEqual(m_Utils.LastClientData.ClientName, adminReport.ClientData.ClientName);
                Assert.AreEqual(m_Utils.LastClientData.ClientRequestId, adminReport.ClientData.ClientRequestId);
                Assert.AreEqual(0, adminReport.ContextId);
                Assert.AreNotEqual(null, adminReport.LastException);
                Assert.AreEqual(true, adminReport.LastException.Contains("username and password"));
                Assert.AreEqual(StackHashAdminOperation.DownloadCabCompleted, adminReport.Operation);
                Assert.AreEqual(StackHashAsyncOperationResult.Failed, adminReport.ResultData);

                // Should receive 3 admin register + download started + download completed.
                Assert.AreEqual(5, m_Utils.AllReports.Count);
            }
            finally
            {
                m_Utils.DeactivateContext(0);
                m_Utils.DeleteIndex(0);
            }
        }
示例#2
0
        private void testAddNEventInfo(IErrorIndex index, int numEventInfos)
        {
            index.Activate();
            StackHashProduct product =
                new StackHashProduct(DateTime.Now, DateTime.Now, "http://www.cucku.com", 1, "TestProduct1", 20, 30, "2.10.02123.1293");
            StackHashFile file = new StackHashFile(new DateTime(100), new DateTime(101), 39, new DateTime(102), "filename.dll", "1.2.3.4");
            StackHashParameterCollection parameters = new StackHashParameterCollection();

            parameters.Add(new StackHashParameter("param1", "param1value"));
            parameters.Add(new StackHashParameter("param2", "param2value"));
            StackHashEventSignature signature = new StackHashEventSignature(parameters);

            StackHashEvent theEvent = new StackHashEvent(new DateTime(102), new DateTime(103), "EventType1", 20000, signature, -1, 2);

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

            StackHashEventInfoCollection eventInfoCollection = new StackHashEventInfoCollection();
            int totalHits = 0;

            for (int i = 0; i < numEventInfos; i++)
            {
                int hitsForThisEvent = (i + 1);
                totalHits += hitsForThisEvent;

                StackHashEventInfo eventInfo = new StackHashEventInfo(DateTime.Now.AddDays(i).ToUniversalTime(),
                                                                      DateTime.Now.AddDays(i + 1).ToUniversalTime(), DateTime.Now.AddDays(i + 2).ToUniversalTime(), "English" + i.ToString(),
                                                                      i, "locale" + i.ToString(), "OS" + i.ToString(), "OSVersion" + i.ToString(), hitsForThisEvent);
                eventInfoCollection.Add(eventInfo);
            }

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


            // Now get all the event info and make sure it all matches.
            StackHashEventInfoCollection eventInfoCollection2 = index.LoadEventInfoList(product, file, theEvent);

            Assert.AreEqual(0, eventInfoCollection.CompareTo(eventInfoCollection2));

            StackHashEventPackageCollection eventPackages = index.GetProductEvents(product);

            Assert.AreEqual(1, eventPackages.Count);
            Assert.AreEqual(totalHits, eventPackages[0].EventData.TotalHits);
        }
示例#3
0
        /// <summary>
        /// Gets all the event data matching the specified search criteria.
        /// </summary>
        /// <param name="requestData">Request data.</param>
        /// <returns>Event package included per instance and cab data.</returns>
        public GetAllEventPackageResponse GetEventPackages(GetAllEventPackageRequest requestData)
        {
            if (requestData == null)
            {
                throw new ArgumentNullException("requestData");
            }

            GetAllEventPackageResponse resp = new GetAllEventPackageResponse();

            StackHashEventPackageCollection eventPackages =
                StaticObjects.TheStaticObjects.TheController.GetEvents(requestData.ContextId, requestData.SearchCriteriaCollection);

            resp.EventPackages = eventPackages;

            resp.ResultData = new StackHashServiceResultData(
                StackHashServiceResult.Success, s_OperationSuccessful, null);
            return(resp);
        }
示例#4
0
        public void getProductEvents(IErrorIndex index, int numProducts, int numFiles, int numEvents)
        {
            StackHashProductCollection products = new StackHashProductCollection();
            int productId            = 0x1234567;
            int eventsForThisProduct = numEvents;
            int eventId = 10000;
            int fileId  = 20;

            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 product          = new StackHashProduct(creationDateTime, modifiedDateTime, "www.files.com", productId + productCount, @"P""r:o?d:u@(XP_2k)", productCount, productCount + 1, "1:2:3:4");

                index.AddProduct(product);
                products.Add(product);

                for (int i = 0; i < numFiles; i++)
                {
                    StackHashFile file = new StackHashFile(DateTime.Now, DateTime.Now, fileId++, DateTime.Now, "FileName", "1.2.3.4");
                    index.AddFile(product, file);

                    for (int j = 0; j < eventsForThisProduct; j++)
                    {
                        StackHashEvent theEvent = new StackHashEvent(DateTime.Now, DateTime.Now, "Event type", eventId++, new StackHashEventSignature(), j, i + 1000);
                        theEvent.EventSignature.Parameters = new StackHashParameterCollection();
                        index.AddEvent(product, file, theEvent);
                    }
                }
                eventsForThisProduct += 10;
            }

            eventsForThisProduct = numEvents;
            for (int productCount = 0; productCount < numProducts; productCount++)
            {
                StackHashEventPackageCollection events = index.GetProductEvents(products[productCount]);

                Assert.AreEqual(numFiles * eventsForThisProduct, events.Count);
                eventsForThisProduct += 10;
            }
        }
示例#5
0
        /// <summary>
        /// Product doesn't exist.
        /// </summary>
        public void downloadCabProductDoesntExist(ErrorIndexType indexType)
        {
            m_Utils.RegisterForNotifications(true, m_Utils.ApplicationGuid);
            m_Utils.CreateAndSetNewContext(indexType);
            m_Utils.ActivateContext(0);

            StackHashTestIndexData indexData = new StackHashTestIndexData();

            indexData.NumberOfProducts   = 1;
            indexData.NumberOfFiles      = 1;
            indexData.NumberOfEvents     = 1;
            indexData.NumberOfCabs       = 1;
            indexData.NumberOfEventInfos = 1;

            m_Utils.CreateTestIndex(0, indexData);

            try
            {
                try
                {
                    StackHashProductInfoCollection  products = m_Utils.GetProducts(0).Products;
                    StackHashFileCollection         files    = m_Utils.GetFiles(0, products[0].Product).Files;
                    StackHashEventPackageCollection events   = m_Utils.GetProductEventPackages(0, products[0].Product).EventPackages;
                    StackHashCabPackageCollection   cabs     = events[0].Cabs;

                    products[0].Product.Id++; // Wrong ID.
                    DownloadCabResponse resp = m_Utils.DownloadCab(0, products[0].Product, files[0], events[0].EventData, events[0].Cabs[0].Cab, 30000);
                }
                catch (FaultException <ReceiverFaultDetail> ex)
                {
                    Assert.AreEqual(true, ex.Message.Contains("Product does not exist"));
                }
            }
            finally
            {
                m_Utils.DeactivateContext(0);
                m_Utils.DeleteIndex(0);
            }
        }
示例#6
0
        public void RunBugReportSpecificEvent()
        {
            m_Utils.RegisterForNotifications(true, m_Utils.ApplicationGuid);
            m_Utils.CreateAndSetNewContext(ErrorIndexType.SqlExpress);

            GetContextBugTrackerPlugInSettingsResponse resp = m_Utils.GetContextBugTrackerPlugInSettings(0);

            Assert.AreNotEqual(null, resp.BugTrackerPlugInSettings);
            Assert.AreNotEqual(null, resp.BugTrackerPlugInSettings.PlugInSettings);
            Assert.AreEqual(0, resp.BugTrackerPlugInSettings.PlugInSettings.Count);

            resp.BugTrackerPlugInSettings.PlugInSettings.Add(new StackHashBugTrackerPlugIn());
            resp.BugTrackerPlugInSettings.PlugInSettings[0].Enabled    = true;
            resp.BugTrackerPlugInSettings.PlugInSettings[0].Name       = "TestPlugIn";
            resp.BugTrackerPlugInSettings.PlugInSettings[0].Properties = new StackHashNameValueCollection();
            resp.BugTrackerPlugInSettings.PlugInSettings[0].Properties.Add(new StackHashNameValuePair()
            {
                Name = "TestParam1", Value = "TestValue1"
            });
            resp.BugTrackerPlugInSettings.PlugInSettings[0].Properties.Add(new StackHashNameValuePair()
            {
                Name = "TestParam2", Value = "TestValue2"
            });

            m_Utils.SetContextBugTrackerPlugInSettings(0, resp.BugTrackerPlugInSettings);

            m_Utils.RestartService();
            m_Utils.ActivateContext(0);

            StackHashTestIndexData indexData = new StackHashTestIndexData();

            indexData.NumberOfProducts   = 1;
            indexData.NumberOfFiles      = 1;
            indexData.NumberOfEvents     = 1;
            indexData.NumberOfCabs       = 1;
            indexData.NumberOfEventInfos = 1;

            m_Utils.CreateTestIndex(0, indexData);

            try
            {
                StackHashProductInfoCollection  products = m_Utils.GetProducts(0).Products;
                StackHashFileCollection         files    = m_Utils.GetFiles(0, products[0].Product).Files;
                StackHashEventPackageCollection events   = m_Utils.GetProductEventPackages(0, products[0].Product).EventPackages;
                StackHashCabPackageCollection   cabs     = events[0].Cabs;

                StackHashBugReportDataCollection bugReportDataCollection = new StackHashBugReportDataCollection();
                bugReportDataCollection.Add(new StackHashBugReportData()
                {
                    Product    = products[0].Product,
                    File       = files[0],
                    TheEvent   = events[0].EventData,
                    Cab        = null,
                    ScriptName = null,
                    Options    = StackHashReportOptions.IncludeAllObjects
                });

                m_Utils.RunBugReportTask(0, bugReportDataCollection, 30000, true);
            }
            finally
            {
                m_Utils.DeactivateContext(0);
                m_Utils.DeleteIndex(0);
            }
        }
示例#7
0
        public void RunBugReportSpecificFileProgressCheckManyEventsAbortTest()
        {
            m_Utils.RegisterForNotifications(true, m_Utils.ApplicationGuid);
            m_Utils.CreateAndSetNewContext(ErrorIndexType.SqlExpress);

            GetContextBugTrackerPlugInSettingsResponse resp = m_Utils.GetContextBugTrackerPlugInSettings(0);

            Assert.AreNotEqual(null, resp.BugTrackerPlugInSettings);
            Assert.AreNotEqual(null, resp.BugTrackerPlugInSettings.PlugInSettings);
            Assert.AreEqual(0, resp.BugTrackerPlugInSettings.PlugInSettings.Count);

            resp.BugTrackerPlugInSettings.PlugInSettings.Add(new StackHashBugTrackerPlugIn());
            resp.BugTrackerPlugInSettings.PlugInSettings[0].Enabled    = true;
            resp.BugTrackerPlugInSettings.PlugInSettings[0].Name       = "TestPlugIn";
            resp.BugTrackerPlugInSettings.PlugInSettings[0].Properties = new StackHashNameValueCollection();
            resp.BugTrackerPlugInSettings.PlugInSettings[0].Properties.Add(new StackHashNameValuePair()
            {
                Name = "TestParam1", Value = "TestValue1"
            });
            resp.BugTrackerPlugInSettings.PlugInSettings[0].Properties.Add(new StackHashNameValuePair()
            {
                Name = "TestParam2", Value = "TestValue2"
            });

            m_Utils.SetContextBugTrackerPlugInSettings(0, resp.BugTrackerPlugInSettings);

            m_Utils.RestartService();
            m_Utils.ActivateContext(0);

            StackHashTestIndexData indexData = new StackHashTestIndexData();

            indexData.NumberOfProducts   = 1;
            indexData.NumberOfFiles      = 1;
            indexData.NumberOfEvents     = 200;
            indexData.NumberOfCabs       = 1;
            indexData.NumberOfEventInfos = 1;

            m_Utils.CreateTestIndex(0, indexData);

            try
            {
                StackHashProductInfoCollection  products = m_Utils.GetProducts(0).Products;
                StackHashFileCollection         files    = m_Utils.GetFiles(0, products[0].Product).Files;
                StackHashEventPackageCollection events   = m_Utils.GetProductEventPackages(0, products[0].Product).EventPackages;
                StackHashCabPackageCollection   cabs     = events[0].Cabs;

                StackHashBugReportDataCollection bugReportDataCollection = new StackHashBugReportDataCollection();
                bugReportDataCollection.Add(new StackHashBugReportData()
                {
                    Product    = products[0].Product,
                    File       = files[0],
                    TheEvent   = null,
                    Cab        = null,
                    ScriptName = null,
                    Options    = StackHashReportOptions.IncludeAllObjects
                });

                m_Utils.RunBugReportTask(0, bugReportDataCollection, 0, false); // Don't wait.
                m_Utils.WaitForBugReportProgress(30000);
                m_Utils.AbortTask(0, StackHashTaskType.BugReportTask);
                m_Utils.WaitForBugReportTaskCompleted(30000);

                // Check the progress reports.
                Assert.AreEqual(true, m_Utils.BugReportProgressReports.Count < 100);

                long lastProgress = -1;
                foreach (StackHashAdminReport report in m_Utils.BugReportProgressReports)
                {
                    StackHashBugReportProgressAdminReport progress = report as StackHashBugReportProgressAdminReport;

                    Assert.AreEqual(true, progress.CurrentEvent > lastProgress);
                    Assert.AreEqual(true, progress.CurrentEvent < progress.TotalEvents);
                    lastProgress = progress.CurrentEvent;
                }
            }
            finally
            {
                m_Utils.DeactivateContext(0);
                m_Utils.DeleteIndex(0);
            }
        }
示例#8
0
        /// <summary>
        /// Copies the specified event packages to the destination index along with any other event information, such as
        /// event and cab notes from the source index.
        /// </summary>
        /// <param name="product">Product owning the file.</param>
        /// <param name="file">File owning the events.</param>
        /// <param name="eventPackages">Events to copy.</param>
        private void copyEventBlock(StackHashProduct product, StackHashFile file, StackHashEventPackageCollection eventPackages)
        {
            foreach (StackHashEventPackage eventPackage in eventPackages)
            {
                if (this.CurrentTaskState.AbortRequested)
                {
                    throw new StackHashException("Index event copy aborted", StackHashServiceErrorCode.Aborted);
                }

                // Only add the event if it doesn't already exist in the destination index.
                if (!m_DestinationIndex.EventExists(product, file, eventPackage.EventData))
                {
                    m_DestinationIndex.AddEvent(product, file, eventPackage.EventData);
                }

                // Only normalize when copying from an XML index. Normalizing the event infos sets the dates to midnight PST.
                // The old XML index had - non-normalized dates.
                if (m_SourceIndex.IndexType == ErrorIndexType.Xml)
                {
                    eventPackage.EventInfoList = eventPackage.EventInfoList.Normalize();
                }

                // This call will only add new event infos. Duplicates will be discarded.
                m_DestinationIndex.AddEventInfoCollection(product, file, eventPackage.EventData, eventPackage.EventInfoList);

                // Copy the cabs for the event package.
                foreach (StackHashCabPackage cab in eventPackage.Cabs)
                {
                    if (this.CurrentTaskState.AbortRequested)
                    {
                        throw new StackHashException("Index cab copy aborted", StackHashServiceErrorCode.Aborted);
                    }

                    // Only add the cab if it doesn't already exist.
                    if (!m_DestinationIndex.CabExists(product, file, eventPackage.EventData, cab.Cab))
                    {
                        m_DestinationIndex.AddCab(product, file, eventPackage.EventData, cab.Cab, true);
                    }

                    // Get the cab notes. This call will retrieve them in the order they were added so no need to sort.
                    StackHashNotes cabNotes     = m_SourceIndex.GetCabNotes(product, file, eventPackage.EventData, cab.Cab);
                    StackHashNotes destCabNotes = m_DestinationIndex.GetCabNotes(product, file, eventPackage.EventData, cab.Cab);

                    foreach (StackHashNoteEntry note in cabNotes)
                    {
                        if (this.CurrentTaskState.AbortRequested)
                        {
                            throw new StackHashException("Index cab note copy aborted", StackHashServiceErrorCode.Aborted);
                        }

                        // Only add the note if it hasn't already been added to the destination index.
                        // This could have happened if the same event is associated with more than 1 file or product.
                        if (!destCabNotes.ContainsNote(note))
                        {
                            // Set the note id to 0 so a new one will be allocated.
                            note.NoteId = 0;
                            m_DestinationIndex.AddCabNote(product, file, eventPackage.EventData, cab.Cab, note);
                        }
                    }

                    // Copy the cab files over.
                    copyCabFiles(m_SourceIndex, m_DestinationIndex, product, file, eventPackage, cab.Cab);
                }

                // Copy the cab notes for this event.
                StackHashNotes eventNotes     = m_SourceIndex.GetEventNotes(product, file, eventPackage.EventData);
                StackHashNotes destEventNotes = m_DestinationIndex.GetEventNotes(product, file, eventPackage.EventData);

                foreach (StackHashNoteEntry note in eventNotes)
                {
                    if (this.CurrentTaskState.AbortRequested)
                    {
                        throw new StackHashException("Index event note copy aborted", StackHashServiceErrorCode.Aborted);
                    }

                    // Only add the note if it hasn't already been added to the destination index.
                    if (!destEventNotes.ContainsNote(note))
                    {
                        // Set the note id to 0 so a new one will be added (and not replace an existing one).
                        note.NoteId = 0;
                        m_DestinationIndex.AddEventNote(product, file, eventPackage.EventData, note);
                    }
                }

                // Report progress to clients. Progress is reported after each event but only for integral % completions.
                // Therefore this call won't actually send an event to the client every time.
                m_CurrentEvent++;
                reportProgress(m_CurrentEvent, m_TotalEvents, eventPackage.EventData.Id);
            }
        }
示例#9
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));
                }
            }
        }
示例#10
0
        /// <summary>
        /// Processes a specific file.
        /// </summary>
        private void processFile(StackHashBugReportData request, StackHashProduct product, StackHashFile file)
        {
            if (this.CurrentTaskState.AbortRequested)
            {
                throw new OperationCanceledException("Reporting events to Bug Tracker plug-ins");
            }

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

            if (((request.Options & StackHashReportOptions.IncludeFiles) != 0) ||
                ((request.Options & StackHashReportOptions.IncludeAllObjects) != 0))
            {
                m_TaskParameters.PlugInContext.FileAdded(m_PlugIns, m_ReportType, btProduct, btFile);
                checkPlugInStatus(m_PlugIns);
            }

            if (request.TheEvent == null)
            {
                // Parse the events.
                StackHashSortOrderCollection sortOrder = new StackHashSortOrderCollection()
                {
                    new StackHashSortOrder(StackHashObjectType.Event, "Id", true),
                    new StackHashSortOrder(StackHashObjectType.Event, "EventTypeName", true)
                };

                StackHashSearchOptionCollection searchOptions = new StackHashSearchOptionCollection()
                {
                    new IntSearchOption(StackHashObjectType.Product, "Id", StackHashSearchOptionType.Equal, product.Id, 0),
                    new IntSearchOption(StackHashObjectType.File, "Id", StackHashSearchOptionType.Equal, file.Id, 0),
                };

                StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection()
                {
                    new StackHashSearchCriteria(searchOptions)
                };


                int startRow     = 1;
                int numberOfRows = 100;
                StackHashEventPackageCollection allPackages = null;
                do
                {
                    allPackages = m_Index.GetEvents(allCriteria, startRow, numberOfRows, sortOrder, null);

                    foreach (StackHashEventPackage eventPackage in allPackages)
                    {
                        processEventPackage(request, product, file, eventPackage);
                    }

                    startRow += numberOfRows;
                } while (allPackages.Count > 0);
            }
            else
            {
                StackHashSearchOptionCollection searchOptions = new StackHashSearchOptionCollection()
                {
                    new IntSearchOption(StackHashObjectType.Product, "Id", StackHashSearchOptionType.Equal, product.Id, 0),
                    new IntSearchOption(StackHashObjectType.File, "Id", StackHashSearchOptionType.Equal, file.Id, 0),
                    new IntSearchOption(StackHashObjectType.Event, "Id", StackHashSearchOptionType.Equal, request.TheEvent.Id, 0),
                    new StringSearchOption(StackHashObjectType.Event, "EventTypeName", StackHashSearchOptionType.Equal, request.TheEvent.EventTypeName, request.TheEvent.EventTypeName, false),
                };

                StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection()
                {
                    new StackHashSearchCriteria(searchOptions)
                };

                StackHashEventPackageCollection eventPackages = m_Index.GetEvents(allCriteria, null);

                if ((eventPackages != null) && (eventPackages.Count == 1))
                {
                    processEventPackage(request, product, file, eventPackages[0]);
                }
            }
        }
示例#11
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 addRemoveCabNotes(int numberOfNotes)
        {
            StackHashTestIndexData testIndexData = new StackHashTestIndexData();

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

            // 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;
                StackHashEventPackageCollection events  = m_Utils.GetProductEventPackages(0, product).EventPackages;

                StackHashCab cab = events[0].Cabs[0].Cab;


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

                    m_Utils.AddCabNote(0, product, files[0], events[0].EventData, cab, note);

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

                    Assert.AreEqual(cabCount + 1, notes.Count);
                    bool found = false;
                    foreach (StackHashNoteEntry noteEntry in notes)
                    {
                        if (noteEntry.NoteId == cabCount + 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.DeleteCabNote(0, product, files[0], events[0].EventData, cab, eventCount + 1);

                    expectedEventNotes--;

                    StackHashNotes notes = m_Utils.GetCabNotes(0, product, files[0], events[0].EventData, cab).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);
            }
        }
示例#12
0
        private void testMergeOneNewEventInfoWithOverlap(IErrorIndex index, int numEventInfos, int overlap)
        {
            // Add event info - then add another new one.
            index.Activate();
            StackHashProduct product =
                new StackHashProduct(DateTime.Now, DateTime.Now, "http://www.cucku.com", 1, "TestProduct1", 20, 30, "2.10.02123.1293");
            StackHashFile file = new StackHashFile(new DateTime(100), new DateTime(101), 39, new DateTime(102), "filename.dll", "1.2.3.4");
            StackHashParameterCollection parameters = new StackHashParameterCollection();

            parameters.Add(new StackHashParameter("param1", "param1value"));
            parameters.Add(new StackHashParameter("param2", "param2value"));
            StackHashEventSignature signature = new StackHashEventSignature(parameters);

            StackHashEvent theEvent = new StackHashEvent(new DateTime(102), new DateTime(103), "EventType1", 20000, signature, -1, 2);

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

            StackHashEventInfoCollection eventInfoCollection = new StackHashEventInfoCollection();
            int totalHits = 0;

            for (int i = 0; i < numEventInfos; i++)
            {
                if (i < numEventInfos - overlap)
                {
                    totalHits += i + 1;
                }

                StackHashEventInfo eventInfo = new StackHashEventInfo(DateTime.Now.AddDays(-3 * i).Date,
                                                                      DateTime.Now.AddDays(-2 * i).Date, DateTime.Now.AddDays(-1 * i).Date, "English" + i.ToString(),
                                                                      i, "locale" + i.ToString(), "OS" + i.ToString(), "OSVersion" + i.ToString(), i + 1);
                eventInfoCollection.Add(eventInfo);
            }

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


            StackHashEventInfoCollection eventInfoCollectionNew = new StackHashEventInfoCollection();

            for (int i = numEventInfos - overlap; i < numEventInfos * 2 - overlap; i++)
            {
                StackHashEventInfo eventInfo = new StackHashEventInfo(DateTime.Now.AddDays(-3 * i).Date,
                                                                      DateTime.Now.AddDays(-2 * i).Date, DateTime.Now.AddDays(-1 * i).Date, "English" + i.ToString(),
                                                                      i, "locale" + i.ToString(), "OS" + i.ToString(), "OSVersion" + i.ToString(), overlap + i + 1);

                if (i >= numEventInfos - overlap)
                {
                    totalHits += overlap + i + 1;
                }

                StackHashEventInfo foundEventInfo = eventInfoCollection.FindEventInfoByHitDate(eventInfo);

                if (foundEventInfo != null)
                {
                    foundEventInfo.SetWinQualFields(eventInfo);
                }
                else
                {
                    eventInfoCollection.Add(eventInfo);
                }

                eventInfoCollectionNew.Add(eventInfo);
            }

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


            // Now get all the event info and make sure it all matches.
            StackHashEventInfoCollection eventInfoCollection2 = index.LoadEventInfoList(product, file, theEvent);

            Assert.AreEqual(0, eventInfoCollection.CompareTo(eventInfoCollection2));

            StackHashEventPackageCollection eventPackages = index.GetProductEvents(product);

            Assert.AreEqual(1, eventPackages.Count);
            Assert.AreEqual(totalHits, eventPackages[0].EventData.TotalHits);
        }
示例#13
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;
        }