示例#1
0
        /// <summary>
        /// Removes all resources.
        /// </summary>
        protected void ClearResources()
        {
            Lwm2mResource[] Resources;

            lock (this.resources)
            {
                Resources = new Lwm2mResource[this.resources.Count];
                this.resources.Values.CopyTo(Resources, 0);
                this.resources.Clear();
            }

            foreach (Lwm2mResource Resource in Resources)
            {
                this.obj?.Client?.CoapEndpoint.Unregister(Resource);
            }
        }
示例#2
0
        /// <summary>
        /// Adds a resource.
        /// </summary>
        /// <param name="Resource">Resource.</param>
        public void Add(Lwm2mResource Resource)
        {
            lock (this.resources)
            {
                if (Resource.ResourceId < 0)
                {
                    throw new ArgumentException("Invalid resource ID.", nameof(Resource));
                }

                if (this.resources.ContainsKey(Resource.ResourceId))
                {
                    throw new ArgumentException("A resource with ID " + Resource.ResourceId +
                                                " is already registered.", nameof(Resource));
                }

                this.resources[Resource.ResourceId] = Resource;
                Resource.ObjectInstance             = this;
            }
        }
示例#3
0
 /// <summary>
 /// Method called when the resource value has been updated.
 /// </summary>
 /// <param name="Resource">Resource reporting an updated value.</param>
 public virtual Task ValueUpdated(Lwm2mResource Resource)
 {
     return(Task.CompletedTask);
 }