Beispiel #1
0
        public Task BTreeStructure()
        {
            var treeName = GetStringQueryString("name", required: true);

            using (ContextPool.AllocateOperationContext(out DocumentsOperationContext context))
                using (var tx = context.OpenReadTransaction())
                {
                    var tree = tx.InnerTransaction.ReadTree(treeName)
                               ?? throw new InvalidOperationException("Tree name '" + treeName + "' was not found. Existing trees: " +
                                                                      string.Join(", ", GetTreeNames(tx.InnerTransaction, RootObjectType.VariableSizeTree))
                                                                      );

                    HttpContext.Response.ContentType = "text/html";
                    DebugStuff.DumpTreeToStream(tree, ResponseBodyStream());
                }

            return(Task.CompletedTask);
        }
        public HttpResponseMessage DumpTree(string name)
        {
            var transactionalStorage = Database.TransactionalStorage as Raven.Storage.Voron.TransactionalStorage;

            if (transactionalStorage == null)
            {
                return(GetMessageWithObject(new
                {
                    Error = "The database storage is not Voron"
                }, HttpStatusCode.BadRequest));
            }
            using (var tx = transactionalStorage.Environment.NewTransaction(TransactionFlags.Read))
            {
                var readTree = tx.ReadTree(name);
                if (readTree == null)
                {
                    return(GetMessageWithObject(new
                    {
                        Error = "The database storage does not contains a tree named: " + name
                    }, HttpStatusCode.NotFound));
                }
            }

            return(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new PushStreamContent((stream, content, arg3) =>
                {
                    using (stream)
                        using (var tx = transactionalStorage.Environment.NewTransaction(TransactionFlags.Read))
                        {
                            var readTree = tx.ReadTree(name);

                            DebugStuff.DumpTreeToStream(readTree, stream);
                        }
                })
                {
                    Headers = { ContentType = MediaTypeHeaderValue.Parse("text/html") }
                }
            });
        }