Beispiel #1
0
        public void ProductSyncListAddTwoEntriesRemoveFirst()
        {
            String settingsFileName = Path.GetTempFileName();

            File.Delete(settingsFileName);

            try
            {
                SettingsManager          settingsManager = new SettingsManager(settingsFileName);
                StackHashContextSettings contextSettings = settingsManager.CreateNewContextSettings();
                Assert.AreNotEqual(null, contextSettings.WinQualSettings.ProductsToSynchronize);

                settingsManager.SetProductSynchronization(0, 10, true);
                settingsManager.SetProductSynchronization(0, 20, true);
                StackHashSettings currentSettings = settingsManager.CurrentSettings;
                Assert.AreEqual(2, currentSettings.ContextCollection[0].WinQualSettings.ProductsToSynchronize.Count);
                StackHashProductSyncData productSyncData = currentSettings.ContextCollection[0].WinQualSettings.ProductsToSynchronize.FindProduct(10);
                Assert.AreNotEqual(null, productSyncData);
                Assert.AreEqual(10, productSyncData.ProductId);
                productSyncData = currentSettings.ContextCollection[0].WinQualSettings.ProductsToSynchronize.FindProduct(20);
                Assert.AreNotEqual(null, productSyncData);
                Assert.AreEqual(20, productSyncData.ProductId);

                // Check the settings are persisted.
                settingsManager = new SettingsManager(settingsFileName);
                currentSettings = settingsManager.CurrentSettings;
                Assert.AreEqual(2, currentSettings.ContextCollection[0].WinQualSettings.ProductsToSynchronize.Count);
                productSyncData = currentSettings.ContextCollection[0].WinQualSettings.ProductsToSynchronize.FindProduct(10);
                Assert.AreNotEqual(null, productSyncData);
                Assert.AreEqual(10, productSyncData.ProductId);
                productSyncData = currentSettings.ContextCollection[0].WinQualSettings.ProductsToSynchronize.FindProduct(20);
                Assert.AreNotEqual(null, productSyncData);
                Assert.AreEqual(20, productSyncData.ProductId);

                settingsManager.SetProductSynchronization(0, 10, false);
                currentSettings = settingsManager.CurrentSettings;
                Assert.AreEqual(1, currentSettings.ContextCollection[0].WinQualSettings.ProductsToSynchronize.Count);
                productSyncData = currentSettings.ContextCollection[0].WinQualSettings.ProductsToSynchronize.FindProduct(20);
                Assert.AreNotEqual(null, productSyncData);
                Assert.AreEqual(20, productSyncData.ProductId);

                // Check the settings are persisted.
                settingsManager = new SettingsManager(settingsFileName);
                currentSettings = settingsManager.CurrentSettings;
                Assert.AreEqual(1, currentSettings.ContextCollection[0].WinQualSettings.ProductsToSynchronize.Count);
                productSyncData = currentSettings.ContextCollection[0].WinQualSettings.ProductsToSynchronize.FindProduct(20);
                Assert.AreNotEqual(null, productSyncData);
                Assert.AreEqual(20, productSyncData.ProductId);
            }
            finally
            {
                if (File.Exists(settingsFileName))
                {
                    File.Delete(settingsFileName);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Determines if the specified product should be searched for cabs to process.
        /// </summary>
        /// <param name="product">The product to check.</param>
        /// <returns>True - process the product, false - don't process.</returns>
        private bool shouldProcessProduct(StackHashProduct product)
        {
            if (m_TaskParameters.ProductsToSynchronize == null)
            {
                return(false);
            }

            // If no syncData available then the user is not interested in synchronizing thus product.
            StackHashProductSyncData syncData = m_TaskParameters.ProductsToSynchronize.FindProduct(product.Id);

            return(syncData != null);
        }
Beispiel #3
0
        /// <summary>
        /// Called when a change occurs to the underlying real index.
        /// Just reports to any upstream objects.
        /// </summary>
        /// <param name="source">Should be the real index.</param>
        /// <param name="e">Identifies the change.</param>
        private void ErrorIndexUpdated(Object source, ErrorIndexEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            if (e.ChangeInformation == null)
            {
                throw new ArgumentException("Change information is invalid", "e");
            }

            if (e.ChangeInformation.TypeOfChange == StackHashChangeType.NewEntry)
            {
                switch (e.ChangeInformation.DataThatChanged)
                {
                case StackHashDataChanged.Product:
                    m_Statistics.Products++;

                    // New products should be enabled automatically if requested.
                    if (shouldEnableNewProductsAutomatically())
                    {
                        // Check if auto product enabling is enabled.
                        StackHashProductSyncData productToSync = new StackHashProductSyncData((int)e.ChangeInformation.ProductId);
                        m_TaskParameters.SettingsManager.SetProductSyncData(m_TaskParameters.ContextId, productToSync);
                    }
                    break;

                case StackHashDataChanged.File:
                    m_Statistics.Files++;
                    break;

                case StackHashDataChanged.Event:
                    m_Statistics.Events++;
                    break;

                case StackHashDataChanged.Hit:
                    m_Statistics.EventInfos++;
                    break;

                case StackHashDataChanged.Cab:
                    m_Statistics.Cabs++;
                    break;
                }
            }
        }
Beispiel #4
0
        // Get the
        public void productInfoGet(ErrorIndexType indexType, int numProducts, bool resetService)
        {
            // Add a context.
            CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(indexType);

            String testPath = "c:\\stackhashunittests\\testindex\\";

            resp.Settings.ErrorIndexSettings.Folder = testPath;
            resp.Settings.ErrorIndexSettings.Name   = "TestIndex";
            m_Utils.SetContextSettings(resp.Settings);
            m_Utils.DeleteIndex(0); // Make sure it is empty.
            m_Utils.ActivateContext(0);

            // Create a test index with one cab file.
            StackHashTestIndexData testIndexData = new StackHashTestIndexData();

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

            m_Utils.CreateTestIndex(0, testIndexData);

            // Service is now started with the specified index.
            // Make sure we can get at least the list of products.
            GetProductsResponse getProductsResp = m_Utils.GetProducts(0);

            Assert.AreEqual(numProducts, getProductsResp.Products.Count());

            foreach (StackHashProductInfo productInfo in getProductsResp.Products)
            {
                StackHashProduct product = productInfo.Product;

                Assert.AreEqual(false, productInfo.SynchronizeEnabled);
                Assert.AreEqual(null, productInfo.ProductSyncData);
            }

            // Now enable the products for sync.
            foreach (StackHashProductInfo productInfo in getProductsResp.Products)
            {
                m_Utils.SetProductSynchronizationState(0, productInfo.Product.Id, true);
            }

            // Get the list of product data again.
            getProductsResp = m_Utils.GetProducts(0);

            Assert.AreEqual(numProducts, getProductsResp.Products.Count());

            foreach (StackHashProductInfo productInfo in getProductsResp.Products)
            {
                StackHashProduct product = productInfo.Product;

                Assert.AreEqual(true, productInfo.SynchronizeEnabled);
                Assert.AreNotEqual(null, productInfo.ProductSyncData);
                Assert.AreEqual(productInfo.Product.Id, productInfo.ProductSyncData.ProductId);
            }


            foreach (StackHashProductInfo productInfo in getProductsResp.Products)
            {
                StackHashProductSyncData syncData = new StackHashProductSyncData();
                syncData.ProductId = productInfo.Product.Id;
                m_Utils.SetProductSynchronizationData(0, syncData);
            }

            // Get the list of product data again.
            getProductsResp = m_Utils.GetProducts(0);
            Assert.AreEqual(numProducts, getProductsResp.Products.Count());

            if (resetService)
            {
                m_Utils.RestartService();
            }

            // Get the list of product data again.
            getProductsResp = m_Utils.GetProducts(0);
            Assert.AreEqual(numProducts, getProductsResp.Products.Count());

            foreach (StackHashProductInfo productInfo in getProductsResp.Products)
            {
                StackHashProduct product = productInfo.Product;

                Assert.AreEqual(true, productInfo.SynchronizeEnabled);
                Assert.AreNotEqual(null, productInfo.ProductSyncData);
                Assert.AreEqual(productInfo.Product.Id, productInfo.ProductSyncData.ProductId);
            }

            // Disable all products for sync.
            foreach (StackHashProductInfo productInfo in getProductsResp.Products)
            {
                m_Utils.SetProductSynchronizationState(0, productInfo.Product.Id, false);
            }


            getProductsResp = m_Utils.GetProducts(0);

            Assert.AreEqual(numProducts, getProductsResp.Products.Count());

            foreach (StackHashProductInfo productInfo in getProductsResp.Products)
            {
                StackHashProduct product = productInfo.Product;

                Assert.AreEqual(false, productInfo.SynchronizeEnabled);
                Assert.AreEqual(null, productInfo.ProductSyncData);
            }



            m_Utils.DeactivateContext(0);
            m_Utils.DeleteIndex(0);
        }