Esempio 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"));
                 //}
             }
         }
     }
 }
Esempio n. 2
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();
            }
        }
Esempio n. 3
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"));
            }
        }