Exemplo n.º 1
0
 /// <summary>
 /// Configures the mappers.
 /// </summary>
 /// <param name="document">The document.</param>
 public static void ConfigureMappers(XmlDocument document)
 {
     Mapper.Configuration.DisableConstructorMapping();
     if (document != null)
     {
         foreach (XmlNode node in document.SelectNodes("configuration/mappers/mapper"))
         {
             NodeAttributes attributes     = new NodeAttributes(node);
             Type           sourceType     = TypesManager.ResolveType(attributes.AsString("source"));
             Type           targetType     = TypesManager.ResolveType(attributes.AsString("target"));
             bool           defaultMapping = attributes.AsBool("defaultMapping", true);
             if ((sourceType != null) && (targetType != null))
             {
                 // TODO: Add mappers using Automapper.
                 //IMapper mapper = ObjectProxyFactory.NewMapper(sourceType, targetType);
                 //if (defaultMapping)
                 //{
                 //    mapper.DefaultMap();
                 //}
                 //foreach (XmlNode mapNode in node.SelectNodes("mappings/mapping"))
                 //{
                 //    NodeAttributes mapAttributes = new NodeAttributes(mapNode);
                 //    mapper.Map(mapAttributes.AsString("source"), mapAttributes.AsString("target"));
                 //}
             }
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Loads the actions.
 /// </summary>
 /// <param name="node">The node.</param>
 public void LoadActions(XmlNode node, string path)
 {
     foreach (XmlNode actionNode in node.SelectNodes("actions/action"))
     {
         NodeAttributes attributes = new NodeAttributes(actionNode);
         TemplateAction action     = new TemplateAction(this, attributes.AsString("type"), path + "\\" + attributes.AsString("source"), attributes.AsString("target"));
         this.Actions.Add(action);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Loads the rules.
 /// </summary>
 /// <param name="document">The document.</param>
 private void LoadRules(XmlDocument document, string path)
 {
     foreach (XmlNode node in document.SelectNodes("template/rules/rule"))
     {
         NodeAttributes attributes = new NodeAttributes(node);
         TemplateRule   rule       = new TemplateRule(this, attributes.AsString("iterator"), attributes.AsString("condition"));
         rule.LoadActions(node, path);
         this.Rules.Add(rule);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Configures the API from a root node.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="configuration">The configuration.</param>
        private static void ConfigureApi(XmlNode node, IServiceConfiguration configuration)
        {
            NodeAttributes attributes = new NodeAttributes(node);
            Type           dtoType    = GetDtoType(attributes.AsString("dtoType"), attributes.AsString("dtoName"), attributes.AsString("path"), attributes.AsString("entityName"), attributes.AsString("entityType"));

            if (dtoType != null)
            {
                string parameterName = attributes.AsString("parameterName");
                if (string.IsNullOrEmpty(parameterName))
                {
                    parameterName = GetParameterName(attributes.AsString("path"), dtoType);
                }
                ApiNode childnode = configuration.AddNode(attributes.AsString("path"), dtoType, parameterName, attributes.AsString("byparent"));
                foreach (XmlNode subnode in node.SelectNodes("api"))
                {
                    ConfigureApi(subnode, childnode);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Configures the entities.
        /// </summary>
        /// <param name="rootNode">The root node.</param>
        /// <param name="metatables">The metatables.</param>
        protected void ConfigureEntities(XmlNode rootNode, Dictionary <string, MetaPersistentType> metatables)
        {
            NodeAttributes rootAtributes = new NodeAttributes(rootNode);
            bool           autoscan      = rootAtributes.AsBool("autoscan", true);
            string         entityPreffix = rootAtributes.AsString("entityPreffix");

            if (autoscan)
            {
                this.Scanner = new SecurityScanner(this);
                this.Scanner.EntityPreffix = rootAtributes.AsString("entityPreffix");
                this.Scanner.EntitySuffix  = rootAtributes.AsString("entitySuffix");
                this.Scanner.DtoPreffix    = rootAtributes.AsString("dtoPreffix");
                this.Scanner.DtoSuffix     = rootAtributes.AsString("dtoSuffix", "Dto");
                this.Scanner.FilterPreffix = rootAtributes.AsString("filterPreffix");
                this.Scanner.FilterSuffix  = rootAtributes.AsString("filterSuffix", "Filter");
                this.Scanner.BOPreffix     = rootAtributes.AsString("boPreffix");
                this.Scanner.BOSuffix      = rootAtributes.AsString("boSuffix", "BO");
                this.Scanner.Metatables    = metatables;
                this.Scanner.ScanNamespace(rootAtributes.AsString("namespaces"));
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Configures the service.
        /// </summary>
        /// <param name="document">The document.</param>
        private static void ConfigureService(XmlDocument document)
        {
            ISecurityManager securityManager = IoC.Get <ISecurityManager>();
            XmlNode          serviceNode     = document.SelectSingleNode("configuration/service");

            if (serviceNode != null)
            {
                NodeAttributes       serviceAttributes = new NodeAttributes(serviceNode);
                ServiceConfiguration configuration     = new ServiceConfiguration();
                configuration.ApiPath      = serviceAttributes.AsString("apiPath");
                configuration.IsCors       = serviceAttributes.AsBool("cors");
                configuration.IsHateoas    = serviceAttributes.AsBool("hateoas");
                configuration.IsCamelCase  = serviceAttributes.AsBool("camel", true);
                configuration.IncludeNulls = serviceAttributes.AsBool("includeNulls", false);
                configuration.Indented     = serviceAttributes.AsBool("indented", true);

                JsonSerializer         serializer = new JsonSerializer();
                JsonSerializerSettings settings   = new JsonSerializerSettings();
                if (configuration.IsCamelCase)
                {
                    serializer.ContractResolver = new CamelCasePropertyNamesContractResolver();
                    settings.ContractResolver   = new CamelCasePropertyNamesContractResolver();
                }
                if (configuration.IncludeNulls)
                {
                    serializer.NullValueHandling = NullValueHandling.Include;
                    settings.NullValueHandling   = NullValueHandling.Include;
                }
                else
                {
                    serializer.NullValueHandling = NullValueHandling.Ignore;
                    settings.NullValueHandling   = NullValueHandling.Ignore;
                }
                IoC.Register(serializer);
                IoC.Register(settings);

                foreach (XmlNode apiNode in serviceNode.SelectNodes("api"))
                {
                    ConfigureApi(apiNode, configuration);
                }
                IoC.Register <IServiceConfiguration>(configuration);
                IoC.Get <IAuditManager>().Configure();
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Configures the security manager.
        /// </summary>
        /// <param name="document">The document.</param>
        private static void ConfigureSecurityManager(XmlDocument document)
        {
            ISecurityManager securityManager = null;
            XmlNode          securityNode    = document.SelectSingleNode("configuration/security");

            if (securityNode != null)
            {
                NodeAttributes securityAttributes = new NodeAttributes(securityNode);
                if (!string.IsNullOrEmpty(securityAttributes.AsString("sessionManager")))
                {
                    Type sessionManagerType = TypesManager.ResolveType(securityAttributes.AsString("sessionManager"));
                    if (sessionManagerType != null)
                    {
                        ISessionManager sessionManager = (ISessionManager)Activator.CreateInstance(sessionManagerType);
                        IoC.Register <ISessionManager>(sessionManager);
                    }
                }
                if (!string.IsNullOrEmpty(securityAttributes.AsString("auditManager")))
                {
                    Type auditManagerType = TypesManager.ResolveType(securityAttributes.AsString("auditManager"));
                    if (auditManagerType != null)
                    {
                        IAuditManager auditManager = (IAuditManager)Activator.CreateInstance(auditManagerType);
                        IoC.Register <IAuditManager>(auditManager);
                    }
                }
                if (!string.IsNullOrEmpty(securityAttributes.AsString("securityManager")))
                {
                    Type securityManagerType = TypesManager.ResolveType(securityAttributes.AsString("securityManager"));
                    if (securityManagerType != null)
                    {
                        securityManager = (ISecurityManager)Activator.CreateInstance(securityManagerType);
                        IoC.Register <ISecurityManager>(securityManager);
                        string mappersName = securityAttributes.AsString("mapper");
                        securityManager.Configure(mappersName);
                    }
                }
            }
        }