Beispiel #1
0
        /// <summary>
        /// Create the index.
        /// </summary>
        /// <param name="index">Sql or xml index.</param>
        /// <param name="testData">Defines size and type of entries.</param>
        public static void CreateTestIndex(IErrorIndex index, StackHashTestIndexData testData)
        {
            int productId = 26214;
            int fileId    = 1035620;
            int eventId   = 1099309964;
            int cabId     = 939529168;

            // Randomize some selections.
            Random rand = new Random(1);

            int totalEventsPerProduct = testData.NumberOfFiles * testData.NumberOfEvents;

            for (int i = 0; i < testData.NumberOfProducts; i++)
            {
                StackHashProduct product = new StackHashProduct();
                product.DateCreatedLocal  = DateTime.Now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180));
                product.DateModifiedLocal = product.DateCreatedLocal.AddDays(rand.Next(-10, 10));
                product.FilesLink         = "http://www.cucku.com";
                product.Id             = productId++;
                product.Name           = "StackHash";
                product.TotalEvents    = totalEventsPerProduct;
                product.TotalResponses = 1;
                product.Version        = String.Format("{0}.{1}.{2}{3}.{4}",
                                                       i.ToString(CultureInfo.InvariantCulture), rand.Next() % 99, rand.Next() % 366, rand.Next() % 5 + 2005, (i + 1) * 1237);
                index.AddProduct(product);

                Console.WriteLine(String.Format("Adding product {0} of {1}", i, testData.NumberOfProducts));

                for (int j = 0; j < testData.NumberOfFiles; j++)
                {
                    StackHashFile file = new StackHashFile();
                    file.DateCreatedLocal  = DateTime.Now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180));
                    file.DateModifiedLocal = file.DateCreatedLocal.AddDays(rand.Next(-10, 10));
                    file.Id            = fileId++;
                    file.LinkDateLocal = file.DateCreatedLocal.AddDays(rand.Next(-10, 10));

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

                    index.AddFile(product, file);
                    Console.WriteLine(String.Format("Adding File {0} of {1}", j, testData.NumberOfFiles));

                    for (int k = 0; k < testData.NumberOfEvents; k++)
                    {
                        StackHashEvent theEvent = new StackHashEvent();
                        theEvent.DateCreatedLocal  = DateTime.Now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180));
                        theEvent.DateModifiedLocal = theEvent.DateCreatedLocal.AddDays(rand.Next(-10, 10));

                        // Select a random event type.
                        theEvent.EventTypeName = s_EventTypes[rand.Next(0, s_EventTypes.Length)];
                        theEvent.FileId        = file.Id;
                        theEvent.Id            = eventId++;

                        theEvent.EventSignature = new StackHashEventSignature();
                        theEvent.EventSignature.ApplicationName      = "StackHash.exe";
                        theEvent.EventSignature.ApplicationTimeStamp = DateTime.Now.ToUniversalTime().AddDays(-180);
                        theEvent.EventSignature.ApplicationVersion   = String.Format("{0}.{1}.{2}{3}.{4}",
                                                                                     rand.Next() % 99, rand.Next() % 99, rand.Next() % 366, rand.Next() % 5 + 2005, (eventId + 1) * 1234);
                        theEvent.EventSignature.ExceptionCode   = 0xc0000000 + rand.Next(0, 16);
                        theEvent.EventSignature.ModuleName      = s_ModuleNames[rand.Next() % s_ModuleNames.Length];
                        theEvent.EventSignature.ModuleTimeStamp = DateTime.Now.ToUniversalTime().AddDays(-1 * ((rand.Next() % 200)));
                        theEvent.EventSignature.ModuleVersion   = String.Format("{0}.{1}.{2}{3}.{4}",
                                                                                rand.Next() % 99, rand.Next() % 99, rand.Next() % 366, rand.Next() % 5 + 2005, (eventId + 1) * 1234);
                        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()));
                        theEvent.EventSignature.Parameters.Add(new StackHashParameter("applicationVersion", theEvent.EventSignature.ApplicationVersion));
                        theEvent.EventSignature.Parameters.Add(new StackHashParameter("exceptionCode", String.Format("{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()));
                        theEvent.EventSignature.Parameters.Add(new StackHashParameter("moduleVersion", theEvent.EventSignature.ModuleVersion.ToString()));
                        theEvent.EventSignature.Parameters.Add(new StackHashParameter("offset", String.Format("{0:X}", theEvent.EventSignature.Offset.ToString())));

                        index.AddEvent(product, file, theEvent);
                        DateTime startTime = DateTime.Now;

                        Console.WriteLine(String.Format("P:{0} F:{1} Ev {2} of {3}", i, j, k, testData.NumberOfEvents));

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

                            StackHashEventInfo eventInfo = new StackHashEventInfo();
                            eventInfo.DateCreatedLocal  = DateTime.Now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180));
                            eventInfo.DateModifiedLocal = eventInfo.DateCreatedLocal.AddDays(l);
                            eventInfo.HitDateLocal      = DateTime.Now.ToUniversalTime().AddDays(-1 * l);
                            eventInfo.Language          = s_Languages[languageIndex];
                            eventInfo.Lcid   = s_Lcids[languageIndex];
                            eventInfo.Locale = "locale";
                            int osIndex = rand.Next(0, s_OperatingSystems.Length);

                            eventInfo.OperatingSystemName    = s_OperatingSystems[osIndex];
                            eventInfo.OperatingSystemVersion = s_OperatingSystemVersions[osIndex];
                            eventInfo.TotalHits = l + 1;
                            eventInfoCollection.Add(eventInfo);
                        }

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


                        for (int m = 0; m < testData.NumberOfCabs; m++)
                        {
                            StackHashCab cab = new StackHashCab();
                            cab.DateCreatedLocal  = DateTime.Now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180));
                            cab.DateModifiedLocal = cab.DateCreatedLocal.AddDays(m);
                            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);

                            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(@"R:\stackhash\BusinessLogic\BusinessLogic\TestData\Cabs\", testData.CabFileName), cabFileName);
                                }
                                else if (testData.UseLargeCab)
                                {
                                    File.Copy(@"R:\stackhash\BusinessLogic\BusinessLogic\TestData\Cabs\1630796338-Crash32bit-0760025228.cab", cabFileName);
                                }
                                else
                                {
                                    File.Copy(@"R:\stackhash\BusinessLogic\BusinessLogic\TestData\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);
                        }
                        Console.WriteLine(String.Format("Added Event {0} of {1} - Duration: {2}", k, testData.NumberOfEvents, (DateTime.Now - startTime).TotalMilliseconds));
                    }
                }
            }
        }