Example #1
0
 protected override void DoGet(CoapExchange exchange)
 {
     // Accept the request to promise the client this request will be acted.
     exchange.Accept();
     
     // ... and then do nothing. Pretty mean...
 }
Example #2
0
        /// <inheritdoc/>
        public virtual void HandleRequest(Exchange exchange)
        {
            CoapExchange ce = new CoapExchange(exchange, this);

            switch (exchange.Request.Method)
            {
            case Method.GET:
                DoGet(ce);
                break;

            case Method.POST:
                DoPost(ce);
                break;

            case Method.PUT:
                DoPut(ce);
                break;

            case Method.DELETE:
                DoDelete(ce);
                break;

            default:
                break;
            }
        }
Example #3
0
        protected override void DoPost(CoAP.Server.Resources.CoapExchange exchange)
        {
            String          payload         = exchange.Request.PayloadString;
            EntidadPeticion entidadPeticion = JsonConvert.DeserializeObject <EntidadPeticion>(payload);

            Task.Run(async() => await servicioInsertaInformacion.InsertaPeticion(entidadPeticion));

            Console.WriteLine(entidadPeticion.Sensor);
            exchange.Respond(CoAP.StatusCode.Changed);
        }
Example #4
0
 protected override void DoGet(CoapExchange exchange)
 {
     if (_content != null)
     {
         exchange.Respond(_content);
     }
     else
     {
         String subtree = LinkFormat.Serialize(this, null);
         exchange.Respond(StatusCode.Content, subtree, MediaType.ApplicationLinkFormat);
     }
 }
Example #5
0
        protected override void DoPost(CoapExchange exchange)
        {
            String payload = exchange.Request.PayloadString;
            if (payload == null)
                payload = String.Empty;
            String[] parts = payload.Split('\\');
            String[] path = parts[0].Split('/');
            IResource resource = Create(new LinkedList<String>(path));

            Response response = new Response(StatusCode.Created);
            response.LocationPath = resource.Uri;
            exchange.Respond(response);
        }
 protected override void DoPost(CoapExchange exchange)
 {
     Response response = Response.CreateResponse(exchange.Request, StatusCode.Changed);
     exchange.Respond(response);
     if (Execute == null)
     {
         Console.Write("Execute ");
         Console.WriteLine(this.Uri.ToString());
     }
     else
     {
         Execute(this, null);
     }
 }
 protected override void DoPost(CoapExchange exchange)
 {
     LWM2MServerResource lWM2MServerResource = LWM2MServerResource.Deserialise(exchange.Request);
     if (lWM2MServerResource == null)
     {
         Response response = Response.CreateResponse(exchange.Request, StatusCode.BadRequest);
         exchange.Respond(response);
     }
     else
     {
         this.Add(lWM2MServerResource);
         Response response = Response.CreateResponse(exchange.Request, StatusCode.Changed);
         exchange.Respond(response);
     }
 }
 protected override void DoPut(CoapExchange exchange)
 {
     SecurityResource securityResource = SecurityResource.Deserialise(exchange.Request);
     if (securityResource == null)
     {
         Response response = Response.CreateResponse(exchange.Request, StatusCode.BadRequest);
         exchange.Respond(response);
     }
     else
     {
         this.Add(securityResource);
         Response response = Response.CreateResponse(exchange.Request, StatusCode.Changed);
         exchange.Respond(response);
     }
 }
Example #9
0
        protected override void DoGet(CoapExchange exchange)
        {
            // Accept the request to promise the client this request will be acted.
            exchange.Accept();

            // Do sth. time-consuming
            Thread.Sleep(2000);

            // Now respond the previous request.
            Response response = new Response(StatusCode.Content);
            response.PayloadString = "This message was sent by a separate response.\n" +
                "Your client will need to acknowledge it, otherwise it will be retransmitted.";

            exchange.Respond(response);
        }
 protected override void DoPut(CoapExchange exchange)
 {
     ConnectivityStatisticsResource connectivityStatisticsResource = ConnectivityStatisticsResource.Deserialise(exchange.Request);
     if (connectivityStatisticsResource == null)
     {
         Response response = Response.CreateResponse(exchange.Request, StatusCode.BadRequest);
         exchange.Respond(response);
     }
     else
     {
         connectivityStatisticsResource.Name = this.GetNextChildName();
         this.Add(connectivityStatisticsResource);
         Response response = Response.CreateResponse(exchange.Request, StatusCode.Changed);
         exchange.Respond(response);
         OnChildCreated(connectivityStatisticsResource);
     }
 }
 protected override void DoPut(CoapExchange exchange)
 {
     DeviceCapabilityResource deviceCapabilityResource = DeviceCapabilityResource.Deserialise(exchange.Request);
     if (deviceCapabilityResource == null)
     {
         Response response = Response.CreateResponse(exchange.Request, StatusCode.BadRequest);
         exchange.Respond(response);
     }
     else
     {
         deviceCapabilityResource.Name = this.GetNextChildName();
         this.Add(deviceCapabilityResource);
         Response response = Response.CreateResponse(exchange.Request, StatusCode.Changed);
         exchange.Respond(response);
         OnChildCreated(deviceCapabilityResource);
     }
 }
 protected override void DoPut(CoapExchange exchange)
 {
     FlowObjectResource flowObjectResource = FlowObjectResource.Deserialise(exchange.Request);
     if (flowObjectResource == null)
     {
         Response response = Response.CreateResponse(exchange.Request, StatusCode.BadRequest);
         exchange.Respond(response);
     }
     else
     {
         flowObjectResource.Name = this.GetNextChildName();
         this.Add(flowObjectResource);
         Response response = Response.CreateResponse(exchange.Request, StatusCode.Changed);
         exchange.Respond(response);
         OnChildCreated(flowObjectResource);
     }
 }
 protected override void DoPost(CoapExchange exchange)
 {
     FlowObjectResource flowObjectResource = FlowObjectResource.Deserialise(exchange.Request);
     if (flowObjectResource == null)
     {
         Response response = Response.CreateResponse(exchange.Request, StatusCode.BadRequest);
         exchange.Respond(response);
     }
     else
     {
         flowObjectResource.Name = this.GetNextChildName();
         this.Add(flowObjectResource);
         Response response = Response.CreateResponse(exchange.Request, StatusCode.Created);
         response.AddOption(Option.Create(OptionType.LocationPath, string.Concat(flowObjectResource.Path,flowObjectResource.Name)));
         exchange.Respond(response);
         OnChildCreated(flowObjectResource);
     }
 }
Example #14
0
 protected override void DoGet(CoapExchange exchange)
 {
     Response response;
     if (exchange.Request.Observe.HasValue && exchange.Request.Observe.Value == 0)
     {
         response = Response.CreateResponse(exchange.Request, StatusCode.Content);
         response.MaxAge = 86400;
     }
     else
         response = Response.CreateResponse(exchange.Request, StatusCode.Content);
     using (MemoryStream steam = new MemoryStream())
     {
         TlvWriter writer = new TlvWriter(steam);
         this.Serialise(writer);
         response.Payload = steam.ToArray();
     }
     response.ContentType = TlvConstant.CONTENT_TYPE_TLV;
     exchange.Respond(response);
 }
Example #15
0
        protected override void DoGet(CoapExchange exchange)
        {
            String file = "data\\image\\";
            Int32 ct = MediaType.ImagePng;
            Request request = exchange.Request;

            if ((ct = MediaType.NegotiationContent(ct, _supported, request.GetOptions(OptionType.Accept)))
                == MediaType.Undefined)
            {
                exchange.Respond(StatusCode.NotAcceptable);
            }
            else
            {
                file += "image." + MediaType.ToFileExtension(ct);
                if (File.Exists(file))
                {
                    Byte[] data = null;
                    
                    try
                    {
                        data = File.ReadAllBytes(file);
                    }
                    catch (Exception ex)
                    {
                        exchange.Respond(StatusCode.InternalServerError, "IO error");
                        Console.WriteLine(ex.Message);
                    }

                    Response response = new Response(StatusCode.Content);
                    response.Payload = data;
                    response.ContentType = ct;
                    exchange.Respond(response);
                }
                else
                {
                    exchange.Respond(StatusCode.InternalServerError, "Image file not found");
                }
            }
        }
Example #16
0
 /// <inheritdoc/>
 protected override void DoGet(CoapExchange exchange)
 {
     exchange.Respond(StatusCode.Content,
         LinkFormat.Serialize(_root, exchange.Request.UriQueries),
         MediaType.ApplicationLinkFormat);
 }
Example #17
0
 protected override void DoGet(CoapExchange exchange)
 {
     exchange.Respond("Hello World!");
 }
 protected override void DoGet(CoapExchange exchange)
 {
     exchange.Respond(RESPONSE_PAYLOAD);
 }
Example #19
0
 protected override void DoPut(CoAP.Server.Resources.CoapExchange exchange)
 {
     exchange.Respond(payload);
 }
Example #20
0
 /// <summary>
 /// Handles the DELETE request in the given CoAPExchange.
 /// By default it responds with a 4.05 (Method Not Allowed).
 /// Override this method to respond differently.
 /// The response code to a DELETE request should be a 2.02 (Deleted).
 /// </summary>
 protected virtual void DoDelete(CoapExchange exchange)
 {
     exchange.Respond(StatusCode.MethodNotAllowed);
 }
Example #21
0
 /// <summary>
 /// Handles the DELETE request in the given CoAPExchange.
 /// By default it responds with a 4.05 (Method Not Allowed).
 /// Override this method to respond differently.
 /// The response code to a DELETE request should be a 2.02 (Deleted).
 /// </summary>
 protected virtual void DoDelete(CoapExchange exchange)
 {
     exchange.Respond(StatusCode.MethodNotAllowed);
 }
Example #22
0
 protected override void DoPost(CoapExchange exchange)
 {
     exchange.Respond(SERVER_RESPONSE);
 }
Example #23
0
        protected override void DoGet(CoapExchange exchange)
        {
            Response response = null;

            if (exchange.Request.Observe.HasValue && exchange.Request.Observe.Value == 0)
            {
                response = Response.CreateResponse(exchange.Request, StatusCode.Content);
                response.MaxAge = 86400;
            }
            else
                response = Response.CreateResponse(exchange.Request, StatusCode.Content);

            using (MemoryStream steam = new MemoryStream())
            {
                using (MemoryStream itemSteam = new MemoryStream())
                {
                    TlvWriter writer = new TlvWriter(steam);
                    TlvWriter itemWriter = new TlvWriter(itemSteam);

                    foreach (LWM2MResource item in Children)
                    {
                        if (ModifiedResource == null || ModifiedResource == item)
                        {
                            itemSteam.SetLength(0);
                            ushort identifier = ushort.Parse(item.Name);
                            item.Serialise(itemWriter);
                            writer.Write(TTlvTypeIdentifier.ObjectInstance, identifier, itemSteam.ToArray());
                        }
                    }
                    ModifiedResource = null;
                    response.Payload = steam.ToArray();
                }
            }
            response.ContentType = TlvConstant.CONTENT_TYPE_TLV;
            exchange.Respond(response);
        }
Example #24
0
 protected override void DoGet(CoapExchange exchange)
 {
     exchange.Respond("Response " + (++_counter) + " from resource " + Name);
 }
Example #25
0
 /// <inheritdoc/>
 protected override void DoGet(CoapExchange exchange)
 {
     exchange.Respond(StatusCode.Content,
                      LinkFormat.Serialize(_root, exchange.Request.UriQueries),
                      MediaType.ApplicationLinkFormat);
 }
Example #26
0
 protected override void DoPut(CoapExchange exchange)
 {
     if (exchange.Request.ContentType == TlvConstant.CONTENT_TYPE_TLV)
     {
         using (TlvReader reader = new TlvReader(exchange.Request.Payload))
         {
             this.Deserialise(reader);
         }
         Response response = Response.CreateResponse(exchange.Request, StatusCode.Changed);
         exchange.Respond(response);
     }
     else
         base.DoPut(exchange);
 }
 protected override void DoPut(CoapExchange exchange)
 {
     Response response = Response.CreateResponse(exchange.Request, StatusCode.BadRequest);
     exchange.Respond(response);
 }
Example #28
0
 /// <inheritdoc/>
 public virtual void HandleRequest(Exchange exchange)
 {
     CoapExchange ce = new CoapExchange(exchange, this);
     switch (exchange.Request.Method)
     {
         case Method.GET:
             DoGet(ce);
             break;
         case Method.POST:
             DoPost(ce);
             break;
         case Method.PUT:
             DoPut(ce);
             break;
         case Method.DELETE:
             DoDelete(ce);
             break;
         default:
             break;
     }
 }
Example #29
0
 protected override void DoPut(CoapExchange exchange)
 {
     Request request = exchange.Request;
     bool processed = false;
     if ((request.ContentType == TlvConstant.CONTENT_TYPE_TLV))
     {
         using (TlvReader reader = new TlvReader(request.Payload))
         {
             this.Deserialise(reader);
             processed = true;
         }
     }
     if (processed)
     {
         Response response = Response.CreateResponse(exchange.Request, StatusCode.Changed);
         exchange.Respond(response);
         if (Updated != null)
             Updated(this, null);
     }
     else
     {
         Response response = Response.CreateResponse(exchange.Request, StatusCode.BadRequest);
         exchange.Respond(response);
     }
 }
Example #30
0
 protected override void DoGet(CoapExchange exchange)
 {
     exchange.Respond(StatusCode.Content, _now.ToString(), MediaType.TextPlain);
 }
Example #31
0
 protected override void DoPut(CoapExchange exchange)
 {
     UpdateResource(exchange);
 }
Example #32
0
 protected override void DoPost(CoapExchange exchange)
 {
     String old = _content;
     _content = exchange.Request.PayloadString;
     exchange.Respond(StatusCode.Changed, old);
     Changed();
 }
Example #33
0
 private void UpdateResource(CoapExchange exchange)
 {
     OpaqueResource opaqueResource = OpaqueResource.Deserialise(exchange.Request);
     if (opaqueResource == null)
     {
         Response response = Response.CreateResponse(exchange.Request, StatusCode.BadRequest);
         exchange.Respond(response);
     }
     else
     {
         Value = opaqueResource.Value;
         Response response = Response.CreateResponse(exchange.Request, StatusCode.Changed);
         exchange.Respond(response);
     }
 }
Example #34
0
 protected override void DoGet(CoapExchange exchange)
 {
     exchange.Respond(payload);
 }
 protected override void DoPost(CoapExchange exchange)
 {
     _WaitHandle.Set();
     Response response = Response.CreateResponse(exchange.Request, StatusCode.Changed);
     exchange.Respond(response);
 }