static void Main(string[] args)
        {
            string csv_file_path = string.Empty;

            install();
            //string csv_file_path = @"C:\ASA\input\demodata.csv";
            string[] filePath = Directory.GetFiles(@"E:\MSFT Laptop\ASA-Packt\ASA-Demos\accelerometer", "*.csv");
            int      size     = filePath.Length;

            for (int i = 0; i < size; i++)
            {
                Console.WriteLine(filePath[i]);
                csv_file_path = filePath[i];
            }

            // string csv_file_path = @"C:\Users\Anindita\OneDrive\MAX451\BGClub\Attendance\All_Clubs_Progrma_Attendance_12.2015.csv";
            DataTable csvData = GetDataTableFromCSVFile(csv_file_path);

            Console.WriteLine("Rows count:" + csvData.Rows.Count);
            DataTable table = csvData;

            foreach (DataRow row in table.Rows)
            {
                // Console.WriteLine("---Row---");
                foreach (var item in row.ItemArray)
                {
                    data = item.ToString();
                    Console.Write(data);

                    var eventHubClient = EventHubClient.CreateFromConnectionString(connectionString, eventHubName);
                    //while (true)
                    //{

                    try
                    {
                        foreach (DataRow rows in table.Rows)
                        {
                            var info = new Accelerometer
                            {
                                ID           = rows.ItemArray[0].ToString(),
                                Coordinate_X = rows.ItemArray[1].ToString(),
                                Coordinate_Y = rows.ItemArray[2].ToString(),
                                Coordinate_Z = rows.ItemArray[3].ToString()
                            };
                            var serializedString = JsonConvert.SerializeObject(info);
                            var message          = data;
                            Console.WriteLine("{0}> Sending events: {1}", DateTime.Now.ToString(), serializedString.ToString());
                            eventHubClient.SendAsync(new EventData(Encoding.UTF8.GetBytes(serializedString.ToString())));
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("{0} > Exception: {1}", DateTime.Now.ToString(), ex.Message);
                        Console.ResetColor();
                    }
                    Task.Delay(200);
                    //}
                }
            }
            // Console.ReadLine();

            Console.WriteLine("Press Ctrl-C to stop the sender process");
            Console.WriteLine("Press Enter to start now");
            Console.ReadLine();

            //   SendingRandomMessages().Wait();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            
            string csv_file_path = string.Empty;
            install();
            //string csv_file_path = @"C:\ASA\input\demodata.csv";
            string[] filePath = Directory.GetFiles(@"D:\Windows Azure\ASA\Sensors\Accelerometer\", "*.csv");
            int size = filePath.Length;
            for (int i = 0; i < size; i++)
            {
                Console.WriteLine(filePath[i]);
                 csv_file_path = filePath[i];
            }
            
           // string csv_file_path = @"C:\Users\Anindita\OneDrive\MAX451\BGClub\Attendance\All_Clubs_Progrma_Attendance_12.2015.csv";
            DataTable csvData = GetDataTableFromCSVFile(csv_file_path);
            Console.WriteLine("Rows count:" + csvData.Rows.Count);
            DataTable table = csvData;
            foreach (DataRow row in table.Rows)
            {
                // Console.WriteLine("---Row---");
                   foreach (var item in row.ItemArray)
                    {

                        data = item.ToString();
                        Console.Write(data);

                        var eventHubClient = EventHubClient.CreateFromConnectionString(connectionString, eventHubName);
                        //while (true)
                        //{

                        try
                        {
                            foreach (DataRow rows in table.Rows)
                            {
                                var info = new Accelerometer
                                {



                                    ID = rows.ItemArray[0].ToString(),
                                    Coordinate_X = rows.ItemArray[1].ToString(),
                                    Coordinate_Y = rows.ItemArray[2].ToString(),
                                    Coordinate_Z = rows.ItemArray[3].ToString()

                                    

                                };
                                var serializedString = JsonConvert.SerializeObject(info);
                                var message = data;
                                Console.WriteLine("{0}> Sending events: {1}", DateTime.Now.ToString(), serializedString.ToString());
                                eventHubClient.SendAsync(new EventData(Encoding.UTF8.GetBytes(serializedString.ToString())));

                            }
                        }
                        catch (Exception ex)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("{0} > Exception: {1}", DateTime.Now.ToString(), ex.Message);
                            Console.ResetColor();
                        }
                            Task.Delay(200);
                        //}


                    }
                
            }
            // Console.ReadLine();

            Console.WriteLine("Press Ctrl-C to stop the sender process");
            Console.WriteLine("Press Enter to start now");
            Console.ReadLine();
            
         //   SendingRandomMessages().Wait();

        }