Пример #1
0
        private void CheckRole(MobeelizerApplicationDefinition definition, String role)
        {
            foreach (MobeelizerRoleDefinition radRole in definition.Roles)
            {
                if (radRole.ResolveName().Equals(role))
                {
                    return;
                }
            }

            throw new InvalidOperationException("Role " + role + " doesn't exist in definition.");
        }
Пример #2
0
        internal IList <MobeelizerModel> Convert(MobeelizerApplicationDefinition definition, String entityPackage, String role)
        {
            CheckRole(definition, role);
            IList <MobeelizerModel> models = new List <MobeelizerModel>();

            foreach (MobeelizerModelDefinition radModel in definition.Models)
            {
                MobeelizerModelCredentialsDefinition modelCredentials = HasAccess(radModel, role);
                if (modelCredentials == null)
                {
                    continue;
                }

                Type type = null;
                if (entityPackage != null)
                {
                    type = FindType(radModel, entityPackage);
                }
                else
                {
                    throw new ConfigurationException("app.conig file have to include 'entitiesNamespace' definition.");
                }

                IList <MobeelizerField> fields = new List <MobeelizerField>();
                foreach (MobeelizerModelFieldDefinition radField in radModel.Fields)
                {
                    MobeelizerModelFieldCredentialsDefinition fieldCredentials = HasAccess(radField, role);
                    if (fieldCredentials == null)
                    {
                        continue;
                    }

                    fields.Add(new MobeelizerField(type, radField, fieldCredentials));
                }

                MobeelizerModel model = new MobeelizerModel(type, radModel.Name, modelCredentials, fields);
                models.Add(model);
            }

            return(models);
        }
Пример #3
0
        private MobeelizerApplicationDefinition ParseDefinition(XDocument document)
        {
            MobeelizerApplicationDefinition definition = new MobeelizerApplicationDefinition();
            XElement application = document.Root;

            definition.Application  = application.Attribute(MobeelizerDefinitionTag.APPLICATION_TAG).Value;
            definition.ConflictMode = application.Attribute(MobeelizerDefinitionTag.CONFLICT_MODE_TAG).Value;
            definition.Vendor       = application.Attribute(MobeelizerDefinitionTag.VENDOR_TAG).Value;
            XElement devices = application.Element(XName.Get(MobeelizerDefinitionTag.DEVICES_TAG, MobeelizerDefinitionTag.NAMESPACE));

            if (devices != null)
            {
                definition.Devices = new List <MobeelizerDeviceDefinition>();
                foreach (XElement device in devices.Elements(XName.Get(MobeelizerDefinitionTag.DEVICE_TAG, MobeelizerDefinitionTag.NAMESPACE)))
                {
                    MobeelizerDeviceDefinition deviceDef = new MobeelizerDeviceDefinition();
                    deviceDef.Name = device.Attribute(MobeelizerDefinitionTag.NAME_TAG).Value;
                    definition.Devices.Add(deviceDef);
                }
            }

            XElement groups = application.Element(XName.Get(MobeelizerDefinitionTag.GROUPS_TAG, MobeelizerDefinitionTag.NAMESPACE));

            if (groups != null)
            {
                definition.Groups = new List <MobeelizerGroupDefinition>();
                foreach (XElement group in groups.Elements(XName.Get(MobeelizerDefinitionTag.GROUP_TAG, MobeelizerDefinitionTag.NAMESPACE)))
                {
                    MobeelizerGroupDefinition groupDef = new MobeelizerGroupDefinition();
                    groupDef.Name = group.Attribute(MobeelizerDefinitionTag.NAME_TAG).Value;
                    definition.Groups.Add(groupDef);
                }
            }

            XElement roles = application.Element(XName.Get(MobeelizerDefinitionTag.ROLES_TAG, MobeelizerDefinitionTag.NAMESPACE));

            if (roles != null)
            {
                definition.Roles = new List <MobeelizerRoleDefinition>();
                foreach (XElement role in roles.Elements(XName.Get(MobeelizerDefinitionTag.ROLE_TAG, MobeelizerDefinitionTag.NAMESPACE)))
                {
                    MobeelizerRoleDefinition roleDef = new MobeelizerRoleDefinition();
                    roleDef.Device = role.Attribute(MobeelizerDefinitionTag.DEVICE_TAG).Value;
                    roleDef.Group  = role.Attribute(MobeelizerDefinitionTag.GROUP_TAG).Value;
                    definition.Roles.Add(roleDef);
                }
            }

            XElement models = application.Element(XName.Get(MobeelizerDefinitionTag.MODELS_TAG, MobeelizerDefinitionTag.NAMESPACE));

            if (models != null)
            {
                definition.Models = new List <MobeelizerModelDefinition>();
                foreach (XElement model in models.Elements(XName.Get(MobeelizerDefinitionTag.MODEL_TAG, MobeelizerDefinitionTag.NAMESPACE)))
                {
                    definition.Models.Add(ParseModel(model));
                }
            }

            return(definition);
        }