示例#1
0
        public void GetSetSyncProgressReload()
        {
            m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder);
            m_Index.DeleteIndex();
            m_Index.Activate();

            StackHashSyncProgress syncProgress = new StackHashSyncProgress(1, 2, 3, "EventTypeName", 4, StackHashSyncPhase.Events);

            m_Index.SyncProgress = syncProgress;

            StackHashSyncProgress newProgress = m_Index.SyncProgress;

            Assert.AreEqual(0, newProgress.CompareTo(syncProgress));


            m_Index.Deactivate();
            m_Index.Dispose();

            // Load again to make sure the data was persisted.
            m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder);
            m_Index.Activate();

            newProgress = m_Index.SyncProgress;

            Assert.AreEqual(0, newProgress.CompareTo(syncProgress));
        }
示例#2
0
        public void GetSetSyncProgress()
        {
            m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder);
            m_Index.DeleteIndex();
            m_Index.Activate();

            StackHashSyncProgress syncProgress = new StackHashSyncProgress(1, 2, 3, "EventTypeName", 4, StackHashSyncPhase.Events);

            m_Index.SyncProgress = syncProgress;

            StackHashSyncProgress newProgress = m_Index.SyncProgress;

            Assert.AreEqual(0, newProgress.CompareTo(syncProgress));
        }
示例#3
0
        /// <summary>
        /// Synchronizes the online WinQual database with the local copy.
        /// The local copy is effectively a cache of the online copy.
        /// </summary>
        /// <param name="errorIndex">Error index to add to.</param>
        /// <param name="forceResynchronize">True - sync everything, false - just sync from last sync time.</param>
        /// <param name="lastProgress">Last point at which the sync stopped.</param>
        /// <returns></returns>
        public void SynchronizeWithWinQualOnline(IErrorIndex errorIndex, bool forceResynchronize, StackHashSyncProgress lastProgress)
        {
            if (errorIndex == null)
            {
                throw new ArgumentNullException("errorIndex");
            }
            m_ErrorIndex = errorIndex;

            m_SyncProgress = new StackHashSyncProgress();

            m_AbortRequested = false;

            ProductCollection products = Product.GetProducts(ref m_Login);

            UpdateProducts(forceResynchronize, errorIndex, products, false, false); // Don't get events or cabs first time around.
            onProgress(WinQualProgressType.ProductListUpdated, null);

            UpdateProducts(forceResynchronize, errorIndex, products, true, false); // Get the events but not the cabs.
            UpdateProducts(forceResynchronize, errorIndex, products, true, true);  // Get everything.
        }
示例#4
0
        public void GetSetSyncProgressNTimes()
        {
            m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder);
            m_Index.DeleteIndex();
            m_Index.Activate();

            int numTimes = 100;

            Random rand = new Random(1);

            for (int i = 0; i < numTimes; i++)
            {
                StackHashSyncPhase phase = (StackHashSyncPhase)rand.Next(0, 4);

                StackHashSyncProgress syncProgress = new StackHashSyncProgress(1 + i, 2 + i, 3 + i, "EventTypeName" + i.ToString(), 4 + i, phase);
                m_Index.SyncProgress = syncProgress;

                StackHashSyncProgress newProgress = m_Index.SyncProgress;
                Assert.AreEqual(0, newProgress.CompareTo(syncProgress));
            }
        }
示例#5
0
        public override void EntryPoint()
        {
            bool loginFailed = false;
            bool loggedOn    = false;

            try
            {
                SetTaskStarted(m_TaskParameters.ErrorIndex);


                // Don't allow the PC to go into sleep mode while syncing.
                StackHashUtilities.SystemInformation.DisableSleep();

                DateTime startSyncTime = DateTime.Now.ToUniversalTime();

                checkLicense();

                // Hook up to receive events about new error index items.
                m_TaskParameters.ErrorIndex.IndexUpdated += new EventHandler <ErrorIndexEventArgs>(this.ErrorIndexUpdated);
                m_Statistics = new StackHashSynchronizeStatistics();

                try
                {
                    // Hook up to the WinQual service for progress events.
                    m_WinQualServices.Progress += new EventHandler <WinQualProgressEventArgs>(this.WinQualSyncEventHandler);

                    // Create a new WinQual context. This stores information about the
                    // configuration and state of the WinQual connection.
                    // Note that the WinQualServices is passed in here so that WinQualContext can
                    // be tested with a dummy.
                    m_WinQualContext = new WinQualContext(m_WinQualServices);


                    try
                    {
                        // Log on to WinQual.
                        m_WinQualContext.WinQualServices.LogOn(m_TaskParameters.WinQualSettings.UserName, m_TaskParameters.WinQualSettings.Password);
                        loggedOn = true;
                    }
                    catch (System.Exception ex)
                    {
                        m_LastLogOnException = ex;
                        loginFailed          = true;
                        throw;
                    }

                    // Set the products that should not be synced.
                    if (m_TaskParameters.JustSyncProductList)
                    {
                        m_WinQualServices.ProductsToSynchronize = null;
                    }
                    else
                    {
                        m_WinQualServices.ProductsToSynchronize = m_TaskParameters.ProductsToSynchronize;
                    }

                    m_WinQualServices.EnableNewProductsAutomatically = shouldEnableNewProductsAutomatically();


                    // Set the collection policy - dictates the number of cabs to download etc...
                    m_WinQualServices.CollectionPolicy = m_TaskParameters.CollectionPolicy;

                    m_WinQualServices.MaxConsecutiveCabDownloadFailures = m_TaskParameters.WinQualSettings.MaxCabDownloadFailuresBeforeAbort;

                    long totalEventsAllowedForThisContext = m_TaskParameters.TheLicenseManager.MaxEvents
                                                            - (m_TaskParameters.TotalStoredEvents - m_TaskParameters.ErrorIndex.TotalStoredEvents);
                    if (totalEventsAllowedForThisContext < 0)
                    {
                        totalEventsAllowedForThisContext = 0;
                    }

                    m_WinQualServices.SetLicenseRestrictions(totalEventsAllowedForThisContext);


                    // Determine if we should be doing a full sync or not.
                    // After the nth sync a resync is forced.
                    m_IsResync = m_TaskParameters.ForceFullSynchronize;

                    int syncCount = m_TaskParameters.ErrorIndex.SyncCount;

                    syncCount++;
                    if ((syncCount >= m_TaskParameters.WinQualSettings.SyncsBeforeResync) &&
                        (!m_TaskParameters.JustSyncProductList))
                    {
                        m_IsResync = true;
                    }

                    // Get the last point at which the sync failed.
                    StackHashSyncProgress lastProgress = m_TaskParameters.ErrorIndex.SyncProgress;
                    if (m_IsResync)
                    {
                        lastProgress = null;
                    }

                    // Call the WinQual services to synchronize.
                    m_WinQualServices.SynchronizeWithWinQualOnline(m_TaskParameters.ErrorIndex, m_IsResync, lastProgress);

                    // Don't update the sync count for a mere product only sync.
                    if (!m_TaskParameters.JustSyncProductList)
                    {
                        if (m_IsResync)
                        {
                            m_TaskParameters.ErrorIndex.SyncCount = 0;
                        }
                        else
                        {
                            m_TaskParameters.ErrorIndex.SyncCount = syncCount;
                        }
                    }


                    if (m_TaskParameters.ErrorIndex.TotalStoredEvents >= totalEventsAllowedForThisContext)
                    {
                        throw new StackHashException("Licensed event limit reached: " +
                                                     m_TaskParameters.ErrorIndex.TotalStoredEvents.ToString(CultureInfo.InvariantCulture),
                                                     StackHashServiceErrorCode.LicenseEventCountExceeded);
                    }
                }
                finally
                {
                    try
                    {
                        if (loggedOn)
                        {
                            m_WinQualContext.WinQualServices.LogOff();
                        }
                    }
                    catch (System.Exception ex)
                    {
                        DiagnosticsHelper.LogException(DiagSeverity.Warning, "Failed to log off Win Qual", ex);
                    }

                    // Don't reset the sync progress for just product only syncs or if the login to winqual failed.
                    if (!m_TaskParameters.JustSyncProductList && !loginFailed)
                    {
                        m_TaskParameters.ErrorIndex.SyncProgress = m_WinQualServices.SyncProgress;
                    }

                    m_WinQualServices.Progress -= new EventHandler <WinQualProgressEventArgs>(this.WinQualSyncEventHandler);

                    // Unhook from the event index.
                    m_TaskParameters.ErrorIndex.IndexUpdated -= new EventHandler <ErrorIndexEventArgs>(this.ErrorIndexUpdated);
                }
            }
            catch (Exception ex)
            {
                LastException = ex;
            }
            finally
            {
                StackHashUtilities.SystemInformation.EnableSleep();
                SetTaskCompleted(m_TaskParameters.ErrorIndex);
            }
        }
示例#6
0
        /// <summary>
        /// Starts a sync to download products, files, events, event infos and cabs.
        /// Data is added to the specified error index according to the directions specified
        /// in the testdata passed into the constructor.
        /// </summary>
        /// <param name="errorIndex">The index to add the new data to.</param>
        /// <param name="forceResynchronize">True - forces a resync of every event that is available. False - sync new events only.</param>
        /// <param name="lastProgress">Point at which the last sync attempt reached.</param>
        public void SynchronizeWithWinQualOnline(StackHashErrorIndex.IErrorIndex errorIndex, bool forceResynchronize, StackHashSyncProgress lastProgress)
        {
            if (errorIndex == null)
            {
                throw new ArgumentNullException("errorIndex");
            }

            int fileId  = 1;
            int eventId = 1;
            int cabId   = 1;

            m_SyncProgress = new StackHashSyncProgress();

            m_AbortRequested = false;
            onProgress(WinQualProgressType.DownloadingProductList, null);
            m_SyncProgress.SyncPhase = StackHashSyncPhase.ProductsOnly;
            errorIndex.SetLastSyncTimeLocal(-2, DateTime.Now.AddDays(-14));

            for (int i = 0; i < m_TestSettings.ObjectsToCreate.NumberOfProducts; i++)
            {
                if (m_AbortRequested)
                {
                    throw new OperationCanceledException("Abort requested during Win Qual synchronize");
                }

                StackHashProduct product = new StackHashProduct();
                product.DateCreatedLocal  = DateTime.Now.ToUniversalTime();
                product.DateModifiedLocal = product.DateCreatedLocal;
                product.FilesLink         = "http://www.cucku.com";
                product.Id             = i + 1;
                product.Name           = "Product" + (i + 1).ToString(CultureInfo.InvariantCulture);
                product.TotalEvents    = i;
                product.TotalResponses = i;
                product.Version        = "1.2.3." + i.ToString(CultureInfo.InvariantCulture);

                if (!errorIndex.ProductExists(product))
                {
                    if (m_EnableNewProductsAutomatically)
                    {
                        m_ProductsToSynchronize.Add(new StackHashProductSyncData(product.Id));
                    }

                    errorIndex.AddProduct(product);
                }
            }
            onProgress(WinQualProgressType.ProductListUpdated, null);

            DateTime eventInfoDate = DateTime.Now.Date;


            if (m_TestSettings.FailSync)
            {
                throw new StackHashException("Test sync failure", StackHashServiceErrorCode.SqlConnectionError);
            }

            m_SyncProgress.SyncPhase = StackHashSyncPhase.EventInfosAndCabs;
            for (int i = 0; i < m_TestSettings.ObjectsToCreate.NumberOfProducts; i++)
            {
                if (m_AbortRequested)
                {
                    throw new OperationCanceledException("Abort requested during Win Qual synchronize");
                }

                DateTime productSyncStartTime = DateTime.Now;

                StackHashProduct product = new StackHashProduct();
                product.DateCreatedLocal  = DateTime.Now.ToUniversalTime();
                product.DateModifiedLocal = product.DateCreatedLocal;
                product.FilesLink         = "http://www.cucku.com";
                product.Id             = i + 1;
                product.Name           = "Product" + (i + 1).ToString(CultureInfo.InvariantCulture);
                product.TotalEvents    = i;
                product.TotalResponses = i;
                product.Version        = "1.2.3." + i.ToString(CultureInfo.InvariantCulture);

                m_SyncProgress.ProductId = product.Id;

                errorIndex.AddProduct(product);
                if (isExcludedProduct(product.Id))
                {
                    continue;
                }

                if (m_TestSettings.ObjectsToCreate.DuplicateFileIdsAcrossProducts)
                {
                    eventId = 1;
                    cabId   = 1;
                }

                for (int j = 0; j < m_TestSettings.ObjectsToCreate.NumberOfFiles; j++)
                {
                    if (m_AbortRequested)
                    {
                        throw new OperationCanceledException("Abort requested during Win Qual synchronize");
                    }

                    StackHashFile file = new StackHashFile();
                    file.DateCreatedLocal  = DateTime.Now.ToUniversalTime();
                    file.DateModifiedLocal = DateTime.Now.ToUniversalTime();
                    file.Id            = fileId;
                    file.LinkDateLocal = DateTime.Now.ToUniversalTime();
                    file.Name          = "File" + fileId.ToString(CultureInfo.InvariantCulture);
                    file.Version       = "1.2.3." + fileId.ToString(CultureInfo.InvariantCulture);

                    m_SyncProgress.FileId = file.Id;

                    errorIndex.AddFile(product, file);
                    fileId++;

                    onProgress(WinQualProgressType.DownloadingProductEvents, product, null, null, null, 0, 0,
                               productSyncStartTime, new DateTime(0), errorIndex.GetLastSyncTimeLocal(product.Id));
                    onProgress(WinQualProgressType.DownloadingProductCabs, product, null, null, null, 0, 0,
                               productSyncStartTime, new DateTime(0), errorIndex.GetLastSyncTimeLocal(product.Id));

                    for (int k = 0; k < m_TestSettings.ObjectsToCreate.NumberOfEvents; k++)
                    {
                        if (m_AbortRequested)
                        {
                            throw new OperationCanceledException("Abort requested during Win Qual synchronize");
                        }

                        if (errorIndex.TotalStoredEvents >= m_MaxEvents)
                        {
                            break;
                        }

                        StackHashEvent theEvent = new StackHashEvent();
                        theEvent.DateCreatedLocal  = DateTime.Now.ToUniversalTime();
                        theEvent.DateModifiedLocal = theEvent.DateCreatedLocal;
                        theEvent.EventTypeName     = "CLR";
                        theEvent.FileId            = fileId;
                        theEvent.Id             = eventId++;
                        theEvent.EventSignature = new StackHashEventSignature();
                        theEvent.EventSignature.ApplicationName      = "AppName";
                        theEvent.EventSignature.ApplicationTimeStamp = DateTime.Now.ToUniversalTime();
                        theEvent.EventSignature.ApplicationVersion   = "1.2.3.4";
                        theEvent.EventSignature.ExceptionCode        = 123;
                        theEvent.EventSignature.ModuleName           = "ModuleName";
                        theEvent.EventSignature.ModuleTimeStamp      = DateTime.Now.ToUniversalTime();
                        theEvent.EventSignature.ModuleVersion        = "4.3.2.1";
                        theEvent.EventSignature.Offset     = 12;
                        theEvent.EventSignature.Parameters = new StackHashParameterCollection();
                        theEvent.EventSignature.Parameters.Add(new StackHashParameter("Param", "Value"));

                        if (m_TestSettings.ObjectsToCreate.SetBugId)
                        {
                            theEvent.BugId       = "BugId" + theEvent.Id.ToString(CultureInfo.InvariantCulture);
                            theEvent.PlugInBugId = "PlugInOriginalId" + theEvent.Id.ToString(CultureInfo.InvariantCulture);
                        }
                        errorIndex.AddEvent(product, file, theEvent);
                        m_SyncProgress.EventId       = theEvent.Id;
                        m_SyncProgress.EventTypeName = theEvent.EventTypeName;

                        StackHashEventInfoCollection eventInfoCollection = new StackHashEventInfoCollection();
                        for (int l = 0; l < m_TestSettings.ObjectsToCreate.NumberOfEventInfos; l++)
                        {
                            if (m_AbortRequested)
                            {
                                throw new OperationCanceledException("Abort requested during Win Qual synchronize");
                            }

                            StackHashEventInfo eventInfo = new StackHashEventInfo();
                            eventInfo.DateCreatedLocal  = DateTime.Now.ToUniversalTime();
                            eventInfo.DateModifiedLocal = DateTime.Now.ToUniversalTime();
                            eventInfo.HitDateLocal      = eventInfoDate;
                            eventInfo.Language          = "lang";
                            eventInfo.Lcid   = 234;
                            eventInfo.Locale = "locale";
                            eventInfo.OperatingSystemName    = "XP";
                            eventInfo.OperatingSystemVersion = "SP2";
                            eventInfo.TotalHits = l;
                            eventInfoCollection.Add(eventInfo);

                            eventInfoDate.AddDays(1);
                        }

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


                        for (int m = 0; m < m_TestSettings.ObjectsToCreate.NumberOfCabs; m++)
                        {
                            if (m_AbortRequested)
                            {
                                throw new OperationCanceledException("Abort requested during Win Qual synchronize");
                            }

                            StackHashCab cab = new StackHashCab();
                            cab.DateCreatedLocal  = DateTime.Now.ToUniversalTime();
                            cab.DateModifiedLocal = DateTime.Now.ToUniversalTime();
                            cab.EventId           = theEvent.Id;
                            cab.EventTypeName     = theEvent.EventTypeName;
                            cab.FileName          = "cab" + cabId.ToString(CultureInfo.InvariantCulture) + ".cab";
                            cab.Id          = cabId++;
                            cab.SizeInBytes = 100;

                            errorIndex.AddCab(product, file, theEvent, cab, false);
                            m_SyncProgress.CabId = cab.Id;

                            // Copy in a test cab file.

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

                            if (!File.Exists(cabFileName))
                            {
                                if (m_TestSettings.ObjectsToCreate.UseUnmanagedCab)
                                {
                                    File.Copy(TestSettings.TestDataFolder + @"Cabs\1629290733-SpecialException-1073810027.cab", cabFileName);
                                }
                                else if (m_TestSettings.ObjectsToCreate.UseLargeCab)
                                {
                                    File.Copy(TestSettings.TestDataFolder + @"Cabs\1630796338-Crash32bit-0760025228.cab", cabFileName);
                                }
                                else
                                {
                                    File.Copy(TestSettings.TestDataFolder + @"Cabs\1641909485-Crash32bit-0773522646.cab", cabFileName);
                                }
                            }
                            // Make sure the file is not read only.
                            FileAttributes attributes = File.GetAttributes(cabFileName);
                            attributes &= ~FileAttributes.ReadOnly;
                            File.SetAttributes(cabFileName, attributes);
                        }
                    }
                    onProgress(WinQualProgressType.ProductCabsUpdated, product, null, null, null, 0, 0,
                               productSyncStartTime, DateTime.Now, errorIndex.GetLastSyncTimeLocal(product.Id));
                    onProgress(WinQualProgressType.ProductEventsUpdated, product, null, null, null, 0, 0,
                               productSyncStartTime, DateTime.Now, errorIndex.GetLastSyncTimeLocal(product.Id));
                }
                errorIndex.UpdateProductStatistics(product);
                errorIndex.SetLastSyncTimeLocal(product.Id, productSyncStartTime);
                errorIndex.SetLastSyncCompletedTimeLocal(product.Id, DateTime.Now);
            }
            onProgress(WinQualProgressType.Complete);
        }