Exemple #1
0
        //private const string eventHubConnectionString = "Endpoint=sb://airjaldipingappns.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=1vr9oBgCU3vPIXiJ4QTGqXQvteBVV3njdXaphgBgFDE=";
        //private const string eventHubName = "airjaldipingapp";

        //files 1,2,4 have ip addresses in the first column of the file hence they would have the _IP_COLUMN set to 1
        //file 3 has the ip address column in the file to be the 3rd column hence the _IP_COLUMN value would be set to 3

        static void Main(string[] args)
        {
            string eventHubConnectionString = FetchSecretValueFromKeyVault(GetToken()); // "Endpoint=sb://pingfunc.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=0CJEApfxuNJzRE0AoJcIX04InowYYYwmy0tKRkKDOnw=";
            string eventHubName             = config["EventHub"];

            config = new ConfigurationBuilder()
                     .AddJsonFile("appsettings.json", true, true)
                     .Build();

            for (int x = 0; x >= 0; x++)
            {
                var watch = System.Diagnostics.Stopwatch.StartNew();
                var connectionStringBuilder = new EventHubsConnectionStringBuilder(eventHubConnectionString)
                {
                    EntityPath = eventHubName
                };
                _eventHubMessageSender = new EventHubMessageSender(new EventHubConfiguration(eventHubConnectionString, eventHubName));
                _eventMessageModels    = new List <EventMessageModel>();
                AsyncContext.Run(() => MainAsyncPing(args));
                // Console.WriteLine("Press ENTER to exit.");
                watch.Stop();
                var elapsedMs = watch.ElapsedMilliseconds;
                Console.Write("\n Finished Ping Results in ... " + elapsedMs + " milliseconds");

                var watchtwo = System.Diagnostics.Stopwatch.StartNew();
                Console.WriteLine("\n Events Sent to Event Hub - {0} are {1} in total", eventHubName, _eventMessageModels.Count());
                AsyncContext.Run(() => MainAsyncEventHub(args));
                watchtwo.Stop();
                var elapsedMstwo = watchtwo.ElapsedMilliseconds;
                Console.Write("\n Finished sending events to Event Hub in ... " + elapsedMstwo + " milliseconds");

                Console.Write(" \n Iteration Number: #" + x + " \n");
                Console.Write(" \n Sleeping for 1min..... \n");
                Thread.Sleep(60000);
            }

            Console.WriteLine("\n Press ENTER to exit.");
            Console.ReadLine();
        }
Exemple #2
0
        //private const string eventHubConnectionString = "Endpoint=sb://airjaldipingappns.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=1vr9oBgCU3vPIXiJ4QTGqXQvteBVV3njdXaphgBgFDE=";
        //private const string eventHubName = "airjaldipingapp";

        //files 1,2,4 have ip addresses in the first column of the file hence they would have the _IP_COLUMN set to 1
        //file 3 has the ip address column in the file to be the 3rd column hence the _IP_COLUMN value would be set to 3

        static void Main(string[] args)
        {
            //Code to read csv file from blob storage

            //string connectionString = CloudConfigurationManager.GetSetting("StorageConnectionString"); //blob connection string
            //string sourceContainerName = ConfigurationManager.AppSettings["sourcecontainerName"]; //source blob container name
            //string sourceBlobFileName = "test.csv"; //source blob name



            //string connectionString = CloudConfigurationManager.GetSetting("StorageConnectionString"); //blob connection string
            //string sourceContainerName = ConfigurationManager.AppSettings["sourcecontainerName"]; //source blob container name
            //string sourceBlobFileName = config["SELECTED_FILENAME"]; //source blob name
            //var csvData = GetCSVBlobData(sourceBlobFileName, connectionString, sourceContainerName);



            //*************************************************************************\\
            config = new ConfigurationBuilder()
                     .AddJsonFile("appsettings.json", true, true)
                     .Build();

            string eventHubConnectionString = FetchSecretValueFromKeyVault(GetToken()); // "Endpoint=sb://pingfunc.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=0CJEApfxuNJzRE0AoJcIX04InowYYYwmy0tKRkKDOnw=";
            string eventHubName             = config["EventHub"];
            string blobAccountKey           = FetchBlobKeySecretValueFromKeyVault(GetToken());

            // string blobAccountKey = config["BlobStorageAccountPrimaryKey"];

            string fileinblob = config["FILELOCATION_BLOB"];

            //if file is in blob storage get it and save it in local file storage
            if (fileinblob == "true")
            {
                string myAccountName = config["BlobStorageAccountName"];
                //string myAccountKey = config["BlobStorageAccountPrimaryKey"];
                string myAccountKey   = blobAccountKey;
                string mycontainer    = config["BlobStorageContainerName"];
                string myFileName     = config["SELECTED_FILENAME"];
                string myFileSavePath = config["LOCAL_FILEPATH"] + "\\" + config["SELECTED_FILENAME"];


                var storageCredentials  = new StorageCredentials(myAccountName, myAccountKey);
                var cloudStorageAccount = new CloudStorageAccount(storageCredentials, true);
                var cloudBlobClient     = cloudStorageAccount.CreateCloudBlobClient();

                var container = cloudBlobClient.GetContainerReference(mycontainer);
                container.CreateIfNotExistsAsync().Wait();


                var newBlob = container.GetBlockBlobReference(myFileName);
                newBlob.DownloadToFileAsync(myFileSavePath, FileMode.Create).Wait();
            }
            //*****************************************************\\

            for (int x = 0; x >= 0; x++)
            {
                var watch = System.Diagnostics.Stopwatch.StartNew();
                var connectionStringBuilder = new EventHubsConnectionStringBuilder(eventHubConnectionString)
                {
                    EntityPath = eventHubName
                };
                _eventHubMessageSender = new EventHubMessageSender(new EventHubConfiguration(eventHubConnectionString, eventHubName));
                _eventMessageModels    = new List <EventMessageModel>();
                AsyncContext.Run(() => MainAsyncPing(args));
                // Console.WriteLine("Press ENTER to exit.");
                watch.Stop();
                var elapsedMs = watch.ElapsedMilliseconds;
                Console.Write("\n Finished Ping Results in ... " + elapsedMs + " milliseconds");

                var watchtwo = System.Diagnostics.Stopwatch.StartNew();
                Console.WriteLine("\n Events Sent to Event Hub - {0} are {1} in total", eventHubName, _eventMessageModels.Count());
                AsyncContext.Run(() => MainAsyncEventHub(args));
                watchtwo.Stop();
                var elapsedMstwo = watchtwo.ElapsedMilliseconds;
                Console.Write("\n Finished sending events to Event Hub in ... " + elapsedMstwo + " milliseconds");

                Console.Write(" \n Iteration Number: #" + x + " \n");


                String sleepIntMin    = config["PingFrequencyInterval"];
                int    numvalSleepInt = 1;

                try
                {
                    numvalSleepInt = Convert.ToInt32(sleepIntMin);
                }
                catch (FormatException e)
                {
                    numvalSleepInt = 1;
                    Console.Write("\n Sleep Interval is not correct, please open appsettings.json to input a valid integer whole number value for minutes");
                }

                int sleepIntMs = numvalSleepInt * 60000;

                Thread.Sleep(sleepIntMs);
                Console.Write(" \n Sleeping for" + numvalSleepInt + "minutes \n");
            }

            Console.WriteLine("\n Press ENTER to exit.");
            Console.ReadLine();
        }