public List <Level> readContext() { List <Level> levels = new List <Level>(); string h_path = Application.persistentDataPath + hash_path; using (StreamReader sr = File.OpenText(h_path)) { int lv_number = 0; while (!sr.EndOfStream) { Level level; List <Bulb> bulbs = new List <Bulb>(); string dec = Security.Decrypt(sr.ReadLine(), "89ABCDEF01234567"); string[] s = dec.Split('/'); int n = Convert.ToInt16(s[0]); //char type = s[1][0]; for (int i = 1; i < s.Length; i++) { string[] ef = s[i].Split(' '); List <int> eff = new List <int>(); for (int j = 0; j < ef.Length; j++) { eff.Add(Convert.ToInt16(ef[j])); } Bulb b = new Bulb(i - 1, false, eff); bulbs.Add(b); } level = new Level(lv_number++, bulbs); levels.Add(level); } } return(levels); }
// Do not use simplified object initialization to ease debugging and exception catching public Bulb Build() { var bulbData = _bytes.ToArray(); var bulb = new Bulb(); bulb.Id = BitConverter.ToUInt16(bulbData, 0); bulb.MacAddress = BitConverter.ToUInt64(bulbData, 2); bulb.Type = bulbData[9]; bulb.FirmwareVersion = BitConverter.ToUInt32(bulbData, 10); bulb.IsAvailable = BitConverter.ToBoolean(bulbData, 14); bulb.GroupId = BitConverter.ToUInt16(bulbData, 15); bulb.IsOn = BitConverter.ToBoolean(bulbData, 17); bulb.Brightness = bulbData[18]; bulb.Temperature = BitConverter.ToInt16(bulbData, 19); bulb.Color = Color.FromArgb(bulbData[24], bulbData[21], bulbData[22], bulbData[23]); bulb.Name = Encoding.Default.GetString(bulbData, 25, bulbData.Length - 25); _bytes.Clear(); if (bulb.MacAddress == 0) // There's clearly something wrong if the mac address is equal to 0 { return(null); } return(bulb); }
public static BulbCacheWriteObject Create(Bulb data, Guid accountId) { if (data == null) { return(null); } var result = new BulbCacheWriteObject() { Id = data.Id, CreateDate = data.CreateDate, AccountId = accountId, IsDeleted = data.IsDeleted, LastChildBulbId = data.LastChildBulbId, ActualDate = data.ActualDate, Status = data.Status, Count = data.Count, StartDate = data.StartDate, Message = data.Message, StatusEventId = data.StatusEventId, UnitTestId = data.UnitTestId, PreviousStatus = data.PreviousStatus, MetricId = data.MetricId, LastEventId = data.LastEventId, HasSignal = data.HasSignal, FirstEventId = data.FirstEventId, EventCategory = data.EventCategory, EndDate = data.EndDate, ComponentId = data.ComponentId }; return(result); }
public Bulb CreateEfStatusData() { var result = new Bulb() { Id = Id, IsDeleted = IsDeleted, LastChildBulbId = LastChildBulbId, ActualDate = ActualDate, Status = Status, Count = Count, StartDate = StartDate, Message = Message, StatusEventId = StatusEventId, UnitTestId = UnitTestId, PreviousStatus = PreviousStatus, MetricId = MetricId, LastEventId = LastEventId, HasSignal = HasSignal, FirstEventId = FirstEventId, EventCategory = EventCategory, EndDate = EndDate, ComponentId = ComponentId, CreateDate = CreateDate }; return(result); }
private void button5_Click(object sender, EventArgs e) { if (tbManualBulbMac.Text.Length != 6 || !System.Text.RegularExpressions.Regex.IsMatch(tbManualBulbMac.Text, @"\A\b[0-9a-fA-F]+\b\Z")) { MessageBox.Show( "Enter the last six characters of the bulb's MAC address. This can be found in the \"Edit Light\" dialog of the Android app, amongst other places. For a virtual bulb, just enter 000000."); return; } var n = _bulbController.Bulbs.Where(x => x.Label.Length > 12 && x.Label.Substring(0, 12) == "Manual Bulb ") .Select(x => int.Parse(x.Label.Substring(12))); int n2 = 1; if (n.Count() > 0) { n2 = n.Max() + 1; } Bulb b = new Bulb() { Label = "Manual Bulb " + n2, Location = ScreenLocation.All, MacAddress = "D073D5" + tbManualBulbMac.Text.Length }; _bulbController.Bulbs.Add(b); PopulateBulbListbox(); _suspendUi = false; SaveSettings(); _suspendUi = true; }
public void AttachTest() { // интересна статья на эту тему // http://ethereal-developer.blogspot.ru/2014/11/a-referential-integrity-constraint.html var account = TestHelper.GetTestAccount(); using (var accountDbContext = account.CreateAccountDbContext()) { accountDbContext.Configuration.AutoDetectChangesEnabled = false; var child = new Bulb() { Id = Guid.NewGuid(), CreateDate = DateTime.Now }; accountDbContext.Bulbs.Attach(child); var parent1 = new Bulb() { Id = Guid.NewGuid(), CreateDate = DateTime.Now, LastChildBulbId = child.Id }; accountDbContext.Bulbs.Attach(parent1); parent1.LastChildBulbId = Guid.NewGuid(); var parent2 = new Bulb() { Id = Guid.NewGuid(), CreateDate = DateTime.Now, LastChildBulbId = child.Id }; accountDbContext.Bulbs.Attach(parent2); } }
public void AddBulb(Bulb bulb) { GetComponent <AudioSource>().PlayOneShot(pickupSound); Bulb original = bulbs.item; bulbs.item = bulb; bulbs.item = original; }
public static void ConsumePowerFromBatteriesIn(int index) { BatteriesIn.ElementAt(index).ConsumePower(Bulb.GetStrength()); if (BatteriesIn.ElementAt(index).GetPower() < 0) { BatteriesIn.ElementAt(index).SetPower(0); } }
public void doTheConstructorsWork() { var bulb = new Bulb("192.168.1.139"); var secondBulb = new Bulb(new IPAddress(new byte[] { 192, 168, 1, 110 })); Assert.True(bulb is Bulb, "First bulb is a bulb"); Assert.True(secondBulb is Bulb, "Second bulb is a bulb"); }
internal override void Apply(Bulb bulb) { bulb.TimeInfo = new BulbTimeInfo { Time = _time, Uptime = bulb.TimeInfo.Uptime, Downtime = bulb.TimeInfo.Downtime, }; }
internal override void Apply(Bulb bulb) { bulb.Version = new BulbVersion { Product = _bulbProduct, Vendor = _bulbVendor, Version = _bulbVersion, }; }
private Bulb[] _GenBulbs(int n) { var list = new Bulb[n]; for (int i = 0; i < list.Length; ++i) { list[i] = new Bulb(); } return(list); }
public void TestBulbOn() { PowerSupply supply = new PowerSupply(amperage: 10, voltage: 10); Bulb bulb = new Bulb { MinimumPower = 20 }; bulb.Previous = supply; Assert.IsTrue(bulb.IsOn); }
internal override void Apply(Bulb bulb) { bulb.WifiInfo = new Lib.WifiInfo { Signal = _signal, Tx = _tx, Rx = _rx, McuTemperature = _mcuTemperature, WifiFirmwareBuildTime = bulb.WifiInfo.WifiFirmwareBuildTime, WifiFirmwareInstallTime = bulb.WifiInfo.WifiFirmwareInstallTime, }; }
internal override void Apply(Bulb bulb) { bulb.WifiInfo = new Lib.WifiInfo { WifiFirmwareBuildTime = _buildTimestamp, WifiFirmwareInstallTime = _installTimestamp, Signal = bulb.WifiInfo.Signal, Tx = bulb.WifiInfo.Tx, Rx = bulb.WifiInfo.Rx, McuTemperature = bulb.WifiInfo.McuTemperature, }; }
internal override void Apply(Bulb bulb) { bulb.MeshInfo = new Lib.MeshInfo { Signal = _signal, Rx = _rx, Tx = _tx, McuTemperature = _mcuTemperature, FirmwareBuild = bulb.MeshInfo.FirmwareBuild, FirmwareInstall = bulb.MeshInfo.FirmwareInstall, FirmwareVersion = bulb.MeshInfo.FirmwareVersion, }; }
internal override void Apply(Bulb bulb) { bulb.MeshInfo = new Lib.MeshInfo { FirmwareBuild = _fwBuild, FirmwareInstall = _fwInstall, FirmwareVersion = _fwVersion, Signal = bulb.MeshInfo.Signal, Tx = bulb.MeshInfo.Tx, Rx = bulb.MeshInfo.Rx, McuTemperature = bulb.MeshInfo.McuTemperature, }; }
public void DoSomething() { var bulb = new Bulb(); var refrigerator = new Refrigerator(); var equipmentSwitch = new Switch(); equipmentSwitch.SetEquipment(bulb); equipmentSwitch.On(); equipmentSwitch.Off(); equipmentSwitch.SetEquipment(refrigerator); equipmentSwitch.On(); equipmentSwitch.Off(); }
private void buttonReplaceTheBulb_Click(object sender, EventArgs e) { bool parser; int output; parser = Int32.TryParse(textBoxSelectBulbPower.Text, out output); if (parser && output > 0 && output <= 10) { Bulb.SetBulbPower(output); } else { MessageBox.Show("Źle wprowadzone dane", "Błąd"); } }
private void buttonON_Click(object sender, EventArgs e) { if (textBoxState.Text != "ON") { if (Flashlight.IsBulbIn() && Flashlight.GetBatteriesCount() >= 2 && Flashlight.PowerSupply()) { Flashlight.TurnOn(); textBoxState.Text = "ON"; for (int i = 0; i < Flashlight.GetBatteriesCount(); i++) { switch (i + 1) { case 1: Flashlight.updateBatteryStatus(Bulb.GetBulbPower(), i); textBoxBattery1.Text = Flashlight.GetVoltage(i).ToString() + " %"; break; case 2: Flashlight.updateBatteryStatus(Bulb.GetBulbPower(), i); textBoxBattery2.Text = Flashlight.GetVoltage(i).ToString() + " %"; break; case 3: Flashlight.updateBatteryStatus(Bulb.GetBulbPower(), i); textBoxBattery3.Text = Flashlight.GetVoltage(i).ToString() + " %"; break; } } } if (!Flashlight.IsBulbIn()) { MessageBox.Show("Nie włożono żarówki do latarki.", "Niepoprawne uruchomienie latarki."); } if (Flashlight.GetBatteriesCount() < 2) { MessageBox.Show("Niewystarczająca ilość baterii.", "Niepoprawne uruchomienie latarki"); } if (Flashlight.GetBatteriesCount() >= 2 && !Flashlight.PowerSupply()) { MessageBox.Show("Zbyt niskie napięcie w bateriach.", "Wymień baterie"); } } else { MessageBox.Show("Latarka jest już włączona", "Informacja"); } }
static void Main(string[] args) { Bulb bulb = new Bulb(); bulb.BulbOn += Bulb_BulbOn; bulb.Switch(); Console.WriteLine(bulb.state); bulb.Switch(); Console.WriteLine(bulb.state); bulb.Switch(); Console.WriteLine(bulb.state); bulb.Switch(); Console.WriteLine(bulb.state); bulb.Switch(); Console.WriteLine(bulb.state); }
public static StatusDataInfo GetStatusDataInfo(Bulb data) { if (data == null) { return(null); } return(new StatusDataInfo() { Id = data.Id, OwnerId = data.GetOwnerId(), ActualDate = data.ActualDate, EndDate = data.EndDate, Message = data.Message, HasSignal = data.HasSignal, StartDate = data.StartDate, Status = data.Status }); }
public static StatusInfo Create(Bulb bulb, Component component, DateTime now) { if (bulb == null) { throw new ArgumentNullException("bulb"); } if (component == null) { throw new ArgumentNullException("component"); } return(new StatusInfo() { Category = bulb.EventCategory, EventId = bulb.StatusEventId, ComponentId = bulb.ComponentId.Value, Component = component, Duration = bulb.GetDuration(now), Importance = EventImportanceHelper.Get(bulb.Status), CreateDate = bulb.StartDate, PreviousImportance = EventImportanceHelper.Get(bulb.PreviousStatus) }); }
private void btnBulbChange_Click(object sender, EventArgs e) { if (Flashlight.GetBulbState()) { string inputbox = Interaction.InputBox("Podaj moc nowej żaróweczki [1-10]", "Wymieniamy żaróweczkę", Bulb.GetStrength().ToString(), -1, -1); int output; bool isInt = Int32.TryParse(inputbox, out output); if (isInt && output >= 1 && output <= 10) { Bulb.SetStrength(output); tbBulbStrength.Text = output.ToString(); tbBulbStrength.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255 - output * 25))))); } else { MessageBox.Show("Zła wartość!", "Błąd!"); } } else { MessageBox.Show("Najpierw wsadź żarówkę!", "Błąd!"); } }
private async Task <Bulb> GetBulb(Device device) { Dictionary <YeelightAPI.Models.PROPERTIES, object> props = await device.GetAllProps(); bool rgbMode = (props[YeelightAPI.Models.PROPERTIES.color_mode].ToString() == "1"); Bulb b = new Bulb(); b.Hostname = device.Hostname; b.Power = (props[YeelightAPI.Models.PROPERTIES.power].ToString() == "on"); Color c = GetColorFromInt(int.Parse(props[YeelightAPI.Models.PROPERTIES.rgb].ToString())); b.Color = new YeelightColor(); b.Color.R = c.R; b.Color.G = c.G; b.Color.B = c.B; b.Brightness = int.Parse(props[YeelightAPI.Models.PROPERTIES.bright].ToString()); if (!rgbMode) { b.Temperature = int.Parse(props[YeelightAPI.Models.PROPERTIES.ct].ToString()); } return(b); }
internal override void Apply(Bulb bulb) { bulb.ResetSwitchPosition = _position; }
internal override void Apply(Bulb bulb) { bulb.Name = _name; bulb.IsPowerOn = _power != 0; bulb.Color = new HsvColor(_hue, _saturation / 100.0, _brightness / 255.0, _kelvin); }
internal override void Apply(Bulb bulb) { bulb.Name = _label; }
internal override void Apply(Bulb bulb) { bulb.Voltage = _voltage; }
internal override void Apply(Bulb bulb) { bulb.IsPowerOn = _isOn; }
internal FacadeClass() { bulb = new Bulb(); ds = new DerailingSwitch(); }