public HueBuildLight(string ip, IEnumerable<string> lights, string intensity) { _hueClient = new HueClient(ip); _hueClient.Initialize(AppKey); _lights = lights.ToList(); int parsedInt; if (int.TryParse(intensity, out parsedInt)) { _intensity = parsedInt; } else { _intensity = MAX_INTENSITY; } }
public override int Run(string[] remainingArguments) { var hueClient = new HueClient(_ip); var result = hueClient.RegisterAsync(HueBuildLight.AppName, HueBuildLight.AppKey).Result; if (result) { Console.WriteLine("Registered correctly."); return 0; } //If we failed to register, attempt to initialise and see if we succeed as we may already be registered. hueClient.Initialize(HueBuildLight.AppKey); var initialised = hueClient.IsInitialized; Console.WriteLine(initialised ? "Already registered." : "Failed to register"); return initialised ? 0 : 1; }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AutoMapperConfig.Configure(); // Create the container builder. var builder = new ContainerBuilder(); // Register the Web API controllers. builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); builder.RegisterControllers(Assembly.GetExecutingAssembly()); // Register other dependencies. var client = new HueClient(HueConfig.HueIP); client.Initialize(HueConfig.HueMd5); builder.Register(c => client).As<IHueClient>().SingleInstance(); var list = new List<Light> { new Light {Id = "1"}, new Light {Id = "2"}, new Light {Id = "3"}, new Light {Id = "4"}, new Light {Id = "6"} }; HueListConfig.UpdateLights(client, list); builder.Register(l => list).As<IList<Light>>().SingleInstance(); // Build the container. var container = builder.Build(); // Create the depenedency resolver. var webApiResolver = new AutofacWebApiDependencyResolver(container); // Configure Web API with the dependency resolver. GlobalConfiguration.Configuration.DependencyResolver = webApiResolver; DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }