public void Run(Action <List <BSONMention> > cacheFullCallback) { List <BSONMention> cache = new List <BSONMention>(); Stopwatch sw = new Stopwatch(); //Console.WriteLine("Starting generation of " + this.TotalItems.ToString() + " items..."); sw.Start(); for (int i = 0; i < TotalItems; i++) { var date = BeforeTodaySource.Next(); string guidValue; if (Guids != null && NextRand(0, 101) < GuidReusePercentage) { guidValue = Guids[NextRand(0, Guids.Length)].ToString(); } else { guidValue = GetRandomMd5Hash(); } var newItem = new BSONMention { Sentiment = NextRand(-100, 101), Influence = NextRand(0, 101), Name = ShortTextSource.Next(), Description = null,//TextSource.Next(), OccurredOnTicks = date.Ticks, Guid = guidValue }; newItem.CreatedOnTicks = new DateTime(newItem.OccurredOnTicks).AddDays(rand.Next(0, 5)).AddHours(NextRand(0, 10)).AddMinutes(NextRand(0, 60)).Ticks; int numTags = NextRand(0, 10); newItem.Tags = new List <int>(); for (int j = 0; j < numTags; ++j) { var targetTag = Tags[NextRand(0, Tags.Length)]; newItem.Tags.Add(targetTag.Id); } cache.Add(newItem); if ((i + 1) % (CacheSize) == 0 && i > 0) { cacheFullCallback.Invoke(cache); cache.Clear(); } } sw.Stop(); //Console.WriteLine("Finished generation in: " + sw.Elapsed.ToString()); }
public void Run(Action<List<BSONMention>> cacheFullCallback) { List<BSONMention> cache = new List<BSONMention>(); Stopwatch sw = new Stopwatch(); //Console.WriteLine("Starting generation of " + this.TotalItems.ToString() + " items..."); sw.Start(); for (int i = 0; i < TotalItems; i++) { var date = BeforeTodaySource.Next(); string guidValue; if (Guids != null && NextRand(0, 101) < GuidReusePercentage) guidValue = Guids[NextRand(0, Guids.Length)].ToString(); else guidValue = GetRandomMd5Hash(); var newItem = new BSONMention { Sentiment = NextRand(-100, 101), Influence = NextRand(0, 101), Name = ShortTextSource.Next(), Description = null,//TextSource.Next(), OccurredOnTicks = date.Ticks, Guid = guidValue }; newItem.CreatedOnTicks = new DateTime(newItem.OccurredOnTicks).AddDays(rand.Next(0, 5)).AddHours(NextRand(0, 10)).AddMinutes(NextRand(0, 60)).Ticks; int numTags = NextRand(0, 10); newItem.Tags = new List<int>(); for (int j = 0; j < numTags; ++j) { var targetTag = Tags[NextRand(0, Tags.Length)]; newItem.Tags.Add(targetTag.Id); } cache.Add(newItem); if ((i + 1) % (CacheSize) == 0 && i > 0) { cacheFullCallback.Invoke(cache); cache.Clear(); } } sw.Stop(); //Console.WriteLine("Finished generation in: " + sw.Elapsed.ToString()); }