Пример #1
0
        static int Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            string environment = Environment.GetEnvironmentVariable(Constants.Environment);

            if (String.IsNullOrWhiteSpace(environment))
            {
                throw new ArgumentNullException("Environment not found in:" + Constants.Environment);
            }

            Console.WriteLine("Environment: {0}", environment);

            // all passwords should be stored in
            // %APPDATA%\microsoft\UserSecrets\luga\secrets.json
            // https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets?tabs=visual-studio

            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{environment}.json", optional: true)
                          .AddEnvironmentVariables();

            if (environment != null && environment.Contains("Dev"))
            {
                builder.AddUserSecrets <Program>();
            }

            var cfg = builder.Build();

            Console.WriteLine($"Connection string: {cfg[Constants.ConnectionString]}");

            return((int)HostFactory.Run(x =>
            {
                var mqttConfig = new LuGaMqttConfig
                                 (
                    cfg[Constants.Username],
                    cfg[Constants.Password],
                    cfg[Constants.ClientId],
                    cfg[Constants.Host],
                    Convert.ToInt32(cfg[Constants.Port]));

                var readingRepository = new ReadingsRepository(cfg[Constants.ConnectionString]);

                x.Service(y => new LuGaMqtt(mqttConfig, readingRepository));

                x.SetServiceName(Constants.ServiceName);
                x.SetDisplayName(Constants.ServiceName);
            }));
        }
Пример #2
0
        static void Main(string[] args)
        {
            var timer      = new Timer();
            var connection = new NetworkStatusConnection(
                new HttpNetworkClient(new HttpClient()), new Uri("https://www.google.com"));
            var sensor       = new ConnectionSensor(connection);
            var timerFactory = new TimerFactory();
            var repository   = new ReadingsRepository();
            var scheduler    = new ReadScheduler(timerFactory, repository);

            var scheduledReadings = scheduler.ScheduleReadings(sensor, 15);

            System.Console.ReadKey();
        }
Пример #3
0
 public ReadingsController()
 {
     repository = new ReadingsRepository();
 }