Exemple #1
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);
         }
     }
 }
Exemple #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);
     }
 }
Exemple #3
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);
             }
         }
     }
 }
Exemple #4
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();
            }
        }
Exemple #5
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);
     }
 }