Ejemplo n.º 1
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());
            }
        }
Ejemplo n.º 2
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());
                }
            }
        }
Ejemplo n.º 3
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();
         }
     }
 }
Ejemplo n.º 4
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());
            }
        }
Ejemplo n.º 5
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());
            }
        }
Ejemplo 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();
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Converts to HATEOAS response.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="path">The path.</param>
        /// <param name="isPostPut">if set to <c>true</c> [is post put].</param>
        /// <returns></returns>
        private object ConvertToHateoas(object source, IServiceConfiguration configuration, MessagePath path, bool isPostPut = false)
        {
            IList <HateoasLink> links      = path.Links;
            JsonSerializer      serializer = IoC.Get <JsonSerializer>();

            if ((path.HasKeyParameter) || (path.IsByParent) || isPostPut)
            {
                JObject jobject = JObject.FromObject(source, serializer);
                JArray  jarray  = JArray.FromObject(links, serializer);
                if (configuration.IsCamelCase)
                {
                    jobject.Add("links", jarray);
                }
                else
                {
                    jobject.Add("Links", jarray);
                }
                return(jobject);
            }
            else
            {
                HateoasReponse response = new HateoasReponse();
                response.Items = source;
                response.Links = links;
                return(JObject.FromObject(response, serializer));
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Converts to HATEOAS response.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="configuration">The configuration.</param>
 /// <param name="path">The path.</param>
 /// <param name="isPostPut">if set to <c>true</c> [is post put].</param>
 /// <returns></returns>
 private object ConvertToHateoas(object source, IServiceConfiguration configuration, MessagePath path, bool isPostPut = false)
 {
     IList<HateoasLink> links = path.Links;
     JsonSerializer serializer = IoC.Get<JsonSerializer>();
     if ((path.HasKeyParameter) || (path.IsByParent) || isPostPut)
     {
         JObject jobject = JObject.FromObject(source, serializer);
         JArray jarray = JArray.FromObject(links, serializer);
         if (configuration.IsCamelCase)
         {
             jobject.Add("links", jarray);
         }
         else
         {
             jobject.Add("Links", jarray);
         }
         return jobject;
     }
     else
     {
         HateoasReponse response = new HateoasReponse();
         response.Items = source;
         response.Links = links;
         return JObject.FromObject(response, serializer);
     }
 }
Ejemplo n.º 9
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();
     }
 }
Ejemplo n.º 10
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();
            }
        }