Ejemplo n.º 1
0
        public void Initialize(bool ensureDefaultCounterExists = false)
        {
            if (isInitialized)
            {
                throw new InvalidOperationException($"CounterStore already initialized. (name = {Name})");
            }

            isInitialized = true;
            SecurityExtensions.InitializeSecurity(CountersConvention, JsonRequestFactory, Url, Credentials.Credentials);

            if (ensureDefaultCounterExists)
            {
                if (string.IsNullOrWhiteSpace(Name))
                {
                    throw new InvalidOperationException("Name is null or empty and ensureDefaultCounterExists = true --> cannot create default counter storage with empty name");
                }

                var existingCounterStorageNames = AsyncHelpers.RunSync(() => Admin.GetCounterStoragesNamesAsync());
                if (!existingCounterStorageNames.Contains(Name, StringComparer.OrdinalIgnoreCase))
                {
                    //this statement will essentially overwrite the counter storage, therefore it should not be called if the storage is already there
                    Admin.CreateCounterStorageAsync(new CounterStorageDocument
                    {
                        Id       = Constants.Counter.Prefix + Name,
                        Settings = new Dictionary <string, string>
                        {
                            { "Raven/Counter/DataDir", @"~\Counters\" + Name }
                        },
                    }, Name).ConfigureAwait(false).GetAwaiter().GetResult();
                }
            }

            replicationInformer = new CounterReplicationInformer(JsonRequestFactory, this, CountersConvention); // make sure it is initialized
        }
Ejemplo n.º 2
0
        public void Initialize(bool ensureDefaultTimeSeriesExists = false)
        {
            if (isInitialized)
            {
                throw new InvalidOperationException(string.Format("TimeSeriesStore already initialized. (name = {0})", Name));
            }

            isInitialized = true;

            if (string.IsNullOrEmpty(Credentials.ApiKey) == false)
            {
                Credentials = null;
            }

            SecurityExtensions.InitializeSecurity(TimeSeriesConvention, JsonRequestFactory, Url);

            if (ensureDefaultTimeSeriesExists && !string.IsNullOrWhiteSpace(Name))
            {
                if (String.IsNullOrWhiteSpace(Name))
                {
                    throw new InvalidOperationException("Name is null or empty and ensureDefaultTimeSeriesExists = true --> cannot create default time series with empty name");
                }

                Admin.CreateTimeSeriesAsync(MultiDatabase.CreateTimeSeriesDocument(Name)).ConfigureAwait(false).GetAwaiter().GetResult();
            }

            replicationInformer = new TimeSeriesReplicationInformer(JsonRequestFactory, this, TimeSeriesConvention); // make sure it is initialized
        }
Ejemplo n.º 3
0
        public RavenCountersClient(string serverUrl, string counterStorageName, ICredentials credentials = null, string apiKey = null)
        {
            try
            {
                ServerUrl = serverUrl;
                if (ServerUrl.EndsWith("/"))
                {
                    ServerUrl = ServerUrl.Substring(0, ServerUrl.Length - 1);
                }

                CounterStorageName = counterStorageName;
                Credentials        = credentials ?? CredentialCache.DefaultNetworkCredentials;
                ApiKey             = apiKey;

                convention = new CounterConvention();
                //replicationInformer = new RavenFileSystemReplicationInformer(convention, JsonRequestFactory);
                //readStripingBase = replicationInformer.GetReadStripingBase();
                //todo: implement remote counter changes
                //notifications = new RemoteFileSystemChanges(serverUrl, apiKey, credentials, jsonRequestFactory, convention, replicationInformer, () => { });

                SecurityExtensions.InitializeSecurity(convention, JsonRequestFactory, ServerUrl);
            }
            catch (Exception)
            {
                Dispose();
                throw;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <returns></returns>
        public IDocumentStore Initialize(bool ensureDatabaseExists)
        {
            if (initialized)
            {
                return(this);
            }

            AssertValidConfiguration();

            jsonRequestFactory = new HttpJsonRequestFactory(MaxNumberOfCachedRequests, HttpMessageHandlerFactory, Conventions.AcceptGzipContent, Conventions.AuthenticationScheme);

            try
            {
                SecurityExtensions.InitializeSecurity(Conventions, jsonRequestFactory, Url);
                InitializeInternal();

                if (Conventions.DocumentKeyGenerator == null)// don't overwrite what the user is doing
                {
                    var generator = new MultiDatabaseHiLoGenerator(32);
                    Conventions.DocumentKeyGenerator = (dbName, databaseCommands, entity) => generator.GenerateDocumentKey(dbName, databaseCommands, Conventions, entity);
                }

                if (Conventions.AsyncDocumentKeyGenerator == null && asyncDatabaseCommandsGenerator != null)
                {
                    var generator = new AsyncMultiDatabaseHiLoKeyGenerator(32);
                    Conventions.AsyncDocumentKeyGenerator = (dbName, commands, entity) => generator.GenerateDocumentKeyAsync(dbName, commands, Conventions, entity);
                }

                initialized = true;

#if !(MONO || DNXCORE50)
                RecoverPendingTransactions();
#endif
                if (ensureDatabaseExists &&
                    string.IsNullOrEmpty(DefaultDatabase) == false &&
                    DefaultDatabase.Equals(Constants.SystemDatabase) == false) //system database exists anyway
                {
                    //If we have indication that the database is part of a replication cluster we don't want to create it,
                    //the reason for this is that we want the client to failover to a diffrent database.
                    var serverHash          = ServerHash.GetServerHash(DatabaseCommands.Url);
                    var document            = ReplicationInformerLocalCache.TryLoadReplicationInformationFromLocalCache(serverHash);
                    var replicationDocument = document?.DataAsJson.JsonDeserialization <ReplicationDocumentWithClusterInformation>();
                    if (replicationDocument == null)
                    {
                        DatabaseCommands.ForSystemDatabase().GlobalAdmin.EnsureDatabaseExists(DefaultDatabase, true);
                    }
                }
            }
            catch (Exception)
            {
                Dispose();
                throw;
            }

            return(this);
        }
Ejemplo n.º 5
0
        private const int DefaultNumberOfCachedRequests = 2048;         //put this in asyncserverclient

        public SynchronizationServerClient(string serverUrl, string fileSystem, string apiKey, ICredentials credentials, FilesConvention convention = null,
                                           OperationCredentials operationCredentials = null, HttpJsonRequestFactory requestFactory = null, NameValueCollection operationsHeaders = null)
        {
            serverUrl                 = serverUrl.TrimEnd('/');
            baseUrl                   = serverUrl + "/fs/" + Uri.EscapeDataString(fileSystem);
            credentials               = credentials ?? CredentialCache.DefaultNetworkCredentials;
            this.filesConvention      = convention ?? new FilesConvention();
            this.operationCredentials = operationCredentials ?? new OperationCredentials(apiKey, credentials);
            this.requestFactory       = requestFactory ?? new HttpJsonRequestFactory(DefaultNumberOfCachedRequests);
            this.OperationsHeaders    = operationsHeaders ?? new NameValueCollection();

            SecurityExtensions.InitializeSecurity(Conventions, RequestFactory, serverUrl, credentials);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <returns></returns>
        public IDocumentStore Initialize(bool ensureDatabaseExists)
        {
            if (initialized)
            {
                return(this);
            }

            AssertValidConfiguration();

            jsonRequestFactory = new HttpJsonRequestFactory(MaxNumberOfCachedRequests, HttpMessageHandlerFactory, Conventions.AcceptGzipContent);

            try
            {
                SecurityExtensions.InitializeSecurity(Conventions, jsonRequestFactory, Url);

                InitializeInternal();

                if (Conventions.DocumentKeyGenerator == null)// don't overwrite what the user is doing
                {
                    var generator = new MultiDatabaseHiLoGenerator(32);
                    Conventions.DocumentKeyGenerator = (dbName, databaseCommands, entity) => generator.GenerateDocumentKey(dbName, databaseCommands, Conventions, entity);
                }

                if (Conventions.AsyncDocumentKeyGenerator == null && asyncDatabaseCommandsGenerator != null)
                {
                    var generator = new AsyncMultiDatabaseHiLoKeyGenerator(32);
                    Conventions.AsyncDocumentKeyGenerator = (dbName, commands, entity) => generator.GenerateDocumentKeyAsync(dbName, commands, Conventions, entity);
                }

                initialized = true;

#if !MONO
                RecoverPendingTransactions();
#endif

                if (ensureDatabaseExists &&
                    string.IsNullOrEmpty(DefaultDatabase) == false &&
                    DefaultDatabase.Equals(Constants.SystemDatabase) == false) //system database exists anyway
                {
                    DatabaseCommands.ForSystemDatabase().GlobalAdmin.EnsureDatabaseExists(DefaultDatabase, ignoreFailures: true);
                }
            }
            catch (Exception)
            {
                Dispose();
                throw;
            }

            return(this);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <returns></returns>
        public IDocumentStore Initialize(bool ensureDatabaseExists)
        {
            if (initialized)
            {
                return(this);
            }

            AssertValidConfiguration();

            jsonRequestFactory = new HttpJsonRequestFactory(MaxNumberOfCachedRequests, HttpMessageHandlerFactory, Conventions.AcceptGzipContent, Conventions.AuthenticationScheme);

            try
            {
                if (string.IsNullOrEmpty(ApiKey) == false)
                {
                    Credentials = null;
                }
                SecurityExtensions.InitializeSecurity(Conventions, jsonRequestFactory, Url, Credentials);

                InitializeInternal();

                if (Conventions.DocumentKeyGenerator == null)// don't overwrite what the user is doing
                {
                    var generator = new MultiDatabaseHiLoGenerator(32);
                    Conventions.DocumentKeyGenerator = (dbName, databaseCommands, entity) => generator.GenerateDocumentKey(dbName, databaseCommands, Conventions, entity);
                }

                if (Conventions.AsyncDocumentKeyGenerator == null && asyncDatabaseCommandsGenerator != null)
                {
                    var generator = new AsyncMultiDatabaseHiLoKeyGenerator(32);
                    Conventions.AsyncDocumentKeyGenerator = (dbName, commands, entity) => generator.GenerateDocumentKeyAsync(dbName, commands, Conventions, entity);
                }

                Smuggler = new DatabaseSmuggler(this);

                initialized = true;
            }
            catch (Exception)
            {
                Dispose();
                throw;
            }

            return(this);
        }
Ejemplo n.º 8
0
        public IFilesStore Initialize(bool ensureFileSystemExists = true, bool failIfCannotCreate = true)
        {
            if (initialized)
            {
                return(this);
            }
            disableReplicationInformerGeneration = true;
            jsonRequestFactory = new HttpJsonRequestFactory(MaxNumberOfCachedRequests, HttpMessageHandlerFactory, authenticationScheme: conventions.AuthenticationScheme);

            try
            {
                SecurityExtensions.InitializeSecurity(Conventions, jsonRequestFactory, Url, Credentials);

                InitializeInternal();

                initialized = true;

                if (ensureFileSystemExists && string.IsNullOrEmpty(DefaultFileSystem) == false)
                {
                    try
                    {
                        AsyncFilesCommands.ForFileSystem(DefaultFileSystem).EnsureFileSystemExistsAsync().GetAwaiter().GetResult();
                    }
                    catch (Exception)
                    {
                        if (failIfCannotCreate)
                        {
                            throw;
                        }
                    }
                }
            }
            catch (Exception)
            {
                Dispose();
                throw;
            }
            finally
            {
                disableReplicationInformerGeneration = false;
            }

            return(this);
        }
Ejemplo n.º 9
0
        public IFilesStore Initialize(bool ensureFileSystemExists = true, bool failIfCannotCreate = true)
        {
            if (initialized)
            {
                return(this);
            }

            jsonRequestFactory = new HttpJsonRequestFactory(MaxNumberOfCachedRequests, HttpMessageHandlerFactory);

            try
            {
                SecurityExtensions.InitializeSecurity(Conventions, JsonRequestFactory, Url);

                InitializeInternal();

                initialized = true;

                if (ensureFileSystemExists && string.IsNullOrEmpty(DefaultFileSystem) == false)
                {
                    try
                    {
                        AsyncFilesCommands.ForFileSystem(DefaultFileSystem)
                        .EnsureFileSystemExistsAsync().ConfigureAwait(false)
                        .GetAwaiter().GetResult();
                    }
                    catch (Exception)
                    {
                        if (failIfCannotCreate)
                        {
                            throw;
                        }
                    }
                }
            }
            catch (Exception)
            {
                Dispose();
                throw;
            }

            return(this);
        }
        protected AsyncServerClientBase(string serverUrl, TConvention convention, OperationCredentials credentials, HttpJsonRequestFactory jsonRequestFactory,
                                        Guid?sessionId, NameValueCollection operationsHeaders, Func <string, TReplicationInformer> replicationInformerGetter, string resourceName)
        {
            WasDisposed = false;

            ServerUrl   = serverUrl.TrimEnd('/');
            Conventions = convention ?? new TConvention();
            CredentialsThatShouldBeUsedOnlyInOperationsWithoutReplication = credentials;
            RequestFactory = jsonRequestFactory ?? new HttpJsonRequestFactory(DefaultNumberOfCachedRequests, authenticationScheme: Conventions.AuthenticationScheme);

            if (jsonRequestFactory == null)
            {
                SecurityExtensions.InitializeSecurity(Conventions, RequestFactory, ServerUrl);
            }

            SessionId         = sessionId;
            OperationsHeaders = operationsHeaders ?? DefaultNameValueCollection;

            ReplicationInformerGetter = replicationInformerGetter ?? DefaultReplicationInformerGetter();
            replicationInformer       = new Lazy <TReplicationInformer>(() => ReplicationInformerGetter(resourceName), true);
            MaxQuerySizeForGetRequest = 8 * 1024;
        }