Пример #1
0
        protected static void ReadOptions(CoapMessage message)
        {
            object[] ifmatch       = message.Options.GetOptionValues(OptionType.IfMatch);
            object[] etag          = message.Options.GetOptionValues(OptionType.ETag);
            object[] locationpath  = message.Options.GetOptionValues(OptionType.LocationPath);
            object[] uripath       = message.Options.GetOptionValues(OptionType.UriPath);
            object[] uriquery      = message.Options.GetOptionValues(OptionType.UriQuery);
            object[] locationquery = message.Options.GetOptionValues(OptionType.LocationQuery);
            object   observe       = message.Options.GetOptionValue(OptionType.Observe);

            message.ResourceUri = message.Options.GetResourceUri();

            message._ifMatch      = ifmatch == null ? new List <byte[]>() : new List <byte[]>(ifmatch as byte[][]);
            message._eTag         = etag == null ? new List <byte[]>() : new List <byte[]>(etag as byte[][]);
            message.IfNoneMatch   = message.Options.Contains(new CoapOption(OptionType.IfNoneMatch, null));
            message._locationPath = locationpath == null ? new List <string>() : new List <string>(locationpath as string[]);

            if (observe != null)
            {
                message.Observe = ((uint)observe) == 0 ? true : false;
            }

            object contentType = (message.Options.GetOptionValue(OptionType.ContentFormat));

            if (contentType != null)
            {
                message.ContentType = (MediaType)Convert.ToInt32(contentType);
            }

            message.MaxAge = message.Options.GetOptionValue(OptionType.MaxAge) != null ? (uint)message.Options.GetOptionValue(OptionType.MaxAge) : 0;

            object accept = message.Options.GetOptionValue(OptionType.Accept);

            if (accept != null)
            {
                message.Accept = (MediaType)Convert.ToInt32(accept);
            }

            //message.Accept = message.Options.GetOptionValue(OptionType.Accept) != null ? (uint)message.Options.GetOptionValue(OptionType.Accept) : 0;
            message._locationQuery = locationquery == null ? new List <string>() : new List <string>(locationquery as string[]);
            message.ProxyUri       = message.Options.GetOptionValue(OptionType.ProxyUri) as string;
            message.ProxyScheme    = message.Options.GetOptionValue(OptionType.ProxyScheme) as string;
            message.Size1          = message.Options.GetOptionValue(OptionType.Size1) != null ? (uint)message.Options.GetOptionValue(OptionType.Size1) : 0;
        }
Пример #2
0
        public void DispatchResponse(CoapMessage message)
        {
            var observeQuery = observeContainer.Where(c => c.Key == Convert.ToBase64String(message.Token));

            foreach (var item in observeQuery)
            {
                item.Value(message.Code, MediaTypeConverter.ConvertFromMediaType(message.ContentType), message.Payload);
            }

            if (observeQuery.Count() == 0)
            {
                var query = container.Where(c => c.Value.Item1 == Convert.ToBase64String(message.Token));
                KeyValuePair <ushort, Tuple <string, DateTime, Action <CodeType, string, byte[]> > >[]
                kvps = query.ToArray();
                foreach (var kvp in kvps)
                {
                    kvp.Value.Item3(message.Code, MediaTypeConverter.ConvertFromMediaType(message.ContentType),
                                    message.Payload);
                    container.Remove(kvp.Key);
                }
            }

            timer.Enabled = container.Count() > 0;
        }
Пример #3
0
 public CoapMessageEventArgs(CoapMessage message)
 {
     Message = message;
 }