public void TestOverlappingCyclesWeekRollover() { var sprinklerController = new SprinklerController(); var zoneConfig = new ZoneConfig { ZoneNumber = 1, RunTime = 10 }; sprinklerController.AddProgram(new ProgramConfig("Program 1", new CycleConfig[] { new CycleConfig() { DaysOfWeek = new DayOfWeek[] { DayOfWeek.Saturday }, StartHour = 23, StartMinute = 55, ZoneConfigs = new ZoneConfig[] { zoneConfig } } })); Assert.ThrowsException <SprinklerControllerException>(() => sprinklerController.AddProgram(new ProgramConfig("Program 2", new CycleConfig[] { new CycleConfig() { DaysOfWeek = new DayOfWeek[] { DayOfWeek.Sunday }, StartHour = 0, StartMinute = 0, ZoneConfigs = new ZoneConfig[] { zoneConfig } } }))); }
public void TestNonOverlappingCycles() { var sprinklerController = new SprinklerController(); var zoneConfig = new ZoneConfig { ZoneNumber = 1, RunTime = 10 }; sprinklerController.AddProgram(new ProgramConfig("Program 1", new CycleConfig[] { new CycleConfig() { DaysOfWeek = new DayOfWeek[] { DayOfWeek.Monday }, StartHour = 9, StartMinute = 30, ZoneConfigs = new ZoneConfig[] { zoneConfig } } })); sprinklerController.AddProgram(new ProgramConfig("Program 2", new CycleConfig[] { new CycleConfig() { DaysOfWeek = new DayOfWeek[] { DayOfWeek.Monday }, StartHour = 9, StartMinute = 41, ZoneConfigs = new ZoneConfig[] { zoneConfig } } })); }
private void SwitchZoneSelector(ZoneConfig zoneConfig) { switch (zoneConfig) { case ZoneConfig.SoloMap: ZoneSelectionPanel.Content = _singleZoneSelector; break; case ZoneConfig.MultiMap: ZoneSelectionPanel.Content = _multipleMapSelector; break; } }
public void LoadFake() { AuthorizedDevices.Fake(); DeviceConfig.Fake(); EventConfig.Fake(); //GlobalConfig.Fake(); GsmConfig.Fake(); ZoneConfig.Fake(); UserConfig.Fake(); InputConfig.Fake(); OutputConfig.Fake(); RelayConfig.Fake(); }
public VyosConfiguration(ZoneConfig zoneConfig, CLIOptions options) { foreach (ZoneName zName in zoneConfig.Zones) { ZoneConfiguration.Add(zName, new ZoneConfiguration(zName, zoneConfig.ZoneDefinitions.GetValueOrDefault(zName, Zone.DefaultZone))); FirewallConfiguration.Add(zName, new Dictionary <ZoneName, FirewallConfiguration>()); foreach (ZoneName other in zoneConfig.Zones.Where(z => z != zName)) { var dict = FirewallConfiguration[zName]; dict.Add(other, new FirewallConfiguration($"{zName}-{other}", options)); } } foreach (var(zName, definition) in zoneConfig.ZoneDefinitions) { var pingableZones = definition.AllowPingTo == TargetDefinition.All ? TargetDefinition.GetTargetDefinition(FirewallConfiguration[zName].Keys.ToList()) : definition.AllowPingTo; foreach (var pingableZone in pingableZones) { FirewallConfiguration[zName][pingableZone.Name].AllowPing(); } var whitelistedZones = definition.AllowTrafficTo == TargetDefinition.All ? TargetDefinition.GetTargetDefinition(FirewallConfiguration[zName].Keys.ToList()) : definition.AllowTrafficTo; foreach (var whitelistedZone in whitelistedZones) { if (whitelistedZone.Name == TargetDefinition.WILDCARD) { foreach (var other in TargetDefinition.GetTargetDefinition(FirewallConfiguration[zName].Keys.ToList())) { FirewallConfiguration[zName][other.Name].AllowTraffic(whitelistedZone.AllowedPorts, whitelistedZone.AllowedAddresses); } } else { FirewallConfiguration[zName][whitelistedZone.Name].AllowTraffic(whitelistedZone.AllowedPorts, whitelistedZone.AllowedAddresses); } } } }
public void TestRunningZone() { var currentTime = DateTime.Now; var startTime = currentTime.Subtract(TimeSpan.FromMinutes(5)); var sprinklerController = new SprinklerController(); var zoneConfigs = new ZoneConfig[] { new ZoneConfig { ZoneNumber = 1, RunTime = 10 }, new ZoneConfig { ZoneNumber = 5, RunTime = 10 } }; var programId = sprinklerController.AddProgram(new ProgramConfig("Program 1", new CycleConfig[] { new CycleConfig() { DaysOfWeek = new DayOfWeek[] { startTime.DayOfWeek }, StartHour = startTime.Hour, StartMinute = startTime.Minute, ZoneConfigs = zoneConfigs } })); var program = sprinklerController.GetProgram(programId); Assert.IsTrue(program.Cycles[0].Zones[0].IsRunning(currentTime.DayOfWeek, currentTime.Hour, currentTime.Minute)); Assert.IsFalse(program.Cycles[0].Zones[1].IsRunning(currentTime.DayOfWeek, currentTime.Hour, currentTime.Minute)); currentTime = currentTime.AddMinutes(10); Assert.IsFalse(program.Cycles[0].Zones[0].IsRunning(currentTime.DayOfWeek, currentTime.Hour, currentTime.Minute)); Assert.IsTrue(program.Cycles[0].Zones[1].IsRunning(currentTime.DayOfWeek, currentTime.Hour, currentTime.Minute)); }
/// <summary> /// Tries to retrieve a <see cref="ZoneConfig"/> by its id /// </summary> public bool TryGetZoneConfig(int zoneId, out ZoneConfig zoneConfig) { zoneConfig = null; return(this.zones != null && (zoneConfig = Array.Find(this.zones, z => z.id == zoneId)) != null); }
public ZoneConfigChange(RoutedEvent routedEvent, ZoneConfig zoneConfig) : base(routedEvent) { this._zoneConfig = zoneConfig; }