public static SmokingDetector CreateDetectors(int device_id, string email) { Random r = new Random(); Calendar myCal = CultureInfo.InvariantCulture.Calendar; DateTime myDT = DateTime.Now; double latitude = Convert.ToInt32(34.86 + Math.Round((r.NextDouble() / 100), 4)); double longitude = Convert.ToInt32(32.5 + Math.Round((r.NextDouble()), 6)); Console.WriteLine(longitude + ", " + latitude + "-------------------------------------------------------------"); string address = "null"; DateTime time = myCal.AddDays(myDT, r.Next(1, 30)); SmokingDetector newDetector = new SmokingDetector(email, device_id.ToString(), email + device_id.ToString(), address, "A", longitude.ToString(), latitude.ToString(), time); return(newDetector); }
public static async Task Simulation(CloudTableClient tableClient) { List <SmokingDetector> detectorsArray = new List <SmokingDetector>(); CloudTable clientsTable = tableClient.GetTableReference("ClientsTable"); CloudTable detectorsTable = tableClient.GetTableReference("DetectorsEntities"); cosmosClient = new CosmosClient(EndpointUri, PrimaryKey); database = cosmosClient.GetDatabase(databaseId); container = database.GetContainer(containerId); Random r = new Random(); int event_id = 0; for (int i = 0; i <= 50; i++) { Client newclient = CreateClient(i); Console.WriteLine("Finished to create client to array"); clientslist.Add(newclient); try { TableOperation updateClient = TableOperation.InsertOrReplace(newclient); Console.WriteLine("Here1, {0}, {1}, {2}, {3}, {4}, {5}", newclient.RowKey, newclient.PartitionKey, newclient.password, newclient.phone_number, newclient.name, newclient.time); await clientsTable.ExecuteAsync(updateClient); Console.WriteLine("Success Inserting client: {0}", newclient.PartitionKey); } catch { Console.WriteLine("Failed Inserting client: {0} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@", newclient.PartitionKey); } } Console.WriteLine("Here {0}", clientslist[0].PartitionKey); foreach (Client client in clientslist) { Console.WriteLine("Here1"); detectorsArray = new List <SmokingDetector>(); r.Next(1, 4); int NumOfDetectors = r.Next(1, 4); int detector_id = 1; Console.WriteLine("Here2"); for (int i = 0; i <= NumOfDetectors; i++) { SmokingDetector newdetector = CreateDetectors(detector_id, client.PartitionKey); Console.WriteLine("Finished to create detctor"); detectorsArray.Add(newdetector); try { TableOperation updateAlert = TableOperation.InsertOrReplace(newdetector); await detectorsTable.ExecuteAsync(updateAlert); Console.WriteLine("Success Inserting client: {0}", newdetector.PartitionKey); } catch { Console.WriteLine("Failed Inserting client: {0} @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@", newdetector.PartitionKey); } await CreateEvent(event_id, detector_id.ToString(), newdetector.PartitionKey, newdetector.latitude, newdetector.longitude, container); detector_id++; event_id++; } clientsdetectors.Add(new ClientDetectorsObj(client, detectorsArray)); } }