Beispiel #1
0
        public static string GetMessageType(JupyterMessageContent source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            return(GetMessageType(source.GetType()));
        }
Beispiel #2
0
        private static string GetMessageType(JupyterMessageContent source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            var attribute = source.GetType().GetCustomAttribute <JupyterMessageTypeAttribute>() ?? throw new InvalidOperationException("source is not annotated with JupyterMessageTypeAttribute");

            return(attribute.Type);
        }
Beispiel #3
0
        public static Message Create(JupyterMessageContent content, Header parentHeader, IReadOnlyList <IReadOnlyList <byte> > identifiers = null, string signature = null)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            var messageType = JupyterMessageContent.GetMessageType(content);
            var session     = parentHeader?.Session ?? Guid.NewGuid().ToString();

            var message = new Message(Header.Create(messageType, session), parentHeader: parentHeader, content: content, identifiers: identifiers, signature: signature);


            return(message);
        }
Beispiel #4
0
 public Message(Header header,
                JupyterMessageContent content = null,
                Header parentHeader           = null,
                string signature = null,
                IReadOnlyDictionary <string, object> metaData     = null,
                IReadOnlyList <IReadOnlyList <byte> > identifiers = null,
                IReadOnlyList <IReadOnlyList <byte> > buffers     = null)
 {
     Header       = header;
     ParentHeader = parentHeader;
     Buffers      = buffers ?? new List <IReadOnlyList <byte> >();
     Identifiers  = identifiers ?? new List <IReadOnlyList <byte> >();
     MetaData     = metaData ?? new Dictionary <string, object>();
     Content      = content ?? JupyterMessageContent.Empty;
     Signature    = signature ?? string.Empty;
 }
Beispiel #5
0
        public static Message CreateResponse(JupyterMessageContent content,
                                             Message request)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var replyMessage = Create(content, request.Header, request.Identifiers, request.Signature);

            return(replyMessage);
        }
Beispiel #6
0
 public static Header Create(Type messageType, string session)
 {
     return(Create(JupyterMessageContent.GetMessageType(messageType), session));
 }