public IActionResult AddNode(Node node) { if (node == null) { throw new ArgumentNullException(nameof(node)); } try { if (!IsNodeValid(node)) { throw new InvalidNodeException(); } var dbOptions = new DbContextOptionsBuilder <ServerDbContext>() .UseSqlServer(DbConnectionString) .Options; NodeDAL dal = new NodeDAL(new ServerDbContext(dbOptions)); dal.AddNode(node); foreach (IAddNodePlugin plugin in GetPlugins()) { plugin.AfterNodeAdded(node); } _currentIndex = 0; return(Ok()); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex)); } }
public NodeDALTest() { // create in-memory DB just for this test var dbOptions = new DbContextOptionsBuilder <ServerDbContext>().UseInMemoryDatabase("UnitTests").Options; _dbContext = new ServerDbContext(dbOptions); // this is important, in-mempry DB exists for the whole lifetime of the process _dbContext.Database.EnsureDeleted(); _dal = new NodeDAL(_dbContext); }
public ActionResult Delete(NodeModel model) { if (NodeDAL.DeleteSubNodes(model)) { LogDAL.AppendSQLLog(MTConfig.CurrentUserID, "Node"); return(JsonSuccess(DeleteSuccess, "/Admin/Node/Index")); } return(Error(DeleteError)); }
private void CreateConfiguration_Services() { ZoneGuardConfigContextFactory factory = new ZoneGuardConfigContextFactory(); Guid serverNodeGuid = new Guid("5c7a6580-45fc-4402-9ebe-07de9884f5b0"); using (ZoneGuardConfigContext context = factory.CreateDbContext()) { node = null; if (!context.Node.Any()) { node = new NodeDAL { UniqueIdentifier = serverNodeGuid, Name = "Server" }; context.Node.Add(node); context.SaveChanges(); } else { node = context.Node.Where <NodeDAL>(n => n.UniqueIdentifier == serverNodeGuid).FirstOrDefault <NodeDAL>(); } ThingDAL thing; thing = AddService(context, "MQ", "MQ Client", ThingType.Service, new Dictionary <string, string> { { "category", "service" }, { "config_class", "ConfigServiceMQ" }, { "thing_class", "ServiceMQ" }, { "name", "MQ" }, { "host", "192.168.9.40" }, { "user", "svc-alarm-test" }, { "password", "Alarm01" }, { "vhost", "zoneguard-test" } }); //ConfigServiceMQTT csMQTT = new ConfigServiceMQTT(paramMQTT); //addService(new ServiceMQTT(new ConfigServiceMQTT(paramMQTT), this)); thing = AddService(context, "MQTT", "MQTT Client", ThingType.Service, new Dictionary <string, string> { { "category", "service" }, { "config_class", "ConfigServiceMQTT" }, { "thing_class", "ServiceMQTT" }, { "name", "MQTT" }, { "host", "192.168.1.50" }, { "user", "svc-openhab" }, { "password", "#openHAB@Home#" } }); } }
/// <summary> /// 使用在列表页面 首页等位置 生成头部的title keywords description /// </summary> /// <param name="controller"></param> /// <param name="areaName"></param> /// <param name="controllerName"></param> /// <param name="actionName"></param> public static void GetHeadMeta(this Controller controller, string areaName, string controllerName, string actionName) { List <NodeModel> nodeList = NodeDAL.GetNodeByArea(areaName); string link = "/" + string.Join("/", new[] { areaName, controllerName, actionName }); var actionObj = nodeList.FirstOrDefault(s => !string.IsNullOrEmpty(s.Link) && s.Link.ToLower() == link.ToLower()); controller.ViewBag.Title = ""; controller.ViewBag.Keywords = ""; controller.ViewBag.Description = ""; if (actionObj != null) { controller.ViewBag.Title = actionObj.HeadTitle; controller.ViewBag.Keywords = actionObj.HeadKeywords; controller.ViewBag.Description = actionObj.HeadDescription; } }
/// <summary> /// 使用在列表页面 首页等位置 生成头部的title keywords description /// </summary> /// <param name="controller"></param> public static void GetHeadMeta(this Controller controller) { List <NodeModel> nodeList = NodeDAL.GetNodeByArea(HtmlExtend.GetArea()); RouteValueDictionary vd = controller.RouteData.Values; string actionName = vd["action"].ToString().ToLower(); string controllerName = vd["controller"].ToString().ToLower(); string link = "/" + string.Join("/", new[] { HtmlExtend.GetArea(), controllerName, actionName }); var actionObj = nodeList.FirstOrDefault(s => !string.IsNullOrEmpty(s.Link) && s.Link.ToLower() == link); controller.ViewBag.Title = ""; controller.ViewBag.Keywords = ""; controller.ViewBag.Description = ""; if (actionObj != null) { controller.ViewBag.Title = actionObj.HeadTitle; controller.ViewBag.Keywords = actionObj.HeadKeywords; controller.ViewBag.Description = actionObj.HeadDescription; } }
public ActionResult Index(string token = "") { if (!string.IsNullOrEmpty(token)) { if (token == MTConfig.AdminToken) { MTConfig.CurrentUser = UserModel.FirstOrDefault("where Id = 1 "); } } if (MTConfig.CurrentUser == null) { return(RedirectToAction("Login")); } //List<NoticeModel> notmodels = // NoticeModel.Fetch("select top 10 * from Notice where userid = @0 and ConfirmTime is NULL", // MTConfig.CurrentUserID); //foreach (var item in notmodels) //{ // item.SendDate = DateTimeHelper.showTime(item.SendTime); //} //ViewBag.notmodels = notmodels; //int notcount = // NoticeModel.repo.ExecuteScalar<int>( // "select count(*) from Notice where userid = @0 and ConfirmTime is NULL", MTConfig.CurrentUserID); //ViewBag.notcount = notcount; #region 刷新当前用户权限信息 IndexViewModel model = new IndexViewModel(); MTConfig.AuthInfo = NodeDAL.GetAccessNodeList(MTConfig.CurrentUserID); model.NodeList = MTConfig.AuthInfo; MTConfig.CurrentRole = RoleDAL.GetAllRoleByUserID(MTConfig.CurrentUserID); MTConfig.CurrentUser = UserModel.FirstOrDefault("where Id = @0", MTConfig.CurrentUserID); model.UserInfo = MTConfig.CurrentUser; model.GroupList = GroupDAL.GetAllGroup(); #endregion return(View(model)); }
// Token: 0x06000880 RID: 2176 RVA: 0x0003E0E0 File Offset: 0x0003C2E0 public static Dictionary <string, object> GetVolumeCustomProperties(int volumeId, ICollection <string> properties) { Volume volume = VolumeDAL.GetVolume(volumeId); Dictionary <string, object> dictionary = new Dictionary <string, object>(); if (properties == null || properties.Count == 0) { properties = volume.CustomProperties.Keys; } MacroParser macroParser = new MacroParser(new Action <string, int>(BusinessLayerOrionEvent.WriteEvent)) { ObjectType = "Volume", ActiveObject = volume.ID.ToString(), NetObjectID = volume.ID.ToString(), NetObjectName = volume.FullName, NodeID = volume.NodeID, NodeName = NodeDAL.GetNode(volume.NodeID).Name }; using (macroParser.MyDBConnection = DatabaseFunctions.CreateConnection()) { foreach (string text in properties) { string key = text.Trim(); if (volume.CustomProperties.ContainsKey(key)) { object obj = volume.CustomProperties[key]; if (obj != null && obj.ToString().Contains("${")) { dictionary[key] = macroParser.ParseMacros(obj.ToString(), false); } else { dictionary[key] = obj; } } } } return(dictionary); }
public static Dictionary <string, object> GetVolumeCustomProperties( int volumeId, ICollection <string> properties) { Volume volume = VolumeDAL.GetVolume(volumeId); Dictionary <string, object> dictionary = new Dictionary <string, object>(); if (properties == null || properties.Count == 0) { properties = volume.get_CustomProperties().Keys; } MacroParser macroParser1 = new MacroParser(new Action <string, int>(BusinessLayerOrionEvent.WriteEvent)); macroParser1.set_ObjectType("Volume"); macroParser1.set_ActiveObject(volume.get_ID().ToString()); macroParser1.set_NetObjectID(volume.get_ID().ToString()); macroParser1.set_NetObjectName(volume.get_FullName()); macroParser1.set_NodeID(volume.get_NodeID()); macroParser1.set_NodeName(NodeDAL.GetNode(volume.get_NodeID()).get_Name()); MacroParser macroParser2 = macroParser1; SqlConnection connection; macroParser2.set_MyDBConnection(connection = DatabaseFunctions.CreateConnection()); using (connection) { foreach (string property in (IEnumerable <string>)properties) { string key = property.Trim(); if (volume.get_CustomProperties().ContainsKey(key)) { object customProperty = volume.get_CustomProperties()[key]; dictionary[key] = customProperty == null || !customProperty.ToString().Contains("${") ? customProperty : (object)macroParser2.ParseMacros(customProperty.ToString(), false); } } } return(dictionary); }
//, Dictionary<string, string> parameters private ThingDAL AddMQTTSensor(ZoneGuardConfigContext context, NodeDAL node, String Name, String _description, ThingType _type, String sensorType, String locationId, Boolean isPerimeter, String topicOffset) { ThingDAL thing = null; List <ThingParameterDAL> thingParameters = new List <ThingParameterDAL>(); DateTime timestamp = DateTime.UtcNow; thing = new ThingDAL { Name = Name, Description = _description, ThingType = _type, NodeId = node.Id, Timestamp = timestamp }; thingParameters.Add(new ThingParameterDAL { Name = ConfigCore.PARAMETER_THING_CATEGORY, Value = "sensor", Timestamp = timestamp }); thingParameters.Add(new ThingParameterDAL { Name = ConfigCore.PARAMETER_CONFIG_CLASS, Value = "ConfigSensor", Timestamp = timestamp }); thingParameters.Add(new ThingParameterDAL { Name = ConfigCore.PARAMETER_THING_CLASS, Value = "SensorMQTT", Timestamp = timestamp }); thingParameters.Add(new ThingParameterDAL { Name = ConfigCore.PARAMETER_TYPE, Value = sensorType, Timestamp = timestamp }); thingParameters.Add(new ThingParameterDAL { Name = ConfigCore.PARAMETER_NAME, Value = Name, Timestamp = timestamp }); thingParameters.Add(new ThingParameterDAL { Name = ConfigCore.PARAMETER_IS_PERIMETER, Value = isPerimeter.ToString().ToLower() }); thingParameters.Add(new ThingParameterDAL { Name = ConfigCore.PARAMETER_TOPIC_STATE, Value = topicOffset + locationId.ToLower() + "/" + Name.ToLower() + "/state" }); thingParameters.Add(new ThingParameterDAL { Name = ConfigCore.PARAMETER_TOPIC_COMMAND, Value = "" }); DbInitializer.ThingConfig_Create(context, thing, thingParameters.ToArray()); return(thing); }
/// <summary> /// 获得所有节点 /// </summary> /// <param name="roleId"></param> /// <param name="productId"></param> /// <returns></returns> public ActionResult TreeNode(int?roleId) { List <NodeModel> accessList = NodeDAL.GetAccessByRole(roleId); return(Json(accessList, JsonRequestBehavior.AllowGet)); }