Example #1
0
        public static StackHashEventCollection GetEventsApi(ref Login login, ApplicationFile file, out List <Event> rawEvents, DateTime startTime)
        {
            EventPageReader          eventPageReader    = file.GetEvents(startTime); // Get all events.
            StackHashEventCollection apiStackHashEvents = new StackHashEventCollection();

            rawEvents = new List <Event>();

            // Read each page of new events.
            while (eventPageReader.Read(ref login) == true)
            {
                // Get the events for the page.
                EventReader events = eventPageReader.Events;

                while (events.Read() == true)
                {
                    // Get the event
                    Event dpEvent = events.Event;
                    rawEvents.Add(dpEvent);
                    StackHashEvent stackHashEvent = ObjectConversion.ConvertEvent(dpEvent, file.ID);


                    apiStackHashEvents.Add(stackHashEvent);
                }
            }
            return(apiStackHashEvents);
        }
Example #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);
                    }
                }
            }
        }