Example #1
0
        /// <summary>
        /// Discovers remote resources.
        /// </summary>
        /// <param name="query">the query to filter resources</param>
        /// <returns>the descoverd <see cref="WebLink"/> representing remote resources, or null if no response</returns>
        public IEnumerable <WebLink> Discover(String query)
        {
            Request discover = Prepare(Request.NewGet());

            discover.ClearUriPath().ClearUriQuery().UriPath = CoapConstants.DefaultWellKnownURI;
            if (!String.IsNullOrEmpty(query))
            {
                discover.UriQuery = query;
            }
            Response links = discover.Send().WaitForResponse(_timeout);

            if (links == null)
            {
                // if no response, return null (e.g., timeout)
                return(null);
            }
            else if (links.ContentFormat != MediaType.ApplicationLinkFormat)
            {
                return(EmptyLinks);
            }
            else
            {
                return(LinkFormat.Parse(links.PayloadString));
            }
        }
Example #2
0
        public void ConcreteTest()
        {
            String   link   = "</careless>;rt=\"SepararateResponseTester\";title=\"This resource will ACK anything, but never send a separate response\",</feedback>;rt=\"FeedbackMailSender\";title=\"POST feedback using mail\",</helloWorld>;rt=\"HelloWorldDisplayer\";title=\"GET a friendly greeting!\",</image>;ct=21;ct=22;ct=23;ct=24;rt=\"Image\";sz=18029;title=\"GET an image with different content-types\",</large>;rt=\"block\";title=\"Large resource\",</large_update>;rt=\"block\";rt=\"observe\";title=\"Large resource that can be updated using PUT method\",</mirror>;rt=\"RequestMirroring\";title=\"POST request to receive it back as echo\",</obs>;obs;rt=\"observe\";title=\"Observable resource which changes every 5 seconds\",</query>;title=\"Resource accepting query parameters\",</seg1/seg2/seg3>;title=\"Long path resource\",</separate>;title=\"Resource which cannot be served immediately and which cannot be acknowledged in a piggy-backed way\",</storage>;obs;rt=\"Storage\";title=\"PUT your data here or POST new resources!\",</test>;title=\"Default test resource\",</timeResource>;rt=\"CurrentTime\";title=\"GET the current time\",</toUpper>;rt=\"UppercaseConverter\";title=\"POST text here to convert it to uppercase\",</weatherResource>;rt=\"ZurichWeather\";title=\"GET the current weather in zurich\"";
            Resource res    = RemoteResource.NewRoot(link);
            String   result = LinkFormat.Serialize(res, null, true);

            Assert.AreEqual(link, result);
        }
Example #3
0
        public void ConversionTest()
        {
            String   link1  = "</myUri/something>;ct=42;if=\"/someRef/path\";obs;rt=\"MyName\";sz=10";
            String   link2  = "</myUri>;rt=\"NonDefault\"";
            String   link3  = "</a>";
            String   format = link1 + "," + link2 + "," + link3;
            Resource res    = RemoteResource.NewRoot(format);
            String   result = LinkFormat.Serialize(res, null, true);

            Assert.AreEqual(link3 + "," + link2 + "," + link1, result);
        }
        public void TestDiscoveryFiltering()
        {
            String expected = "</sensors/light>;if=\"sensor\";rt=\"light-lux\"";

            Request request = Request.NewGet();

            request.SetUri("/.well-known/core?rt=light-lux");

            DiscoveryResource discovery  = new DiscoveryResource(_root);
            String            serialized = LinkFormat.Serialize(_root, request.UriQueries);

            Assert.AreEqual(expected, serialized);
        }
        public void TestDiscovery()
        {
            String expected = "</sensors>;title=\"Sensor Index\"," +
                              "</sensors/light>;if=\"sensor\";rt=\"light-lux\"," +
                              "</sensors/temp>;bar=\"one two\";foo;if=\"sensor\";rt=\"temperature-c\"";
            DiscoveryResource discovery  = new DiscoveryResource(_root);
            String            serialized = LinkFormat.Serialize(_root);

            Assert.AreEqual(expected, serialized);

            serialized = LinkFormat.Serialize(_root, new List <String>());
            Assert.AreEqual(expected, serialized);
        }
Example #6
0
        public void MatchTest()
        {
            String   link1  = "</myUri/something>;ct=42;if=\"/someRef/path\";obs;rt=\"MyName\";sz=10";
            String   link2  = "</myUri>;ct=50;rt=\"MyName\"";
            String   link3  = "</a>;sz=10;rt=\"MyNope\"";
            String   format = link1 + "," + link2 + "," + link3;
            Resource res    = RemoteResource.NewRoot(format);

            List <Option> query = new List <Option>();

            query.Add(Option.Create(OptionType.UriQuery, "rt=MyName"));

            String queried = LinkFormat.Serialize(res, query, true);

            Assert.AreEqual(link2 + "," + link1, queried);
        }