Ejemplo n.º 1
0
        public Task GetAll()
        {
            var name = GetStringQueryString("name", required: false);

            var start    = GetStart();
            var pageSize = GetPageSize();

            DocumentsOperationContext context;

            using (ContextPool.AllocateOperationContext(out context))
                using (var writer = new BlittableJsonTextWriter(context, ResponseBodyStream()))
                {
                    TransformerDefinition[] transformerDefinitions;
                    if (string.IsNullOrEmpty(name))
                    {
                        transformerDefinitions = Database.TransformerStore
                                                 .GetTransformers()
                                                 .OrderBy(x => x.Name)
                                                 .Skip(start)
                                                 .Take(pageSize)
                                                 .Select(x => x.Definition)
                                                 .ToArray();
                    }
                    else
                    {
                        var transformer = Database.TransformerStore.GetTransformer(name);
                        if (transformer == null)
                        {
                            HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                            return(Task.CompletedTask);
                        }

                        transformerDefinitions = new[] { transformer.Definition };
                    }

                    writer.WriteStartArray();

                    var isFirst = true;
                    foreach (var transformerDefinition in transformerDefinitions)
                    {
                        if (isFirst == false)
                        {
                            writer.WriteComma();
                        }

                        isFirst = false;

                        writer.WriteTransformerDefinition(context, transformerDefinition);
                    }

                    writer.WriteEndArray();
                }

            return(Task.CompletedTask);
        }
Ejemplo n.º 2
0
 public static void Export(BlittableJsonTextWriter writer, Transformer transformer, JsonOperationContext context)
 {
     writer.WriteTransformerDefinition(context, transformer.Definition);
 }