コード例 #1
0
ファイル: Request.cs プロジェクト: markchipman/echo-process
 UnSubscribeReq(ClientConnectionId id, ProcessId publisher, ProcessId subscriber, ClientConnection connection)
 {
     Id         = id;
     Publisher  = publisher;
     Subscriber = subscriber;
     Connection = connection;
 }
コード例 #2
0
 ClientConnection(ClientConnectionId id, Map <ProcessId, Lst <Subscriber> > subscriptions, DateTime lastAccess, Action <ClientMessageDTO> tell)
 {
     Id = id;
     this.subscriptions = subscriptions;
     this.lastAccess    = lastAccess;
     Tell = tell;
 }
コード例 #3
0
ファイル: Request.cs プロジェクト: markchipman/echo-process
        public static Either <string, Req> Create(ClientConnectionId id, ClientMessageId msgId, ProcessId to, ProcessId sender, string msg, Map <ClientConnectionId, ClientConnection> clientConnections)
        {
            if (!to.IsValid)
            {
                return("Invalid process-id (To)");
            }
            var conn = clientConnections.Find(id);

            if (conn.IsNone)
            {
                return("Invalid connection-id");
            }

            var msgObj = (from type in validMessageTypes(to)
                          let obj = Deserialise.Object(msg, type)
                                    where obj != null
                                    select obj)
                         .FirstOrDefault();

            if (msgObj == null)
            {
                return("Message incompatible with the inbox message type");
            }

            return(new AskReq(id, msgId, to, sender, msgObj, conn.IfNone(() => null)));
        }
コード例 #4
0
ファイル: Request.cs プロジェクト: markchipman/echo-process
 AskReq(ClientConnectionId id, ClientMessageId msgId, ProcessId to, ProcessId sender, object msg, ClientConnection connection)
 {
     Id         = id;
     MessageId  = msgId;
     To         = to;
     Sender     = sender;
     Message    = msg;
     Connection = connection;
 }
コード例 #5
0
ファイル: Request.cs プロジェクト: markchipman/echo-process
        /// <summary>
        /// Parses a client request
        /// </summary>
        /// <param name="msg">Text version of the request
        ///
        ///     procsys:conn
        ///     procsys:diss|<Connection ID>
        ///     procsys:tell|<Connection ID>|<Message ID>|<Process ID: To>|<Process ID: Sender>|<Message JSON>
        ///     procsys:ask|<Connection ID>|<Message ID>|<Process ID: To>|<Process ID: Sender>|<Message JSON>
        ///     procsys:ping|<Connection ID>
        ///     procsys:sub|<Connection ID>|<Process ID: Publisher>|<Process ID: Subscriber>
        ///     procsys:usub|<Connection ID>|<Process ID: Publisher>|<Process ID: Subscriber>
        ///
        /// </param>
        /// <returns></returns>
        public static Either <string, Req> Parse(string msg, string remoteIp, Map <ClientConnectionId, ClientConnection> activeConnections)
        {
            try
            {
                var parse = new BarParse(msg);

                return(from hdr in parse.Header()
                       from typ in parse.GetNext()
                       from res in typ == "tell" ? from connid in parse.GetConnectionId(remoteIp)
                       from msgid  in parse.GetMessageId()
                       from to     in parse.GetProcessId()
                       from sender in parse.GetProcessId()
                       from body   in parse.GetRemaining()
                       select TellReq.Create(connid, msgid, to, sender, body, activeConnections)

                                : typ == "ask"   ? from connid in parse.GetConnectionId(remoteIp)
                       from msgid in parse.GetMessageId()
                       from to in parse.GetProcessId()
                       from sender in parse.GetProcessId()
                       from body in parse.GetRemaining()
                       select AskReq.Create(connid, msgid, to, sender, body, activeConnections)

                                : typ == "conn"  ? Right <string, Req>(ConnectReq.Default)

                                : typ == "diss"  ? DisconnectReq.Create(ClientConnectionId.New(parse.GetNextText()), activeConnections)

                                : typ == "sub"   ? from connid in parse.GetConnectionId(remoteIp)
                       from pub    in parse.GetProcessId()
                       from sub    in parse.GetProcessId()
                       select SubscribeReq.Create(connid, pub, sub, activeConnections)

                                : typ == "usub"  ? from connid in parse.GetConnectionId(remoteIp)
                       from pub    in parse.GetProcessId()
                       from sub    in parse.GetProcessId()
                       select UnSubscribeReq.Create(connid, pub, sub, activeConnections)

                                : typ == "ping"  ? PingReq.Create(ClientConnectionId.New(parse.GetNextText()), activeConnections)

                                : Left <string, Req>("Invalid request")
                       from req in res
                       select req);
            }
            catch (Exception e)
            {
                logErr(e);
                return("Invalid request");
            }
        }
コード例 #6
0
ファイル: Request.cs プロジェクト: markchipman/echo-process
        public static Either <string, Req> Create(ClientConnectionId id, ProcessId publisher, ProcessId subscriber, Map <ClientConnectionId, ClientConnection> clientConnections)
        {
            if (!publisher.IsValid)
            {
                return("Invalid publisher-id");
            }
            if (!subscriber.IsValid)
            {
                return("Invalid subscriber-id");
            }
            var conn = clientConnections.Find(id);

            if (conn.IsNone)
            {
                return("Invalid connection-id");
            }
            return(new UnSubscribeReq(id, publisher, subscriber, conn.IfNone(() => null)));
        }
コード例 #7
0
 public static ClientConnection New(ClientConnectionId id, Action <ClientMessageDTO> tell) =>
 new ClientConnection(id, Map <ProcessId, Lst <Subscriber> >(), DateTime.UtcNow, tell);
コード例 #8
0
ファイル: Request.cs プロジェクト: markchipman/echo-process
 public static Either <string, Req> Create(ClientConnectionId id, Map <ClientConnectionId, ClientConnection> clientConnections) =>
 clientConnections.Find(id).Map(x => new DisconnectReq(id, x) as Req)
 .ToEither("Invalid connection-id");
コード例 #9
0
ファイル: Request.cs プロジェクト: markchipman/echo-process
 DisconnectReq(ClientConnectionId id, ClientConnection connection)
 {
     Id         = id;
     Connection = connection;
 }