Beispiel #1
0
    public void Invoke <T0, T1, T2, T3, T4, T5, T6, T7>(uint type, uint id, uint target, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, bool all = false)
    {
        EventIndex index = new EventIndex(type, id);

        if (all == false)
        {
            if (mEventID.TryGetValue(index, out List <EventID> list))
            {
                for (int i = 0; i < list.Count; ++i)
                {
                    if (mListeners.TryGetValue(list[i], out EventListener listener))
                    {
                        listener?.Invoke(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
                    }
                }
            }
        }
        else
        {
            EventID eventID = new EventID(index, target);
            if (mListeners.TryGetValue(eventID, out EventListener listener))
            {
                listener?.Invoke(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
            }
        }
    }
Beispiel #2
0
    public void AddListener <T0, T1, T2, T3, T4, T5, T6, T7>(uint type, uint id, uint target, Action <T0, T1, T2, T3, T4, T5, T6, T7> call)
    {
        if (call == null)
        {
            return;
        }
        EventIndex index   = new EventIndex(type, id);
        EventID    eventID = new EventID(index, target);

        if (mEventID.TryGetValue(index, out List <EventID> list) == false)
        {
            list = new List <EventID>();
            mEventID.Add(index, list);
        }
        if (list.Contains(eventID) == false)
        {
            list.Add(eventID);
        }
        if (mListeners.TryGetValue(eventID, out EventListener listener) == false)
        {
            listener = new EventListener();
            mListeners.Add(eventID, listener);
        }
        listener.AddListener(call);
    }
Beispiel #3
0
    public void Invoke <T0, T1>(uint type, uint id, uint target, T0 arg0, T1 arg1, bool all = false)
    {
        EventIndex index = new EventIndex(type, id);

        if (all == false)
        {
            if (mEventID.TryGetValue(index, out List <EventID> list))
            {
                for (int i = 0; i < list.Count; ++i)
                {
                    if (mListeners.TryGetValue(list[i], out EventListener listener))
                    {
                        listener?.Invoke(arg0, arg1);
                    }
                }
            }
        }
        else
        {
            EventID eventID = new EventID(index, target);
            if (mListeners.TryGetValue(eventID, out EventListener listener))
            {
                listener?.Invoke(arg0, arg1);
            }
        }
    }
Beispiel #4
0
    public void Clear(uint type, uint id, uint target, bool all = false)
    {
        EventIndex index = new EventIndex(type, id);

        if (all)
        {
            if (mEventID.TryGetValue(index, out List <EventID> list))
            {
                for (int i = 0; i < list.Count; ++i)
                {
                    if (mListeners.TryGetValue(list[i], out EventListener listener))
                    {
                        listener.Clear();
                    }
                    mListeners.Remove(list[i]);
                }
                mEventID.Remove(index);
            }
        }
        else
        {
            EventID eventID = new EventID(index, target);
            if (mListeners.TryGetValue(eventID, out EventListener listener))
            {
                listener.Clear();
            }
            mListeners.Remove(eventID);
        }
    }
Beispiel #5
0
 public EventStats(IElasticClient elasticClient, EventIndex eventIndex, QueryBuilderRegistry queryBuilder, ILogger <EventStats> logger)
 {
     _elasticClient = elasticClient;
     _eventIndex    = eventIndex;
     _queryBuilder  = queryBuilder;
     _logger        = logger;
 }
Beispiel #6
0
        public EventRepository(ElasticRepositoryContext <PersistentEvent> context, EventIndex index) : base(context, index)
        {
            DisableCache();
            BatchNotifications = true;

            GetDocumentIdFunc    = GetDocumentId;
            GetDocumentIndexFunc = GetDocumentIndex;
        }
        /// <summary>Returns a string that represents the current object.</summary>
        /// <returns>A string that represents the current object.</returns>
        public override string ToString()
        {
            var segments = new[]
            {
                ParentItemHash,
                ((byte)WeekType).ToString(),
                ((byte)WeekDay).ToString(),
                EventIndex.ToString(),
                Place
            };

            return(string.Join(':', segments));
        }
Beispiel #8
0
        internal int CompareTo(EventIndex index)
        {
            int dateTimeCompareResult = this.Timestamp.CompareTo(index.Timestamp);

            if (dateTimeCompareResult != 0)
            {
                return(dateTimeCompareResult);
            }

            if (this.TimestampDifferentiator < index.TimestampDifferentiator)
            {
                return(-1);
            }
            else if (this.TimestampDifferentiator == index.TimestampDifferentiator)
            {
                return(0);
            }
            else
            {
                return(1);
            }
        }
Beispiel #9
0
    public ExceptionlessElasticConfiguration(
        AppOptions appOptions,
        IQueue <WorkItemData> workItemQueue,
        JsonSerializerSettings serializerSettings,
        ICacheClient cacheClient,
        IMessageBus messageBus,
        IServiceProvider serviceProvider,
        ILoggerFactory loggerFactory
        ) : base(workItemQueue, cacheClient, messageBus, loggerFactory)
    {
        _appOptions         = appOptions;
        _serializerSettings = serializerSettings;

        _logger.LogInformation("All new indexes will be created with {ElasticsearchNumberOfShards} Shards and {ElasticsearchNumberOfReplicas} Replicas", _appOptions.ElasticsearchOptions.NumberOfShards, _appOptions.ElasticsearchOptions.NumberOfReplicas);
        AddIndex(Stacks        = new StackIndex(this));
        AddIndex(Events        = new EventIndex(this, serviceProvider, appOptions));
        AddIndex(Migrations    = new MigrationIndex(this, _appOptions.ElasticsearchOptions.ScopePrefix + "migrations", appOptions.ElasticsearchOptions.NumberOfReplicas));
        AddIndex(Organizations = new OrganizationIndex(this));
        AddIndex(Projects      = new ProjectIndex(this));
        AddIndex(Tokens        = new TokenIndex(this));
        AddIndex(Users         = new UserIndex(this));
        AddIndex(WebHooks      = new WebHookIndex(this));
    }
 public ActionResult Home(Guid id)
 {
     EventIndex eventInfo = new EventIndex();
     eventInfo.eventInfo = db.tblEvent.Find(id);
     eventInfo.eventParticipants = db.tblUserEvents.Where(e => e.tblEvent.GUID == id && !e.tblUser.tblRol.Name.Equals("Manager")).ToList();
     return View(eventInfo);
 }
Beispiel #11
0
        private static string CreateDestinationFileName(string etlFileName, string additionalSuffix, bool isActiveEtl, EventIndex lastEventIndexProcessed)
        {
            string differentiator = string.Format(
                CultureInfo.InvariantCulture,
                "{0:D10}",
                isActiveEtl ? lastEventIndexProcessed.TimestampDifferentiator : int.MaxValue);

            string traceFileNamePrefix = string.Format(
                CultureInfo.InvariantCulture,
                "{0}_{1}_{2:D20}_{3}{4}.",
                TestNodeId,
                Path.GetFileNameWithoutExtension(etlFileName),
                lastEventIndexProcessed.Timestamp.Ticks,
                differentiator,
                additionalSuffix);

            return(string.Concat(
                       traceFileNamePrefix,
                       EtlConsumerConstants.FilteredEtwTraceFileExtension));
        }
Beispiel #12
0
        private static IDcaInMemoryConsumer CreateEtlToInMemoryBufferWriter(string logDirectory, bool?slow)
        {
            EventIndex globalLastEventIndexProcessed = default(EventIndex);

            globalLastEventIndexProcessed.Set(DateTime.MinValue, -1);
            InternalFileSink fileSink = new InternalFileSink(Utility.TraceSource, LogSourceId);
            EventIndex       lastEventIndexProcessed = default(EventIndex);

            var onProcessingPeriodStartActionForFastWriter = new Action <string, bool, string>((traceFileName, isActiveEtl, traceFileSubFolder) =>
            {
                fileSink.Initialize();
                lastEventIndexProcessed.Set(DateTime.MinValue, -1);
            });

            var maxIndexAlreadyProcessedForFastWriter = new Func <string, EventIndex>((traceFileSubFolder) =>
            {
                return(globalLastEventIndexProcessed);
            });

            var consumerProcessTraceEventActionForFastWriter = new Action <DecodedEventWrapper, string>((decodedEventWrapper, traceFileSubFolder) =>
            {
                string etwEvent = decodedEventWrapper.StringRepresentation.Replace("\r\n", "\r\t").Replace("\n", "\t");
                fileSink.WriteEvent(etwEvent);
                lastEventIndexProcessed.Set(decodedEventWrapper.Timestamp, decodedEventWrapper.TimestampDifferentiator);
            });

            var onProcessingPeriodStopActionForFastWriter = new Action <string, bool, string>((traceFileName, isActiveEtl, traceFileSubFolder) =>
            {
                if (slow.HasValue && slow.Value)
                {
                    Thread.Sleep(2000);
                }

                fileSink.Close();
                if (fileSink.WriteStatistics.EventsWritten > 0)
                {
                    var additionalSuffix = (slow.HasValue) ? (slow.Value ? "_slow" : "_fast") : (string.Empty);
                    var destFileName     = CreateDestinationFileName(traceFileName, additionalSuffix, isActiveEtl, lastEventIndexProcessed);
                    File.Move(fileSink.TempFileName, Path.Combine(logDirectory, "output", destFileName));
                    globalLastEventIndexProcessed.Set(lastEventIndexProcessed.Timestamp, lastEventIndexProcessed.TimestampDifferentiator);
                }
                else
                {
                    fileSink.Delete();
                }
            });

            var dcaInMemoryConsumer = TestUtility.MockRepository.Create <IDcaInMemoryConsumer>();

            dcaInMemoryConsumer.Setup(c => c.ConsumerProcessTraceEventAction)
            .Returns(consumerProcessTraceEventActionForFastWriter);

            dcaInMemoryConsumer.Setup(c => c.MaxIndexAlreadyProcessed)
            .Returns(maxIndexAlreadyProcessedForFastWriter);

            dcaInMemoryConsumer.Setup(c => c.OnProcessingPeriodStart(It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <string>()))
            .Callback((string traceFileName, bool isActiveEtl, string traceFileSubFolder) => onProcessingPeriodStartActionForFastWriter(traceFileName, isActiveEtl, traceFileSubFolder));

            dcaInMemoryConsumer.Setup(c => c.OnProcessingPeriodStop(It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <string>()))
            .Callback((string traceFileName, bool isActiveEtl, string traceFileSubFolder) => onProcessingPeriodStopActionForFastWriter(traceFileName, isActiveEtl, traceFileSubFolder));

            return(dcaInMemoryConsumer.Object);
        }
Beispiel #13
0
        /// <summary>
        /// Updates the bookmark file with the last event read index.
        /// </summary>
        /// <param name="bookmarkFolder"></param>
        /// <param name="lastReadEventIndexPosition"></param>
        /// <param name="eventIndex"></param>
        /// <param name="bytesWritten"></param>
        /// <returns></returns>
        internal bool UpdateBookmarkFile(
            string bookmarkFolder,
            long lastReadEventIndexPosition,
            EventIndex eventIndex,
            out long bytesWritten)
        {
            bytesWritten = 0;
            FileStream   fs           = null;
            StreamWriter writer       = null;
            string       bookmarkFile = Path.Combine(bookmarkFolder, BookmarkFileName);

            if (false == FabricFile.Exists(bookmarkFile))
            {
                return(false);
            }

            try
            {
                // Open the bookmark file
                try
                {
                    Utility.PerformIOWithRetries(
                        () =>
                    {
                        fs     = new FileStream(bookmarkFile, FileMode.Open);
                        writer = new StreamWriter(fs);
                    },
                        this.methodExecutionInitialRetryIntervalMs,
                        this.methodExecutionMaxRetryCount,
                        this.methodExecutionMaxRetryIntervalMs);
                }
                catch (Exception e)
                {
                    this.traceSource.WriteExceptionAsError(
                        this.logSourceId,
                        e,
                        "Unable to open bookmark file {0} while processing events.",
                        bookmarkFile);
                    return(false);
                }

                // Move the stream position to the point where the event index needs to be written
                fs.Position = lastReadEventIndexPosition;

                long localBytesWritten = 0;

                // Write the timestamp and index of the last event read and close the file
                string lastEventReadString = string.Format("{0},{1},{2}", eventIndex.Timestamp.ToBinary(), eventIndex.Timestamp.ToString(), eventIndex.TimestampDifferentiator);
                try
                {
                    Utility.PerformIOWithRetries(
                        () =>
                    {
                        writer.WriteLine(lastEventReadString);
                        localBytesWritten = lastEventReadString.Length + 2;
                        writer.Dispose();
                        fs.Dispose();
                    },
                        this.methodExecutionInitialRetryIntervalMs,
                        this.methodExecutionMaxRetryCount,
                        this.methodExecutionMaxRetryIntervalMs);
                }
                catch (Exception e)
                {
                    this.traceSource.WriteExceptionAsError(
                        this.logSourceId,
                        e,
                        "Unable to write last event read {0} in bookmark file {1} while processing events.",
                        lastEventReadString,
                        bookmarkFile);
                    return(false);
                }

                // record bytes written
                bytesWritten = localBytesWritten;
            }
            finally
            {
                if (null != writer)
                {
                    writer.Dispose();
                }

                if (null != fs)
                {
                    fs.Dispose();
                }
            }

            return(true);
        }
 public EventRepository(IElasticClient elasticClient, EventIndex index, IValidator <PersistentEvent> validator = null, IMessagePublisher messagePublisher = null)
     : base(elasticClient, index, validator, null, messagePublisher)
 {
     EnableCache        = false;
     BatchNotifications = true;
 }
Beispiel #15
0
        /// <inheritdoc />
        public virtual SummaryIndexBase[] ConvertEventsToSummaryIndices(IEnumerable <EventBase> events, TimeSpan unitTime, TimeSpan duration, double scoreThreshold)
        {
            if (duration == TimeSpan.Zero)
            {
                return(null);
            }

            double units = duration.TotalSeconds / unitTime.TotalSeconds;

            // get whole minutes
            int unitCount = (int)(units / 1);

            // add fractional minute
            if (units % 1 > 0.0)
            {
                unitCount += 1;
            }

            // to store event counts
            var eventsPerUnitTime = new int[unitCount];

            // to store counts of high scoring events
            var bigEvsPerUnitTime = new int[unitCount];

            foreach (var anEvent in events)
            {
                // note: absolute determines what value is used
                // EventStartSeconds (relative to ~~segment~~, 2017-09: RELATIVE TO RECORDING)
                // StartOffset (relative to recording)
                double eventStart = anEvent.EventStartSeconds;
                double eventScore = anEvent.Score;
                var    timeUnit   = (int)(eventStart / unitTime.TotalSeconds);

                // NOTE: eventScore filter replaced with greater then as opposed to not equal to
                if (eventScore >= 0.0)
                {
                    eventsPerUnitTime[timeUnit]++;
                }

                if (eventScore > scoreThreshold)
                {
                    bigEvsPerUnitTime[timeUnit]++;
                }
            }

            var indices = new SummaryIndexBase[eventsPerUnitTime.Length];

            for (int i = 0; i < eventsPerUnitTime.Length; i++)
            {
                var newIndex = new EventIndex
                {
                    ResultStartSeconds     = unitTime.Multiply(i).TotalSeconds,
                    EventsTotal            = eventsPerUnitTime[i],
                    EventsTotalThresholded = bigEvsPerUnitTime[i],
                    SegmentDurationSeconds = unitTime.TotalSeconds,
                };

                indices[i] = newIndex;
            }

            return(indices);
        }
 ShippingEvent GetShippingEvent(EventIndex eventIdx) => GetValueFromStorageMap <ShippingEvent>("ProductTracking", "AllEvents", eventIdx);
Beispiel #17
0
 public EventID(uint eventType, uint eventId, uint eventTarget)
 {
     index  = new EventIndex(eventType, eventId);
     target = eventTarget;
 }
Beispiel #18
0
        /// <summary>
        /// Retrieves the last event index processed.
        /// </summary>
        /// <param name="bookmarkFolder"></param>
        /// <param name="bytesRead"></param>
        /// <returns></returns>
        internal EventIndex ReadBookmarkFile(
            string bookmarkFolder,
            out long bytesRead)
        {
            bytesRead = 0;
            EventIndex lastEventIndex = new EventIndex();

            lastEventIndex.Set(DateTime.MinValue, -1);

            string bookmarkFile = Path.Combine(bookmarkFolder, BookmarkFileName);

            if (false == FabricFile.Exists(bookmarkFile))
            {
                // Bookmark file doesn't exist
                return(lastEventIndex);
            }

            StreamReader reader = null;

            try
            {
                // Open the file
                try
                {
                    Utility.PerformIOWithRetries(
                        () =>
                    {
                        FileStream fileStream = FabricFile.Open(bookmarkFile, FileMode.Open, FileAccess.Read);
                        Helpers.SetIoPriorityHint(fileStream.SafeFileHandle, Kernel32Types.PRIORITY_HINT.IoPriorityHintVeryLow);
                        reader = new StreamReader(fileStream);
                    },
                        this.methodExecutionInitialRetryIntervalMs,
                        this.methodExecutionMaxRetryCount,
                        this.methodExecutionMaxRetryIntervalMs);
                }
                catch (Exception e)
                {
                    this.traceSource.WriteExceptionAsError(
                        this.logSourceId,
                        e,
                        "Unable to open bookmark file {0}.",
                        bookmarkFile);
                    return(lastEventIndex);
                }

                long localBytesRead = 0;

                // Get the version
                string versionString = string.Empty;
                try
                {
                    Utility.PerformIOWithRetries(
                        () =>
                    {
                        versionString   = reader.ReadLine();
                        localBytesRead += versionString.Length + 2;
                    },
                        this.methodExecutionInitialRetryIntervalMs,
                        this.methodExecutionMaxRetryCount,
                        this.methodExecutionMaxRetryIntervalMs);
                }
                catch (Exception e)
                {
                    this.traceSource.WriteExceptionAsError(
                        this.logSourceId,
                        e,
                        "Unable to read version information from bookmark file {0}.",
                        bookmarkFile);
                    return(lastEventIndex);
                }

                // Check the version
                if (false == versionString.Equals(BookmarkFileFormatVersionString, StringComparison.Ordinal))
                {
                    this.traceSource.WriteError(
                        this.logSourceId,
                        "Unexpected version string {0} encountered in bookmark file {1}.",
                        versionString,
                        bookmarkFile);
                    return(lastEventIndex);
                }

                // Get information about the last event that we read
                string infoLine = string.Empty;
                try
                {
                    Utility.PerformIOWithRetries(
                        () =>
                    {
                        infoLine        = reader.ReadLine();
                        localBytesRead += infoLine.Length + 2;
                    },
                        this.methodExecutionInitialRetryIntervalMs,
                        this.methodExecutionMaxRetryCount,
                        this.methodExecutionMaxRetryIntervalMs);
                }
                catch (Exception e)
                {
                    this.traceSource.WriteExceptionAsError(
                        this.logSourceId,
                        e,
                        "Unable to read information about last event read from bookmark file {0}.",
                        bookmarkFile);
                    return(lastEventIndex);
                }

                string[] infoLineParts = infoLine.Split(',');
                if (infoLineParts.Length != (int)LastEventReadInfoParts.Count)
                {
                    this.traceSource.WriteError(
                        this.logSourceId,
                        "The information in bookmark file {0} about the last event read is not in the expected format. {1}",
                        bookmarkFile,
                        infoLine);
                    return(lastEventIndex);
                }

                string lastEventTimestampString = infoLineParts[(int)LastEventReadInfoParts.LastEventTimestampLong].Trim();
                long   lastEventTimestampBinary;
                if (false == long.TryParse(lastEventTimestampString, out lastEventTimestampBinary))
                {
                    this.traceSource.WriteError(
                        this.logSourceId,
                        "Unable to retrieve timestamp of last event from bookmark file {0}.",
                        bookmarkFile);
                    return(lastEventIndex);
                }

                DateTime lastEventTimestamp = DateTime.FromBinary(lastEventTimestampBinary);

                string lastEventTimestampDifferentiatorString = infoLineParts[(int)LastEventReadInfoParts.LastEventIndex].Trim();
                int    lastEventTimestampDifferentiator;
                if (false == int.TryParse(lastEventTimestampDifferentiatorString, out lastEventTimestampDifferentiator))
                {
                    this.traceSource.WriteError(
                        this.logSourceId,
                        "Unable to retrieve timestamp differentiator of last event from bookmark file {0}.",
                        bookmarkFile);
                    return(lastEventIndex);
                }

                // record bytes read
                bytesRead = localBytesRead;

                lastEventIndex.Set(lastEventTimestamp, lastEventTimestampDifferentiator);
            }
            finally
            {
                if (null != reader)
                {
                    reader.Dispose();
                }
            }

            return(lastEventIndex);
        }
Beispiel #19
0
 public EventID(EventIndex eventIndex, uint eventTarget)
 {
     index  = eventIndex;
     target = eventTarget;
 }
Beispiel #20
0
 public EventStats(IElasticClient elasticClient, EventIndex eventIndex)
 {
     _elasticClient = elasticClient;
     _eventIndex    = eventIndex;
 }
 public EventUID(EventIndex eventId, double time)
 {
     EventId = eventId;
     Time    = time;
 }