private Event CreateSimpleEvent() { var ev = new Event { Date = DateTime.Now, Message = "Testing", Type = Event.KnownTypes.Log, Source = "StorageSerializer" }; if (RandomData.GetBool(80)) { ev.Geo = RandomData.GetCoordinate(); } if (RandomData.GetBool(20)) { ev.Value = RandomData.GetDecimal(); } if (RandomData.GetBool(20)) { ev.Count = RandomData.GetInt(); } if (RandomData.GetBool(80)) { ev.ReferenceId = RandomData.GetAlphaNumericString(0, 10); } return(ev); }
public static Employee Generate(string id = null, string name = null, int?age = null, int?yearsEmployed = null, string companyName = null, string companyId = null, DateTime?createdUtc = null, DateTime?updatedUtc = null) { return(new Employee { Id = id, Name = name, Age = age ?? RandomData.GetInt(18, 100), YearsEmployed = yearsEmployed ?? RandomData.GetInt(0, 1), CompanyName = companyName, CompanyId = companyId ?? ObjectId.GenerateNewId().ToString(), CreatedUtc = createdUtc.GetValueOrDefault(), UpdatedUtc = updatedUtc.GetValueOrDefault(), Location = RandomData.GetCoordinate() }); }
public static Employee GenerateRandom(string id = null, string name = null, int?age = null, int?yearsEmployed = null, string companyName = null, string companyId = null, string location = null, DateTime?lastReview = null, DateTimeOffset?nextReview = null, DateTime?createdUtc = null, DateTime?updatedUtc = null) { var employee = new Employee { Id = id, Name = name ?? RandomData.GetAlphaString(), Age = age ?? RandomData.GetInt(18, 100), YearsEmployed = yearsEmployed ?? RandomData.GetInt(0, 40), CompanyName = companyName ?? RandomData.GetAlphaString(), CompanyId = companyId ?? ObjectId.GenerateNewId().ToString(), LastReview = lastReview ?? RandomData.GetDateTime(DateTime.Now.SubtractDays(365), DateTime.Now), CreatedUtc = createdUtc ?? RandomData.GetDateTime(DateTime.Now.SubtractDays(365), DateTime.Now), Location = location ?? RandomData.GetCoordinate() }; employee.NextReview = nextReview ?? RandomData.GetDateTimeOffset(employee.NextReview, DateTime.Now); employee.UpdatedUtc = updatedUtc ?? RandomData.GetDateTime(employee.CreatedUtc, DateTime.Now); return(employee); }
public void PopulateEvent(Event ev, bool setUserIdentity = true) { 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); } if (setUserIdentity) { 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(); } } }