コード例 #1
0
ファイル: ApiModule.cs プロジェクト: junxie6/messageVault
        void BuildRoutes()
        {
            Get["/"] = x => "This is MessageVault speaking!";


            Get["/streams/{id}"] = x => {
                this.RequiresAuthentication();
                var id = (string)x.id;
                RequiresReadAccess(id);


                var response = _scheduler.GetReadAccess(id);
                return(Response.AsJson(response));
            };
            Post["/streams/{id}", true] = async(x, ct) => {
                this.RequiresAuthentication();
                var id = (string)x.id;
                RequiresWriteAccess(id);

                try {
                    // read messages in request thread
                    var messages = TransferFormat.ReadMessages(Request.Body);
                    var response = await _scheduler.Append(id, messages);

                    return(Response.AsJson(response));
                }
                catch (Exception ex) {
                    Serilog.Log.Error(ex, "Failure in POST to {id}", id);
                    return(WrapException(ex));
                }
            };
        }
コード例 #2
0
        public void ValidHash()
        {
            using (var mem = new MemoryStream()) {
                var messages = GenerateMessages(7);
                TransferFormat.WriteMessages(messages, mem);
                mem.Seek(0, SeekOrigin.Begin);

                var actual = TransferFormat.ReadMessages(mem);

                AssertEqual(messages, actual);
            }
        }
コード例 #3
0
        public void InValidHash()
        {
            using (var mem = new MemoryStream()) {
                var messages = GenerateMessages(7);
                TransferFormat.WriteMessages(messages, mem);

                // zero the hash
                mem.Seek(-16, SeekOrigin.Current);
                mem.Write(new byte[16], 0, 4);

                mem.Seek(0, SeekOrigin.Begin);

                var actual = TransferFormat.ReadMessages(mem);

                AssertEqual(messages, actual);
            }
        }