Example #1
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);
        }
        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);
        }