Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessagePath"/> class.
 /// </summary>
 /// <param name="information">The information.</param>
 /// <param name="forParent">if set to <c>true</c> [for parent].</param>
 public MessagePath(MessageInformation information, bool forParent)
 {
     this.Configuration   = IoC.Get <IServiceConfiguration>();
     this.SecurityManager = IoC.Get <ISecurityManager>();
     this.Information     = information;
     this.Build(forParent);
 }
Exemplo n.º 2
0
        public Message Put(Message message)
        {
            MessageInformation information = new MessageInformation(message);

            try
            {
                string      sessionToken = this.GetSessionToken(information);
                MessagePath path         = new MessagePath(information);
                if (path.HasKeyParameter)
                {
                    throw new ArgumentException("POST operation cannot have a key parameter in the path.");
                }
                ISecurityManager       securityManager = IoC.Get <ISecurityManager>();
                dynamic                bo            = securityManager.DynamicGetBO(path.DtoType, sessionToken);
                dynamic                dto           = information.GetBody(path.DtoType);
                object                 response      = bo.Update(dto);
                IServiceConfiguration  configuration = IoC.Get <IServiceConfiguration>();
                JsonSerializerSettings settings      = IoC.Get <JsonSerializerSettings>();
                if (configuration.IsHateoas)
                {
                    response = this.ConvertToHateoas(response, configuration, path);
                }
                return(response.ToJsonMessage(settings, configuration.Indented));
            }
            catch (Exception ex)
            {
                return(ex.Message.ToJsonMessage());
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Gets the session token.
 /// </summary>
 /// <param name="information">The information.</param>
 /// <returns></returns>
 /// <exception cref="System.ArgumentNullException">A session token must be provided</exception>
 private string GetSessionToken(MessageInformation information)
 {
     if (!information.LowParameters.ContainsKey("sessiontoken"))
     {
         throw new ArgumentNullException("A session token must be provided");
     }
     return(information.LowParameters["sessiontoken"]);
 }
Exemplo n.º 4
0
        public Message Get(Message message)
        {
            MessageInformation information = new MessageInformation(message);

            try
            {
                string           sessionToken    = this.GetSessionToken(information);
                MessagePath      path            = new MessagePath(information);
                ISecurityManager securityManager = IoC.Get <ISecurityManager>();
                object           response;
                if (path.IsByParent)
                {
                    MessagePath parentPath = new MessagePath(information, true);
                    if (!parentPath.HasKeyParameter)
                    {
                        throw new ArgumentException("A link to a parent must have parameter key");
                    }
                    dynamic      bo     = securityManager.DynamicGetBO(parentPath.DtoType, sessionToken);
                    object       parent = bo.GetOne(string.Empty, parentPath.QueryInfo);
                    IObjectProxy proxy  = ObjectProxyFactory.Get(parent);
                    object       value  = proxy.GetValue(parent, path.ParentKeyParameter);
                    QueryInfo    query  = new QueryInfo();
                    query.Equal(path.KeyParameterName, value.ToString());
                    bo       = securityManager.DynamicGetBO(path.DtoType, sessionToken);
                    response = bo.GetOne(string.Empty, query);
                }
                else
                {
                    dynamic bo = securityManager.DynamicGetBO(path.DtoType, sessionToken);
                    if (path.HasKeyParameter)
                    {
                        response = bo.GetOne(string.Empty, path.QueryInfo);
                    }
                    else
                    {
                        response = bo.GetAll(path.QueryInfo);
                    }
                }
                IServiceConfiguration  configuration = IoC.Get <IServiceConfiguration>();
                JsonSerializerSettings settings      = IoC.Get <JsonSerializerSettings>();
                if (configuration.IsHateoas)
                {
                    response = this.ConvertToHateoas(response, configuration, path);
                }
                return(response.ToJsonMessage(settings, configuration.Indented));
            }
            catch (Exception ex)
            {
                if (ex is TargetInvocationException)
                {
                    return(ex.InnerException.Message.ToJsonMessage());
                }
                else
                {
                    return(ex.Message.ToJsonMessage());
                }
            }
        }
Exemplo n.º 5
0
        public Message Post(Message message)
        {
            MessageInformation information = new MessageInformation(message);

            try
            {
                string                 sessionToken    = this.GetSessionToken(information);
                MessagePath            path            = new MessagePath(information);
                ISecurityManager       securityManager = IoC.Get <ISecurityManager>();
                IServiceConfiguration  configuration   = IoC.Get <IServiceConfiguration>();
                JsonSerializerSettings settings        = IoC.Get <JsonSerializerSettings>();
                if (path.IsQuery)
                {
                    dynamic   bo   = securityManager.DynamicGetBO(path.DtoType, sessionToken);
                    QueryInfo info = information.GetBody <QueryInfo>();
                    info.AddFacetsFrom(path.QueryInfo);
                    object response;
                    if (path.HasKeyParameter)
                    {
                        response = bo.GetOne(string.Empty, info);
                    }
                    else
                    {
                        response = bo.GetAll(info);
                    }
                    if (configuration.IsHateoas)
                    {
                        response = this.ConvertToHateoas(response, configuration, path);
                    }
                    return(response.ToJsonMessage(settings, configuration.Indented));
                }
                else
                {
                    if (path.HasKeyParameter)
                    {
                        throw new ArgumentException("POST operation cannot have a key parameter in the path.");
                    }
                    dynamic bo       = securityManager.DynamicGetBO(path.DtoType, sessionToken);
                    dynamic dto      = information.GetBody(path.DtoType);
                    object  response = bo.Insert(dto);
                    if (configuration.IsHateoas)
                    {
                        response = ConvertToHateoas(response, configuration, path, true);
                    }
                    return(response.ToJsonMessage());
                }
            }
            catch (Exception ex)
            {
                return(ex.Message.ToJsonMessage());
            }
        }
Exemplo n.º 6
0
        public Message Delete(Message message)
        {
            MessageInformation information = new MessageInformation(message);

            try
            {
                string      sessionToken = this.GetSessionToken(information);
                MessagePath path         = new MessagePath(information);
                if (!path.HasKeyParameter)
                {
                    throw new ArgumentException("DELETE operation must have a key parameter in the path.");
                }
                ISecurityManager securityManager = IoC.Get <ISecurityManager>();
                dynamic          bo       = securityManager.DynamicGetBO(path.DtoType, sessionToken);
                object           response = bo.Delete(path.KeyParameter);
                return(response.ToJsonMessage());
            }
            catch (Exception ex)
            {
                return(ex.Message.ToJsonMessage());
            }
        }