public async Task <AreaDescriptor> CheckArea(int id, string name) { while (adding) { await Task.Delay(1000); } if (!Collection.Any(a => a.Id == id)) { var area = new AreaDescriptor() { Id = id, Name = name }; adding = true; await Dispatcher.UIThread.InvokeAsync(() => { Collection.Add(area); adding = false; }); return(area); } else { return(Collection.First(a => a.Id == id)); } }
public Room(string uid, IEnumerable <string> neighbors, string lamp, IConcurrencyProvider concurrencyProvider, ILogger logger, IMessageBroker messageBroker, AreaDescriptor areaDescriptor, MotionConfiguration motionConfiguration) { Uid = uid ?? throw new ArgumentNullException(nameof(uid)); _neighbors = neighbors ?? throw new ArgumentNullException(nameof(neighbors)); _lamp = lamp ?? throw new ArgumentNullException(nameof(lamp)); _logger = logger; _motionConfiguration = motionConfiguration; _concurrencyProvider = concurrencyProvider; _messageBroker = messageBroker; _areaDescriptor = areaDescriptor; if (areaDescriptor.WorkingTime == WorkingTime.DayLight) { _turnOnConditionsValidator.WithCondition(new IsDayCondition(_messageBroker)); } else if (areaDescriptor.WorkingTime == WorkingTime.AfterDusk) { _turnOnConditionsValidator.WithCondition(new IsNightCondition(_messageBroker)); } _turnOnConditionsValidator.WithCondition(new IsEnabledAutomationCondition(this)); _turnOffConditionsValidator.WithCondition(new IsEnabledAutomationCondition(this)); _turnOffConditionsValidator.WithCondition(new IsTurnOffAutomaionCondition(this)); _TurnOffTimeOut = new Timeout(_areaDescriptor.TurnOffTimeout, _motionConfiguration.TurnOffPresenceFactor); }
public void WriteControllerActions_MultiAction() { var area = new AreaDescriptor(""); var controller = new ControllerDescriptor(area, "Home"); controller.Actions.Add(new ActionDescriptor(controller, "Index")); controller.Actions.Add(new ActionDescriptor(controller, "Contact")); // Act CodeGenerator.WriteControllerActions(_writer, controller); // Assert Assert.Equal(@"public HomeControllerActions Home => new HomeControllerActions(urlHelper); public class HomeControllerActions { private readonly IUrlHelper urlHelper; public HomeControllerActions(IUrlHelper urlHelper) { this.urlHelper = urlHelper; } public string Index() => urlHelper.Action(""Index"", ""Home"", new { area = """" }); public string Contact() => urlHelper.Action(""Contact"", ""Home"", new { area = """" }); } ", _code.ToString()); }
public Room(string uid, IEnumerable <string> neighbors, Component lamp, IDaylightService daylightService, IConcurrencyProvider concurrencyProvider, ILogger logger, AreaDescriptor areaDescriptor, MotionConfiguration motionConfiguration, IEnumerable <IEventDecoder> eventsDecoders) { Uid = uid ?? throw new ArgumentNullException(nameof(uid)); Neighbors = neighbors ?? throw new ArgumentNullException(nameof(neighbors)); Lamp = lamp ?? throw new ArgumentNullException(nameof(lamp)); if (areaDescriptor.WorkingTime == WorkingTime.DayLight) { _turnOnConditionsValidator.WithCondition(ConditionRelation.And, new IsDayCondition(daylightService)); } else if (areaDescriptor.WorkingTime == WorkingTime.AfterDusk) { _turnOnConditionsValidator.WithCondition(ConditionRelation.And, new IsNightCondition(daylightService)); } _turnOnConditionsValidator.WithCondition(ConditionRelation.And, new IsEnabledAutomationCondition(this)); _turnOffConditionsValidator.WithCondition(ConditionRelation.And, new IsEnabledAutomationCondition(this)); _turnOffConditionsValidator.WithCondition(ConditionRelation.And, new IsTurnOffAutomaionCondition(this)); _logger = logger; _motionConfiguration = motionConfiguration; _concurrencyProvider = concurrencyProvider; _eventsDecoders = eventsDecoders; AreaDescriptor = areaDescriptor; _TurnOffTimeOut = new Timeout(AreaDescriptor.TurnOffTimeout, _motionConfiguration.TurnOffPresenceFactor); _eventsDecoders?.ForEach(decoder => decoder.Init(this)); }
public void WriteAreaActions_MultiController() { var area = new AreaDescriptor("Custom"); area.Controllers.Add(new ControllerDescriptor(area, "Home")); area.Controllers.Add(new ControllerDescriptor(area, "Contact")); // Act CodeGenerator.WriteAreaActions(_writer, area); // Assert Assert.Equal(@"public static CustomUrlActions CustomActions(this IUrlHelper urlHelper) => new CustomUrlActions(urlHelper); public class CustomUrlActions { private readonly IUrlHelper urlHelper; public CustomUrlActions(IUrlHelper urlHelper) { this.urlHelper = urlHelper; } public HomeControllerActions Home => new HomeControllerActions(urlHelper); public class HomeControllerActions { private readonly IUrlHelper urlHelper; public HomeControllerActions(IUrlHelper urlHelper) { this.urlHelper = urlHelper; } } public ContactControllerActions Contact => new ContactControllerActions(urlHelper); public class ContactControllerActions { private readonly IUrlHelper urlHelper; public ContactControllerActions(IUrlHelper urlHelper) { this.urlHelper = urlHelper; } } } ", _code.ToString()); }
public void WriteAction_Simple() { var area = new AreaDescriptor(""); var controller = new ControllerDescriptor(area, "Home"); var action = new ActionDescriptor(controller, "Index"); // Act CodeGenerator.WriteAction(_writer, action); // Assert Assert.Equal(@"public string Index() => urlHelper.Action(""Index"", ""Home"", new { area = """" }); ", _code.ToString()); }
public void WriteAction_WithParametersDefaultValue() { var area = new AreaDescriptor(""); var controller = new ControllerDescriptor(area, "Home"); var action = new ActionDescriptor(controller, "List"); action.Parameters.Add(new ParameterDescriptor("search", "string", false, null)); action.Parameters.Add(new ParameterDescriptor("page", "int", true, 1)); // Act CodeGenerator.WriteAction(_writer, action); // Assert Assert.Equal(@"public string List(string search, int page = 1) => urlHelper.Action(""List"", ""Home"", new { area = """", search, page }); ", _code.ToString()); }
public void WriteControllerActions_NoAction() { var area = new AreaDescriptor(""); var controller = new ControllerDescriptor(area, "Home"); // Act CodeGenerator.WriteControllerActions(_writer, controller); // Assert Assert.Equal(@"public HomeControllerActions Home => new HomeControllerActions(urlHelper); public class HomeControllerActions { private readonly IUrlHelper urlHelper; public HomeControllerActions(IUrlHelper urlHelper) { this.urlHelper = urlHelper; } } ", _code.ToString()); }
public void WriteAreaActions_CustomArea() { var area = new AreaDescriptor("Custom"); // Act CodeGenerator.WriteAreaActions(_writer, area); // Assert Assert.Equal(@"public static CustomUrlActions CustomActions(this IUrlHelper urlHelper) => new CustomUrlActions(urlHelper); public class CustomUrlActions { private readonly IUrlHelper urlHelper; public CustomUrlActions(IUrlHelper urlHelper) { this.urlHelper = urlHelper; } } ", _code.ToString()); }