コード例 #1
0
 public static DateTimeResources Deserialise(TlvReader reader)
 {
     DateTimeResources result = null;
     if (reader.TlvRecord == null)
         reader.Read();
     if (reader.TlvRecord != null)
     {
         if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.MultipleResources)
         {
             result = new DateTimeResources(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)
                         {
                             DateTimeResource childResource = new DateTimeResource(childReader.TlvRecord.Identifier.ToString());
                             childResource.Value = childReader.TlvRecord.ValueAsDateTime();
                             result.Add(childResource);
                         }
                     }
                 }
             }
         }
     }
     return result;
 }
コード例 #2
0
        public static DateTimeResources Deserialise(TlvReader reader)
        {
            DateTimeResources result = null;

            if (reader.TlvRecord == null)
            {
                reader.Read();
            }
            if (reader.TlvRecord != null)
            {
                if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.MultipleResources)
                {
                    result = new DateTimeResources(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)
                                {
                                    DateTimeResource childResource = new DateTimeResource(childReader.TlvRecord.Identifier.ToString());
                                    childResource.Value = childReader.TlvRecord.ValueAsDateTime();
                                    result.Add(childResource);
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
コード例 #3
0
 public static bool Deserialise(TlvReader reader, DateTimeResource item)
 {
     bool result = false;
     if (reader.TlvRecord == null)
         reader.Read();
     if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ResourceWithValue)
     {
         item.Value = reader.TlvRecord.ValueAsDateTime();
         result = true;
     }
     return result;
 }
コード例 #4
0
        public static bool Deserialise(TlvReader reader, DateTimeResource item)
        {
            bool result = false;

            if (reader.TlvRecord == null)
            {
                reader.Read();
            }
            if (reader.TlvRecord.TypeIdentifier == TTlvTypeIdentifier.ResourceWithValue)
            {
                item.Value = reader.TlvRecord.ValueAsDateTime();
                result     = true;
            }
            return(result);
        }
コード例 #5
0
 public static DateTimeResource Deserialise(Request request)
 {
     DateTimeResource result = null;
     string name = request.UriPaths.Last();
     if (!string.IsNullOrEmpty(name) && (request.ContentType == TlvConstant.CONTENT_TYPE_TLV))
     {
         DateTimeResource resource = new DateTimeResource(name);
         using (TlvReader reader = new TlvReader(request.Payload))
         {
             if (Deserialise(reader, resource))
                 result = resource;
         }
     }
     return result;
 }
コード例 #6
0
        private void UpdateResource(CoapExchange exchange)
        {
            DateTimeResource dateTimeResource = DateTimeResource.Deserialise(exchange.Request);

            if (dateTimeResource == null)
            {
                Response response = Response.CreateResponse(exchange.Request, StatusCode.BadRequest);
                exchange.Respond(response);
            }
            else
            {
                Value = dateTimeResource.Value;
                Response response = Response.CreateResponse(exchange.Request, StatusCode.Changed);
                exchange.Respond(response);
            }
        }
コード例 #7
0
        public static DateTimeResource Deserialise(Request request)
        {
            DateTimeResource result = null;
            string           name   = request.UriPaths.Last();

            if (!string.IsNullOrEmpty(name) && (request.ContentType == TlvConstant.CONTENT_TYPE_TLV))
            {
                DateTimeResource resource = new DateTimeResource(name);
                using (TlvReader reader = new TlvReader(request.Payload))
                {
                    if (Deserialise(reader, resource))
                    {
                        result = resource;
                    }
                }
            }
            return(result);
        }
コード例 #8
0
        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();
                        }
                    }
                }
            }
        }