Inheritance: Hal.HalNode, IHalResource
示例#1
0
        protected HttpResponseMessage GetResponse(HalResource resource)
        {
            string halDocument = HalDocument.Create(resource, UriFactory.GetRelationsUri(), "rel");

             var content = new StringContent(halDocument, Encoding.UTF8, "application/hal+json");

             var response = new HttpResponseMessage(HttpStatusCode.OK)
             {
            Content = content
             };

             return response;
        }
示例#2
0
        public static string Create(HalResource halResource, string relationsUri = null, string relationPlaceholder = null)
        {
            if (relationsUri != null)
             {
            // Add curies to the links of the top level resource.
            halResource.Links.Curies = new List<CurieLink>
            {
               new CurieLink(relationsUri, relationPlaceholder)
            };
             }

             var jsonSettings = new JsonSerializerSettings
             {
            Formatting = Formatting.Indented,
            NullValueHandling = NullValueHandling.Ignore,
            ContractResolver = new CamelCasePropertyNamesContractResolver()
             };

             string halDocument = JsonConvert.SerializeObject(halResource, jsonSettings);

             return halDocument;
        }
示例#3
0
 internal HalDocument(HalResource root)
     : this((string)null)
 {
     Root = root;
 }
示例#4
0
 public HalDocument(string href, string rel = "self")
 {
     Namespaces = new List<Tuple<string, Uri>>();
     Root = new HalResource(rel, href);
 }
示例#5
0
 public PropertyFinder(HalResource root)
 {
     _root = root;
 }
示例#6
0
        private static void InternalFindAllLinks(HalResource resource, IList<HalLink> outList)
        {
            outList.Add(resource.ResourceLink);

            foreach (var node in resource.Contents.Values.OfType<HalLink>()) {
                outList.Add(node);
            }

            foreach (var node in resource.Contents.Values.OfType<HalResource>()) {
                InternalFindAllLinks(node, outList);
            }
        }