コード例 #1
0
        public async Task BroadcastMessageAsync(OicMessage request)
        {
            var message = request.ToCoapMessage();

            message.IsMulticast = true;
            message.Type        = CoapMessageType.NonConfirmable;

            await _client.SendAsync(message);
        }
コード例 #2
0
        public async Task <int> SendMessageAsync(OicMessage request, IOicEndpoint endpoint = null)
        {
            var coapEndpoint = endpoint as OicCoapEndpoint
                               ?? throw new ArgumentException($"{nameof(endpoint)} is not of type {nameof(OicCoapEndpoint)}", nameof(endpoint));

            var message = request.ToCoapMessage();

            var baseRequest = message.Clone();

            baseRequest.Payload = null;
            _requestMessages.Add(request.RequestId, baseRequest);


            return((await _client.SendAsync(message, coapEndpoint._coapEndpoint)).Id);
        }
コード例 #3
0
ファイル: OicCoapExtensions.cs プロジェクト: NZSmartie/OICNet
        public static CoapMessage ToCoapMessage(this OicMessage message)
        {
            var coapMessage = new CoapMessage
            {
                Payload = message.Content,
                Token   = BitConverter.GetBytes(message.RequestId),
            };

            if (message.ContentType != OicMessageContentType.None)
            {
                coapMessage.Options.Add(new CoAPNet.Options.ContentFormat(message.ContentType.ToCoapContentFormat()));
            }

            if (message.ToUri != null)
            {
                if (message.ToUri.IsAbsoluteUri)
                {
                    coapMessage.SetUri(new UriBuilder(message.ToUri)
                    {
                        Scheme = "coap"
                    }.Uri);
                }
                else
                {
                    coapMessage.SetUri(message.ToUri, UriComponents.PathAndQuery);
                }
            }

            if (message is OicRequest request)
            {
                coapMessage.Code = request.Operation.ToCoapMessageCode();
                foreach (var contentType in request.Accepts)
                {
                    coapMessage.Options.Add(new CoAPNet.Options.Accept(contentType.ToCoapContentFormat()));
                }
            }
            else if (message is OicResponse response)
            {
                coapMessage.Code = response.ResposeCode.ToCoapMessageCode();
            }

            return(coapMessage);
        }
コード例 #4
0
 public virtual Task BroadcastMessageAsync(OicMessage message)
 {
     return(Task.CompletedTask);
 }
コード例 #5
0
 public virtual Task <int> MockSendMessageAsync(OicMessage packet)
 {
     return(Task.FromResult(0));
 }
コード例 #6
0
 public Task <int> SendMessageAsync(OicMessage message, IOicEndpoint endpoint = null)
 {
     return(IsDisposed
         ? throw new OicException("Encdpoint Disposed")
         : MockSendMessageAsync(message));
 }