コード例 #1
0
    public static OperationalMessage?MessageFrom(string content)
    {
        if (content.StartsWith(APP))
        {
            return(ApplicationSays.From(content));
        }

        if (content.StartsWith(DIR))
        {
            return(Directory.From(content));
        }

        if (content.StartsWith(ELECT))
        {
            return(Elect.From(content));
        }

        if (content.StartsWith(JOIN))
        {
            return(Join.From(content));
        }

        if (content.StartsWith(LEADER))
        {
            return(Leader.From(content));
        }

        if (content.StartsWith(LEAVE))
        {
            return(Leave.From(content));
        }

        if (content.StartsWith(PING))
        {
            return(Ping.From(content));
        }

        if (content.StartsWith(PULSE))
        {
            return(Pulse.From(content));
        }

        if (content.StartsWith(SPLIT))
        {
            return(Split.From(content));
        }

        if (content.StartsWith(VOTE))
        {
            return(Vote.From(content));
        }

        return(null);
    }
コード例 #2
0
        public void TestGenerateSplitMessage()
        {
            var split = new Split(Id.Of(1));

            MessageConverters.MessageToBytes(split, _messageBuffer);
            var raw = OperationalMessage.SPLIT + "\nid=1";

            _expectedBuffer.Write(Converters.TextToBytes(raw));
            Assert.Equal(_expectedBuffer.ToArray(), _messageBuffer.ToArray());

            Assert.Equal(split, Split.From(raw));
        }