public static IntegerResources Deserialise(TlvReader reader)
 {
     IntegerResources result = null;
     if (reader.TlvRecord == null)
         reader.Read();
     if (reader.TlvRecord != null)
     {
         if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.MultipleResources)
         {
             result = new IntegerResources(reader.TlvRecord.Identifier.ToString());
             if (reader.TlvRecord.Value != null)
             {
                 using (TlvReader childReader = new TlvReader(reader.TlvRecord.Value))
                 {
                     while (childReader.Read())
                     {
                         if (childReader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ResourceInstance)
                         {
                             IntegerResource childResource = new IntegerResource(childReader.TlvRecord.Identifier.ToString());
                             childResource.Value = childReader.TlvRecord.ValueAsInt64();
                             result.Add(childResource);
                         }
                     }
                 }
             }
         }
     }
     return result;
 }
        public static IntegerResources Deserialise(TlvReader reader)
        {
            IntegerResources result = null;

            if (reader.TlvRecord == null)
            {
                reader.Read();
            }
            if (reader.TlvRecord != null)
            {
                if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.MultipleResources)
                {
                    result = new IntegerResources(reader.TlvRecord.Identifier.ToString());
                    if (reader.TlvRecord.Value != null)
                    {
                        using (TlvReader childReader = new TlvReader(reader.TlvRecord.Value))
                        {
                            while (childReader.Read())
                            {
                                if (childReader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ResourceInstance)
                                {
                                    IntegerResource childResource = new IntegerResource(childReader.TlvRecord.Identifier.ToString());
                                    childResource.Value = childReader.TlvRecord.ValueAsInt64();
                                    result.Add(childResource);
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
 public static bool Deserialise(TlvReader reader, IntegerResource item)
 {
     bool result = false;
     if (reader.TlvRecord == null)
         reader.Read();
     if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ResourceWithValue)
     {
         item.Value = reader.TlvRecord.ValueAsInt64();
         result = true;
     }
     return result;
 }
 public static IntegerResource Deserialise(Request request)
 {
     IntegerResource result = null;
     string name = request.UriPaths.Last();
     if (!string.IsNullOrEmpty(name) && (request.ContentType == TlvConstant.CONTENT_TYPE_TLV))
     {
         IntegerResource resource = new IntegerResource(name);
         using (TlvReader reader = new TlvReader(request.Payload))
         {
             if (Deserialise(reader, resource))
                 result = resource;
         }
     }
     return result;
 }
        public static bool Deserialise(TlvReader reader, IntegerResource item)
        {
            bool result = false;

            if (reader.TlvRecord == null)
            {
                reader.Read();
            }
            if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ResourceWithValue)
            {
                item.Value = reader.TlvRecord.ValueAsInt64();
                result     = true;
            }
            return(result);
        }
        private void UpdateResource(CoapExchange exchange)
        {
            IntegerResource integerResource = IntegerResource.Deserialise(exchange.Request);

            if (integerResource == null)
            {
                Response response = Response.CreateResponse(exchange.Request, StatusCode.BadRequest);
                exchange.Respond(response);
            }
            else
            {
                Value = integerResource.Value;
                Response response = Response.CreateResponse(exchange.Request, StatusCode.Changed);
                exchange.Respond(response);
            }
        }
        public static IntegerResource Deserialise(Request request)
        {
            IntegerResource result = null;
            string          name   = request.UriPaths.Last();

            if (!string.IsNullOrEmpty(name) && (request.ContentType == TlvConstant.CONTENT_TYPE_TLV))
            {
                IntegerResource resource = new IntegerResource(name);
                using (TlvReader reader = new TlvReader(request.Payload))
                {
                    if (Deserialise(reader, resource))
                    {
                        result = resource;
                    }
                }
            }
            return(result);
        }
        public override void Execute()
        {
            if (Parameters.Count > 1)
            {
                if (Parameters[0].StartsWith("/"))
                    Parameters[0] = Parameters[0].Substring(1);
                LWM2MResource resource = _Client.GetResource(Parameters[0]) as LWM2MResource;
                if (resource == null)
                {
                    IResource parentResource = _Client.GetParentResource(Parameters[0]);

                    resource = parentResource as LWM2MResource;

                    if (resource == null && parentResource.Parent != null && String.IsNullOrEmpty(parentResource.Parent.Path))
                    {
                        // object instance does not exist
                        LWM2MResources resources = parentResource as LWM2MResources;
                        string instanceID = Parameters[0].Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[1];
                        parentResource = resource = resources.CreateResource(instanceID);

                        resources.ModifiedResource = resource;

                        resources.Changed();
                        //(parentResource as LWM2MResource).Changed();
                        resource = null;
                    }

                    if (resource == null)
                    {
                        LWM2MResources resources = parentResource as LWM2MResources;

                        if (resources != null)
                        {
                            string[] paths = Parameters[0].Split('/');
                            string name = paths[paths.Length - 1];
                            LWM2MResource childResource = null;
                            BooleanResources booleanResources = resources as BooleanResources;
                            if (booleanResources == null)
                            {
                                DateTimeResources dateTimeResources = resources as DateTimeResources;
                                if (dateTimeResources == null)
                                {
                                    FloatResources floatResources = resources as FloatResources;
                                    if (floatResources == null)
                                    {
                                        IntegerResources integerResources = resources as IntegerResources;
                                        if (integerResources == null)
                                        {
                                            OpaqueResources opaqueResources = resources as OpaqueResources;
                                            if (opaqueResources == null)
                                            {
                                                StringResources stringResources = resources as StringResources;
                                                if (stringResources == null)
                                                {

                                                }
                                                else
                                                    childResource = new StringResource(name);
                                            }
                                            else
                                                childResource = new OpaqueResource(name);
                                        }
                                        else
                                            childResource = new IntegerResource(name);
                                    }
                                    else
                                        childResource = new FloatResource(name);
                                }
                                else
                                    childResource = new DateTimeResource(name);
                            }
                            else
                                childResource = new BooleanResource(name);

                            if (childResource != null)
                            {
                                childResource.SetValue(Parameters[1]);
                                resources.Add(childResource);
                            }

                        }
                    }
                    else
                    {

                    }

                }
                else
                {
                    resource.SetValue(Parameters[1]);
                    resource.Changed();
                    LWM2MResource parent = resource.Parent as LWM2MResource;
                    if (parent != null)
                    {
                        parent.Changed();
                        LWM2MResources grandparent = parent.Parent as LWM2MResources;
                        if (grandparent != null)
                        {
                            grandparent.Changed();
                        }
                    }
                }
            }
        }