protected override IQueryable <RuleInterfaceInstance> GetAll(AutomaticaContext context)
 {
     return(context.RuleInterfaceInstances
            .Include(a => a.This2RuleInstanceNavigation)
            .Include(a => a.This2RuleInterfaceTemplateNavigation)
            .AsNoTracking());
 }
Esempio n. 2
0
        public static IList <RuleFactory> LoadSingle(ILogger logger, Plugin plugin, AutomaticaContext database)
        {
            var fileInfo = new FileInfo(Assembly.GetEntryAssembly().Location);
            var dir      = Path.Combine(fileInfo.DirectoryName, ServerInfo.LogicsDirectory, plugin.ComponentName);

            return(Loader.Load <RuleFactory>(dir, "*.dll", logger, database, false));
        }
Esempio n. 3
0
 private string GetApiKey()
 {
     using (var dbContext = new AutomaticaContext(_config))
     {
         return($"{dbContext.Settings.SingleOrDefault(a => a.ValueKey == "apiKey").ValueText}/{ServerInfo.ServerUid}");
     }
 }
Esempio n. 4
0
 public Setting GetSetting(string key)
 {
     using (var db = new AutomaticaContext(_config))
     {
         return(db.Settings.SingleOrDefault(a => a.ValueKey == key));
     }
 }
Esempio n. 5
0
        private static AreaInstance RecursiveLoad(AreaInstance parent, AutomaticaContext dbContext)
        {
            var loaded = dbContext.AreaInstances
                         .Include(a => a.InverseThis2ParentNavigation)
                         .Include(a => a.This2AreaTemplateNavigation)
                         .ThenInclude(a => a.This2AreaTypeNavigation)
                         .Include(a => a.This2AreaTemplateNavigation)
                         .ThenInclude(a => a.NeedsThis2AreaTypeNavigation)
                         .Include(a => a.This2AreaTemplateNavigation)
                         .ThenInclude(a => a.ProvidesThis2AreayTypeNavigation).SingleOrDefault(a => a.ObjId == parent.ObjId);

            var newChilds = new List <AreaInstance>();

            if (loaded == null)
            {
                return(null);
            }

            foreach (var child in loaded.InverseThis2ParentNavigation)
            {
                newChilds.Add(RecursiveLoad(child, dbContext));
            }

            loaded.InverseThis2ParentNavigation = newChilds;
            return(loaded);
        }
Esempio n. 6
0
        public async Task RemoveLogicInstance()
        {
            await using var db = new AutomaticaContext(Configuration);

            var logicTemplateFactory = new RuleTemplateFactory(db, Configuration);

            var pages = Controller.GetPages().ToList();
            var page  = pages.First();

            var ruleInstance1 = logicTemplateFactory.CreateRuleInstance(Controller.GetRuleTemplates().First());
            var ruleInstance2 = logicTemplateFactory.CreateRuleInstance(Controller.GetRuleTemplates().First());

            page.RuleInstance.Add(ruleInstance1);
            page.RuleInstance.Add(ruleInstance2);

            var savedPages = (await Controller.Save(pages)).ToList();

            var ruleInstance2ToRemove = savedPages.First().RuleInstance.First(a => a.ObjId == ruleInstance2.ObjId);

            savedPages.First().RuleInstance.Remove(ruleInstance2ToRemove);

            savedPages = (await Controller.Save(savedPages)).ToList();

            Assert.Single(savedPages.First().RuleInstance);
            Assert.Equal(savedPages.First().RuleInstance.First().ObjId, ruleInstance1.ObjId);
        }
Esempio n. 7
0
        protected override IQueryable <RuleInstance> GetAll(AutomaticaContext context)
        {
            var all = context.RuleInstances
                      .Include(a => a.RuleInterfaceInstance)
                      .ThenInclude(a => a.This2RuleInterfaceTemplateNavigation)
                      .AsNoTracking();

            foreach (var item in all)
            {
                if (item.This2AreaInstance.HasValue)
                {
                    if (!_areaCache.ContainsKey(item.This2AreaInstance.Value))
                    {
                        _areaCache.Add(item.This2AreaInstance.Value, new List <RuleInstance>());
                    }

                    _areaCache[item.This2AreaInstance.Value].Add(item);
                }

                if (item.This2CategoryInstance.HasValue)
                {
                    if (!_categoryCache.ContainsKey(item.This2CategoryInstance.Value))
                    {
                        _categoryCache.Add(item.This2CategoryInstance.Value, new List <RuleInstance>());
                    }

                    _categoryCache[item.This2CategoryInstance.Value].Add(item);
                }
            }

            return(all);
        }
Esempio n. 8
0
        public async Task TestAddLogicInstancesAndLink()
        {
            await using var db = new AutomaticaContext(Configuration);

            var logicTemplateFactory = new RuleTemplateFactory(db, Configuration);

            var pages = Controller.GetPages().ToList();
            var page  = pages.First();

            var ruleInstance1 = logicTemplateFactory.CreateRuleInstance(Controller.GetRuleTemplates().First());
            var ruleInstance2 = logicTemplateFactory.CreateRuleInstance(Controller.GetRuleTemplates().First());

            page.RuleInstance.Add(ruleInstance1);
            page.RuleInstance.Add(ruleInstance2);

            page.Link.Add(new Link
            {
                This2RuleInterfaceInstanceInputNavigation  = ruleInstance2.RuleInterfaceInstance.First(a => a.This2RuleInterfaceTemplateNavigation.This2RuleInterfaceDirection == (long)RuleInterfaceDirection.Input),
                This2RuleInterfaceInstanceOutputNavigation = ruleInstance2.RuleInterfaceInstance.First(a => a.This2RuleInterfaceTemplateNavigation.This2RuleInterfaceDirection == (long)RuleInterfaceDirection.Output)
            });

            var savedPages = (await Controller.Save(pages)).ToList();

            Assert.Equal(2, savedPages.First().RuleInstance.Count);
            Assert.NotEmpty(savedPages.First().Link);
        }
Esempio n. 9
0
        private static void GenerateIfNotExists(AutomaticaContext context, Guid objId, Guid category, string name, string icon)
        {
            CategoryInstance group = context.CategoryInstances.SingleOrDefault(a => a.ObjId == objId);

            bool isNew = false;

            if (group == null)
            {
                isNew = true;
                group = new CategoryInstance()
                {
                    ObjId        = objId,
                    Color        = "rgba(255, 255, 255, 1)",
                    IsFavorite   = false,
                    Rating       = 1,
                    Icon         = icon,
                    IsDeleteable = false
                };
            }

            group.Name               = $"COMMON.CATEGORY_INSTANCE.{name.ToUpperInvariant()}.NAME";
            group.Description        = $"COMMON.CATEGORY_INSTANCE.{name.ToUpperInvariant()}.DESCRIPTION";
            group.This2CategoryGroup = category;
            group.IsDeleteable       = false;
            group.Icon               = icon;

            if (isNew)
            {
                context.CategoryInstances.Add(group);
            }
            else
            {
                context.CategoryInstances.Update(group);
            }
        }
Esempio n. 10
0
 private VisuPage LoadPage(AutomaticaContext context, Guid pageId)
 {
     return(context.VisuPages
            .AsNoTracking()
            .Include(a => a.VisuObjectInstances)
            .ThenInclude(b => b.PropertyInstance)
            .ThenInclude(c => c.This2PropertyTemplateNavigation)
            .ThenInclude(c => c.Constraints)
            .ThenInclude(c => c.ConstraintData).Include(a => a.VisuObjectInstances)
            .ThenInclude(a => a.This2VisuObjectTemplateNavigation)
            .Include(a => a.VisuObjectInstances)
            .ThenInclude(b => b.PropertyInstance).ThenInclude(c => c.This2PropertyTemplateNavigation)
            .ThenInclude(d => d.This2PropertyTypeNavigation)
            .Include(a => a.VisuObjectInstances)
            .ThenInclude(b => b.PropertyInstance)
            .ThenInclude(b => b.ValueNodeInstanceNavigation)
            .Include(a => a.This2VisuPageTypeNavigation)
            .Include(a => a.VisuObjectInstances)
            .ThenInclude(b => b.PropertyInstance)
            .ThenInclude(b => b.ValueRulePageNavigation)
            .Include(a => a.VisuObjectInstances)
            .ThenInclude(b => b.PropertyInstance)
            .ThenInclude(b => b.ValueVisuPageNavigation).Include(a => a.VisuObjectInstances)
            .ThenInclude(a => a.PropertyInstance)
            .ThenInclude(a => a.ValueAreaInstanceNavigation).Single(a => a.ObjId == pageId));
 }
Esempio n. 11
0
 private string GetUrl()
 {
     using (var dbContext = new AutomaticaContext(_config))
     {
         return($"{dbContext.Settings.SingleOrDefault(a => a.ValueKey == "cloudUrl").ValueText}");
     }
 }
Esempio n. 12
0
        public void Init()
        {
            _timer.Stop();
            using (var context = new AutomaticaContext(_config))
            {
                var autoUpdate     = context.Settings.SingleOrDefault(a => a.ValueKey == "autoUpdate");
                var autoUpdateTime = context.Settings.SingleOrDefault(a => a.ValueKey == "autoUpdateTime");

                if (autoUpdate != null && (bool)autoUpdate.Value && autoUpdateTime != null && autoUpdateTime.Value is DateTime updateTime)
                {
                    var now             = DateTime.Now;
                    var updateTimeToday = new DateTime(now.Year, now.Month, now.Day, updateTime.Hour, updateTime.Minute,
                                                       updateTime.Second);

                    if (now > updateTimeToday)
                    {
                        updateTimeToday = updateTimeToday.AddDays(1);
                    }
                    var diff = (updateTimeToday - now).TotalSeconds;

                    _timer.Interval = diff * 1000;
                    SystemLogger.Instance.LogInformation($"Next check for update is in {diff} seconds at {updateTimeToday}");
                    _timer.Start();
                }
                else
                {
                    SystemLogger.Instance.LogInformation("Auto update seems to be disabled");
                }
            }
        }
Esempio n. 13
0
        protected override IQueryable <VisuPage> GetAll(AutomaticaContext context)
        {
            var pages = context.VisuPages.AsNoTracking().ToList();

            var ret = new List <VisuPage>();

            foreach (var page in pages)
            {
                var loadedPage = LoadPage(context, page.ObjId);
                ret.Add(loadedPage);

                if (loadedPage.DefaultPage)
                {
                    if (!_defaultPages.ContainsKey(loadedPage.This2VisuPageType))
                    {
                        _defaultPages.Add(loadedPage.This2VisuPageType, loadedPage);
                    }
                    else
                    {
                        _defaultPages[loadedPage.This2VisuPageType] = loadedPage;
                    }
                }
            }

            return(ret.AsQueryable());
        }
Esempio n. 14
0
 public void Add(Trending value, NodeInstance nodeInstance)
 {
     using var context = new AutomaticaContext(_config);
     _logger.LogInformation($"Save trend for {nodeInstance.Name} ({nodeInstance.ObjId}) with value {value.Value}...");
     context.Add(value);
     context.SaveChanges();
 }
Esempio n. 15
0
        public static void GenerateIfNotExists(AutomaticaContext context, Guid objId, string name)
        {
            CategoryGroup group = context.CategoryGroups.SingleOrDefault(a => a.ObjId == objId);

            bool isNew = false;

            if (group == null)
            {
                isNew = true;
                group = new CategoryGroup()
                {
                    ObjId = objId
                };
            }

            group.Name        = $"COMMON.CATEGORY_GROUP.{name.ToUpperInvariant()}.NAME";
            group.Description = $"COMMON.CATEGORY_GROUP.{name.ToUpperInvariant()}.DESCRIPTION";

            if (isNew)
            {
                context.CategoryGroups.Add(group);
            }
            else
            {
                context.CategoryGroups.Update(group);
            }
        }
Esempio n. 16
0
        protected override IQueryable <Setting> GetAll(AutomaticaContext context)
        {
            var settings = context.Settings.AsNoTracking().Where(a => a.IsVisible).OrderBy(a => a.Order).ToList();

            settings.Add(new Setting
            {
                ValueKey   = "ServerUid",
                Order      = -1,
                Type       = (long)PropertyTemplateType.Text,
                Value      = ServerInfo.ServerUid,
                Group      = "SERVER.COMMON",
                IsReadonly = true,
                IsVisible  = true,
                ObjId      = -5000
            });

            foreach (var setting in settings)
            {
                _byKeyCache.Add(setting.ValueKey, setting);
            }

            var all = settings.OrderBy(a => a.Order).AsQueryable();

            return(all);
        }
Esempio n. 17
0
 protected override IQueryable <RulePage> GetAll(AutomaticaContext context)
 {
     return(context.RulePages.Include(a => a.This2RulePageTypeNavigation)
            .Include(a => a.Link)
            .ThenInclude(a => a.This2NodeInstance2RulePageInputNavigation)
            .ThenInclude(a => a.This2NodeInstanceNavigation)
            .ThenInclude(a => a.This2NodeTemplateNavigation)
            .Include(a => a.Link)
            .ThenInclude(a => a.This2NodeInstance2RulePageOutputNavigation)
            .ThenInclude(a => a.This2NodeInstanceNavigation)
            .ThenInclude(a => a.This2NodeTemplateNavigation)
            .Include(a => a.Link)
            .ThenInclude(a => a.This2RuleInterfaceInstanceInputNavigation)
            .ThenInclude(a => a.This2RuleInstanceNavigation)
            .Include(a => a.Link)
            .ThenInclude(a => a.This2RuleInterfaceInstanceOutputNavigation)
            .ThenInclude(a => a.This2RuleInstanceNavigation)
            .Include(a => a.NodeInstance2RulePage).ThenInclude(b => b.This2NodeInstanceNavigation)
            .ThenInclude(x => x.PropertyInstance)
            .Include(a => a.NodeInstance2RulePage).ThenInclude(b => b.This2NodeInstanceNavigation)
            .ThenInclude(b => b.This2NodeTemplateNavigation)
            .Include(a => a.RuleInstance).ThenInclude(a => a.This2RuleTemplateNavigation)
            .ThenInclude(a => a.RuleInterfaceTemplate)
            .Include(a => a.RuleInstance).ThenInclude(a => a.RuleInterfaceInstance)
            .ThenInclude(a => a.This2RuleInterfaceTemplateNavigation)
            .ThenInclude(a => a.This2RuleInterfaceDirectionNavigation)
            .Include(a => a.RuleInstance).ThenInclude(a => a.This2AreaInstanceNavigation)
            .Include(a => a.RuleInstance).ThenInclude(a => a.This2CategoryInstanceNavigation));
 }
 public NodeInstanceController(AutomaticaContext db, INotifyDriver notifyDriver, INodeInstanceCache nodeInstanceCache, ICoreServer server)
     : base(db)
 {
     _notifyDriver      = notifyDriver;
     _nodeInstanceCache = nodeInstanceCache;
     _server            = server;
 }
Esempio n. 19
0
 public static void GenerateDefault(AutomaticaContext context)
 {
     GenerateIfNotExists(context, ShadingGroup, "SHADING");
     GenerateIfNotExists(context, LightningGroup, "LIGHTNING");
     GenerateIfNotExists(context, HvacGroup, "HVAC");
     GenerateIfNotExists(context, MultimediaGroup, "MULTIMEDIA");
     GenerateIfNotExists(context, OtherGroup, "OTHER");
 }
Esempio n. 20
0
        public async Task RemoveAll()
        {
            await using var db = new AutomaticaContext(Configuration);

            var empty = await Controller.Save(new List <RulePage>());

            Assert.Empty(empty);
        }
Esempio n. 21
0
 public DriverLoader(ILogger <DriverLoader> logger, AutomaticaContext dbContext, ILocalizationProvider localizationProvider, IConfiguration config, ILoadedStore store, IDriverFactoryStore driverFactoryStore)
 {
     _logger               = logger;
     _dbContext            = dbContext;
     _localizationProvider = localizationProvider;
     _config               = config;
     _store = store;
     _driverFactoryStore = driverFactoryStore;
 }
Esempio n. 22
0
 protected override IQueryable <Link> GetAll(AutomaticaContext context)
 {
     return(context.Links
            .Include(a => a.This2NodeInstance2RulePageInputNavigation)
            .Include(a => a.This2NodeInstance2RulePageOutputNavigation)
            .Include(a => a.This2RuleInterfaceInstanceInputNavigation)
            .Include(a => a.This2RuleInterfaceInstanceOutputNavigation)
            .AsNoTracking());
 }
Esempio n. 23
0
 public PluginHandler(ILogger <PluginHandler> logger, AutomaticaContext dbContext, IDriverLoader driverLoader, ILogicLoader logicLoader, INodeTemplateCache nodeTemplateCache, IConfiguration config, IPluginInstaller pluginInstaller)
 {
     _logger            = logger;
     _dbContext         = dbContext;
     _driverLoader      = driverLoader;
     _logicLoader       = logicLoader;
     _nodeTemplateCache = nodeTemplateCache;
     _config            = config;
     _pluginInstaller   = pluginInstaller;
 }
Esempio n. 24
0
        private void AddLogicTemplate()
        {
            using var db = new AutomaticaContext(Configuration);

            var logicTemplateFactory = new RuleTemplateFactory(db, Configuration);

            var factory = new TestLogicFactory();

            factory.InitTemplates(logicTemplateFactory);
        }
Esempio n. 25
0
        protected override IQueryable <NodeTemplate> GetAll(AutomaticaContext context)
        {
            var x = context.NodeTemplates.AsNoTracking()
                    .Include(a => a.This2NodeDataTypeNavigation)
                    .Include(a => a.NeedsInterface2InterfacesTypeNavigation)
                    .Include(a => a.ProvidesInterface2InterfaceTypeNavigation)
                    .Include(a => a.PropertyTemplate).ThenInclude(b => b.This2PropertyTypeNavigation)
                    .Include(a => a.PropertyTemplate).ThenInclude(b => b.Constraints).ThenInclude(c => c.ConstraintData);

            return(x);
        }
Esempio n. 26
0
 public RulesController(AutomaticaContext db, IRuleDataHandler ruleDataHandler, ILogicCacheFacade logicCacheFacade, IConfiguration config,
                        INotifyDriver notifyDriver, INodeInstanceCache nodeInstanceCache, ICoreServer coreServer)
     : base(db)
 {
     _ruleDataHandler   = ruleDataHandler;
     _logicCacheFacade  = logicCacheFacade;
     _config            = config;
     _notifyDriver      = notifyDriver;
     _nodeInstanceCache = nodeInstanceCache;
     _coreServer        = coreServer;
 }
Esempio n. 27
0
        public void Initialize(AutomaticaContext database, IConfiguration config)
        {
            var factory = new VisuMobileTemplateFactory(database, config);

            var label = VisuMobileObjectTemplateTypeAttribute.GetFromEnum(VisuMobileObjectTemplateTypes.Label);

            factory.CreateVisuMobileTemplate(label, "VISU.OBJECT.LABEL.NAME", "VISU.OBJECT.LABEL.DESCRIPTION", "label", "VISU.CATEGORY.COMMON.NAME", 1, 1, true);

            AddCommonProperty(label, factory);
            AddTextProperty(label, factory);

            factory.CreatePropertyTemplate(new Guid("d7d8dd9d-3c45-44b6-9bbd-d7d00825ebdb"), "VISU.APPEARANCE.NODE_VALUE.NAME", "VISU.APPEARANCE.NODE_VALUE.DESCRIPTION", "nodeInstance",
                                           PropertyTemplateType.NodeInstance, label, "VISU.CATEGORY.APPEARANCE.NAME", true, false, null, null, 1, 2);

            var link = VisuMobileObjectTemplateTypeAttribute.GetFromEnum(VisuMobileObjectTemplateTypes.Link);

            factory.CreateVisuMobileTemplate(link, "VISU.OBJECT.LINK.NAME", "VISU.OBJECT.LINK.DESCRIPTION", "link",
                                             "VISU.CATEGORY.COMMON.NAME", 1, 1, true);
            factory.CreatePropertyTemplate(new Guid("bea56e63-47e9-4050-9333-e54de0cdcfb6"), "VISU.APPEARANCE.LINK.NAME", "VISU.APPEARANCE.LINK.DESCRIPTION", "link",
                                           PropertyTemplateType.VisuMobilePage, link, "VISU.CATEGORY.APPEARANCE.NAME", true, false, null, null, 1, 2);

            factory.CreatePropertyTemplate(new Guid("fb20bc35-3b9a-4b70-8483-ba79c5cd8cf0"), "VISU.APPEARANCE.AREA_LINK.NAME", "VISU.APPEARANCE.AREA_LINK.DESCRIPTION", "area_link",
                                           PropertyTemplateType.AreaInstanceLink, link, "VISU.CATEGORY.APPEARANCE.NAME", true, false, null, null, 1, 2);

            AddTextProperty(link, factory);
            AddCommonProperty(link, factory);

            var slider = VisuMobileObjectTemplateTypeAttribute.GetFromEnum(VisuMobileObjectTemplateTypes.Slider);

            factory.CreateVisuMobileTemplate(slider, "VISU.OBJECT.SLIDER.NAME", "VISU.OBJECT.SLIDER.DESCRIPTION", "slider",
                                             "VISU.CATEGORY.COMMON.NAME", 1, 1, true);

            AddCommonProperty(slider, factory);
            AddTextProperty(slider, factory);

            factory.CreatePropertyTemplate(new Guid("ac6a8a89-6361-48c1-b1d9-82439eeff7ea"), "VISU.APPEARANCE.MIN.NAME", "VISU.APPEARANCE.MIN.DESCRIPTION", "min",
                                           PropertyTemplateType.Integer, slider, "VISU.CATEGORY.APPEARANCE.NAME", true, false, null, 0, 1, 2);

            factory.CreatePropertyTemplate(new Guid("55c3b706-62c4-4e9e-b066-798c893a8e9f"), "VISU.APPEARANCE.MAX.NAME", "VISU.APPEARANCE.MAX.DESCRIPTION", "max",
                                           PropertyTemplateType.Integer, slider, "VISU.CATEGORY.APPEARANCE.NAME", true, false, null, 100, 1, 2);

            factory.CreatePropertyTemplate(new Guid("e51cbe53-6301-4b11-a523-864f453b7b24"), "VISU.APPEARANCE.NODE_VALUE.NAME", "VISU.APPEARANCE.NODE_VALUE.DESCRIPTION", "nodeInstance",
                                           PropertyTemplateType.NodeInstance, slider, "VISU.CATEGORY.APPEARANCE.NAME", true, false, null, null, 1, 2);

            factory.CreatePropertyTemplate(new Guid("1b6b41c9-2494-42d4-893e-63d0d9fec2e7"), "VISU.APPEARANCE.READONLY.NAME", "VISU.APPEARANCE.READONLY.DESCRIPTION", "readonly",
                                           PropertyTemplateType.Bool, slider, "VISU.CATEGORY.APPEARANCE.NAME", true, false, "false", 100, 1, 2);

            AddToggleButton(factory);
            AddNumberBox(factory);


            AddWindowMonitor(factory);
            AddRgbControl(factory);
        }
Esempio n. 28
0
        private string GetCloudEnvironmentType()
        {
            using var dbContext = new AutomaticaContext(_config);
            var cloudEnv = dbContext.Settings.FirstOrDefault(a => a.ValueKey == "cloudEnvironment");

            if (cloudEnv == null)
            {
                return("develop");
            }
            return($"{cloudEnv.ValueText}");
        }
Esempio n. 29
0
        private string GetApiKey()
        {
            using var dbContext = new AutomaticaContext(_config);
            var apiKey = dbContext.Settings.First(a => a.ValueKey == "apiKey").ValueText;

            if (string.IsNullOrEmpty(apiKey))
            {
                throw new NoApiKeyException();
            }

            return($"{apiKey}/{ServerInfo.ServerUid}");
        }
Esempio n. 30
0
        protected override IQueryable <AreaInstance> GetAll(AutomaticaContext context)
        {
            var rootItems = context.AreaInstances.AsNoTracking().Where(a => a.This2Parent == null).ToList();
            var items     = new List <AreaInstance>();

            foreach (var root in rootItems)
            {
                items.Add(RecursiveLoad(root, context));
            }

            return(items.AsQueryable());
        }