Exemplo n.º 1
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;
        }
Exemplo n.º 2
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();
            }
        }
Exemplo n.º 3
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();
        }