Ejemplo n.º 1
0
        public string Inject(string content, IList <Relations> relations, IRequestInfoFinder requestInfo)
        {
            var xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(content);

            var nodes = xmlDocument.DocumentElement.GetElementsByTagName("entry");

            for (var i = 0; i < nodes.Count; i++)
            {
                var currentNode     = nodes[i];
                var currentRelation = relations[i];

                foreach (var relation in currentRelation.GetAll())
                {
                    var transition = BuildTransition(xmlDocument, relation);
                    currentNode.AppendChild(transition);
                }

                ReplaceEntryUrl(currentNode, currentRelation);
            }

            ReplaceFeedUrl(xmlDocument.DocumentElement, requestInfo);

            return(xmlDocument.InnerXml);
        }
        public string Build(object model, IRequestInfoFinder finder)
        {
            var content = serializer.Serialize(model);

            if (model.GetType().IsAResource())
            {
                var resource = model.AsResource();
                var relations = relationsFactory.NewRelations();
                resource.SetRelations(relations);
                content = hypermedia.Inject(content, relations, finder);
            } else if (model.GetType().IsAListOfResources())
            {
                var allRelations = new List<Relations>();

                var resources = model.AsResourceArray();
                foreach (var resource in resources)
                {
                    var relations = relationsFactory.NewRelations();
                    resource.SetRelations(relations);
                    allRelations.Add(relations);
                }

                content = hypermedia.Inject(content, allRelations, finder);
            }

            return content;
        }
        public string Inject(string content, IList<Relations> relations, IRequestInfoFinder requestInfo)
        {
            var listOfSingleObjects = SplitContentIntoListOfSingleJsonObjects(content);

            var injectedContent = new StringBuilder();
            injectedContent.Append("[");

            for (var index = 0; index < listOfSingleObjects.Count; index++)
            {
                var singleObject = listOfSingleObjects[index];

                try
                {
                    var singleObjectWithTransition = InjectJsonTransitions(singleObject, relations[index]);
                    injectedContent.Append(singleObjectWithTransition);
                } catch (IndexOutOfRangeException)
                {
                    injectedContent.Append(singleObject);
                } catch (ArgumentOutOfRangeException)
                {
                    injectedContent.Append(singleObject);
                }

                injectedContent.Append(",");
            }
            if (injectedContent.Length > 1)
                // Removes last comma ','
                injectedContent.Remove(injectedContent.Length - 1, 1);

            injectedContent.Append("]");

            return injectedContent.ToString();
        }
Ejemplo n.º 4
0
        public string Build(object model, IRequestInfoFinder finder)
        {
            var content = serializer.Serialize(model);

            if (model.GetType().IsAResource())
            {
                var resource  = model.AsResource();
                var relations = relationsFactory.NewRelations();
                resource.SetRelations(relations);
                content = hypermedia.Inject(content, relations, finder);
            }
            else if (model.GetType().IsAListOfResources())
            {
                var allRelations = new List <Relations>();

                var resources = model.AsResourceArray();
                foreach (var resource in resources)
                {
                    var relations = relationsFactory.NewRelations();
                    resource.SetRelations(relations);
                    allRelations.Add(relations);
                }

                content = hypermedia.Inject(content, allRelations, finder);
            }

            return(content);
        }
Ejemplo n.º 5
0
        private ActionResult RestfulieResult(ActionExecutedContext context, IMediaType type, IRequestInfoFinder requestInfoFinder)
        {
            var result = (RestfulieResult) context.Result;
            result.MediaType = type;
            result.RequestInfo = requestInfoFinder;

            return result;
        }
Ejemplo n.º 6
0
        public ActionResult BasedOnMediaType(ActionExecutedContext context, IMediaType type, IRequestInfoFinder requestInfoFinder)
        {
            if (!context.Result.IsRestfulieResult())
                return context.Result;

            if (type is HTML && (context.Result is OK || context.Result is Created))
                return AspNetResult(context);

            return RestfulieResult(context, type, requestInfoFinder);
        }
Ejemplo n.º 7
0
        public void SetUp()
        {
            result = new SomeResult();

            context = new ActionExecutedContext
                          {
                              Controller = new SomeController {ViewData = new ViewDataDictionary()}, 
                              Result = result
                          };

            requestInfo = new Mock<IRequestInfoFinder>().Object;
        }
Ejemplo n.º 8
0
        public void SetUp()
        {
            result = new SomeResult();

            context = new ActionExecutedContext
            {
                Controller = new SomeController {
                    ViewData = new ViewDataDictionary()
                },
                Result = result
            };

            requestInfo = new Mock <IRequestInfoFinder>().Object;
        }
        public string Inject(string content, Relations relations, IRequestInfoFinder requestInfo)
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(content);

            foreach (var state in relations.GetAll())
            {
                var transition = GetTransition(xmlDocument, state);

                xmlDocument.DocumentElement.AppendChild(transition);
            }

            return xmlDocument.InnerXml;
        }
Ejemplo n.º 10
0
        public string Inject(string content, Relations relations, IRequestInfoFinder requestInfo)
        {
            var xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(content);

            foreach (var state in relations.GetAll())
            {
                var transition = GetTransition(xmlDocument, state);

                xmlDocument.DocumentElement.AppendChild(transition);
            }

            return(xmlDocument.InnerXml);
        }
        public string Inject(string content, IList<Relations> relations, IRequestInfoFinder requestInfo)
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(content);

            for (var i = 0; i < xmlDocument.DocumentElement.ChildNodes.Count; i++)
            {
                var node = xmlDocument.DocumentElement.ChildNodes[i];

                foreach (var relation in relations[i].GetAll())
                {
                    var transition = GetTransition(xmlDocument, relation);
                    node.AppendChild(transition);
                }
            }

            return xmlDocument.InnerXml;
        }
Ejemplo n.º 12
0
        public string Inject(string content, IList <Relations> relations, IRequestInfoFinder requestInfo)
        {
            var xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(content);

            for (var i = 0; i < xmlDocument.DocumentElement.ChildNodes.Count; i++)
            {
                var node = xmlDocument.DocumentElement.ChildNodes[i];

                foreach (var relation in relations[i].GetAll())
                {
                    var transition = GetTransition(xmlDocument, relation);
                    node.AppendChild(transition);
                }
            }

            return(xmlDocument.InnerXml);
        }
Ejemplo n.º 13
0
        public string Inject(string content, IList <Relations> relations, IRequestInfoFinder requestInfo)
        {
            var listOfSingleObjects = SplitContentIntoListOfSingleJsonObjects(content);

            var injectedContent = new StringBuilder();

            injectedContent.Append("[");

            for (var index = 0; index < listOfSingleObjects.Count; index++)
            {
                var singleObject = listOfSingleObjects[index];

                try
                {
                    var singleObjectWithTransition = InjectJsonTransitions(singleObject, relations[index]);
                    injectedContent.Append(singleObjectWithTransition);
                } catch (IndexOutOfRangeException)
                {
                    injectedContent.Append(singleObject);
                } catch (ArgumentOutOfRangeException)
                {
                    injectedContent.Append(singleObject);
                }

                injectedContent.Append(",");
            }
            if (injectedContent.Length > 1)
            {
                // Removes last comma ','
                injectedContent.Remove(injectedContent.Length - 1, 1);
            }

            injectedContent.Append("]");

            return(injectedContent.ToString());
        }
        public string Inject(string content, IList<Relations> relations, IRequestInfoFinder requestInfo)
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(content);

            var nodes = xmlDocument.DocumentElement.GetElementsByTagName("entry");
            for (var i = 0; i < nodes.Count; i++)
            {
                var currentNode = nodes[i];
                var currentRelation = relations[i];

                foreach (var relation in currentRelation.GetAll())
                {
                    var transition = BuildTransition(xmlDocument, relation);
                    currentNode.AppendChild(transition);
                }

                ReplaceEntryUrl(currentNode, currentRelation);
            }

            ReplaceFeedUrl(xmlDocument.DocumentElement, requestInfo);

            return xmlDocument.InnerXml;
        }
Ejemplo n.º 15
0
        private void ReplaceFeedUrl(XmlNode node, IRequestInfoFinder requestInfo)
        {
            var id = FindNode(node, "id");

            id.InnerText = requestInfo.GetUrl();
        }
Ejemplo n.º 16
0
        public ActionResult BasedOnMediaType(ActionExecutedContext context, IMediaType type, IRequestInfoFinder requestInfoFinder)
        {
            if (!context.Result.IsRestfulieResult())
            {
                return(context.Result);
            }

            if (type is HTML && (context.Result is OK || context.Result is Created))
            {
                return(AspNetResult(context));
            }

            return(RestfulieResult(context, type, requestInfoFinder));
        }
Ejemplo n.º 17
0
 public ActionResult BasedOnMediaType(ActionExecutedContext context, IMediaType type, IRequestInfoFinder requestInfoFinder)
 {
     if (!context.Result.IsRestfulieResult()) return context.Result;
     return (type is HTML) ? AspNetResult(context) : RestfulieResult(context, type, requestInfoFinder);
 }
Ejemplo n.º 18
0
 public void SetUp()
 {
     requestInfo = new Mock <IRequestInfoFinder>().Object;
 }
Ejemplo n.º 19
0
 public void GetRequestInfo(ControllerContext filterContext)
 {
     requestInfo = requestInfoFactory.BasedOn(filterContext.HttpContext);
 }
 public void SetUp()
 {
     requestInfo = new Mock<IRequestInfoFinder>().Object;
 }
 public string Inject(string content, Relations relations, IRequestInfoFinder requestInfo)
 {
     return InjectJsonTransitions(content, relations);
 }
Ejemplo n.º 22
0
 public string Inject(string content, Relations relations, IRequestInfoFinder requestInfo)
 {
     return(InjectJsonTransitions(content, relations));
 }
 private void ReplaceFeedUrl(XmlNode node, IRequestInfoFinder requestInfo)
 {
     var id = FindNode(node, "id");
     id.InnerText = requestInfo.GetUrl();
 }
Ejemplo n.º 24
0
        private ActionResult RestfulieResult(ActionExecutedContext context, IMediaType type, IRequestInfoFinder requestInfoFinder)
        {
            var result = (RestfulieResult)context.Result;

            result.MediaType   = type;
            result.RequestInfo = requestInfoFinder;

            return(result);
        }
Ejemplo n.º 25
0
 public void GetRequestInfo(ControllerContext filterContext)
 {
     requestInfo = requestInfoFactory.BasedOn(filterContext.HttpContext);
 }