Exemplo n.º 1
0
        public void PopulateEvent(Event ev) {
            if (MinDate.HasValue || MaxDate.HasValue)
                ev.Date = RandomData.GetDateTime(MinDate ?? DateTime.MinValue, MaxDate ?? DateTime.MaxValue);

            ev.Type = EventTypes.Random();
            if (ev.Type == Event.KnownTypes.FeatureUsage)
                ev.Source = FeatureNames.Random();
            else if (ev.Type == Event.KnownTypes.NotFound)
                ev.Source = PageNames.Random();
            else if (ev.Type == Event.KnownTypes.Log) {
                ev.Source = LogSources.Random();
                ev.Message = RandomData.GetString();

                string level = LogLevels.Random();
                if (!String.IsNullOrEmpty(level))
                    ev.Data[Event.KnownDataKeys.Level] = level;
            }

            if (RandomData.GetBool(80))
                ev.Geo = RandomData.GetCoordinate();

            if (RandomData.GetBool(20))
                ev.Value = RandomData.GetDecimal();

            ev.SetUserIdentity(Identities.Random());
            ev.SetVersion(RandomData.GetVersion("2.0", "4.0"));

            ev.AddRequestInfo(new RequestInfo {
                //ClientIpAddress = ClientIpAddresses.Random(),
                Path = PageNames.Random()
            });

            ev.Data.Add(Event.KnownDataKeys.EnvironmentInfo, new EnvironmentInfo {
                IpAddress = MachineIpAddresses.Random() + ", " + MachineIpAddresses.Random(),
                MachineName = MachineNames.Random()
            });

            for (int i = 0; i < RandomData.GetInt(1, 3); i++) {
                string key = RandomData.GetWord();
                while (ev.Data.ContainsKey(key) || key == Event.KnownDataKeys.Error)
                    key = RandomData.GetWord();

                ev.Data.Add(key, RandomData.GetString());
            }

            int tagCount = RandomData.GetInt(1, 3);
            for (int i = 0; i < tagCount; i++) {
                string tag = EventTags.Random();
                if (!ev.Tags.Contains(tag))
                    ev.Tags.Add(tag);
            }

            if (ev.Type == Event.KnownTypes.Error) {
                if (RandomData.GetBool()) {
                    // limit error variation so that stacking will occur
                    if (_randomErrors == null)
                        _randomErrors = new List<Error>(Enumerable.Range(1, 25).Select(i => GenerateError()));

                    ev.Data[Event.KnownDataKeys.Error] = _randomErrors.Random();
                } else {
                    // limit error variation so that stacking will occur
                    if (_randomSimpleErrors == null)
                        _randomSimpleErrors = new List<SimpleError>(Enumerable.Range(1, 25).Select(i => GenerateSimpleError()));

                    ev.Data[Event.KnownDataKeys.SimpleError] = _randomSimpleErrors.Random();
                }
            }
        }
Exemplo n.º 2
0
 protected bool Equals(Event other)
 {
     return string.Equals(Type, other.Type) && string.Equals(Source, other.Source) && Tags.CollectionEquals(other.Tags) && string.Equals(Message, other.Message) && string.Equals(Geo, other.Geo) && Value == other.Value && Equals(Data, other.Data);
 }
Exemplo n.º 3
0
 public Event Generate() {
     var ev = new Event();
     PopulateEvent(ev);
     return ev;
 }