Exemple #1
0
        // construct message with token
        public CoapMessage(CoapMessageType type, byte[] token, CoapMessageCode code) : this(type, code)
        {
            if (token.Length > 8)
            {
                throw new CoapMessageFormatException("Token length must be 0-8 characters");
            }

            TokenValue = token;
        }
        void ThrowIfInvalid(CoapMessageCode code)
        {
            if (code.Class > 7)
            {
                throw new CoapProtocolViolationException("Code class is larget than 7.");
            }

            if (code.Detail > 31)
            {
                throw new CoapProtocolViolationException("Code class is larget than 7.");
            }
        }
        static void ThrowIfInvalid(CoapMessageCode code)
        {
            if (code == null)
            {
                throw new CoapProtocolViolationException("Message code is not set.");
            }

            if (code.Class > 7)
            {
                throw new CoapProtocolViolationException("Message code class is larger than 7.");
            }

            if (code.Detail > 31)
            {
                throw new CoapProtocolViolationException("Message detail is larger than 7.");
            }
        }
        public static OicRequestOperation ToOicRequestOperation(this CoapMessageCode code)
        {
            if (code == CoapMessageCode.Get)
            {
                return(OicRequestOperation.Get);
            }
            if (code == CoapMessageCode.Post)
            {
                return(OicRequestOperation.Post);
            }
            if (code == CoapMessageCode.Put)
            {
                return(OicRequestOperation.Put);
            }
            if (code == CoapMessageCode.Delete)
            {
                return(OicRequestOperation.Delete);
            }

            throw new OicException("Unsupported operation", new ArgumentOutOfRangeException(nameof(code), code, null), OicResponseCode.BadRequest);
        }
 public bool TestCoapMessageCodeIsServerError(CoapMessageCode code)
 {
     return(code.IsServerError());
 }
 public bool TestCoapMessageCodeIsClientError(CoapMessageCode code)
 {
     return(code.IsClientError());
 }
 public bool TestCoapMessageCodeIsSuccess(CoapMessageCode code)
 {
     return(code.IsSuccess());
 }
 public static CoapMessage CreateMessage(CoapMessageCode code, string message, CoapMessageType type = CoapMessageType.Confirmable)
 => CoapMessage.Create(code, message, type);
        public static OicResponseCode ToOicResponseCode(this CoapMessageCode code)
        {
            if (code == CoapMessageCode.Created)
            {
                return(OicResponseCode.Created);
            }
            if (code == CoapMessageCode.Delete)
            {
                return(OicResponseCode.Deleted);
            }
            if (code == CoapMessageCode.Valid)
            {
                return(OicResponseCode.Valid);
            }
            if (code == CoapMessageCode.Changed)
            {
                return(OicResponseCode.Changed);
            }
            if (code == CoapMessageCode.Content)
            {
                return(OicResponseCode.Content);
            }
            if (code == CoapMessageCode.BadRequest)
            {
                return(OicResponseCode.BadRequest);
            }
            if (code == CoapMessageCode.Unauthorized)
            {
                return(OicResponseCode.Unauthorized);
            }
            if (code == CoapMessageCode.BadOption)
            {
                return(OicResponseCode.BadOption);
            }
            if (code == CoapMessageCode.Forbidden)
            {
                return(OicResponseCode.Forbidden);
            }
            if (code == CoapMessageCode.NotFound)
            {
                return(OicResponseCode.NotFound);
            }
            if (code == CoapMessageCode.MethodNotAllowed)
            {
                return(OicResponseCode.OperationNotAllowed);
            }
            if (code == CoapMessageCode.NotAcceptable)
            {
                return(OicResponseCode.NotAcceptable);
            }
            if (code == CoapMessageCode.PreconditionFailed)
            {
                return(OicResponseCode.PreconditionFailed);
            }
            if (code == CoapMessageCode.RequestEntityTooLarge)
            {
                return(OicResponseCode.RequestEntityTooLarge);
            }
            if (code == CoapMessageCode.UnsupportedContentFormat)
            {
                return(OicResponseCode.UnsupportedContentType);
            }
            if (code == CoapMessageCode.InternalServerError)
            {
                return(OicResponseCode.InternalServerError);
            }
            if (code == CoapMessageCode.NotImplemented)
            {
                return(OicResponseCode.NotImplemented);
            }
            if (code == CoapMessageCode.BadGateway)
            {
                return(OicResponseCode.BadGateway);
            }
            if (code == CoapMessageCode.ServiceUnavailable)
            {
                return(OicResponseCode.ServiceUnavailable);
            }
            if (code == CoapMessageCode.GatewayTimeout)
            {
                return(OicResponseCode.GatewayTimeout);
            }
            if (code == CoapMessageCode.ProxyingNotSupported)
            {
                return(OicResponseCode.ProxyingNotSupported);
            }

            throw new OicException("Unsupported response code", new ArgumentOutOfRangeException(nameof(code), code, null));
        }
Exemple #10
0
 // Construct a request message without payload
 public CoapRequest(CoapMessageType type, CoapMessageCode code, Uri uri)
 {
     Type = type;
     Uri  = uri;
     Code = code;
 }
Exemple #11
0
 // useful constructor for serialising messages
 public CoapMessage(CoapMessageType type, CoapMessageCode code) : this()
 {
     Type = type;
     Code = code;
 }
Exemple #12
0
 // construct request with url, token and payload
 public CoapMessage(CoapMessageType type, byte[] token, CoapMessageCode code, Uri url, byte[] payload) : this(type, token, code, url)
 {
     Payload = payload;
 }
Exemple #13
0
 // construct request with url and token
 public CoapMessage(CoapMessageType type, byte[] token, CoapMessageCode code, Uri url) : this(type, token, code)
 {
     Uri = url;
 }
Exemple #14
0
 // construct request with url
 public CoapMessage(CoapMessageType type, CoapMessageCode code, Uri url) : this(type, code)
 {
     Uri = url;
 }
 public bool TestCoapMessageCodeIsRequest(CoapMessageCode code)
 {
     return(code.IsRequest());
 }
Exemple #16
0
 public string Convert(CoapMessageCode value)
 {
     return(Consts.MessageCodes.SingleOrDefault(c => c.Item2 == value)?.Item1 ?? string.Empty);
 }
Exemple #17
0
 // Construct a request message with payload
 public CoapRequest(CoapMessageType type, CoapMessageCode code, Uri uri, byte[] payload, ContentFormat format) : this(type, code, uri)
 {
     Payload = payload;
 }