コード例 #1
0
ファイル: CarelessResource.cs プロジェクト: rlusian1/CoAP.NET
 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...
 }
コード例 #2
0
ファイル: Resource.cs プロジェクト: wfvvfw/CoAP.NET
        /// <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;
            }
        }
コード例 #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);
        }
コード例 #4
0
ファイル: StorageResource.cs プロジェクト: rlusian1/CoAP.NET
 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);
     }
 }
コード例 #5
0
ファイル: StorageResource.cs プロジェクト: rlusian1/CoAP.NET
        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);
        }
コード例 #6
0
 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);
     }
 }
コード例 #7
0
 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);
     }
 }
コード例 #8
0
 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);
     }
 }
コード例 #9
0
ファイル: SeparateResource.cs プロジェクト: rlusian1/CoAP.NET
        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);
        }
コード例 #10
0
 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);
     }
 }
コード例 #11
0
 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);
     }
 }
コード例 #12
0
 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);
     }
 }
コード例 #13
0
 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);
     }
 }
コード例 #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);
 }
コード例 #15
0
ファイル: ImageResource.cs プロジェクト: rlusian1/CoAP.NET
        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");
                }
            }
        }
コード例 #16
0
 /// <inheritdoc/>
 protected override void DoGet(CoapExchange exchange)
 {
     exchange.Respond(StatusCode.Content,
         LinkFormat.Serialize(_root, exchange.Request.UriQueries),
         MediaType.ApplicationLinkFormat);
 }
コード例 #17
0
 protected override void DoGet(CoapExchange exchange)
 {
     exchange.Respond("Hello World!");
 }
コード例 #18
0
 protected override void DoGet(CoapExchange exchange)
 {
     exchange.Respond(RESPONSE_PAYLOAD);
 }
コード例 #19
0
 protected override void DoPut(CoAP.Server.Resources.CoapExchange exchange)
 {
     exchange.Respond(payload);
 }
コード例 #20
0
ファイル: Resource.cs プロジェクト: wfvvfw/CoAP.NET
 /// <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);
 }
コード例 #21
0
ファイル: Resource.cs プロジェクト: Kulak/CoAP.NET
 /// <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);
 }
コード例 #22
0
ファイル: MessageTypeTest.cs プロジェクト: rlusian1/CoAP.NET
 protected override void DoPost(CoapExchange exchange)
 {
     exchange.Respond(SERVER_RESPONSE);
 }
コード例 #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);
        }
コード例 #24
0
ファイル: Program.cs プロジェクト: rlusian1/CoAP.NET
 protected override void DoGet(CoapExchange exchange)
 {
     exchange.Respond("Response " + (++_counter) + " from resource " + Name);
 }
コード例 #25
0
 /// <inheritdoc/>
 protected override void DoGet(CoapExchange exchange)
 {
     exchange.Respond(StatusCode.Content,
                      LinkFormat.Serialize(_root, exchange.Request.UriQueries),
                      MediaType.ApplicationLinkFormat);
 }
コード例 #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);
 }
コード例 #27
0
 protected override void DoPut(CoapExchange exchange)
 {
     Response response = Response.CreateResponse(exchange.Request, StatusCode.BadRequest);
     exchange.Respond(response);
 }
コード例 #28
0
ファイル: Resource.cs プロジェクト: Kulak/CoAP.NET
 /// <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;
     }
 }
コード例 #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);
     }
 }
コード例 #30
0
ファイル: TimeResource.cs プロジェクト: rlusian1/CoAP.NET
 protected override void DoGet(CoapExchange exchange)
 {
     exchange.Respond(StatusCode.Content, _now.ToString(), MediaType.TextPlain);
 }
コード例 #31
0
 protected override void DoPut(CoapExchange exchange)
 {
     UpdateResource(exchange);
 }
コード例 #32
0
ファイル: CoapClientTest.cs プロジェクト: rlusian1/CoAP.NET
 protected override void DoPost(CoapExchange exchange)
 {
     String old = _content;
     _content = exchange.Request.PayloadString;
     exchange.Respond(StatusCode.Changed, old);
     Changed();
 }
コード例 #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);
     }
 }
コード例 #34
0
ファイル: LargeResource.cs プロジェクト: rlusian1/CoAP.NET
 protected override void DoGet(CoapExchange exchange)
 {
     exchange.Respond(payload);
 }
コード例 #35
0
 protected override void DoPost(CoapExchange exchange)
 {
     _WaitHandle.Set();
     Response response = Response.CreateResponse(exchange.Request, StatusCode.Changed);
     exchange.Respond(response);
 }