예제 #1
0
        /// <summary>
        /// Syncs up with the files/events on winqual.
        /// </summary>
        /// <param name="lastPullDate">Last time the data was synced.</param>
        /// <param name="errorIndex">Index to add to.</param>
        /// <param name="product">Product to sync.</param>
        /// <param name="stackHashProduct">StackHash version of the product data.</param>
        /// <param name="getCabs">True - get the cabs associated with the events, false - just get the events.</param>
        private void UpdateFiles(DateTime lastPullDate, IErrorIndex errorIndex, Product product, StackHashProduct stackHashProduct, bool getCabs)
        {
            // Get the files associated with the product.
            ApplicationFileCollection files = product.GetApplicationFiles(ref m_Login);

            foreach (ApplicationFile file in files)
            {
                if (m_AbortRequested)
                {
                    throw new OperationCanceledException("Abort requested during Win Qual synchronize");
                }

                StackHashFile stackHashFile = ObjectConversion.ConvertFile(file);

                m_SyncProgress.FileId = stackHashFile.Id;

                // Check the date the file record was created. If the date created is
                // greater than the last pull date then this is a new file and so add a file
                // record.
                if (file.DateCreatedLocal > lastPullDate)
                {
                    errorIndex.AddFile(stackHashProduct, stackHashFile);
                }
                else if (file.DateModifiedLocal > lastPullDate)
                {
                    // Update the product information if product last modified date is greater than
                    // the last pull date.
                    errorIndex.AddFile(stackHashProduct, stackHashFile);
                }
                else
                {
                    // Check if the file exists. If not then add it.
                    if (!errorIndex.FileExists(stackHashProduct, stackHashFile))
                    {
                        errorIndex.AddFile(stackHashProduct, stackHashFile);
                    }
                }

                UpdateEvents(lastPullDate, errorIndex, stackHashProduct, getCabs, file, stackHashFile);
            }
        }
예제 #2
0
        private void UpdateCabs(DateTime lastPullDate, IErrorIndex errorIndex,
                                StackHashProduct stackHashProduct, Event dpEvent, StackHashFile stackHashFile, StackHashEvent stackHashEvent)
        {
            // Get the cabs for the event.
            CabCollection cabs = dpEvent.GetCabs(ref m_Login);

            // Work out how many cabs should be downloaded.
//            int cabsDownloaded = errorIndex.GetCabCount(stackHashProduct, stackHashFile, stackHashEvent);
//            int maxCabsToDownload = m_ProductsToSynchronize.GetMaxCabs(stackHashProduct.Id);

            // Loop through the cab collection
            foreach (Cab cab in cabs)
            {
                if (m_AbortRequested)
                {
                    throw new OperationCanceledException("Abort requested during Win Qual synchronize");
                }

                // Disabled till beta 5.
//                if (cabsDownloaded >= maxCabsToDownload)
//                    break;

                StackHashCab stackHashCab = ObjectConversion.ConvertCab(cab);

                m_SyncProgress.EventId = stackHashEvent.Id;

                String cabFileName = errorIndex.GetCabFileName(stackHashProduct, stackHashFile, stackHashEvent, stackHashCab);

                // Add the cab if not already in the database.
                if (!errorIndex.CabExists(stackHashProduct, stackHashFile, stackHashEvent, stackHashCab) ||
                    !File.Exists(cabFileName))
                {
                    if (cab.DateModifiedLocal <= lastPullDate)
                    {
                        // This shouldn't happen so log it.
                        DiagnosticsHelper.LogMessage(DiagSeverity.Warning, "Cab date older than last pull date but didn't exist in database - adding anyway: " + cab.ID.ToString(CultureInfo.InvariantCulture));
                    }

                    // Save the cab to a folder.
                    string cabFolder = errorIndex.GetCabFolder(stackHashProduct, stackHashFile,
                                                               stackHashEvent, stackHashCab);

                    if (!Directory.Exists(cabFolder))
                    {
                        Directory.CreateDirectory(cabFolder);
                    }


                    int retryCount = 0;

                    do
                    {
                        cab.SaveCab(cabFolder, false, ref m_Login);

                        retryCount++;

                        if (File.Exists(cabFileName))
                        {
                            FileInfo fileInfo = new FileInfo(cabFileName);

                            if (fileInfo.Length != cab.SizeInBytes)
                            {
                                // File was only partially downloaded so delete it and retry.
                                File.Delete(cabFileName);
                            }
                            else
                            {
                                // All appears ok so add the cab to the database.
                                errorIndex.AddCab(stackHashProduct, stackHashFile, stackHashEvent, stackHashCab, false);

                                // Done.
                                break;
                            }
                        }
                    } while (retryCount < s_TotalCabDownloadRetries);
                }
            }
        }
예제 #3
0
        private void UpdateEvents(DateTime lastPullDate, IErrorIndex errorIndex,
                                  StackHashProduct stackHashProduct, bool getCabs, ApplicationFile file, StackHashFile stackHashFile)
        {
            // Get the events for the file with the start date as last pull date + 1.
            // Only stores the last 90 days worth - this will exception if you specify a date
            // before that time. In the case of the last pulldown date being close to 90 days ago
            // just get ALL the events.
            DateTime        startTime = lastPullDate; // This is a local time.
            EventPageReader eventPageReader;
            TimeSpan        timeSinceLastSync = (DateTime.UtcNow - lastPullDate.ToUniversalTime());

            if (timeSinceLastSync.Days >= 89)
            {
                StackHashUtilities.DiagnosticsHelper.LogMessage(DiagSeverity.Information,
                                                                String.Format(CultureInfo.InvariantCulture, "Updating Events for {0} {1} ALL",
                                                                              stackHashProduct.Name, stackHashFile.Name));

                eventPageReader = file.GetEvents(); // Get all events.
            }
            else
            {
                StackHashUtilities.DiagnosticsHelper.LogMessage(DiagSeverity.Information,
                                                                String.Format(CultureInfo.InvariantCulture, "Updating Events for {0} {1} since {2} {3}",
                                                                              stackHashProduct.Name, stackHashFile.Name, startTime, startTime.Kind));
                eventPageReader = file.GetEvents(startTime);
            }

            // Read each page of new events.
            while (eventPageReader.Read(ref m_Login) == true)
            {
                if (m_AbortRequested)
                {
                    throw new OperationCanceledException("Abort requested during Win Qual synchronize");
                }

                // Get the events for the page.
                EventReader events = eventPageReader.Events;

                while (events.Read() == true)
                {
                    if (m_AbortRequested)
                    {
                        throw new OperationCanceledException("Abort requested during Win Qual synchronize");
                    }

                    // Get the event
                    Event dpEvent = events.Event;

                    StackHashEvent stackHashEvent = ObjectConversion.ConvertEvent(dpEvent, stackHashFile.Id);

                    m_SyncProgress.EventId       = stackHashEvent.Id;
                    m_SyncProgress.EventTypeName = stackHashEvent.EventTypeName;

                    // Check the date created. If it is greater than the last
                    // pull date then this is a new event and hence insert.
                    if (dpEvent.DateCreatedLocal > lastPullDate)
                    {
                        errorIndex.AddEvent(stackHashProduct, stackHashFile, stackHashEvent);
                    }
                    else if (dpEvent.DateModifiedLocal > lastPullDate)
                    {
                        // update the event information if event modified
                        // date is greater than the last pull date
                        errorIndex.AddEvent(stackHashProduct, stackHashFile, stackHashEvent);
                    }
                    else
                    {
                        // Check if the event exists. If not then add it.
                        if (!errorIndex.EventExists(stackHashProduct, stackHashFile, stackHashEvent))
                        {
                            errorIndex.AddEvent(stackHashProduct, stackHashFile, stackHashEvent);
                        }
                    }

                    // Get the details for the event.
                    EventInfoCollection infoCollection = dpEvent.GetEventDetails(ref m_Login);

                    // Loop through the event info.
                    StackHashEventInfo           stackHashEventInfo           = null;
                    StackHashEventInfoCollection stackHashEventInfoCollection = new StackHashEventInfoCollection();
                    foreach (EventInfo info in infoCollection)
                    {
                        if (m_AbortRequested)
                        {
                            throw new OperationCanceledException("Abort requested during Win Qual synchronize");
                        }

                        stackHashEventInfo = ObjectConversion.ConvertEventInfo(info);
                        stackHashEventInfoCollection.Add(stackHashEventInfo);
                    }

                    errorIndex.MergeEventInfoCollection(stackHashProduct, stackHashFile, stackHashEvent, stackHashEventInfoCollection);

                    // Now get the total hits.
                    StackHashEventInfoCollection newEventInfos = errorIndex.LoadEventInfoList(stackHashProduct, stackHashFile, stackHashEvent);

                    int hits = 0;
                    foreach (StackHashEventInfo theEvent in newEventInfos)
                    {
                        hits += theEvent.TotalHits;
                    }

                    // Update the hits count.
                    stackHashEvent.TotalHits = hits;
                    errorIndex.AddEvent(stackHashProduct, stackHashFile, stackHashEvent);

                    if (getCabs)
                    {
                        UpdateCabs(lastPullDate, errorIndex, stackHashProduct, dpEvent, stackHashFile, stackHashEvent);
                    }
                }
            }
        }
예제 #4
0
        private void UpdateProducts(bool forceResynchronize, IErrorIndex errorIndex, ProductCollection products, bool getEvents, bool getCabs)
        {
            // Product -1 is the special product ID that indicates when the last sync of products
            // was complete.
            DateTime lastProductPullDate = errorIndex.GetLastSyncTimeLocal(-1);

            if (forceResynchronize)
            {
                lastProductPullDate = new DateTime(0, DateTimeKind.Local);
            }

            // Add the products first.
            foreach (Product product in products)
            {
                if (m_AbortRequested)
                {
                    throw new OperationCanceledException("Abort requested during Win Qual synchronize");
                }

                m_SyncProgress.ProductId = product.ID;

                StackHashProduct stackHashProduct = ObjectConversion.ConvertProduct(product);

                // Check the date created. If it is greater than the last pull date then
                // this is a new product so add a product record.
                if (product.DateCreatedLocal > lastProductPullDate)
                {
                    errorIndex.AddProduct(stackHashProduct);
                }
                else if (product.DateModifiedLocal > lastProductPullDate)
                {
                    // Update the product information if product last modified date is greater than
                    // the last pull date.
                    errorIndex.AddProduct(stackHashProduct);
                }
                else
                {
                    // Check if the file exists. If not then add it.
                    if (!errorIndex.ProductExists(stackHashProduct))
                    {
                        errorIndex.AddProduct(stackHashProduct);
                    }
                }

                if (getEvents && !isExcludedProduct(stackHashProduct.Id))
                {
                    // Get the last date that this product was synchronized on WinQual.
                    DateTime lastPullDate = errorIndex.GetLastSyncTimeLocal(stackHashProduct.Id);

                    if (forceResynchronize)
                    {
                        lastPullDate = new DateTime(0, DateTimeKind.Local);
                    }

                    UpdateFiles(lastPullDate, errorIndex, product, stackHashProduct, getCabs);

                    if (getCabs)
                    {
                        onProgress(WinQualProgressType.ProductCabsUpdated, stackHashProduct);
                    }
                    else
                    {
                        onProgress(WinQualProgressType.ProductEventsUpdated, stackHashProduct);
                    }

                    if (getCabs)
                    {
                        // Completed getting all events and cabs for this product.
                        errorIndex.SetLastSyncTimeLocal(stackHashProduct.Id, DateTime.Now);
                    }
                }
            }

            errorIndex.SetLastSyncTimeLocal(-1, DateTime.Now);
        }