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

            ev.Type = new [] { Event.KnownTypes.Error, Event.KnownTypes.FeatureUsage, Event.KnownTypes.Log, Event.KnownTypes.NotFound }.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.GetInt(0, 10000);
            }

            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();
                }
            }
        }
Esempio n. 2
0
        private static void SendEvent(bool writeToConsole = true)
        {
            var ev = new Event();

            if (_dateSpans[_dateSpanIndex] != TimeSpan.Zero)
            {
                ev.Date = RandomHelper.GetDateTime(DateTime.Now.Subtract(_dateSpans[_dateSpanIndex]), DateTime.Now);
            }

            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 = RandomHelper.GetPronouncableString(RandomHelper.GetRange(5, 15));
            }

            ev.SetUserIdentity(Identities.Random());

            for (int i = 0; i < RandomHelper.GetRange(1, 5); i++)
            {
                string key = RandomHelper.GetPronouncableString(RandomHelper.GetRange(5, 10));
                while (ev.Data.ContainsKey(key) || key == Event.KnownDataKeys.Error)
                {
                    key = RandomHelper.GetPronouncableString(RandomHelper.GetRange(5, 15));
                }

                ev.Data.Add(key, RandomHelper.GetPronouncableString(RandomHelper.GetRange(5, 25)));
            }

            int tagCount = RandomHelper.GetRange(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)
            {
                // 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();
            }

            // use server settings to see if we should include this data
            if (ExceptionlessClient.Default.Configuration.Settings.GetBoolean("IncludeConditionalData", true))
            {
                ev.AddObject(new { Total = 32.34, ItemCount = 2, Email = "*****@*****.**" }, "Conditional Data");
            }

            //ev.AddRecentTraceLogEntries();

            ExceptionlessClient.Default.SubmitEvent(ev);

            if (writeToConsole)
            {
                Console.SetCursorPosition(0, OPTIONS_MENU_LINE_COUNT + 2);
                Console.WriteLine("Sent 1 event.");
                Trace.WriteLine("Sent 1 event.");

                ClearNonOptionsLines();
            }
        }