Esempio n. 1
0
        /// <summary>
        /// Copies the specified event packages to the destination index along with any other event information, such as
        /// event and cab notes from the source index.
        /// </summary>
        /// <param name="product">Product owning the file.</param>
        /// <param name="file">File owning the events.</param>
        /// <param name="eventPackages">Events to copy.</param>
        private void copyEventBlock(StackHashProduct product, StackHashFile file, StackHashEventPackageCollection eventPackages)
        {
            foreach (StackHashEventPackage eventPackage in eventPackages)
            {
                if (this.CurrentTaskState.AbortRequested)
                {
                    throw new StackHashException("Index event copy aborted", StackHashServiceErrorCode.Aborted);
                }

                // Only add the event if it doesn't already exist in the destination index.
                if (!m_DestinationIndex.EventExists(product, file, eventPackage.EventData))
                {
                    m_DestinationIndex.AddEvent(product, file, eventPackage.EventData);
                }

                // Only normalize when copying from an XML index. Normalizing the event infos sets the dates to midnight PST.
                // The old XML index had - non-normalized dates.
                if (m_SourceIndex.IndexType == ErrorIndexType.Xml)
                {
                    eventPackage.EventInfoList = eventPackage.EventInfoList.Normalize();
                }

                // This call will only add new event infos. Duplicates will be discarded.
                m_DestinationIndex.AddEventInfoCollection(product, file, eventPackage.EventData, eventPackage.EventInfoList);

                // Copy the cabs for the event package.
                foreach (StackHashCabPackage cab in eventPackage.Cabs)
                {
                    if (this.CurrentTaskState.AbortRequested)
                    {
                        throw new StackHashException("Index cab copy aborted", StackHashServiceErrorCode.Aborted);
                    }

                    // Only add the cab if it doesn't already exist.
                    if (!m_DestinationIndex.CabExists(product, file, eventPackage.EventData, cab.Cab))
                    {
                        m_DestinationIndex.AddCab(product, file, eventPackage.EventData, cab.Cab, true);
                    }

                    // Get the cab notes. This call will retrieve them in the order they were added so no need to sort.
                    StackHashNotes cabNotes     = m_SourceIndex.GetCabNotes(product, file, eventPackage.EventData, cab.Cab);
                    StackHashNotes destCabNotes = m_DestinationIndex.GetCabNotes(product, file, eventPackage.EventData, cab.Cab);

                    foreach (StackHashNoteEntry note in cabNotes)
                    {
                        if (this.CurrentTaskState.AbortRequested)
                        {
                            throw new StackHashException("Index cab note copy aborted", StackHashServiceErrorCode.Aborted);
                        }

                        // Only add the note if it hasn't already been added to the destination index.
                        // This could have happened if the same event is associated with more than 1 file or product.
                        if (!destCabNotes.ContainsNote(note))
                        {
                            // Set the note id to 0 so a new one will be allocated.
                            note.NoteId = 0;
                            m_DestinationIndex.AddCabNote(product, file, eventPackage.EventData, cab.Cab, note);
                        }
                    }

                    // Copy the cab files over.
                    copyCabFiles(m_SourceIndex, m_DestinationIndex, product, file, eventPackage, cab.Cab);
                }

                // Copy the cab notes for this event.
                StackHashNotes eventNotes     = m_SourceIndex.GetEventNotes(product, file, eventPackage.EventData);
                StackHashNotes destEventNotes = m_DestinationIndex.GetEventNotes(product, file, eventPackage.EventData);

                foreach (StackHashNoteEntry note in eventNotes)
                {
                    if (this.CurrentTaskState.AbortRequested)
                    {
                        throw new StackHashException("Index event note copy aborted", StackHashServiceErrorCode.Aborted);
                    }

                    // Only add the note if it hasn't already been added to the destination index.
                    if (!destEventNotes.ContainsNote(note))
                    {
                        // Set the note id to 0 so a new one will be added (and not replace an existing one).
                        note.NoteId = 0;
                        m_DestinationIndex.AddEventNote(product, file, eventPackage.EventData, note);
                    }
                }

                // Report progress to clients. Progress is reported after each event but only for integral % completions.
                // Therefore this call won't actually send an event to the client every time.
                m_CurrentEvent++;
                reportProgress(m_CurrentEvent, m_TotalEvents, eventPackage.EventData.Id);
            }
        }
Esempio n. 2
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);
                    }
                }
            }
        }