コード例 #1
0
        public static void Init()
        {
            if (database != null)
                return;

            lock (locker)
            {
                if (database != null)
                    return;

                try
                {
                    var ravenConfiguration = new RavenConfiguration();
                    if (RoleEnvironment.IsAvailable)
                    {
                        ravenConfiguration.RunInMemory = true;
                        // Mount Cloud drive and set it as Data Directory
                        //var currentConfiguredRavenDataDir = ConfigurationManager.AppSettings["Raven/DataDir"] ?? string.Empty;
                        //string azureDrive = @"D:\"; // Environment.GetEnvironmentVariable(RavenDriveConfiguration.AzureDriveEnvironmentVariableName, EnvironmentVariableTarget.Machine);
                        //if (string.IsNullOrWhiteSpace(azureDrive))
                        //{
                        //    throw new ArgumentException("RavenDb drive environment variable is not yet set by worker role. Please, retry in a couple of seconds");
                        //}

                        //string azurePath = Path.Combine(azureDrive,
                        //    currentConfiguredRavenDataDir.StartsWith(@"~\")
                        //        ? currentConfiguredRavenDataDir.Substring(2)
                        //        : "Data");
                        //ravenConfiguration.DataDirectory = azurePath;

                        // Read port number specified for this Raven instance and set it in configuration
                        var endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Raven"];
                        ravenConfiguration.Port = endpoint.IPEndpoint.Port;

                        // When mounting drives in emulator only Munin storage is supported, since drive is not actually present and low level access to it failes (Esent mode)
                    }
                    HttpEndpointRegistration.RegisterHttpEndpointTarget();
                    database = new DocumentDatabase(ravenConfiguration);
                    database.SpinBackgroundWorkers();
                    server = new HttpServer(ravenConfiguration, database);
                    server.Init();
                }
                catch
                {
                    if (database != null)
                    {
                        database.Dispose();
                        database = null;
                    }
                    if (server != null)
                    {
                        server.Dispose();
                        server = null;
                    }
                    throw;
                }

                HostingEnvironment.RegisterObject(new ReleaseRavenDBWhenAppDomainIsTornDown());
            }
        }
コード例 #2
0
		public static void Init()
		{
			if (database != null)
				return;

			lock (locker)
			{
				if (database != null)
					return;

				try
				{
					var ravenConfiguration = new RavenConfiguration();
					HttpEndpointRegistration.RegisterHttpEndpointTarget();
					database = new DocumentDatabase(ravenConfiguration);
					database.SpinBackgroundWorkers();
					server = new HttpServer(ravenConfiguration, database);
					server.Init();
				}
				catch
				{
					if (database != null)
					{
						database.Dispose();
						database = null;
					}
					if (server != null)
					{
						server.Dispose();
						server = null;
					}
					throw;
				}
			}
		}
コード例 #3
0
        public static void Init()
        {
            if (database != null)
                return;

            lock (locker)
            {
                if (database != null)
                    return;

                log.Info("Setting up RavenDB Http Integration to the ASP.Net Pipeline");
                try
                {
                    var ravenConfiguration = new RavenConfiguration();
                    HttpEndpointRegistration.RegisterHttpEndpointTarget();
                    database = new DocumentDatabase(ravenConfiguration);
                    database.SpinBackgroundWorkers();
                    server = new HttpServer(ravenConfiguration, database);
                    server.Init();
                }
                catch
                {
                    if (database != null)
                    {
                        database.Dispose();
                        database = null;
                    }
                    if (server != null)
                    {
                        server.Dispose();
                        server = null;
                    }
                    throw;
                }

                shutdownDetector = new ShutdownDetector(log);
                shutdownDetector.Initialize();

                shutdownDetector.Token.Register(OnShutdown);
            }
        }
コード例 #4
0
		public static void Init()
		{
			if (database != null)
				return;

			lock (locker)
			{
				if (database != null)
					return;

				log.Info("Setting up RavenDB Http Integration to the ASP.Net Pipeline");
				try
				{
					var ravenConfiguration = new RavenConfiguration();
					HttpEndpointRegistration.RegisterHttpEndpointTarget();
					database = new DocumentDatabase(ravenConfiguration);
					database.SpinBackgroundWorkers();
					server = new HttpServer(ravenConfiguration, database);
					server.Init();
				}
				catch
				{
					if (database != null)
					{
						database.Dispose();
						database = null;
					}
					if (server != null)
					{
						server.Dispose();
						server = null;
					}
					throw;
				}

				HostingEnvironment.RegisterObject(new ReleaseRavenDBWhenAppDomainIsTornDown());
			}
		}
コード例 #5
0
        private void StartRaven()
        {
            try
            {
                Trace.TraceInformation("RavenDb: Starting...");

                AnonymousUserAccessMode anonymousUserAccessMode;
                if (!Enum.TryParse(RoleEnvironment.GetConfigurationSettingValue("AnonymousUserAccessMode"), true, out anonymousUserAccessMode))
                    anonymousUserAccessMode = AnonymousUserAccessMode.Get;
                Trace.TraceInformation("Raven Configuration AnonymousUserAccessMode: {0}", anonymousUserAccessMode);

                var httpCompression = Boolean.Parse(RoleEnvironment.GetConfigurationSettingValue("HttpCompression"));
                Trace.TraceInformation("Raven Configuration HttpCompression: {0}", httpCompression);

                var defaultStorageTypeName = RoleEnvironment.GetConfigurationSettingValue("DefaultStorageTypeName");
                Trace.TraceInformation("Raven Configuration DefaultStorageTypeName: {0}", defaultStorageTypeName);

                var port = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Raven"].IPEndpoint.Port;
                Trace.TraceInformation("Raven Configuration Port: {0}", port);

                Trace.TraceInformation("RavenDb: Ensure Can ListenTo When In Non Admin Context...");
                NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port);

                var config = new RavenConfiguration
                {
                    DataDirectory = _dataDrive.LocalPath.EndsWith("\\")
                                        ? _dataDrive.LocalPath + "Data\\"
                                        : _dataDrive.LocalPath + "\\Data\\",
                    AnonymousUserAccessMode = anonymousUserAccessMode,
                    HttpCompression = httpCompression,
                    DefaultStorageTypeName = defaultStorageTypeName,
                    Port = port,
                    PluginsDirectory = "Plugins"
                };
                _database = new DocumentDatabase(config);

                Trace.TraceInformation("RavenDb: Spin Background Workers...");
                _database.SpinBackgroundWorkers();

                _server = new HttpServer(config, _database);
                try
                {
                    Trace.TraceInformation("Http Server: Initializing ...");
                    _server.Init();
                    Trace.TraceInformation("Http Server: Start Listening ...");
                    _server.StartListening();
                }
                catch (Exception)
                {
                    _server.Dispose();
                    _server = null;
                    throw;
                }

                Trace.TraceInformation("RavenDb: Started.");
            }
            catch (Exception)
            {
                if (_database != null)
                {
                    _database.Dispose();
                    _database = null;
                }
                throw;
            }
        }
コード例 #6
0
ファイル: DataProvider.cs プロジェクト: jonaslsl/modSIC
        public IDocumentSession GetSession()
        {
            lock (isStoreSet)
            {
                if (!(bool)isStoreSet)
                {
                    RavenConfiguration ravenConfiguration = null;

                    bool webUIEnabled = false;
                    int webUIPort = 0;

                    var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                    var serviceConfigurationSection = config.GetSection("ServiceConfigurationSection") as ServiceConfigurationSection;
                    if (serviceConfigurationSection != null)
                    {
                        ravenConfiguration = serviceConfigurationSection.ravendb;
                        if (ravenConfiguration != null)
                        {
                            webUIEnabled = ravenConfiguration.WebUIEnabled;
                            webUIPort = ravenConfiguration.WebUIPort;

                            if (webUIEnabled)
                            {
                                if (webUIPort < 0 || webUIPort > 65535)
                                {
                                    webUIEnabled = false;
                                }
                                else
                                {
                                    webUIEnabled = CheckPortIsAvailable(webUIPort);
                                }
                            }
                        }
                    }

                    documentStore = new EmbeddableDocumentStore();
                    documentStore.Configuration.DataDirectory = "Data\\RavenDB";
                    documentStore.Configuration.DefaultStorageTypeName = typeof(Raven.Storage.Esent.TransactionalStorage).AssemblyQualifiedName;
                    documentStore.Conventions.FindIdentityProperty = x => x.Name == "Oid";
                    documentStore.Conventions.MaxNumberOfRequestsPerSession = 1000;
                    documentStore.Initialize();
                    
                    IndexCreation.CreateIndexes(GetType().Assembly, documentStore);

                    if (webUIEnabled)
                    {
                        documentStore.Configuration.Port = webUIPort;
                        var httpServer = new HttpServer(documentStore.Configuration, documentStore.DocumentDatabase);
                        httpServer.Init();
                        httpServer.StartListening();
                    }

                    isStoreSet = true;
                }
            }

            return documentStore.OpenSession();
        }