Example #1
0
		static void Main()
		{
			var consoleAppender = new ConsoleAppender
			{
				Layout = new SimpleLayout(),
			};
			consoleAppender.AddFilter(new LoggerMatchFilter
			{
				AcceptOnMatch = true,
				LoggerToMatch = "Raven.Client"
			});
			consoleAppender.AddFilter(new DenyAllFilter());
			BasicConfigurator.Configure(consoleAppender);

			// start 5 instances of Raven's servers
			Console.WriteLine("Starting...");
			DeleteDirectories("Users", "Blogs", "Posts.1", "Posts.2", "Posts.3");
			var ravenDbServers = StartServers();
			Console.WriteLine("All servers started...");

			var shards = new Shards
			{
				new DocumentStore
				{
					Identifier = "Users",
					Url = "http://*****:*****@ Rahien" };

				session.Store(user);
				session.Store(blog);

				// we have to save to Raven to get the generated id for the blog instance
				session.SaveChanges();
				var posts = new List<Post>();
				for (var i = 0; i < 6; i++)
				{
					var post = new Post
					{
						BlogId = blog.Id,
						UserId = user.Id,
						Content = "Just a post",
						Title = "Post #" + (i + 1)
					};
					posts.Add(post);
					session.Store(post);
				}

				session.SaveChanges();
			}

			// queries
			using (var session = documentStore.OpenSession())
			{
				session.LuceneQuery<User>().WaitForNonStaleResults().ToArray();
				session.LuceneQuery<Blog>().WaitForNonStaleResults().ToArray();
				session.LuceneQuery<Post>().WaitForNonStaleResults().ToArray();
			}

			// loading
			using (var session = documentStore.OpenSession())
			{
				session.Load<User>("users/ayende");
				session.Load<Blog>("blogs/1");
				session.Load<Post>("posts/1/2");
				session.Load<Post>("posts/2/2");
			}

			documentStore.Dispose();

			foreach (var server in ravenDbServers)
			{
				server.Dispose();
			}
		}
Example #2
0
        static void Main()
        {
            var consoleAppender = new ConsoleAppender
            {
                Layout = new SimpleLayout(),
            };

            consoleAppender.AddFilter(new LoggerMatchFilter
            {
                AcceptOnMatch = true,
                LoggerToMatch = "Raven.Client"
            });
            consoleAppender.AddFilter(new DenyAllFilter());
            BasicConfigurator.Configure(consoleAppender);

            // start 5 instances of Raven's servers
            Console.WriteLine("Starting...");
            DeleteDirectories("Users", "Blogs", "Posts.1", "Posts.2", "Posts.3");
            var ravenDbServers = StartServers();

            Console.WriteLine("All servers started...");

            var shards = new Shards
            {
                new DocumentStore
                {
                    Identifier  = "Users",
                    Url         = "http://*****:*****@ Rahien"
                };

                session.Store(user);
                session.Store(blog);

                // we have to save to Raven to get the generated id for the blog instance
                session.SaveChanges();
                var posts = new List <Post>();
                for (var i = 0; i < 6; i++)
                {
                    var post = new Post
                    {
                        BlogId  = blog.Id,
                        UserId  = user.Id,
                        Content = "Just a post",
                        Title   = "Post #" + (i + 1)
                    };
                    posts.Add(post);
                    session.Store(post);
                }

                session.SaveChanges();
            }

            // queries
            using (var session = documentStore.OpenSession())
            {
                session.LuceneQuery <User>().WaitForNonStaleResults().ToArray();
                session.LuceneQuery <Blog>().WaitForNonStaleResults().ToArray();
                session.LuceneQuery <Post>().WaitForNonStaleResults().ToArray();
            }

            // loading
            using (var session = documentStore.OpenSession())
            {
                session.Load <User>("users/ayende");
                session.Load <Blog>("blogs/1");
                session.Load <Post>("posts/1/2");
                session.Load <Post>("posts/2/2");
            }

            documentStore.Dispose();

            foreach (var server in ravenDbServers)
            {
                server.Dispose();
            }
        }