public Register ( string deviceModel, PlatformType platformType, string carrier, string platformOS, int timeZoneOffset, string locale, string manufac, int>.Tuple |
||
deviceModel | string | |
platformType | PlatformType | |
carrier | string | |
platformOS | string | |
timeZoneOffset | int | |
locale | string | |
manufac | string | |
resolution | int>.Tuple | |
리턴 | void |
static void Main(string[] args) { DateTime baseTime = DateTime.UtcNow.AddDays(-1); deviceService = setup(); Random random = new Random(); try { int numberOfRuns = random.Next(numberOfUsesMin, numberOfUsesMax); Console.WriteLine("Number of uploads: {0}", numberOfRuns); int numberOfLoyalusers = random.Next((int)(numberOfLoyalusersMin * 100), (int)(numberOfLoyalUsersMax * 100)); Console.WriteLine("Number of loyal users: {0}", numberOfLoyalusers); string filePath = String.Format("{0}\\LoyalDevices.xml", Environment.CurrentDirectory); FileInfo fileInfo = new FileInfo(filePath); List <Device> deviceLoyalUsedThisTime = new List <Device>(); List <Device> devicesLoyalTotal = new List <Device>(); if (fileInfo.Exists) { devicesLoyalTotal = AppActs.Core.Xml.Serialization.Deserialize <List <Device> >(filePath, Encoding.UTF8); int numOfLoyalUsers = (int)(devicesLoyalTotal.Count * ((decimal)numberOfLoyalusers / 100)); List <int> indexUsed = new List <int>(); int numberOfDevices = devicesLoyalTotal.Count(); for (int i = 0; i < numOfLoyalUsers; i++) { int index = -1; do { index = random.Next(0, numberOfDevices); } while (indexUsed.Contains(index)); deviceLoyalUsedThisTime.Add(devicesLoyalTotal[index]); indexUsed.Add(index); } Console.WriteLine("Number of loyal users in system: {0}", devicesLoyalTotal.Count); } List <Device> newUsers = new List <Device>(); int newUsersCount = numberOfRuns - deviceLoyalUsedThisTime.Count; Console.WriteLine("Number of new users", newUsersCount); for (int i = 0; i < newUsersCount; i++) { Device device = new Device(deviceService, getValue <string>(appVersion), DateTime.SpecifyKind(baseTime.AddHours(getValue <int>(timeDifference)), DateTimeKind.Utc), appId); device.Register( getValue <string>(deviceModel), getValue <PlatformType>(Platform), getValue <string>(Carriers), getValue <string>(platformOS), getValue <int>(TimeZoneOffset), getValue <string>(locale), getValue <string>(manufact), getValue <Tuple <int, int> >(resolution)); string[] loc = getValue <string>(location); string[] locPrecise = getValue <string>(locationPrecise); device.Location(loc[0], loc[1], locPrecise[0], locPrecise[1]); device.User(getValue <SexType>(sex), getValue <int>(age)); newUsers.Add(device); } string lastValue = appVersionMap.OrderBy(x => x.Value).Last().Key; //invoke old users, upgrade them Console.WriteLine("Processing old users: {0}", deviceLoyalUsedThisTime.Count); for (int i = 0; i < deviceLoyalUsedThisTime.Count; i++) { Device device = deviceLoyalUsedThisTime[i]; //don't upgrade the last version, there is nothing to upgrade to if (lastValue != device.Version) { //higher the upgrade chance is more likely device will upgrade if (random.Next(0, upgradeChance) == 1) { int appVersionInt = appVersionMap[device.Version]; string nextVersion = appVersionMap.OrderBy(x => x.Value > appVersionInt).First().Key; device.Version = nextVersion; route_normal_journey_upgrade(device, DateTime.SpecifyKind(baseTime.AddHours(getValue <int>(timeDifference)), DateTimeKind.Utc), device.Version); } } random_journey(device, baseTime.AddHours(getValue <int>(timeDifference)), device.Version); } //process new users Console.WriteLine("Processing new users: {0}", newUsers.Count); for (int i = 0; i < newUsers.Count; i++) { random_journey(newUsers[i], DateTime.SpecifyKind(newUsers[i].DateCreated, DateTimeKind.Utc), newUsers[i].Version); } //save new users int numberOfUsersToBecomeLoyal = newUsers.Count * random.Next((int)(numberOfUsersStartToBeLOyalMin * 100), (int)(numberOfUsersStartToBeLoyalMax * 100)) / 100; Console.WriteLine("Saving new users: {0}", numberOfUsersToBecomeLoyal); for (int i = 0; i < numberOfUsersToBecomeLoyal; i++) { devicesLoyalTotal.Add(newUsers[new Random().Next(0, newUsers.Count - 1)]); } AppActs.Core.Xml.Serialization.Serialize <List <Device> >(devicesLoyalTotal, filePath, Encoding.UTF8); } catch (Exception ex) { } }