Пример #1
0
 public static void PHRegister()
 {
     Console.ForegroundColor = ConsoleColor.Gray;
     Console.WriteLine("Checking for existing PH Username");
     if (iniFile.Section("PhilipsHue").Get("Username") == "?")
     {
         Console.WriteLine("[INI]: " + iniFile.Section("PhilipsHue").Get("Username"));
         Console.WriteLine("Need to register with Philips Hue");
         Console.ForegroundColor = ConsoleColor.Black;
         Console.BackgroundColor = ConsoleColor.Green;
         Console.WriteLine("Please press the button on your Philips Hue to register with SharpBot");
         Console.WriteLine("Press any key when the button has been pressed");
         Console.ForegroundColor = ConsoleColor.White;
         Console.BackgroundColor = ConsoleColor.Black;
         Console.ReadKey();
         try
         {
             Console.ForegroundColor = ConsoleColor.Gray;
             Configuration.AddUser();
             Console.WriteLine("Registered with Philips Hue - Username: "******"Saving to INI File");
             iniFile.Section("PhilipsHue").Set("Username", Configuration.Username);
             Console.WriteLine("[INI]: " + iniFile.Section("PhilipsHue").Get("Username"));
             iniFile.Save(ini);
             lights = new LightCollection();
             Console.WriteLine("A total of {0} lights were found on the bridge", lights.Count);
         }
         catch (Exception ex)
         {
             Console.ForegroundColor = ConsoleColor.Red;
             Console.WriteLine(ex.Message.ToUpper());
             Console.ForegroundColor = ConsoleColor.White;
         }
     }
     else
     {
         try
         {
             Console.WriteLine("Attempting to access bridge with Username: "******"PhilipsHue").Get("Username"));
             Configuration.Initialize(iniFile.Section("PhilipsHue").Get("Username"));
             lights = new LightCollection();
             Console.ForegroundColor = ConsoleColor.White;
             Console.Write("A total of ");
             Console.ForegroundColor = ConsoleColor.Green;
             Console.Write(lights.Count);
             Console.ForegroundColor = ConsoleColor.White;
             Console.WriteLine(" lights were found on the bridge");
         }
         catch (Exception ex)
         {
             Console.ForegroundColor = ConsoleColor.Red;
             Console.WriteLine(ex.Message.ToUpper());
             Console.ForegroundColor = ConsoleColor.White;
             Console.WriteLine("Username did not work, clearing out INI file");
             iniFile.Section("PhilipsHue").Set("Username", "?");
             iniFile.Save(ini);
             Console.WriteLine("Please rerun Register");
         }
     }
 }
Пример #2
0
 /// <summary>
 /// When <see cref="Apply" /> is called, applies the state information stored in this LightStateBuilder to each of the light indices passed in to this method.
 /// </summary>
 /// <param name="lights">The collection of lights that this new state applies to. To select lights, pass in one or more <paramref name="indices" />. To actually apply the new state, call <see cref="Apply" />.</param>
 /// <param name="indices">The indices within the <paramref name="lights" /> collection to apply to.</param>
 /// <returns>This LightStateBuilder instance, for method chaining.</returns>
 public LightStateBuilder For(LightCollection lights, params int[] indices)
 {
     foreach (var i in indices)
     {
         associatedLights.Add(lights[i]);
     }
     return(this);
 }