示例#1
0
        public static async Task Main(string[] args)
        {
            var config        = new EventHubConfig();
            var minutesToSend = GetConfigDouble("MinutesToRun");

            // Configuration can be picked up from Env variable of the step or fall back on App.config
            config.ConnectionString = GetConfigString("EventHubConnectionString");
            config.EventHubName     = GetConfigString("EventHubName");
            config.EventDelayMs     = GetConfigInt("EventDelayMs");
            config.EventsPerMessage = GetConfigInt("EventsPerMessage");
            config.EventType        = GetConfigString("EventType");
            Console.WriteLine("Starting With " + JsonConvert.SerializeObject(config));

            if (config.EventType?.Equals("Sensor") ?? true)
            {
                var eventHubevents = Observable.Interval(TimeSpan.FromMilliseconds(config.EventDelayMs)).
                                     Select(i => Sensor.Generate(config.EventsPerMessage));

                // To send data to EventHub as JSON
                using (var eventHubDis = eventHubevents.Subscribe(new EventHubObserver(config)))
                {
                    await Task.Delay(TimeSpan.FromMinutes(minutesToSend));
                }
            }
        }
示例#2
0
        public EventHubObserver(EventHubConfig config)
        {
            _config = config;
            if (!string.IsNullOrWhiteSpace(_config.ConnectionString))
            {
                _eventHubClient = EventHubClient.CreateFromConnectionString(_config.ConnectionString, _config.EventHubName);
            }
            else
            {
                throw new ArgumentException("EventHub ConnectionString is null or empty");
            }

            this._logger = new Logger(ConfigurationManager.AppSettings["logger_path"]);
        }
 public EventHubObserver(EventHubConfig config)
 {
     try
     {
         _config         = config;
         _eventHubClient = EventHubClient.CreateFromConnectionString(_config.ConnectionString, config.EventHubName);
         this._logger    = new Logger(ConfigurationManager.AppSettings["logger_path"]);
     }
     catch (Exception ex)
     {
         _logger.Write(ex);
         throw ex;
     }
 }
示例#4
0
        public EventHubObserver(EventHubConfig config)
        {
            try
            {
                _config             = config;
                _eventHubRTClient   = EventHubClient.CreateFromConnectionString(_config.ConnectionStringRT, config.EventHubNameRT);
                _eventHubInitClient = EventHubClient.CreateFromConnectionString(_config.ConnectionStringInit, config.EventHubNameInit);

                this._logger = new Logger(ConfigurationManager.AppSettings["logger_path"]);

                SharePointOnlineInterface.SetCredentials(_config.credsName, _config.credsKkey);

                var studentList = new List <string>();

                var             listFrom = "Sharepoint";
                List <ListItem> lItems   = null;

                Console.ForegroundColor = ConsoleColor.Magenta;

                try
                {
                    Console.WriteLine($"Attempting to load items from sharepoint");
                    lItems = SharePointOnlineInterface.GetAllItems(_config.studentSite, _config.studentList);
                    foreach (var it in lItems)
                    {
                        studentList.Add(it["Preferred_Name"].ToString());
                    }
                }
                catch (Exception ex)
                {
                    listFrom = "Internal default";
                    foreach (char a in "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
                    {
                        studentList.Add(a + " student");
                    }
                }

                Console.WriteLine($" Loaded student names from {listFrom}");

                Sensor.SetUserList(studentList);
            }
            catch (Exception ex)
            {
                _logger.Write(ex);
                throw ex;
            }
        }
示例#5
0
        static void Main(string[] args)
        {
            var config = new EventHubConfig();


            // Uncomment for picking from Configuration
            config.ConnectionString = ConfigurationManager.AppSettings["EventHubConnectionString"];
            config.EventHubName     = ConfigurationManager.AppSettings["EventHubName"];

            //To push 1 event per second
            var eventHubevents = Observable.Interval(TimeSpan.FromSeconds(.1)).Select(i => Sensor.Generate());

            //To send Data to EventHub as JSON
            var eventHubDis = eventHubevents.Subscribe(new EventHubObserver(config));

            Console.ReadLine();
            eventHubDis.Dispose();
        }
        static void Main(string[] args)
        {
            var config = new EventHubConfig();


            // Uncomment for picking from Configuration
            config.ConnectionStringRT   = ConfigurationManager.AppSettings["EventHubConnectionStringRT"];
            config.EventHubNameRT       = ConfigurationManager.AppSettings["EventHubRTName"];
            config.ConnectionStringInit = ConfigurationManager.AppSettings["EventHubConnectionStringInit"];
            config.EventHubNameInit     = ConfigurationManager.AppSettings["EventHubInitName"];
            config.credsName            = ConfigurationManager.AppSettings["credsName"];
            config.credsKkey            = ConfigurationManager.AppSettings["credsKey"];
            config.studentSite          = ConfigurationManager.AppSettings["studentSite"];
            config.studentList          = ConfigurationManager.AppSettings["studentList"];

            //To push 3 event per second
            var eventHubevents = Observable.Interval(TimeSpan.FromSeconds(.3)).Select(i => Sensor.Generate());

            //To send Data to EventHub as JSON
            var eventHubDis = eventHubevents.Subscribe(new EventHubObserver(config));

            Console.ReadLine();
            eventHubDis.Dispose();
        }