Beispiel #1
0
        /// <summary>
        /// Starts the application.
        /// </summary>
        /// <param name="config">Options to run with.</param>
        /// <returns></returns>
        private static async Task Run(IoTNetConfiguration config)
        {
            using (var experience = new ExperienceController(new ExperienceControllerConfig
            {
                AppId = config.ExperienceId,
                TrellisToken = config.Token,
                TrellisUrl = config.TrellisUrl
            }))
            {
                ElementData elements;

                // load experience first
                try
                {
                    elements = await experience.Initialize();
                }
                catch (Exception exception)
                {
                    Log.Error($"Could not initialize experience: '{exception}'.");

                    return;
                }

                // connect to Mycelium next
                using (var network = new MyceliumController(new MyceliumControllerConfiguration
                {
                    Ip = config.MyceliumIp,
                    Port = config.MyceliumPort,
                    Token = config.Token
                }))
                {
                    network.Start();

                    // TODO: your controller here

                    Console.ReadLine();
                }
            }

            Log.Information("Shutting down.");
        }
Beispiel #2
0
        /// <summary>
        /// Creates an AppActorConfiguration.
        /// </summary>
        /// <returns></returns>
        private static IoTNetConfiguration Configuration()
        {
            // construct the application config
            var config = new IoTNetConfiguration();

            // override defaults with app-config.json
            if (File.Exists(APP_CONFIG_PATH))
            {
                var src = File.ReadAllText(APP_CONFIG_PATH);
                config.Override(JsonConvert.DeserializeObject <IoTNetConfiguration>(src));
            }

            // override with environment variables
            SetFromEnvironment("EXPERIENCE_ID", ref config.ExperienceId, a => a);
            SetFromEnvironment("TRELLIS_URL", ref config.TrellisUrl, a => a);
            SetFromEnvironment("TRELLIS_TOKEN", ref config.Token, a => a);
            SetFromEnvironment("MYCELIUM_IP", ref config.MyceliumIp, a => a);
            SetFromEnvironment("MYCELIUM_PORT", ref config.MyceliumPort, int.Parse);

            return(config);
        }