Example #1
0
 // ***
 public void RemoveChildPort(PortInfo child)
 {
     ChildPorts.Remove(child);
 }
Example #2
0
 // ***
 public void RemoveChildPort(PortInfo child)
 {
     ChildPorts.Remove(child);
 }
Example #3
0
 public void AddChildPort(PortInfo child)
 {
     ChildPorts.Add(child);
 }
Example #4
0
        private void RemovePortFromConfig(VPort port , VModule module)
        {
            PortInfo targetPortInfo = new PortInfo(port.GetInfo().ModuleFacingName(), module.GetInfo());
            PortInfo matchingPortInfo = config.GetMatchingPortInfo(targetPortInfo);
            if (matchingPortInfo == null)
            {
            }
            else
            {
                config.RemovePort(matchingPortInfo);
            } 

        }
Example #5
0
 public void AddChildPort(PortInfo child)
 {
     ChildPorts.Add(child);
 }
Example #6
0
        /// <summary>
        /// Issues a portinfo object
        /// </summary>
        /// <param name="moduleFacingName">The local name used by the owning module for this port</param>
        /// <param name="module">The owning module</param>
        /// <returns></returns>
        public VPortInfo GetPortInfo(string moduleFacingName, VModule module)
        {
            PortInfo targetPortInfo = new PortInfo(moduleFacingName, module.GetInfo());

            //if matching portInfo exists, return that object
            //NB: we cannot return targetPortInfo itself because that is a different object (which does not have location and other things set)
            VPortInfo matchingPortInfo = config.GetMatchingPortInfo(targetPortInfo);

            if (matchingPortInfo != null)
                return matchingPortInfo;

            //this is not a port that we've seen before
            //make up a friendly name for this port as well as a location
            targetPortInfo.SetFriendlyName(moduleFacingName + " - " + module.GetInfo().FriendlyName());
            targetPortInfo.SetLocation(config.RootLocation);

            config.AddUnconfiguredPort(targetPortInfo);
            return targetPortInfo;
        }
Example #7
0
        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();
            }
        }
Example #8
0
        private bool RemoveUnconfiguredPort(PortInfo portInfo, bool writeToDisk = true)
        {
            lock (configuredPorts)
            {
                lock (unconfiguredPorts)
                {
                    bool result = unconfiguredPorts.Remove(portInfo);

                    if (writeToDisk)
                        WriteServicesList();

                    return result;
                }
            }
        }
Example #9
0
 public bool RemovePort(PortInfo port)
 {
     lock (configuredPorts)
     {
         lock (unconfiguredPorts)
         {
             if (unconfiguredPorts.ContainsKey(port))
                 return RemoveUnconfiguredPort(port);
             else if (configuredPorts.ContainsKey(port))
                 return RemoveConfiguredPort(port);
             else
                 return false;
         }
     }
 }
Example #10
0
        private bool RemoveConfiguredPort(PortInfo portInfo,  bool writeToDisk = true)
        {
            
            //we always lock configuredPorts even if unconfiguredPorts is being touched
            lock (unconfiguredPorts)
            {

                lock (configuredPorts)
                {
                    bool result = configuredPorts.Remove(portInfo);
                    configuredPortNames.Remove(portInfo.GetFriendlyName());
                    
                    //portInfo.SetLocation(parentLocation);
                    //parentLocation.AddChildPort(portInfo);

                    allLocations[portInfo.GetLocation().Name()].RemoveChildPort(portInfo);
                    
                    
                    // if "configured roles in home" list contains any roles from this port
                    // rebuild the configured roles in home list from the "new" configured ports list (i.e., after removing this port)
                    configuredRolesInHome.Clear();
                    foreach (PortInfo port in configuredPorts.Values) // rebuilding the configuredRolesInHome list again
                    {
                        foreach (VRole role in port.GetRoles())
                        {
                            if (!configuredRolesInHome.ContainsKey(role)) // avoiding duplicates
                                configuredRolesInHome[role] = true;
                        }
                    }

                    if (writeToDisk)
                        WriteServicesList();

                    return result;

                }
            }

        }
Example #11
0
        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();
                }
            }
        }
Example #12
0
        public void AddConfiguredPort(PortInfo portInfo, bool writeToDisk=true)
        {

            //we always lock configuredPorts even if unconfiguredPorts is being touched

            lock (configuredPorts)
            {
                //remove from uncofigured list first if it exists there

                if (unconfiguredPorts.ContainsKey(portInfo))
                    unconfiguredPorts.Remove(portInfo);

                configuredPorts.Add(portInfo, portInfo);
                configuredPortNames.Add(portInfo.GetFriendlyName(), portInfo);

                foreach (VRole role in portInfo.GetRoles())
                {
                    if (!configuredRolesInHome.ContainsKey(role))
                        configuredRolesInHome[role] = true;
                }

                if (writeToDisk) 
                    WriteServicesList();
            }

        }
Example #13
0
        public List<ModuleInfo> GetCompatibleModules(PortInfo portInfo)
        {
            var retList = new List<ModuleInfo>();

            foreach (VRole role in portInfo.GetRoles())
            {
                var roleCompatibleModules = GetCompatibleModules(role);

                foreach (var mInfo in roleCompatibleModules)
                {
                    if (!retList.Contains(mInfo))
                        retList.Add(mInfo);
                }
            }

            return retList;
        }
Example #14
0
        private void ReadServicesList()
        {
            string fileName = this.ServicesFile;

            XmlDocument xmlDoc = new XmlDocument();
            XmlReader xmlReader = XmlReader.Create(fileName, xmlReaderSettings);
            xmlDoc.Load(xmlReader);
            XmlElement root = xmlDoc.FirstChild as XmlElement;

            if (!root.Name.Equals("Services"))
                throw new Exception(fileName + " doesn't start with Services");

            foreach (XmlElement xmlChild in root.ChildNodes)
            {
                if (!xmlChild.Name.Equals("Service"))
                    throw new Exception("child is not a Service in " + fileName);

                string configuredString = xmlChild.GetAttribute("Configured").ToLower();
                bool configuredPort = (configuredString.Equals("") || configuredString.Equals("yes"));

                string moduleFacingName = xmlChild.GetAttribute("ModuleFacingName");
                string moduleName = xmlChild.GetAttribute("Module");

                if (!allModules.ContainsKey(moduleName))
                    throw new Exception("Unknown module " + moduleName + " for service " + moduleFacingName);

                PortInfo child = new PortInfo(moduleFacingName, allModules[moduleName]);

                //mark as high security if the security tag is missing or is marked as low
                string security = xmlChild.GetAttribute("Security");
                child.SetSecurity((!security.Equals("") && !security.ToLower().Equals("low")) ? true : false);

                //read in the roles
                IList<VRole> roles = new List<VRole>();

                foreach (XmlElement xmlRole in xmlChild.ChildNodes)
                {
                    if (!xmlRole.Name.Equals("Role"))
                        throw new Exception("child of Service is not Role. it is " + xmlRole.Name);

                    string roleName = xmlRole.GetAttribute("Name");

                    //if (!roleDb.ContainsKey(roleName.ToLower()))
                    //    throw new Exception("unknown role name " + roleName);

                    //roles.Add(roleDb[roleName.ToLower()]);

                    roles.Add(new Role(roleName.ToLower()));
                }

                child.SetRoles(roles);

                string friendlyName = xmlChild.GetAttribute("FriendlyName");
                child.SetFriendlyName(friendlyName);

                //read and verify location
                string locationStr = xmlChild.GetAttribute("Location");
                Location location = GetLocation(locationStr);
                if (location == null)
                   throw new Exception("Unknown location for service: " + locationStr);

                child.SetLocation(location);
                location.AddChildPort(child);

                if (configuredPort)
                {
                    AddConfiguredPort(child, false);
                }
                else
                {
                    AddUnconfiguredPort(child, false);
                }
            }

            xmlReader.Close();
        }