本文整理汇总了C#中Raven.Database.Linq.DynamicViewCompiler类的典型用法代码示例。如果您正苦于以下问题:C# DynamicViewCompiler类的具体用法?C# DynamicViewCompiler怎么用?C# DynamicViewCompiler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DynamicViewCompiler类属于Raven.Database.Linq命名空间,在下文中一共展示了DynamicViewCompiler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanDetectGroupByTarget
public void CanDetectGroupByTarget()
{
var abstractViewGenerator = new DynamicViewCompiler("test", new IndexDefinition { Map = map, Reduce = reduce }, ".").GenerateInstance();
var expandoObject = new ExpandoObject();
((IDictionary<string,object>)expandoObject).Add("blog_id","1");
Assert.Equal("1", abstractViewGenerator.GroupByExtraction(expandoObject));
}
示例2: Can_create_new_instance_from_query
public void Can_create_new_instance_from_query()
{
var dynamicQueryCompiler = new DynamicViewCompiler("pagesByTitle", new IndexDefinition { Map = query }, new AbstractDynamicCompilationExtension[0]);
dynamicQueryCompiler.GenerateInstance();
var compiled = dynamicQueryCompiler.GeneratedType;
Activator.CreateInstance(compiled);
}
示例3: Can_extend_queries
public void Can_extend_queries()
{
var documents =
GetDocumentsFromString(
@"[{loc: 4, lang: 3, '@metadata': {'@id': 1}}]");
var transformer = new DynamicViewCompiler("pagesByTitle", new IndexDefinition
{
Map = @"
from doc in docs
select new { GeoHash = PerformingQueries.SampleGeoLocation.GeoHash(doc.loc, doc.lang) }
"
},
new OrderedPartCollection<AbstractDynamicCompilationExtension>
{
new SampleDynamicCompilationExtension()
}, ".", new InMemoryRavenConfiguration());
var compiledQuery = transformer.GenerateInstance();
var actual = compiledQuery.MapDefinitions[0](documents)
.Cast<object>().ToArray();
var expected = new[]
{
"{ GeoHash = 4#3, __document_id = 1 }",
};
Assert.Equal(expected.Length, actual.Length);
for (var i = 0; i < expected.Length; i++)
{
Assert.Equal(expected[i], actual[i].ToString());
}
}
示例4: Convert_select_many_will_keep_doc_id
public void Convert_select_many_will_keep_doc_id()
{
IndexDefinition indexDefinition = new IndexDefinition<Order>
{
Map = orders => from order in orders
from line in order.OrderLines
select new { line.ProductId }
}.ToIndexDefinition(new DocumentConvention());
var generator = new DynamicViewCompiler("test", indexDefinition, new AbstractDynamicCompilationExtension[0])
.GenerateInstance();
var results = generator.MapDefinition(new[]
{
GetDocumentFromString(
@"
{
'@metadata': {'Raven-Entity-Name': 'Orders', '@id': 1},
'OrderLines': [{'ProductId': 2}, {'ProductId': 3}]
}"),
GetDocumentFromString(
@"
{
'@metadata': {'Raven-Entity-Name': 'Orders', '@id': 2},
'OrderLines': [{'ProductId': 5}, {'ProductId': 4}]
}")
}).Cast<object>().ToArray();
foreach (var result in results)
{
Assert.NotNull(TypeDescriptor.GetProperties(result).Find("__document_id", true));
}
}
示例5: Can_query_json
public void Can_query_json()
{
var documents =
GetDocumentsFromString(
@"[
{'type':'page', title: 'hello', content: 'foobar', size: 2, '@metadata': {'@id': 1}},
{'type':'page', title: 'there', content: 'foobar 2', size: 3, '@metadata': {'@id': 2} },
{'type':'revision', size: 4, _id: 3}
]");
var transformer = new DynamicViewCompiler("pagesByTitle", new IndexDefinition { Map = query }, ".");
var compiledQuery = transformer.GenerateInstance();
var actual = compiledQuery.MapDefinitions[0](documents)
.Cast<object>().ToArray();
var expected = new[]
{
"{ Key = hello, Value = foobar, Size = 2, __document_id = 1 }",
"{ Key = there, Value = foobar 2, Size = 3, __document_id = 2 }"
};
Assert.Equal(expected.Length, actual.Length);
for (var i = 0; i < expected.Length; i++)
{
Assert.Equal(expected[i], actual[i].ToString());
}
}
示例6: Can_compile_map_using_linq_methods
public void Can_compile_map_using_linq_methods()
{
var viewGenerator = new DynamicViewCompiler("test", new IndexDefinition
{
Map = @"docs.Users
.Select(user => new {Location = user.Location, Count = 1})
.Select(user => new {Location = user.Location})"
}).GenerateInstance();
var results = viewGenerator.MapDefinition(new[]
{
GetDocumentFromString(
@"
{
'@metadata': {'Raven-Entity-Name': 'Users', '@id': 1},
'Location': 'Tel Aviv'
}")
}).Cast<object>().ToArray();
var expected = new[]
{
"{ Location = Tel Aviv, __document_id = 1 }",
};
for (var i = 0; i < results.Length; i++)
{
Assert.Equal(expected[i], results[i].ToString());
}
}
示例7: Will_compile_query_successfully
public void Will_compile_query_successfully()
{
var dynamicQueryCompiler = new DynamicViewCompiler("pagesByTitle", new IndexDefinition { Map = query }, new AbstractDynamicCompilationExtension[0]);
dynamicQueryCompiler.GenerateInstance();
var compiled = dynamicQueryCompiler.GeneratedType;
Assert.NotNull(compiled);
}
示例8: Will_keep_cast_in_query
public void Will_keep_cast_in_query()
{
var dynamicQueryCompiler = new DynamicViewCompiler("caster", new IndexDefinition { Map = "from x in docs select new { Id = (int)x.Id }" }, new AbstractDynamicCompilationExtension[0], ".");
dynamicQueryCompiler.GenerateInstance();
Assert.Contains("(int)x.Id", dynamicQueryCompiler.CompiledQueryText);
}
示例9: CanExecuteQuery
public void CanExecuteQuery()
{
var dynamicViewCompiler = new DynamicViewCompiler("test", new IndexDefinition { Map = map, Reduce = reduce });
var abstractViewGenerator = dynamicViewCompiler.GenerateInstance();
var mapResults = abstractViewGenerator.MapDefinition(source).ToArray();
var results = abstractViewGenerator.ReduceDefinition(mapResults).ToArray();
Assert.Equal("{ blog_id = 3, comments_length = 14 }", results[0].ToString());
Assert.Equal("{ blog_id = 5, comments_length = 7 }", results[1].ToString());
Assert.Equal("{ blog_id = 6, comments_length = 6 }", results[2].ToString());
Assert.Equal("{ blog_id = 7, comments_length = 1 }", results[3].ToString());
Assert.Equal("{ blog_id = 2, comments_length = 8 }", results[4].ToString());
Assert.Equal("{ blog_id = 4, comments_length = 3 }", results[5].ToString());
}
示例10: Can_execute_query
public void Can_execute_query()
{
var dynamicQueryCompiler = new DynamicViewCompiler("pagesByTitle", new IndexDefinition { Map = query }, new AbstractDynamicCompilationExtension[0]);
var generator = dynamicQueryCompiler.GenerateInstance();
var results = generator.MapDefinition(new[]
{
GetDocumentFromString(
@"
{
'@metadata': {'@id': 1},
'Type': 'page',
'Title': 'doc1',
'Content': 'Foobar',
'Size': 31
}")
,
GetDocumentFromString(
@"
{
'@metadata': {'@id': 2},
'Type': 'not a page',
}")
,
GetDocumentFromString(
@"
{
'@metadata': {'@id': 3},
'Type': 'page',
'Title': 'doc2',
'Content': 'Foobar',
'Size': 31
}")
,
}).Cast<object>().ToArray();
var expected = new[]
{
"{ Key = doc1, Value = Foobar, Size = 31, __document_id = 1 }",
"{ Key = doc2, Value = Foobar, Size = 31, __document_id = 3 }"
};
for (var i = 0; i < results.Length; i++)
{
Assert.Equal(expected[i], results[i].ToString());
}
}
示例11: Can_compile_map_reduce_using_linq_methods
public void Can_compile_map_reduce_using_linq_methods()
{
var viewGenerator = new DynamicViewCompiler("test", new IndexDefinition
{
Map = @"docs.Users
.Select(user => new {Location = user.Location, Count = 1})",
Reduce =
@"results
.GroupBy(agg => agg.Location)
.Select(g => new {Location = g.Key, Count = g.Sum(x => x.Count)})"
}, ".").GenerateInstance();
var source = viewGenerator.MapDefinitions[0](new[]
{
GetDocumentFromString(
@"
{
'@metadata': {'Raven-Entity-Name': 'Users', '@id': 1},
'Location': 'Tel Aviv'
}"),
GetDocumentFromString(
@"
{
'@metadata': {'Raven-Entity-Name': 'Users', '@id': 1},
'Location': 'Tel Aviv'
}")
}).ToArray();
var results = viewGenerator.ReduceDefinition(source).Cast<object>().ToArray();
var expected = new[]
{
"{ Location = Tel Aviv, Count = 2 }",
};
for (var i = 0; i < results.Length; i++)
{
Assert.Equal(expected[i], results[i].ToString());
}
}
示例12: Main
public static void Main()
{
BasicConfigurator.Configure(new ConsoleAppender
{
Layout = new SimpleLayout()
});
try
{
var dynamicViewCompiler = new DynamicViewCompiler("a", new IndexDefinition
{
Map = @"
from post in docs.Posts
where post.Published == 'aasds'
select new {post.PostedAt }
"
});
dynamicViewCompiler.GenerateInstance();
Console.WriteLine(dynamicViewCompiler.CompiledQueryText);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
示例13: AddAndCompileIndex
private DynamicViewCompiler AddAndCompileIndex(string name, IndexDefinition indexDefinition)
{
var transformer = new DynamicViewCompiler(name, indexDefinition);
var generator = transformer.GenerateInstance();
indexCache.AddOrUpdate(name, generator, (s, viewGenerator) => generator);
logger.InfoFormat("New index {0}:\r\n{1}\r\nCompiled to:\r\n{2}", transformer.Name, transformer.CompiledQueryText,
transformer.CompiledQueryText);
return transformer;
}
示例14: AddAndCompileIndex
private DynamicViewCompiler AddAndCompileIndex(IndexDefinition indexDefinition)
{
var name = FixupIndexName(indexDefinition.Name, path);
var transformer = new DynamicViewCompiler(name, indexDefinition, extensions, path);
var generator = transformer.GenerateInstance();
indexCache.AddOrUpdate(name, generator, (s, viewGenerator) => generator);
indexDefinitions.AddOrUpdate(name, indexDefinition, (s1, definition) =>
{
if (definition.IsCompiled)
throw new InvalidOperationException("Index " + name + " is a compiled index, and cannot be replaced");
return indexDefinition;
});
logger.InfoFormat("New index {0}:\r\n{1}\r\nCompiled to:\r\n{2}", transformer.Name, transformer.CompiledQueryText,
transformer.CompiledQueryText);
return transformer;
}
示例15: ReadAllAggregations
private void ReadAllAggregations(DbIterator it)
{
Slice prefix = "aggregators/";
it.Seek(prefix);
while(it.WithPrefix(prefix))
{
string name = Encoding.UTF8.GetString(it.Key.Array, it.Key.Offset, it.Key.Count);
using (var stream = it.CreateValueStream())
{
var indexDefinition =
new JsonSerializer().Deserialize<IndexDefinition>(new JsonTextReader(new StreamReader(stream)));
_log.Info("Reading aggregator {0}", indexDefinition.Name);
AbstractViewGenerator generator = null;
try
{
var dynamicViewCompiler = new DynamicViewCompiler(indexDefinition.Name, indexDefinition,
Path.Combine(_path, "Generators"));
generator = dynamicViewCompiler.GenerateInstance();
}
catch (Exception e)
{
_log.WarnException("Could not create instance of aggregator " + indexDefinition.Name, e);
// could not create generator, ignoring this and deleting the generator
RemoveAggregation(name);
}
if (generator != null)
{
var aggregator = new Aggregator(this, indexDefinition.Name, generator);
_aggregations.TryAdd(indexDefinition.Name, aggregator);
Background.Work(aggregator.StartAggregation);
}
}
it.Next();
}
}