Exemple #1
0
        public void FixtureSetup()
        {
            this.unityContainer = new UnityContainer();
            IoC.Initialize(
                (x, y) => this.unityContainer.RegisterType(x, y),
                (x, y) => this.unityContainer.RegisterInstance(x, y),
                (x) => { return(unityContainer.Resolve(x)); },
                (x) => { return(unityContainer.ResolveAll(x)); });

            // Context Factory
            RavenUnitOfWorkFactory ctxFactory = new RavenUnitOfWorkFactory();

            Raven.Client.Document.DocumentStore sessionFactory = ctxFactory.CreateDocumentStore();

            IoC.RegisterInstance <IDatabaseManager>(ctxFactory);
            IoC.RegisterInstance <IUnitOfWorkFactory>(ctxFactory);

            this.unityContainer.RegisterType <IDocumentSession, IDocumentSession>(new InjectionFactory((c) =>
            {
                return(ctxFactory.CurrentDocumentSession);
            }));

            // Repositories
            this.unityContainer.RegisterType <IEntityARepository, EntityARavenRepository>();

            // Services
            if (!ctxFactory.DatabaseExists())
            {
                ctxFactory.CreateDatabase();
            }

            ctxFactory.ValidateDatabaseSchema();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="connectionString">RavenDB connection string</param>
        /// <param name="database">Optional : database name to connect to</param>
        /// <returns></returns>
        public static HealthResponse CheckHealth(string connectionString, string database = null)
        {
            try
            {
                ConnectionStringParser <RavenConnectionStringOptions> parser = ConnectionStringParser <RavenConnectionStringOptions> .FromConnectionString(connectionString);

                parser.Parse();
                var store = new Raven.Client.Document.DocumentStore
                {
                    Url             = parser.ConnectionStringOptions.Url,
                    DefaultDatabase = database == null ? parser.ConnectionStringOptions.DefaultDatabase : database
                };
                store.Initialize();
                // Client doesn't seem to throw an exception until we try to do something so let's just do something simple and get the build number of the server.
                var build = store.DatabaseCommands.GlobalAdmin.GetBuildNumber();
                // Dispose the store object
                store.Dispose();

                return(HealthResponse.Healthy(new { server = store.Url, database = store.DefaultDatabase, serverBuild = build.BuildVersion }));
            }
            catch (Exception ex)
            {
                return(HealthResponse.Unhealthy(ex));
            }
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            // Initialize the Repository factory.
            ObjectFactory.Initialize(
                x =>
                {
                    x.For<IUnitOfWorkFactory>().Use<RavenUnitOfWorkFactory>();
                    x.For(typeof(IRepository<>)).Use(typeof(RavenRepository<>));
                }
            );

            // RavenDB initialization method.
            RavenUnitOfWorkFactory.SetObjectContext(
                () =>
                {
                    var documentStore = new Raven.Client.Document.DocumentStore { Url = "http://localhost:8080" };
                    documentStore.Conventions.IdentityPartsSeparator = "-";
                    documentStore.Initialize();

                    return documentStore;
                }
            );
        }
Exemple #4
0
        public IDocumentStore CreateConnection()
        {
            var documentStore = new Raven.Client.Document.DocumentStore {
                Url = _url
            };

            documentStore.Initialize();
            return(documentStore);
        }
Exemple #5
0
        public DocumentStoreInstance(ObjectInstance prototype, RavenDB.Document.DocumentStore documentStore)
            : this(prototype)
        {
            if (documentStore == null)
            {
                throw new ArgumentNullException("documentStore");
            }

            m_documentStore = documentStore;
        }
Exemple #6
0
        public DocumentStoreInstance(ObjectInstance prototype)
            : base(prototype)
        {
            this.PopulateFields();
            this.PopulateFunctions();

            m_documentStore = new DocumentStore {
                Credentials = null
            };
        }
 public void SearchTest()
 {
     var docStore = new Raven.Client.Document.DocumentStore { Url = "http://localhost:8080", DefaultDatabase = "TestDB" };
       docStore.Initialize();
       RavenRepository repository = new RavenRepository(docStore);
       ProductsController target = new ProductsController(repository); // TODO: Initialize to an appropriate value
       string searchStr = "Acer*";
       ActionResult actual;
       actual = target.Search(searchStr);
       Assert.IsNotNull(actual); //TODO: Improve assert here
 }
Exemple #8
0
 private static void StoreSampleDoc(Raven.Client.Document.DocumentStore store, string docName)
 {
     using (var session = store.OpenSession())
     {
         session.Store(new
         {
             Name = "test oauth"
         },
                       docName);
         session.SaveChanges();
     }
 }
Exemple #9
0
 public static Oceny WczytajOceny(String id)
 {
     using (var ds = new Raven.Client.Document.DocumentStore {
         Url = DATABASEURL
     }.Initialize())
     {
         using (var session = ds.OpenSession(DATABASE))
         {
             return(session.Load <Oceny>(id));
         }
     }
 }
Exemple #10
0
 public static void ZapiszStudent(Student student)
 {
     using (var ds = new Raven.Client.Document.DocumentStore {
         Url = DATABASEURL
     }.Initialize())
     {
         using (var session = ds.OpenSession(DATABASE))
         {
             session.Store(student);
             session.SaveChanges();
         }
     }
 }
        private Raven.Client.IDocumentStore GenerateRavenDocStore()
        {
            var docstore = new Raven.Client.Document.DocumentStore
            {
                Url             = "http://localhost:8081/",
                DefaultDatabase = "tobi-test",
                ApiKey          = "tobi/SukWxO6ne9By0hCawMFAc"
            };

            docstore.Initialize();

            return(docstore);
        }
Exemple #12
0
        static void Main(string[] args)
        {
            var documentStore = new Raven.Client.Document.DocumentStore {
                Url = "http://localhost:8080", DefaultDatabase = "TestDB"
            };

            documentStore.Initialize();
            var session = documentStore.OpenSession();


            //FetchTestStoreDataToDb(session);
            CreateTestStoreSearchesDataToDb(session);
        }
        static void Main( string[] args )
        {
            var store = new Raven.Client.Document.DocumentStore()
            {
                Url = "http://*****:*****@ssw0rd" )
            }.Initialize();

            using ( var session = store.OpenSession() )
            {
                session.Store( new Person()
                {
                    FirstName = "Mauro",
                    LastName = "Servienti",
                    BornDate = new DateTime( 1973, 01, 10 )
                } );

                session.Store( new Person()
                {
                    FirstName = "Manuel",
                    LastName = "Scapolan",
                } );

                session.Store( new Person()
                {
                    FirstName = "Marco",
                    LastName = "Parenzan",
                } );

                session.Store( new Person()
                {
                    FirstName = "Andrea",
                    LastName = "Saltarello",
                } );

                session.Store( new Company()
                {
                    CompanyName = "Managed Designs S.r.l.",
                    OpeningDate = new DateTime( 2004, 03, 22 )
                } );

                session.Store( new Company()
                {
                    CompanyName = "CGN"
                } );

                session.SaveChanges();
            }
        }
        static void Main(string[] args)
        {
            var store = new Raven.Client.Document.DocumentStore()
            {
                Url             = "http://*****:*****@ssw0rd")
            }.Initialize();

            using (var session = store.OpenSession())
            {
                session.Store(new Person()
                {
                    FirstName = "Mauro",
                    LastName  = "Servienti",
                    BornDate  = new DateTime(1973, 01, 10)
                });

                session.Store(new Person()
                {
                    FirstName = "Manuel",
                    LastName  = "Scapolan",
                });

                session.Store(new Person()
                {
                    FirstName = "Marco",
                    LastName  = "Parenzan",
                });

                session.Store(new Person()
                {
                    FirstName = "Andrea",
                    LastName  = "Saltarello",
                });

                session.Store(new Company()
                {
                    CompanyName = "Managed Designs S.r.l.",
                    OpeningDate = new DateTime(2004, 03, 22)
                });

                session.Store(new Company()
                {
                    CompanyName = "CGN"
                });

                session.SaveChanges();
            }
        }
Exemple #15
0
 public static void UsunOceny(String id)
 {
     using (var ds = new Raven.Client.Document.DocumentStore {
         Url = DATABASEURL
     }.Initialize())
     {
         using (var session = ds.OpenSession(DATABASE))
         {
             Oceny tmp = session.Load <Oceny>(id);
             session.Delete(tmp);
             session.SaveChanges();
         }
     }
 }
Exemple #16
0
        private static IDocumentStore CreateStore()
        {
            var store = new Raven.Client.Document.DocumentStore
            {
                Url = "http://localhost:8080",
                DefaultDatabase = "test"
            }.Initialize();

            CreateIndexes(store);

            InitialiseConventions(store);

            return store;
        }
Exemple #17
0
        //[HostType("ASP.NET")]
        //[AspNetDevelopmentServerHost("C:\\gitRepositories\\StingyPrice\\StingyPrice", "/")]
        //[UrlToTest("http://localhost:57460/")]
        public void SearchTest()
        {
            var docStore = new Raven.Client.Document.DocumentStore {
                Url = "http://localhost:8080", DefaultDatabase = "TestDB"
            };

            docStore.Initialize();
            RavenRepository    repository = new RavenRepository(docStore);
            ProductsController target     = new ProductsController(repository); // TODO: Initialize to an appropriate value
            string             searchStr  = "Acer*";
            ActionResult       actual;

            actual = target.Search(searchStr);
            Assert.IsNotNull(actual); //TODO: Improve assert here
        }
Exemple #18
0
        public static List <Oceny> ListaOceny()
        {
            using (var ds = new Raven.Client.Document.DocumentStore {
                Url = DATABASEURL
            }.Initialize())
            {
                using (var session = ds.OpenSession(DATABASE))
                {
                    List <Oceny> dbOceny = (from teas in session.Query <Oceny>()
                                            select teas).ToList <Oceny>();

                    return(dbOceny);
                }
            }
        }
Exemple #19
0
        public static List <Przedmiot> ListaPrzedmiot()
        {
            using (var ds = new Raven.Client.Document.DocumentStore {
                Url = DATABASEURL
            }.Initialize())
            {
                using (var session = ds.OpenSession(DATABASE))
                {
                    List <Przedmiot> dbPrzedmiot = (from teas in session.Query <Przedmiot>()
                                                    select teas).ToList <Przedmiot>();

                    return(dbPrzedmiot);
                }
            }
        }
        public void AddTest()
        {
            var docStore = new Raven.Client.Document.DocumentStore { Url = "http://localhost:8080", DefaultDatabase =  "UnitTestDB"};
              docStore.Initialize();
              var rep = new RavenRepository(docStore);
              createTestData();
              rep.Add<CategoryTree>(_testData);
              rep.Save();

             var result = rep.All<CategoryTree>().FirstOrDefault();

              Assert.IsNotNull(result);
              Assert.IsInstanceOfType(result,typeof(CategoryTree));
              Assert.IsTrue(result.Root.SubCategories.Count()==2 );
        }
Exemple #21
0
        public void CanLoadFromIndex_Remote()
        {
            var path =
                System.IO.Path.GetDirectoryName(
                    System.Reflection.Assembly.GetAssembly(typeof(Raven.Tests.Document.DocumentStoreServerTests)).CodeBase);

            path = System.IO.Path.Combine(path, "TestDb").Substring(6);

            using (var server = new Raven.Server.RavenDbServer(new
                                                               Raven.Database.Config.RavenConfiguration()
            {
                HostName = "localhost",
                DataDirectory = path,
                Port = 8088,
                AccessControlAllowOrigin = "*",
                AnonymousUserAccessMode = AnonymousUserAccessMode.All
            }))
                using (IDocumentStore documentStore = new
                                                      Raven.Client.Document.DocumentStore {
                    Url = "http://localhost:8088/"
                }.Initialize())
                {
                    using (IDocumentSession session = documentStore.OpenSession())
                    {
                        new UnsetDocs().Execute(documentStore);
                        session.Store(new Doc
                        {
                            Id   = "test/doc1",
                            Date = SystemTime.UtcNow
                        });
                        session.Store(new Doc {
                            Id = "test/doc2", Date = null
                        });
                        session.SaveChanges();
                    }

                    using (var session = documentStore.OpenSession())
                    {
                        session
                        .Query <Doc, UnsetDocs>()
                        .Customize(x => x.WaitForNonStaleResults())
                        .AsProjection <DocSummary>()
                        .ToArray();
                    }
                }
        }
        private static void deleteTestData()
        {
            var docStore = new Raven.Client.Document.DocumentStore {
                Url = "http://localhost:8080"
            };

            docStore.Initialize();

            var session       = docStore.OpenSession();
            var categorytrees = session.Query <CategoryTree>();

            foreach (var categoryTree in categorytrees)
            {
                session.Delete(categoryTree);
            }

            session.SaveChanges();
        }
        static void Main(string[] args)
        {
            //Uri uri = new Uri( "http://localhost:8080/" );
            //ICredentials credentials = CredentialCache.DefaultCredentials;
            //NetworkCredential credential = credentials.GetCredential( uri, "Basic" );

            var store = new Raven.Client.Document.DocumentStore()
            {
                Url             = "http://localhost:8080/",
                DefaultDatabase = "Samples",
                //Credentials = credential
            }.Initialize();

            //store.Changes()
            //	.ForDocumentsStartingWith( "orders/" );

            //store.Changes()
            //	.ForIndex( "myIndex/Name" );

            using (var session = store.OpenSession())
            {
                var p = new Person()
                {
                    FirstName = "Someone", LastName = "Foo"
                };
                session.Store(p);
                session.SaveChanges();
            }

            using (var session = store.OpenSession())
            {
                var query = session.Query <Person>()
                            .Where(p => p.FirstName.StartsWith("S"))
                            .ToList();
            }

            //var dbCmd = store.DatabaseCommands;
            //dbCmd.Patch( "orders/2", new[] { new PatchRequest
            //{
            //	Type = PatchCommandType.Set,
            //	Name = "Customer",
            //	Value = RavenJToken.Parse( "new customer name" )
            //} } );
        }
        public void AddTest()
        {
            var docStore = new Raven.Client.Document.DocumentStore {
                Url = "http://localhost:8080", DefaultDatabase = "UnitTestDB"
            };

            docStore.Initialize();
            var rep = new RavenRepository(docStore);

            createTestData();
            rep.Add <CategoryTree>(_testData);
            rep.Save();

            var result = rep.All <CategoryTree>().FirstOrDefault();

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(CategoryTree));
            Assert.IsTrue(result.Root.SubCategories.Count() == 2);
        }
Exemple #25
0
        public static void Main(string[] args)
        {
            var store = new Raven.Client.Document.DocumentStore
            {
                Url             = "http://localhost:8081/",
                DefaultDatabase = "tobi-test",
                ApiKey          = "tobi/SukWxO6ne9By0hCawMFAc"
            };

            store.Initialize();

            using (var session = store.OpenSession())
            {
                session.Store(new Bug()
                {
                    Name = "Tobi"
                });                                         // here is the exception
                session.SaveChanges();
            }
        }
Exemple #26
0
        public object TestRavenDBConnection()
        {
            try {
                var store = new Raven.Client.Document.DocumentStore
                {
                    Url = ConfigurationManager.AppSettings["Database"]
                };
                store.Initialize();

                var session = store.OpenSession();
                session.Store(new { Debugging = "This is a debug message" });
                session.SaveChanges();
            } catch( Exception ex )  {
                return new
                {
                    Exception = ex.GetType().FullName,
                    Message = ex.Message
                };
            }

            return "Success";
        }
        private void setupDb()
        {
            // Initialize the Repository factory.
            ObjectFactory.Initialize(
                x =>
                {
                    x.For<IUnitOfWorkFactory>().Use<RavenUnitOfWorkFactory>();
                    x.For(typeof(IRepository<>)).Use(typeof(RavenRepository<>));
                }
            );

            // RavenDB initialization method.
            RavenUnitOfWorkFactory.SetObjectContext(
                () =>
                {
                    var documentStore =
            new Raven.Client.Document.DocumentStore { Url = "http://localhost:8080", DefaultDatabase = "DotNetQuizUnitTest" };
                    documentStore.Conventions.IdentityPartsSeparator = "-";
                    documentStore.Initialize();

                    return documentStore;
                }
            );
        }
Exemple #28
0
 private void SetupRavenDb()
 {
     var documentStore = new Raven.Client.Document.DocumentStore {ConnectionStringName = "RavenDB"};
     documentStore.Initialize();
     Application["DocumentStore"] = documentStore;
 }
Exemple #29
0
        static void Main(string[] args)
        {
            var store = new Raven.Client.Document.DocumentStore()
            {
                Url             = "http://localhost:8080/",
                DefaultDatabase = "Samples"
            }.Initialize();

            //IndexCreation.CreateIndexes( Assembly.GetExecutingAssembly(), store );

            //var id = "";

            //using ( var session = store.OpenSession() )
            //{
            //	var person = new Person()
            //	{
            //		FirstName = "Omar",
            //		LastName = "Damiani"
            //	};

            //	session.Store( person );
            //	id = person.Id;

            //	session.SaveChanges();
            //}

            using (var session = store.OpenSession())
            {
                session.Store(new
                {
                    Id       = "settings/sample",
                    Settings = new Dictionary <String, Object>()
                    {
                        { "kkk", new Sample()
                          {
                              Foo = "bar"
                          } },
                        { "yyy", 12 }
                    }
                });

                session.SaveChanges();
            }

            using (var session = store.OpenSession())
            {
                var t = session.Load <dynamic>("settings/sample");
            }

            //using ( var session = store.OpenSession() )
            //{
            //	//session.Query<Person>()
            //	//	.Customize( c =>
            //	//	{
            //	//		c.WaitForNonStaleResults();
            //	//	} )
            //	//	.Where( p=> p.Id == id )
            //	//	.Single();

            //	//var data = session.Query<Person, Indexes.Person_ByCountry>()
            //	//	.Where( p => p.FirstName.StartsWith( "l*" ) )
            //	//	.ProjectFromIndexFieldsInto<Views.PersonView>();

            //	//var results = data.ToList();



            //	var query = session.Query<Orders.Employee>()
            //		.Where( e => e.FirstName.StartsWith( "A" ) );

            //	foreach ( var emp in query )
            //	{
            //		Console.WriteLine( emp.FirstName );
            //	}

            //	//session.Query<Orders.Employee>()
            //	//	.Where( e => e.LastName.EndsWith( "a" ) )
            //	//	.ToList().ForEach( i =>
            //	//	{
            //	//		Console.WriteLine( i.LastName );
            //	//	} );
            //}
        }
Exemple #30
0
        static void Main(string[] args)
        {
            var documentStore = new Raven.Client.Document.DocumentStore { Url = "http://localhost:8080", DefaultDatabase = "TestDB" };
            documentStore.Initialize();
            var session = documentStore.OpenSession();

            //FetchTestStoreDataToDb(session);
            CreateTestStoreSearchesDataToDb(session);
        }
        static void Main( string[] args )
        {
            var store = new Raven.Client.Document.DocumentStore()
            {
                Url = "http://localhost:8080/",
                DefaultDatabase = "Samples"
            }.Initialize();

            //IndexCreation.CreateIndexes( Assembly.GetExecutingAssembly(), store );

            //var id = "";

            //using ( var session = store.OpenSession() )
            //{
            //	var person = new Person()
            //	{
            //		FirstName = "Omar",
            //		LastName = "Damiani"
            //	};

            //	session.Store( person );
            //	id = person.Id;

            //	session.SaveChanges();
            //}

            using ( var session = store.OpenSession() )
            {
                session.Store( new
                {
                    Id = "settings/sample",
                    Settings = new Dictionary<String, Object>()
                    {
                        { "kkk", new Sample(){ Foo = "bar" } },
                        { "yyy", 12 }
                    }
                } );

                session.SaveChanges();
            }

            using ( var session = store.OpenSession() )
            {
                var t = session.Load<dynamic>( "settings/sample");
            }

            //using ( var session = store.OpenSession() )
            //{
            //	//session.Query<Person>()
            //	//	.Customize( c =>
            //	//	{
            //	//		c.WaitForNonStaleResults();
            //	//	} )
            //	//	.Where( p=> p.Id == id )
            //	//	.Single();

            //	//var data = session.Query<Person, Indexes.Person_ByCountry>()
            //	//	.Where( p => p.FirstName.StartsWith( "l*" ) )
            //	//	.ProjectFromIndexFieldsInto<Views.PersonView>();

            //	//var results = data.ToList();

            //	var query = session.Query<Orders.Employee>()
            //		.Where( e => e.FirstName.StartsWith( "A" ) );

            //	foreach ( var emp in query )
            //	{
            //		Console.WriteLine( emp.FirstName );
            //	}

            //	//session.Query<Orders.Employee>()
            //	//	.Where( e => e.LastName.EndsWith( "a" ) )
            //	//	.ToList().ForEach( i =>
            //	//	{
            //	//		Console.WriteLine( i.LastName );
            //	//	} );
            //}
        }
        private static void deleteTestData()
        {
            var docStore = new Raven.Client.Document.DocumentStore { Url = "http://localhost:8080" };
              docStore.Initialize();

              var session = docStore.OpenSession();
              var categorytrees = session.Query<CategoryTree>();

              foreach (var categoryTree in categorytrees)
              {
            session.Delete(categoryTree);
              }

              session.SaveChanges();
        }