Esempio n. 1
0
        /// <summary>
        /// Adds an object instance.
        /// </summary>
        /// <param name="Instance">Object instance.</param>
        public void Add(Lwm2mObjectInstance Instance)
        {
            lock (this.instances)
            {
                if (Instance.InstanceId < 0)
                {
                    throw new ArgumentException("Invalid object instance ID.", nameof(Instance));
                }

                if (this.instances.ContainsKey(Instance.InstanceId))
                {
                    throw new ArgumentException("An object instance with ID " + Instance.InstanceId +
                                                " is already registered.", nameof(Instance));
                }

                this.instances[Instance.InstanceId] = Instance;
                Instance.Object = this;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Removes all instances.
        /// </summary>
        protected void ClearInstances()
        {
            Lwm2mObjectInstance[] Instances;

            lock (this.instances)
            {
                Instances = new Lwm2mObjectInstance[this.instances.Count];
                this.instances.Values.CopyTo(Instances, 0);
                this.instances.Clear();
            }

            foreach (Lwm2mObjectInstance Instance in Instances)
            {
                this.client?.CoapEndpoint.Unregister(Instance);

                foreach (Lwm2mResource Resource in Instance.Resources)
                {
                    this.client?.CoapEndpoint.Unregister(Resource);
                }
            }
        }