Ejemplo n.º 1
0
        public async Task Init(string name, Providers.IProviderRuntime providerRuntime, Providers.IProviderConfiguration config)
        {
            existingCollections = new ConcurrentDictionary <string, bool>();
            createdCollections  = new ConcurrentDictionary <string, bool>();
            Log = providerRuntime.GetLogger("Storage.DocumentDBStorageProvider");
            try
            {
                isFaultTolerant = false; //by default, unless we found otherwise later

                this.jsonSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(), config);
                var url = config.Properties[URL];
                var key = config.Properties[KEY];
                OfferType    = config.Properties[OFFER_TYPE]; //if V1 => S1, S2, S3 else if V2 => RU as integer
                DatabaseName = config.Properties[DATABASE];
                IndexMode    = config.Properties.ContainsKey(INDEXING_MODE) ? config.Properties[INDEXING_MODE] : INDEXING_MODE_CONSISTENT;
                this.Client  = new DocumentClient(new Uri(url), key, new ConnectionPolicy
                {
                    ConnectionMode     = ConnectionMode.Direct,
                    ConnectionProtocol = Protocol.Tcp
                });

                await this.Client.OpenAsync();

                var databases = await this.Client.ReadDatabaseFeedAsync();

                this.Database = databases.Where(d => d.Id == DatabaseName).FirstOrDefault()
                                ?? await this.Client.CreateDatabaseAsync(new Database { Id = DatabaseName });
            }
            catch (Exception ex)
            {
                Log.Error(0, "Error in DocumentDBStorageProvider Init.", ex);
            }
        }
Ejemplo n.º 2
0
        public async Task Init(string name, Providers.IProviderRuntime providerRuntime, Providers.IProviderConfiguration config)
        {
            try
            {
                this.Name = name;
                var url = config.Properties["Url"];
                var key = config.Properties["Key"];
                this.databaseName   = config.Properties["Database"];
                this.collectionName = config.Properties["Collection"];

                this.Client = new DocumentClient(new Uri(url), key);

                await this.Client.CreateDatabaseAsync(new Database { Id = this.databaseName });

                var myCollection = new DocumentCollection
                {
                    Id = this.collectionName
                };
                await this.Client.CreateDocumentCollectionAsync(
                    UriFactory.CreateDatabaseUri(this.databaseName),
                    myCollection,
                    new RequestOptions { /*OfferThroughput = 20000 */ });
            }
            catch (Exception ex)
            {
                Log.Error(0, "Error in Init.", ex);
                throw;
            }
        }