当前位置: 首页>>代码示例>>C#>>正文


C# DynamicViewCompiler.GenerateInstance方法代码示例

本文整理汇总了C#中Raven.Database.Linq.DynamicViewCompiler.GenerateInstance方法的典型用法代码示例。如果您正苦于以下问题:C# DynamicViewCompiler.GenerateInstance方法的具体用法?C# DynamicViewCompiler.GenerateInstance怎么用?C# DynamicViewCompiler.GenerateInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Raven.Database.Linq.DynamicViewCompiler的用法示例。


在下文中一共展示了DynamicViewCompiler.GenerateInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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);
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:7,代码来源:LinqTransformerCompilationTests.cs

示例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);
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:7,代码来源:LinqTransformerCompilationTests.cs

示例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());
            }
        }
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:30,代码来源:PerformingQueries.cs

示例4: 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);
		}
开发者ID:philiphoy,项目名称:ravendb,代码行数:7,代码来源:LinqTransformerCompilationTests.cs

示例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());
            }
        }
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:25,代码来源:PerformingQueries.cs

示例6: 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());
 }
开发者ID:torkelo,项目名称:ravendb,代码行数:13,代码来源:ViewCompilation.cs

示例7: 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());
			}
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:46,代码来源:LinqTransformerCompilationTests.cs

示例8: 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);
     }
 }
开发者ID:torkelo,项目名称:ravendb,代码行数:24,代码来源:Program.cs

示例9: AddAndCompileIndex

		private DynamicViewCompiler AddAndCompileIndex(IndexDefinition indexDefinition)
		{
			var name = FixupIndexName(indexDefinition.Name, path);
			var transformer = new DynamicViewCompiler(name, indexDefinition, extensions, path, configuration);
			var generator = transformer.GenerateInstance();
			indexCache.AddOrUpdate(name, generator, (s, viewGenerator) => generator);
			
			logger.Info("New index {0}:\r\n{1}\r\nCompiled to:\r\n{2}", transformer.Name, transformer.CompiledQueryText,
							  transformer.CompiledQueryText);
			return transformer;
		}
开发者ID:remcoros,项目名称:ravendb,代码行数:11,代码来源:IndexDefinitionStorage.cs

示例10: 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;
		}
开发者ID:philiphoy,项目名称:ravendb,代码行数:16,代码来源:IndexDefinitionStorage.cs

示例11: Compile

 private void Compile(string code)
 {
     var dynamicViewCompiler = new DynamicViewCompiler("test", new IndexDefinition
     {
         Map = code
     }, new OrderedPartCollection<AbstractDynamicCompilationExtension>(), ".", new InMemoryRavenConfiguration());
     dynamicViewCompiler.GenerateInstance();
 }
开发者ID:j2jensen,项目名称:ravendb,代码行数:8,代码来源:BlockedMethods.cs

示例12: CreateAggregationAsync

		public async Task CreateAggregationAsync(IndexDefinition indexDefinition)
		{
			var dynamicViewCompiler = new DynamicViewCompiler(indexDefinition.Name, indexDefinition, Path.Combine(_path, "Generators"));
			var generator = dynamicViewCompiler.GenerateInstance();

			var writeBatch = new WriteBatch();
			var memoryStream = SmallObjectToMemoryStream(indexDefinition);
			writeBatch.Put("aggregators/" + indexDefinition.Name, memoryStream);
			await _storage.Writer.WriteAsync(writeBatch);

			var aggregator = new Aggregator(this, indexDefinition.Name, generator);
			_aggregations.AddOrUpdate(indexDefinition.Name, aggregator, (s, viewGenerator) => aggregator);
			Background.Work(aggregator.StartAggregation);
		}
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:14,代码来源:AggregationEngine.cs

示例13: 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();
			}
		}
开发者ID:mattwarren,项目名称:temp.raven.storage,代码行数:36,代码来源:AggregationEngine.cs

示例14: CanExecuteTheTransformResultFunction

		public void CanExecuteTheTransformResultFunction()
		{
			var answersIndex = new Answers_ByAnswerEntity2 { Conventions = new DocumentConvention() };
			IndexDefinition indexDefinition = answersIndex.CreateIndexDefinition();
			var dynamicViewCompiler = new DynamicViewCompiler("test", indexDefinition, ".");
			AbstractViewGenerator abstractViewGenerator = dynamicViewCompiler.GenerateInstance();
			using (var documentStore = NewDocumentStore())
			{

				Guid questionId = Guid.NewGuid();
				Guid answerId = Guid.NewGuid();

				using (IDocumentSession session = documentStore.OpenSession())
				{
					var user = new User { Id = @"user\222", DisplayName = "John Doe" };
					session.Store(user);

					var question = new Question2
					{
						Id = questionId,
						Title = "How to do this in RavenDb?",
						Content = "I'm trying to find how to model documents for better DDD support.",
						UserId = @"user\222"
					};
					session.Store(question);


					var answer = new AnswerEntity2
					{
						Id = answerId,
						Question = question,
						Content = "This is doable",
						UserId = user.Id
					};
					answer.Votes = new[]
					{
						new AnswerVoteEntity2
						{
							Id = Guid.NewGuid(),
							QuestionId = questionId,
							Answer = answer,
							Delta = 2
						}
					};


					session.Store(new Answer2
					{
						Id = answerId,
						UserId = user.Id,
						QuestionId = question.Id,
						Content = "This is doable",
						Votes = new[]
						{
							new AnswerVote2
							{
								Id = Guid.NewGuid(),
								QuestionId = questionId,
								AnswerId = answerId,
								Delta = 2
							}
						}
					});

					session.SaveChanges();
				}

				documentStore.DocumentDatabase.TransactionalStorage.Batch(accessor =>
				{
					var documentRetriever = new DocumentRetriever(accessor, new OrderedPartCollection<AbstractReadTrigger>());
					var dynamicJsonObjects = new[] { new DynamicJsonObject(accessor.Documents.DocumentByKey("answer2s/" + answerId.ToString(), null).ToJson()), };
					var transformResultsDefinition = abstractViewGenerator.TransformResultsDefinition(documentRetriever,
																									  dynamicJsonObjects
						);

					transformResultsDefinition.ToArray();
				});



			}
		}
开发者ID:NuvemNine,项目名称:ravendb,代码行数:82,代码来源:ComplexValuesFromTransformResults.cs

示例15: 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;
 }
开发者ID:torkelo,项目名称:ravendb,代码行数:9,代码来源:IndexDefinitionStorage.cs


注:本文中的Raven.Database.Linq.DynamicViewCompiler.GenerateInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。