public void Constructor() { StackHashSynchronizeStatistics stats = new StackHashSynchronizeStatistics(1, 2, 3, 4, 5); Assert.AreEqual(1, stats.Products); Assert.AreEqual(2, stats.Files); Assert.AreEqual(3, stats.Events); Assert.AreEqual(4, stats.EventInfos); Assert.AreEqual(5, stats.Cabs); }
public void Clone() { StackHashSynchronizeStatistics stats = new StackHashSynchronizeStatistics(3, 5, 7, 9, 11); StackHashSynchronizeStatistics stats2 = stats.Clone(); Assert.AreEqual(3, stats2.Products); Assert.AreEqual(5, stats2.Files); Assert.AreEqual(7, stats2.Events); Assert.AreEqual(9, stats2.EventInfos); Assert.AreEqual(11, stats2.Cabs); }
public void Subtract() { StackHashSynchronizeStatistics stats = new StackHashSynchronizeStatistics(3, 5, 7, 9, 11); StackHashSynchronizeStatistics stats2 = new StackHashSynchronizeStatistics(1, 2, 3, 4, 5); stats.Subtract(stats2); Assert.AreEqual(2, stats.Products); Assert.AreEqual(3, stats.Files); Assert.AreEqual(4, stats.Events); Assert.AreEqual(5, stats.EventInfos); Assert.AreEqual(6, stats.Cabs); }
public void Add() { StackHashSynchronizeStatistics stats = new StackHashSynchronizeStatistics(1, 2, 3, 4, 5); StackHashSynchronizeStatistics stats2 = new StackHashSynchronizeStatistics(5, 4, 3, 2, 1); stats.Add(stats2); Assert.AreEqual(6, stats.Products); Assert.AreEqual(6, stats.Files); Assert.AreEqual(6, stats.Events); Assert.AreEqual(6, stats.EventInfos); Assert.AreEqual(6, stats.Cabs); }
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); } }