Esempio n. 1
0
        /// <summary>
        /// Method to run when the root command is executed.
        /// </summary>
        /// <returns>Zero if ok.</returns>
        public int OnExecute(CommandLineApplication app)
        {
            Console.WriteLine($"Settings: {JsonConvert.SerializeObject(this, Formatting.Indented)}");

            try
            {
                if (CheckOptions(app))
                {
                    // Overriding Netatmo data options.
                    _netatmo.BaseAddress  = BaseAddress;
                    _netatmo.Timeout      = Timeout;
                    _netatmo.User         = User;
                    _netatmo.Password     = Password;
                    _netatmo.ClientID     = ClientID;
                    _netatmo.ClientSecret = ClientSecret;

                    if (_netatmo.CheckAccess())
                    {
                        Console.WriteLine($"Netatmo web service found at {BaseAddress}.");
                    }
                    else
                    {
                        Console.WriteLine($"Netatmo web service not found at {BaseAddress}.");
                    }
                }
            }
            catch (Exception ex)
            {
                _logger?.LogError(ex, $"Exception RootCommand Run()");
                Console.WriteLine($"Error connecting to Netatmo web service at {BaseAddress}.");
                return(-1);
            }

            return(0);
        }