public void AddService(PortInfo portInfo, string friendlyName, bool highSecurity, string locationStr, string[] apps) { logger.Log("AddService is called on " + friendlyName + " for " + portInfo.ToString() + " loc:" + locationStr + " sec: " + highSecurity + " #apps " + apps.Length.ToString()); portInfo.SetFriendlyName(friendlyName); portInfo.SetSecurity(highSecurity); Location location = config.GetLocation(locationStr); if (location == null) throw new Exception("Unknown location " + locationStr); portInfo.SetLocation(location); location.AddChildPort(portInfo); config.AddConfiguredPort(portInfo); foreach (string app in apps) { if (config.GetModule(app) != null) AllowAppAcccessToDevice(app, friendlyName); else logger.Log("ERROR: Could not give access to device {0} to app {1} because the app does not exist", friendlyName, app); //AccessRule rule = new AccessRule(); //rule.RuleName = portInfo.GetFriendlyName(); //rule.ModuleName = app; //rule.UserGroup = "everyone"; //rule.AccessMode = Common.AccessMode.Allow; //rule.Priority = 0; //rule.DeviceList = new List<string>(); //rule.DeviceList.Add(friendlyName); //rule.TimeList = new List<TimeOfWeek>(); //rule.TimeList.Add(new TimeOfWeek(-1, 0, 2400)); //policyEngine.AddAccessRule(rule); //config.AddAccessRule(rule); } //send port registration message to all modules now that this service has been registered // first, get the port object and the owner module VPort portToRegister = null; VModule ownerModule = null; lock (this) { foreach (VPort port in registeredPorts.Keys) { if (port.GetInfo().Equals(portInfo)) { portToRegister = port; ownerModule = registeredPorts[port]; break; } } } if (portToRegister != null) { SafeThread newThread = new SafeThread(delegate() { BroadcastPortRegistration(portToRegister, ownerModule); }, "AddService:RegisterPort " + portToRegister, logger); newThread.Start(); } }
public void AddUnconfiguredPort(PortInfo portInfo, bool writeToDisk = true) { lock (configuredPorts) { lock (unconfiguredPorts) { if (configuredPorts.ContainsKey(portInfo)) throw new Exception("adding as unconfigured a port that exists in configured list: " + portInfo.ToString()); if (!unconfiguredPorts.ContainsKey(portInfo)) unconfiguredPorts.Add(portInfo, portInfo); if (writeToDisk) WriteServicesList(); } } }