internal bool Register(Lwm2mClient Client) { if (!this.shortServerId.IntegerValue.HasValue) { return(false); } Lwm2mSecurityObjectInstance SecurityInfo = Client.GetSecurityInfo( (ushort)this.shortServerId.IntegerValue.Value); if (SecurityInfo is null) { return(false); } Lwm2mServerReference Ref = SecurityInfo.GetServerReference(false); if (Ref is null) { return(false); } Client.Register(this.lifetimeSeconds.IntegerValue.HasValue ? (int)this.lifetimeSeconds.IntegerValue.Value : 86400, Ref); return(true); }
/// <summary> /// Executes the PUT method on the resource. /// </summary> /// <param name="Request">CoAP Request</param> /// <param name="Response">CoAP Response</param> /// <exception cref="CoapException">If an error occurred when processing the method.</exception> public void PUT(CoapMessage Request, CoapResponse Response) { if (this.Client.State == Lwm2mState.Bootstrap && this.Client.IsFromBootstrapServer(Request)) { if (!string.IsNullOrEmpty(Request.SubPath) && ushort.TryParse(Request.SubPath.Substring(1), out ushort InstanceId)) { Lwm2mSecurityObjectInstance Instance = new Lwm2mSecurityObjectInstance(InstanceId); this.Add(Instance); this.Client.Endpoint.Register(Instance); Instance.AfterRegister(this.Client); Request.Path += Request.SubPath; Request.SubPath = string.Empty; Instance.PUT(Request, Response); } else { Response.RST(CoapCode.BadRequest); } } else { Response.RST(CoapCode.Unauthorized); } }